Map getFrameworkProperties()

in src/main/java/org/apache/sling/feature/scanner/impl/FelixFrameworkScanner.java [133:182]


    Map<String,String> getFrameworkProperties(final Map<String,String> appProps, final URL framework)
            throws IOException {
        Path appPropsFile = Files.createTempFile("appProps", ".properties");
        Properties appPropsProperties = new Properties();

        for (Map.Entry<String,String> entry : appProps.entrySet()) {
            appPropsProperties.put(entry.getKey(), entry.getValue().replace("{dollar}", "$"));
        }

        try (Writer writer = new FileWriter(appPropsFile.toFile())) {
            appPropsProperties.store(writer, "appProps");
        }

        File frameworkJar = IOUtils.getFileFromURL(framework, true, null);
        File gathererCP = getGathererClassPath();

        Path outFile = Files.createTempFile("frameworkCaps", ".properties");
        Path runDir = Files.createTempDirectory("frameworkCaps");

        List<String> commandLine = Arrays.asList(
                "-cp",
                gathererCP + File.pathSeparator + frameworkJar.getAbsolutePath(),
                FrameworkPropertiesGatherer.class.getName(),
                appPropsFile.toString(),
                outFile.toString());

        try {
            runJava(new ArrayList<>(commandLine), runDir);
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
            throw new IOException(e);
        }

        Properties gatheredProps = new Properties();
        try (Reader reader = new FileReader(outFile.toFile())) {
            gatheredProps.load(reader);
        }

        // after reading, delete all temp files and dirs
        Files.delete(appPropsFile);
        Files.delete(outFile);

        try (Stream<Path> fileStream = Files.walk(runDir)) {
            fileStream.sorted(Comparator.reverseOrder())
            .map(Path::toFile)
            .forEach(File::delete);
        }

        return (Map) gatheredProps;
    }