public void execute()

in src/main/java/org/apache/sling/maven/slingstart/AttachModelArchive.java [69:133]


    public void execute() throws MojoExecutionException, MojoFailureException {
        Model model = ProjectHelper.getRawModel(this.project);
        if (usePomVariables) {
            model = ModelUtility.applyVariables(model, new PomVariableResolver(project));
        }
        if (usePomDependencies) {
            model = ModelUtility.applyArtifactVersions(model, new PomArtifactVersionResolver(project, allowUnresolvedPomDependencies));
        }

        // write the model archive
        final File outputFile = new File(this.project.getBuild().getDirectory() + File.separatorChar + modelArchiveName + "." + ModelArchiveWriter.DEFAULT_EXTENSION);
        outputFile.getParentFile().mkdirs();

        try ( final FileOutputStream fos = new FileOutputStream(outputFile)) {
            // TODO provide base manifest
            final JarOutputStream jos = ModelArchiveWriter.write(fos, model, null, new ModelArchiveWriter.ArtifactProvider() {

                @Override
                public InputStream getInputStream(final Artifact artifact) throws IOException {
                    try {
                        final org.apache.maven.artifact.Artifact a = ModelUtils.getArtifact(project, mavenSession,
                                artifactHandlerManager, resolver,
                                artifact.getGroupId(),
                                artifact.getArtifactId(),
                                artifact.getVersion(),
                                artifact.getType(),
                                artifact.getClassifier());
                        return new FileInputStream(a.getFile());
                    } catch (MojoExecutionException e) {
                        throw (IOException)new IOException("Unable to get artifact: " + artifact.toMvnUrl()).initCause(e);
                    }
                }
            });

            // 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 model archive to " + outputFile + " : " + e.getMessage(), e);
        }

        // attach it as an additional artifact
        projectHelper.attachArtifact(project, ModelArchiveWriter.DEFAULT_EXTENSION,
                    BuildConstants.CLASSIFIER_MAR, outputFile);
    }