private void createArchive()

in src/main/java/org/apache/sling/feature/maven/mojos/AttachFeatureArchivesMojo.java [151:213]


    private void createArchive(
            final List<Feature> features, final String classifier, final String type, final boolean attach)
            throws MojoExecutionException {
        final ArtifactId archiveId =
                features.get(0).getId().changeClassifier(classifier).changeType(type);

        // write the feature model archive
        final File outputFile = new File(
                this.project.getBuild().getDirectory().concat(File.separator).concat(archiveId.toMvnName()));
        outputFile.getParentFile().mkdirs();

        getLog().info("Creating feature archive " + outputFile.getName());
        try (final FileOutputStream fos = new FileOutputStream(outputFile);
                final JarOutputStream jos = ArchiveWriter.write(
                        fos,
                        createBaseManifest(features.size() == 1 ? features.get(0) : null),
                        id -> {
                            try {
                                return ProjectHelper.getOrResolveArtifact(
                                                project, mavenSession, artifactHandlerManager, repoSystem, id)
                                        .getFile()
                                        .toURI()
                                        .toURL();
                            } catch (final MalformedURLException e) {
                                getLog().debug("Malformed url " + e.getMessage(), e);
                                // ignore
                                return null;
                            }
                        },
                        features.toArray(new Feature[features.size()]))) {

            // handle license etc.
            final File classesDir = new File(this.project.getBuild().getOutputDirectory());
            if (classesDir.exists()) {
                final File metaInfDir = new File(classesDir, "META-INF");
                for (final String name : new String[] {"LICENSE", "NOTICE", "DEPENDENCIES"}) {
                    final File f = new File(metaInfDir, name);
                    if (f.exists()) {
                        final JarEntry artifactEntry = new JarEntry("META-INF/" + name);
                        jos.putNextEntry(artifactEntry);

                        final byte[] buffer = new byte[8192];
                        try (final InputStream is = new FileInputStream(f)) {
                            int l = 0;
                            while ((l = is.read(buffer)) > 0) {
                                jos.write(buffer, 0, l);
                            }
                        }
                        jos.closeEntry();
                    }
                }
            }
            jos.finish();
        } catch (final IOException e) {
            throw new MojoExecutionException(
                    "Unable to write feature model archive to " + outputFile + " : " + e.getMessage(), e);
        }

        if (attach) {
            // attach it as an additional artifact
            projectHelper.attachArtifact(project, archiveId.getType(), archiveId.getClassifier(), outputFile);
        }
    }