Search in sources :

Example 11 with MavenArchiver

use of org.apache.maven.archiver.MavenArchiver 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)

Example 12 with MavenArchiver

use of org.apache.maven.archiver.MavenArchiver in project maven-plugins by apache.

the class EarMojo method execute.

/** {@inheritDoc} */
public void execute() throws MojoExecutionException, MojoFailureException {
    // Initializes ear modules
    super.execute();
    zipArchiver.setUseJvmChmod(useJvmChmod);
    zipUnArchiver.setUseJvmChmod(useJvmChmod);
    final JavaEEVersion javaEEVersion = JavaEEVersion.getJavaEEVersion(version);
    // Initializes unpack types
    List<String> unpackTypesList = createUnpackList();
    // Copy modules
    copyModules(javaEEVersion, unpackTypesList);
    // Copy source files
    try {
        File earSourceDir = earSourceDirectory;
        if (earSourceDir.exists()) {
            getLog().info("Copy ear sources to " + getWorkDirectory().getAbsolutePath());
            String[] fileNames = getEarFiles(earSourceDir);
            for (String fileName : fileNames) {
                copyFile(new File(earSourceDir, fileName), new File(getWorkDirectory(), fileName));
            }
        }
        if (applicationXml != null && !"".equals(applicationXml)) {
            // rename to application.xml
            getLog().info("Including custom application.xml[" + applicationXml + "]");
            File metaInfDir = new File(getWorkDirectory(), META_INF);
            copyFile(new File(applicationXml), new File(metaInfDir, "/application.xml"));
        }
    } catch (IOException e) {
        throw new MojoExecutionException("Error copying EAR sources", e);
    } catch (MavenFilteringException e) {
        throw new MojoExecutionException("Error filtering EAR sources", e);
    }
    // Check if deployment descriptor is there
    File ddFile = new File(getWorkDirectory(), APPLICATION_XML_URI);
    if (!ddFile.exists() && (javaEEVersion.lt(JavaEEVersion.FIVE))) {
        // CHECKSTYLE_OFF: LineLength
        throw new MojoExecutionException("Deployment descriptor: " + ddFile.getAbsolutePath() + " does not exist.");
    // CHECKSTYLE_ON: LineLength
    }
    try {
        File earFile = getEarFile(outputDirectory, finalName, classifier);
        final MavenArchiver archiver = new EarMavenArchiver(getModules());
        final JarArchiver theJarArchiver = getJarArchiver();
        getLog().debug("Jar archiver implementation [" + theJarArchiver.getClass().getName() + "]");
        archiver.setArchiver(theJarArchiver);
        archiver.setOutputFile(earFile);
        getLog().debug("Excluding " + Arrays.asList(getPackagingExcludes()) + " from the generated EAR.");
        getLog().debug("Including " + Arrays.asList(getPackagingIncludes()) + " in the generated EAR.");
        archiver.getArchiver().addDirectory(getWorkDirectory(), getPackagingIncludes(), getPackagingExcludes());
        archiver.createArchive(session, getProject(), archive);
        if (classifier != null) {
            projectHelper.attachArtifact(getProject(), "ear", classifier, earFile);
        } else {
            getProject().getArtifact().setFile(earFile);
        }
    } catch (Exception e) {
        throw new MojoExecutionException("Error assembling EAR", e);
    }
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MavenFilteringException(org.apache.maven.shared.filtering.MavenFilteringException) JavaEEVersion(org.apache.maven.plugins.ear.util.JavaEEVersion) EarMavenArchiver(org.apache.maven.plugins.ear.util.EarMavenArchiver) MavenArchiver(org.apache.maven.archiver.MavenArchiver) IOException(java.io.IOException) EarMavenArchiver(org.apache.maven.plugins.ear.util.EarMavenArchiver) File(java.io.File) JarArchiver(org.codehaus.plexus.archiver.jar.JarArchiver) ManifestException(org.codehaus.plexus.archiver.jar.ManifestException) NoSuchArchiverException(org.codehaus.plexus.archiver.manager.NoSuchArchiverException) ArchiverException(org.codehaus.plexus.archiver.ArchiverException) MavenFilteringException(org.apache.maven.shared.filtering.MavenFilteringException) ZipException(java.util.zip.ZipException) IOException(java.io.IOException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException)

Example 13 with MavenArchiver

use of org.apache.maven.archiver.MavenArchiver in project maven-plugins by apache.

the class SiteJarMojo method createArchive.

/**
     * Method that creates the jar file.
     *
     * @param siteDirectory the directory where the site files are located
     * @param jarFilename   the filename of the created jar file
     * @return a File object that contains the created jar file
     * @throws ArchiverException
     * @throws IOException
     * @throws ManifestException
     * @throws DependencyResolutionRequiredException
     */
private File createArchive(File siteDirectory, String jarFilename) throws ArchiverException, IOException, ManifestException, DependencyResolutionRequiredException {
    File siteJar = new File(jarOutputDirectory, jarFilename);
    MavenArchiver archiver = new MavenArchiver();
    archiver.setArchiver(this.jarArchiver);
    archiver.setOutputFile(siteJar);
    if (!siteDirectory.isDirectory()) {
        getLog().warn("JAR will be empty - no content was marked for inclusion !");
    } else {
        archiver.getArchiver().addDirectory(siteDirectory, getArchiveIncludes(), getArchiveExcludes());
    }
    archiver.createArchive(getSession(), getProject(), archive);
    return siteJar;
}
Also used : MavenArchiver(org.apache.maven.archiver.MavenArchiver) File(java.io.File)

Example 14 with MavenArchiver

use of org.apache.maven.archiver.MavenArchiver in project maven-plugins by apache.

the class AbstractSourceJarMojo method createArchiver.

/**
     * @return {@link MavenArchiver}
     * @throws MojoExecutionException in case of an error.
     */
protected MavenArchiver createArchiver() throws MojoExecutionException {
    MavenArchiver archiver = new MavenArchiver();
    archiver.setArchiver(jarArchiver);
    if (project.getBuild() != null) {
        List<Resource> resources = project.getBuild().getResources();
        for (Resource r : resources) {
            if (r.getDirectory().endsWith("maven-shared-archive-resources")) {
                addDirectory(archiver.getArchiver(), new File(r.getDirectory()), getCombinedIncludes(null), getCombinedExcludes(null));
            }
        }
    }
    return archiver;
}
Also used : Resource(org.apache.maven.model.Resource) MavenArchiver(org.apache.maven.archiver.MavenArchiver) File(java.io.File)

Aggregations

MavenArchiver (org.apache.maven.archiver.MavenArchiver)14 File (java.io.File)12 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)10 IOException (java.io.IOException)8 ArchiverException (org.codehaus.plexus.archiver.ArchiverException)8 ManifestException (org.codehaus.plexus.archiver.jar.ManifestException)8 DependencyResolutionRequiredException (org.apache.maven.artifact.DependencyResolutionRequiredException)6 MavenFilteringException (org.apache.maven.shared.filtering.MavenFilteringException)4 Artifact (org.apache.maven.artifact.Artifact)3 Resource (org.apache.maven.model.Resource)2 MojoFailureException (org.apache.maven.plugin.MojoFailureException)2 Date (java.util.Date)1 ZipException (java.util.zip.ZipException)1 MavenArchiveConfiguration (org.apache.maven.archiver.MavenArchiveConfiguration)1 ArtifactRepositoryLayout (org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout)1 DefaultRepositoryLayout (org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout)1 Metadata (org.apache.maven.artifact.repository.metadata.Metadata)1 Snapshot (org.apache.maven.artifact.repository.metadata.Snapshot)1 SnapshotVersion (org.apache.maven.artifact.repository.metadata.SnapshotVersion)1 Versioning (org.apache.maven.artifact.repository.metadata.Versioning)1