in src/main/java/org/apache/sling/installer/factories/subsystems/base/impl/SubsystemBaseTransformer.java [162:216]
private void handleSubsystemArtifact(String artifactName, ZipInputStream zis, ZipOutputStream zos,
StringBuilder subsystemContent) throws IOException {
int idx = artifactName.indexOf('/');
int idx2 = artifactName.lastIndexOf('/');
if (idx != idx2 || idx == 0)
throw new IOException("Invalid entry name, should have format .../<num>/artifact.jar: " + artifactName);
int startOrder = Integer.parseInt(artifactName.substring(0, idx));
idx++;
if (artifactName.length() > idx) {
File tempArtifact = File.createTempFile("sling-generated", ".tmp");
tempArtifact.deleteOnExit();
Path tempPath = tempArtifact.toPath();
Files.copy(zis, tempPath, StandardCopyOption.REPLACE_EXISTING);
try (JarFile jf = new JarFile(tempArtifact)) {
Attributes ma = jf.getManifest().getMainAttributes();
String bsn = ma.getValue(Constants.BUNDLE_SYMBOLICNAME);
String version = ma.getValue(Constants.BUNDLE_VERSION);
if (version == null)
version = "0";
String type = ma.getValue(Constants.FRAGMENT_HOST) != null ?
IdentityNamespace.TYPE_FRAGMENT : IdentityNamespace.TYPE_BUNDLE;
if (bsn != null) {
if (subsystemContent.length() > 0)
subsystemContent.append(',');
subsystemContent.append(bsn);
subsystemContent.append(';');
subsystemContent.append(IdentityNamespace.CAPABILITY_VERSION_ATTRIBUTE);
subsystemContent.append('=');
subsystemContent.append(version);
subsystemContent.append(';');
subsystemContent.append(IdentityNamespace.CAPABILITY_TYPE_ATTRIBUTE);
subsystemContent.append('=');
subsystemContent.append(type);
subsystemContent.append(';');
subsystemContent.append(SubsystemConstants.START_ORDER_DIRECTIVE);
subsystemContent.append(":=");
subsystemContent.append(startOrder);
}
} catch (Exception ex) {
// apparently not a valid JarFile
}
ZipEntry zoe = new ZipEntry(artifactName.substring(idx));
try {
zos.putNextEntry(zoe);
Files.copy(tempPath, zos);
} finally {
zos.closeEntry();
tempArtifact.delete();
}
}
}