private void writeSubsystemManifest()

in esa-maven-plugin/src/main/java/org/apache/aries/plugin/esa/EsaMojo.java [414:491]


    private void writeSubsystemManifest(String fileName)
            throws MojoExecutionException {
        try {
            // TODO: add support for dependency version ranges. Need to pick
            // them up from the pom and convert them to OSGi version ranges.
            FileUtils.fileAppend(fileName, Constants.SUBSYSTEM_MANIFESTVERSION + ": " + "1" + "\n");
            FileUtils.fileAppend(fileName, Constants.SUBSYSTEM_SYMBOLICNAME + ": "
                    + getSubsystemSymbolicName(project.getArtifact()) + "\n");
            FileUtils.fileAppend(fileName, Constants.SUBSYSTEM_VERSION + ": "
                    + getSubsystemVersion() + "\n");
            FileUtils.fileAppend(fileName, Constants.SUBSYSTEM_NAME + ": " + getSubsystemName() + "\n");
            String description = getSubsystemDescription();
            if (description != null) {
                FileUtils.fileAppend(fileName, Constants.SUBSYSTEM_DESCRIPTION + ": " + description + "\n");
            }

            // Write the SUBSYSTEM-CONTENT
            Set<Artifact> artifacts = null;

            switch (EsaManifestContent.valueOf(manifestContent)) {
                case content:
                    // only include the direct dependencies in the content
                    artifacts = project.getDependencyArtifacts();
                    break;
                case all:
                    // include direct and transitive dependencies in content
                    artifacts = project.getArtifacts();
                    break;
                default:
                    throw new MojoExecutionException("Invalid configuration for <manifestContent/>.  Valid values are content and all." );
            }

            artifacts = selectArtifactsInCompileOrRuntimeScope(artifacts);
            artifacts = selectNonJarArtifactsAndBundles(artifacts);

            Iterator<Artifact> iter = artifacts.iterator();

            FileUtils.fileAppend(fileName, Constants.SUBSYSTEM_CONTENT + ": ");
            int order = 0;
            int nbInSubsystemContent = 0;
            while (iter.hasNext()) {
                Artifact artifact = iter.next();
                order++;
                ContentInfo info = ContentInfo.create(artifact, getLog());
                if (info == null) {
                    continue;
                }
                String entry = info.getContentLine();
                if ("dependencies".equals(startOrder)) {
                    entry += ";start-order:=\"" + order + "\"";
                }
                if (iter.hasNext()) {
                    entry += ",\n ";
                }
                nbInSubsystemContent++;
                FileUtils.fileAppend(fileName, entry);
            }
            getLog().info("Added '" + nbInSubsystemContent + "' artefacts to the Subsystem-Content header");

            FileUtils.fileAppend(fileName, "\n");

            Iterator<Map.Entry<?, ?>> instructionIter = instructions.entrySet().iterator();
            while(instructionIter.hasNext()) {
                Map.Entry<?, ?> entry = instructionIter.next();
                String header = entry.getKey().toString();
                if (SKIP_INSTRUCTIONS.contains(header)) {
                    continue;
                }
                getLog().debug("Adding header: " + header);
                FileUtils.fileAppend(fileName, header + ": " + entry.getValue() + "\n");
            }

        } catch (Exception e) {
            throw new MojoExecutionException(
                    "Error writing dependencies into SUBSYSTEM.MF", e);
        }

    }