in src/main/java/org/apache/sling/feature/cpconverter/handlers/BundleEntryHandler.java [86:145]
public void handle(@NotNull String path,
@NotNull Archive archive,
@NotNull Entry entry,
@NotNull ContentPackage2FeatureModelConverter converter,
String runMode) throws IOException, ConverterException {
logger.info("Processing bundle {}...", entry.getName());
Matcher matcher = getPattern().matcher(path);
Integer startLevel = null;
// we are pretty sure it matches, here
if (!matcher.matches()) {
throw new IllegalStateException("Something went terribly wrong: pattern '"
+ getPattern().pattern()
+ "' should have matched already with path '"
+ path
+ "' but it does not, currently");
}
if (enforceBundlesBelowInstallFolder && !"install".equals(matcher.group("foldername"))) {
throw new ConverterException("OSGi bundles are only considered if placed below a folder called 'install', but the bundle at '"+ path + "' is placed outside!");
}
// determine run mode string for current path
String runModeMatch = matcher.group("runmode");
String targetRunMode = extractTargetRunMode(path, converter, runMode,
runModeMatch);
final String value = matcher.group("startlevel");
if (value != null) {
// there is a specified Start Level
startLevel = Integer.parseInt(value); // NumberFormatException impossible due to RegEx
logger.debug("Start level {} was extracted from path {}", startLevel, path);
}
String bundleName = entry.getName();
// Remove the leading path
int idx = bundleName.lastIndexOf('/');
if (idx >= 0) {
bundleName = bundleName.substring(idx + 1);
}
// Remove the extension
int edx = bundleName.lastIndexOf('.');
if (edx > 0) {
bundleName = bundleName.substring(0, edx);
}
// create a temporary JAR file (extracted from archive)
Path tmpBundleJar = Files.createTempFile(converter.getTempDirectory().toPath(), "extracted", bundleName + ".jar");
try {
try (OutputStream output = Files.newOutputStream(tmpBundleJar);
InputStream input = Objects.requireNonNull(archive.openInputStream(entry))) {
IOUtils.copy(input, output);
}
processBundleInputStream(path, tmpBundleJar, bundleName, targetRunMode, startLevel, converter);
} finally {
Files.delete(tmpBundleJar);
}
}