public static Feature createApplication()

in src/main/java/org/apache/sling/feature/launcher/impl/FeatureProcessor.java [65:151]


    public static Feature createApplication(final Logger logger, final LauncherConfig config,
            final ArtifactManager artifactManager, final Map<ArtifactId, Feature> loadedFeatures) throws IOException
    {
        final BuilderContext builderContext = new BuilderContext(id -> {
            try {
                final ArtifactHandler handler = artifactManager.getArtifactHandler(id.toMvnUrl());
                try (final Reader r = new InputStreamReader(handler.getLocalURL().openStream(), "UTF-8")) {
                    final Feature f = FeatureJSONReader.read(r, handler.getUrl());
                    return f;
                }
            } catch (IOException e) {
                // ignore
                return null;
            }
        });
        final ArtifactProvider provider = new ArtifactProvider() {

            @Override
            public URL provide(final ArtifactId id) {
                try {
                    final ArtifactHandler handler = artifactManager.getArtifactHandler(id.toMvnUrl());
                    return handler.getLocalURL();
                } catch (final IOException e) {
                    // ignore
                    return null;
                }
            }
        };
        builderContext.setArtifactProvider(provider);

        config.getArtifactClashOverrides().stream().forEach(id -> builderContext.addArtifactsOverride(id));
        builderContext.addConfigsOverrides(config.getConfigClashOverrides());
        builderContext.addVariablesOverrides(config.getVariables());
        builderContext.addFrameworkPropertiesOverrides(config.getInstallation().getFrameworkProperties());
        builderContext.addMergeExtensions(StreamSupport.stream(Spliterators.spliteratorUnknownSize(
                ServiceLoader.load(MergeHandler.class).iterator(), Spliterator.ORDERED), false)
                    .toArray(MergeHandler[]::new));
        builderContext.addPostProcessExtensions(StreamSupport.stream(Spliterators.spliteratorUnknownSize(
            ServiceLoader.load(PostProcessHandler.class).iterator(), Spliterator.ORDERED), false)
                .toArray(PostProcessHandler[]::new));
        for (Map.Entry<String, Map<String,String>> entry : config.getExtensionConfiguration().entrySet()) {
            builderContext.setHandlerConfiguration(entry.getKey(), entry.getValue());
        }

        List<Feature> features = new ArrayList<>();
        for (final String featureFile : config.getFeatureFiles()) {
            for (final String initFile : IOUtils.getFeatureFiles(config.getHomeDirectory(), featureFile)) {
                if ( initFile.endsWith(IOUtils.EXTENSION_FEATURE_ARCHIVE) ) {
                    logger.debug("Reading feature archive {}", initFile);
                    final ArtifactHandler featureArtifact = artifactManager.getArtifactHandler(initFile);
                    try (final InputStream is = featureArtifact.getLocalURL().openStream()) {
                        for(final Feature feature : ArchiveReader.read(is, (id, stream) -> {
                                final File artifactFile = new File(config.getCacheDirectory(),
                                            id.toMvnPath().replace('/', File.separatorChar));
                                if (!artifactFile.exists()) {
                                    artifactFile.getParentFile().mkdirs();
                                    Files.copy(stream, artifactFile.toPath());
                                }
                            })) {

                            features.add(feature);
                            loadedFeatures.put(feature.getId(), feature);
                        }
                    } catch (final IOException ioe) {
                        logger.info("Unable to read feature archive from " + initFile, ioe);
                    }
                } else {
                    logger.debug("Reading feature file {}", initFile);
                    final ArtifactHandler featureArtifact = artifactManager.getArtifactHandler(initFile);
                    try (final Reader r = new InputStreamReader(featureArtifact.getLocalURL().openStream(), "UTF-8")) {
                        final Feature f = FeatureJSONReader.read(r, featureArtifact.getUrl());
                        loadedFeatures.put(f.getId(), f);
                        features.add(f);
                    } catch (Exception ex) {
                        throw new IOException("Error reading feature: " + initFile, ex);
                    }
                }
            }
        }

        final Feature app = FeatureBuilder.assemble(config.getLaunchFeatureId(), builderContext, features.toArray(new Feature[0]));
        loadedFeatures.put(app.getId(), app);

        FeatureBuilder.resolveVariables(app, config.getVariables());

        return app;
    }