Search in sources :

Example 6 with ManifestException

use of org.codehaus.plexus.archiver.jar.ManifestException in project maven-plugins by apache.

the class AbstractSourceJarMojo method packageSources.

/**
     * @param theProjects {@link MavenProject}
     * @throws MojoExecutionException in case of an error.
     */
protected void packageSources(List<MavenProject> theProjects) throws MojoExecutionException {
    if (project.getArtifact().getClassifier() != null) {
        getLog().warn("NOT adding sources to artifacts with classifier as Maven only supports one classifier " + "per artifact. Current artifact [" + project.getArtifact().getId() + "] has a [" + project.getArtifact().getClassifier() + "] classifier.");
        return;
    }
    MavenArchiver archiver = createArchiver();
    for (MavenProject pItem : theProjects) {
        MavenProject subProject = getProject(pItem);
        if ("pom".equals(subProject.getPackaging())) {
            continue;
        }
        archiveProjectContent(subProject, archiver.getArchiver());
    }
    if (archiver.getArchiver().getResources().hasNext() || forceCreation) {
        if (useDefaultManifestFile && defaultManifestFile.exists() && archive.getManifestFile() == null) {
            getLog().info("Adding existing MANIFEST to archive. Found under: " + defaultManifestFile.getPath());
            archive.setManifestFile(defaultManifestFile);
        }
        File outputFile = new File(outputDirectory, finalName + "-" + getClassifier() + getExtension());
        try {
            archiver.setOutputFile(outputFile);
            archive.setForced(forceCreation);
            archiver.createArchive(session, project, archive);
        } catch (IOException e) {
            throw new MojoExecutionException("Error creating source archive: " + e.getMessage(), e);
        } catch (ArchiverException e) {
            throw new MojoExecutionException("Error creating source archive: " + e.getMessage(), e);
        } catch (DependencyResolutionRequiredException e) {
            throw new MojoExecutionException("Error creating source archive: " + e.getMessage(), e);
        } catch (ManifestException e) {
            throw new MojoExecutionException("Error creating source archive: " + e.getMessage(), e);
        }
        if (attach) {
            projectHelper.attachArtifact(project, getType(), getClassifier(), outputFile);
        } else {
            getLog().info("NOT adding java-sources to attached artifacts list.");
        }
    } else {
        getLog().info("No sources in project. Archive not created.");
    }
}
Also used : DependencyResolutionRequiredException(org.apache.maven.artifact.DependencyResolutionRequiredException) MavenProject(org.apache.maven.project.MavenProject) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ArchiverException(org.codehaus.plexus.archiver.ArchiverException) MavenArchiver(org.apache.maven.archiver.MavenArchiver) IOException(java.io.IOException) ManifestException(org.codehaus.plexus.archiver.jar.ManifestException) File(java.io.File)

Example 7 with ManifestException

use of org.codehaus.plexus.archiver.jar.ManifestException in project maven-plugins by apache.

the class ClassesPackager method packageClasses.

/**
     * Package the classes
     *
     * @param classesDirectory the classes directory
     * @param targetFile the target file
     * @param jarArchiver the jar archiver to use
     * @param session the current session
     * @param project the related project
     * @param archiveConfiguration the archive configuration to use
     * @throws MojoExecutionException if an error occurred while creating the archive
     */
public void packageClasses(File classesDirectory, File targetFile, JarArchiver jarArchiver, MavenSession session, MavenProject project, MavenArchiveConfiguration archiveConfiguration) throws MojoExecutionException {
    try {
        final MavenArchiver archiver = new MavenArchiver();
        archiver.setArchiver(jarArchiver);
        archiver.setOutputFile(targetFile);
        archiver.getArchiver().addDirectory(classesDirectory);
        archiver.createArchive(session, project, archiveConfiguration);
    } catch (ArchiverException e) {
        throw new MojoExecutionException("Could not create classes archive", e);
    } catch (ManifestException e) {
        throw new MojoExecutionException("Could not create classes archive", e);
    } catch (IOException e) {
        throw new MojoExecutionException("Could not create classes archive", e);
    } catch (DependencyResolutionRequiredException e) {
        throw new MojoExecutionException("Could not create classes archive", e);
    }
}
Also used : DependencyResolutionRequiredException(org.apache.maven.artifact.DependencyResolutionRequiredException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ArchiverException(org.codehaus.plexus.archiver.ArchiverException) MavenArchiver(org.apache.maven.archiver.MavenArchiver) IOException(java.io.IOException) ManifestException(org.codehaus.plexus.archiver.jar.ManifestException)

Example 8 with ManifestException

use of org.codehaus.plexus.archiver.jar.ManifestException in project sling by apache.

the class JarArchiverHelper method createManifest.

/**
     * Create a manifest
     */
private void createManifest(final java.util.jar.Manifest manifest) throws MojoExecutionException {
    // create a new manifest
    final Manifest outManifest = new Manifest();
    try {
        boolean hasMain = false;
        // copy entries from existing manifest
        if (manifest != null) {
            final Map<Object, Object> attrs = manifest.getMainAttributes();
            for (final Map.Entry<Object, Object> entry : attrs.entrySet()) {
                final String key = entry.getKey().toString();
                if (!BuildConstants.ATTRS_EXCLUDES.contains(key)) {
                    final Attribute a = new Attribute(key, entry.getValue().toString());
                    outManifest.addConfiguredAttribute(a);
                }
                if (key.equals(BuildConstants.ATTR_MAIN_CLASS)) {
                    hasMain = true;
                }
            }
        }
        outManifest.addConfiguredAttribute(new Attribute(BuildConstants.ATTR_IMPLEMENTATION_BUILD, project.getVersion()));
        outManifest.addConfiguredAttribute(new Attribute(BuildConstants.ATTR_IMPLEMENTATION_VERSION, project.getVersion()));
        String organizationName = project.getOrganization() != null ? project.getOrganization().getName() : null;
        if (organizationName != null) {
            outManifest.addConfiguredAttribute(new Attribute(BuildConstants.ATTR_IMPLEMENTATION_VENDOR, organizationName));
            outManifest.addConfiguredAttribute(new Attribute(BuildConstants.ATTR_CREATED_BY, organizationName));
            outManifest.addConfiguredAttribute(new Attribute(BuildConstants.ATTR_BUILT_BY, organizationName));
            outManifest.addConfiguredAttribute(new Attribute(BuildConstants.ATTR_SPECIFICATION_VENDOR, organizationName));
        }
        outManifest.addConfiguredAttribute(new Attribute(BuildConstants.ATTR_IMPLEMENTATION_VENDOR_ID, project.getGroupId()));
        outManifest.addConfiguredAttribute(new Attribute(BuildConstants.ATTR_IMPLEMENTATION_TITLE, project.getName()));
        outManifest.addConfiguredAttribute(new Attribute(BuildConstants.ATTR_SPECIFICATION_TITLE, project.getName()));
        outManifest.addConfiguredAttribute(new Attribute(BuildConstants.ATTR_SPECIFICATION_VERSION, project.getVersion()));
        if (archiver.getDestFile().getName().endsWith(".jar") && !hasMain) {
            outManifest.addConfiguredAttribute(new Attribute(BuildConstants.ATTR_MAIN_CLASS, BuildConstants.ATTR_VALUE_MAIN_CLASS));
        }
        archiver.addConfiguredManifest(outManifest);
    } catch (final ManifestException e) {
        throw new MojoExecutionException("Unable to create manifest for " + this.archiver.getDestFile(), e);
    }
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) Attribute(org.codehaus.plexus.archiver.jar.Manifest.Attribute) Manifest(org.codehaus.plexus.archiver.jar.Manifest) ManifestException(org.codehaus.plexus.archiver.jar.ManifestException) Map(java.util.Map)

Example 9 with ManifestException

use of org.codehaus.plexus.archiver.jar.ManifestException in project maven-plugins by apache.

the class ManifestCreationFinalizer method finalizeArchiveCreation.

@Override
public void finalizeArchiveCreation(final Archiver archiver) {
    if (archiveConfiguration != null) {
        try {
            Manifest manifest;
            final File manifestFile = archiveConfiguration.getManifestFile();
            if (manifestFile != null) {
                Reader manifestFileReader = null;
                try {
                    manifestFileReader = new InputStreamReader(new FileInputStream(manifestFile), "UTF-8");
                    manifest = new Manifest(manifestFileReader);
                    manifestFileReader.close();
                    manifestFileReader = null;
                } catch (final FileNotFoundException e) {
                    throw new ArchiverException("Manifest not found: " + e.getMessage(), e);
                } catch (final IOException e) {
                    throw new ArchiverException("Error processing manifest: " + e.getMessage(), e);
                } finally {
                    IOUtil.close(manifestFileReader);
                }
            } else {
                manifest = mavenArchiver.getManifest(session, project, archiveConfiguration);
            }
            if ((manifest != null) && (archiver instanceof JarArchiver)) {
                final JarArchiver jarArchiver = (JarArchiver) archiver;
                jarArchiver.addConfiguredManifest(manifest);
            }
        } catch (final ManifestException e) {
            throw new ArchiverException("Error creating manifest: " + e.getMessage(), e);
        } catch (final DependencyResolutionRequiredException e) {
            throw new ArchiverException("Dependencies were not resolved: " + e.getMessage(), e);
        }
    }
}
Also used : DependencyResolutionRequiredException(org.apache.maven.artifact.DependencyResolutionRequiredException) InputStreamReader(java.io.InputStreamReader) ArchiverException(org.codehaus.plexus.archiver.ArchiverException) FileNotFoundException(java.io.FileNotFoundException) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) IOException(java.io.IOException) Manifest(org.codehaus.plexus.archiver.jar.Manifest) ManifestException(org.codehaus.plexus.archiver.jar.ManifestException) File(java.io.File) JarArchiver(org.codehaus.plexus.archiver.jar.JarArchiver) FileInputStream(java.io.FileInputStream)

Example 10 with ManifestException

use of org.codehaus.plexus.archiver.jar.ManifestException in project maven-plugins by apache.

the class EjbMojo method generateEjb.

private File generateEjb() throws MojoExecutionException {
    File jarFile = EjbHelper.getJarFile(outputDirectory, jarName, getClassifier());
    getLog().info("Building EJB " + jarName + " with EJB version " + ejbVersion);
    MavenArchiver archiver = new MavenArchiver();
    archiver.setArchiver(jarArchiver);
    archiver.setOutputFile(jarFile);
    File deploymentDescriptor = new File(sourceDirectory, ejbJar);
    checkEJBVersionCompliance(deploymentDescriptor);
    try {
        List<String> defaultExcludes = Lists.newArrayList(ejbJar, "**/package.html");
        List<String> defaultIncludes = DEFAULT_INCLUDES_LIST;
        IncludesExcludes ie = new IncludesExcludes(Collections.<String>emptyList(), excludes, defaultIncludes, defaultExcludes);
        archiver.getArchiver().addDirectory(sourceDirectory, ie.resultingIncludes(), ie.resultingExcludes());
        // FIXME: We should be able to filter more than just the deployment descriptor?
        if (deploymentDescriptor.exists()) {
            // EJB-34 Filter ejb-jar.xml
            if (filterDeploymentDescriptor) {
                filterDeploymentDescriptor(deploymentDescriptor);
            }
            archiver.getArchiver().addFile(deploymentDescriptor, ejbJar);
        }
        // create archive
        archiver.createArchive(session, project, archive);
    } catch (ArchiverException e) {
        throw new MojoExecutionException("There was a problem creating the EJB archive: " + e.getMessage(), e);
    } catch (ManifestException e) {
        throw new MojoExecutionException("There was a problem creating the EJB archive: " + e.getMessage(), e);
    } catch (IOException e) {
        throw new MojoExecutionException("There was a problem creating the EJB archive: " + e.getMessage(), e);
    } catch (DependencyResolutionRequiredException e) {
        throw new MojoExecutionException("There was a problem creating the EJB archive: " + e.getMessage(), e);
    } catch (MavenFilteringException e) {
        throw new MojoExecutionException("There was a problem filtering the deployment descriptor: " + e.getMessage(), e);
    }
    return jarFile;
}
Also used : DependencyResolutionRequiredException(org.apache.maven.artifact.DependencyResolutionRequiredException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ArchiverException(org.codehaus.plexus.archiver.ArchiverException) MavenFilteringException(org.apache.maven.shared.filtering.MavenFilteringException) MavenArchiver(org.apache.maven.archiver.MavenArchiver) IOException(java.io.IOException) ManifestException(org.codehaus.plexus.archiver.jar.ManifestException) File(java.io.File)

Aggregations

ManifestException (org.codehaus.plexus.archiver.jar.ManifestException)10 ArchiverException (org.codehaus.plexus.archiver.ArchiverException)8 File (java.io.File)7 IOException (java.io.IOException)7 DependencyResolutionRequiredException (org.apache.maven.artifact.DependencyResolutionRequiredException)7 MavenArchiver (org.apache.maven.archiver.MavenArchiver)6 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)6 Manifest (org.codehaus.plexus.archiver.jar.Manifest)4 FileInputStream (java.io.FileInputStream)2 MavenFilteringException (org.apache.maven.shared.filtering.MavenFilteringException)2 Attribute (org.codehaus.plexus.archiver.jar.Manifest.Attribute)2 FileNotFoundException (java.io.FileNotFoundException)1 InputStreamReader (java.io.InputStreamReader)1 PrintWriter (java.io.PrintWriter)1 Reader (java.io.Reader)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 ZipException (java.util.zip.ZipException)1 Resource (org.apache.maven.model.Resource)1 MojoFailureException (org.apache.maven.plugin.MojoFailureException)1