public final void handle()

in src/main/java/org/apache/sling/feature/cpconverter/handlers/AbstractContentPackageHandler.java [46:99]


    public final void handle(@NotNull String path, @NotNull Archive archive, @NotNull Entry entry, @NotNull ContentPackage2FeatureModelConverter converter, String runMode)
            throws IOException, ConverterException {
        logger.info("Processing sub-content package '{}'...", entry.getName());

        final File temporaryDir = new File(converter.getTempDirectory(), "sub-content-packages");
        temporaryDir.mkdirs();
        File temporaryContentPackage = new File(temporaryDir, entry.getName());

        if (entry.getName().contains(SNAPSHOT_POSTFIX) && temporaryContentPackage.exists()) {
            logger.debug("SNAPSHOT content-package detected, deleting previous version on {}...", temporaryContentPackage);
            if (temporaryContentPackage.delete()) {
                logger.debug("Previous SNAPSHOT content-package version on {} deleted", temporaryContentPackage);
            } else {
                logger.warn("Impossible to delete previous SNAPSHOT content-package version on {}, please check current user permissions",
                            temporaryContentPackage);
            }
        }

        if (!temporaryContentPackage.exists()) {
            logger.debug("Extracting sub-content package '{}' to {} for future analysis...", entry.getName(), temporaryContentPackage);

            try (InputStream input = archive.openInputStream(entry);
                    OutputStream output = new FileOutputStream(temporaryContentPackage)) {
                IOUtils.copy(input, output);
            }

            logger.debug("Sub-content package '{}' successfully extracted to {} ", entry.getName(), temporaryContentPackage);
        }

        Matcher matcher = getPattern().matcher(path);

        // 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");
        }


        String targetRunMode;
        // determine run mode string for current path
        String runModeMatch = matcher.group(1);
        targetRunMode = extractTargetRunMode(path, converter, runMode,
            runModeMatch);
        
        boolean isEmbeddedPackage = EMBEDDED_PACKAGE_PATTERN.matcher(path).matches();
        try (VaultPackage vaultPackage = converter.open(temporaryContentPackage)) {
            processSubPackage(path, targetRunMode, vaultPackage, converter, isEmbeddedPackage);
        }

        logger.info("Sub-content package '{}' processing is over", entry.getName());
    }