private List transform()

in src/main/java/org/apache/sling/installer/factory/model/impl/InstallFeatureModelTask.java [125:203]


    private List<InstallableResource> transform(final String featureJson,
            final TaskResource rsrc) {
        Feature feature = null;
        try (final Reader reader = new StringReader(featureJson)) {
            feature = FeatureJSONReader.read(reader, null);
        } catch ( final IOException ioe) {
            logger.warn("Unable to read feature model file", ioe);
        }
        if (feature == null) {
            return null;
        }

        final List<InstallableResource> result = new ArrayList<>();
        // configurations
        for (final Configuration cfg : feature.getConfigurations()) {
            result.add(new InstallableResource("/".concat(cfg.getPid()).concat(".config"), null,
                    cfg.getConfigurationProperties(), null, InstallableResource.TYPE_CONFIG, null));
        }

        // extract artifacts
        if (this.installContext.storageDirectory != null && isFeatureArchive(rsrc ) ) {
            final byte[] buffer = new byte[1024*1024*256];

            try ( final InputStream is = rsrc.getInputStream() ) {
                ArchiveReader.read(is, new ArchiveReader.ArtifactConsumer() {

                    @Override
                    public void consume(final ArtifactId id, final InputStream is) throws IOException {
                        final File artifactFile = getArtifactFile(installContext.storageDirectory, id);
                        if (!artifactFile.exists()) {
                            artifactFile.getParentFile().mkdirs();
                            try (final OutputStream os = new FileOutputStream(artifactFile)) {
                                int l = 0;
                                while ((l = is.read(buffer)) > 0) {
                                    os.write(buffer, 0, l);
                                }
                            }
                        }
                    }
                });
            } catch ( final IOException ioe) {
                logger.warn("Unable to extract artifacts from feature model " + feature.getId().toMvnId(), ioe);
                return null;
            }
        }

        ExtensionHandlerContext context = new ContextImpl(result);

        for (Extension ext : feature.getExtensions()) {
            boolean handlerFound = false;
            for (ExtensionHandler eh : extensionHandlers) {
                try {
                    handlerFound |= eh.handle(context, ext, feature);
                } catch (Exception e) {
                    logger.error("Exception while processing extension {} with handler {}", ext, eh, e);
                }
            }
            if (!handlerFound) {
                if (ExtensionType.ARTIFACTS == ext.getType()) {
                    // Unhandled ARTIFACTS extensions get stored
                    for (final Artifact artifact : ext.getArtifacts()) {
                        addArtifact(artifact, result);
                    }
                } else {
                    // should this be an error?
                    logger.warn("No extension handler found for mandartory extension " + ext);
                }
            }
        }

        // bundles
        for (final Artifact bundle : feature.getBundles()) {
            if (!addArtifact(bundle, result)) {
                return null;
            }
        }

        return result;
    }