Search in sources :

Example 76 with ArchiverException

use of org.codehaus.plexus.archiver.ArchiverException 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 77 with ArchiverException

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

the class JavadocJar method generateArchive.

// ----------------------------------------------------------------------
// private methods
// ----------------------------------------------------------------------
/**
 * Method that creates the jar file
 *
 * @param javadocFiles the directory where the generated jar file will be put
 * @param jarFileName the filename of the generated jar file
 * @return a File object that contains the generated jar file
 * @throws ArchiverException {@link ArchiverException}
 * @throws IOException {@link IOException}
 */
private File generateArchive(File javadocFiles, String jarFileName) throws ArchiverException, IOException {
    File javadocJar = new File(jarOutputDirectory, jarFileName);
    if (javadocJar.exists()) {
        javadocJar.delete();
    }
    MavenArchiver archiver = new MavenArchiver();
    archiver.setArchiver(jarArchiver);
    archiver.setOutputFile(javadocJar);
    File contentDirectory = javadocFiles;
    if (!contentDirectory.exists()) {
        getLog().warn("JAR will be empty - no content was marked for inclusion!");
    } else {
        archiver.getArchiver().addDirectory(contentDirectory, DEFAULT_INCLUDES, DEFAULT_EXCLUDES);
    }
    List<Resource> resources = project.getBuild().getResources();
    for (Resource r : resources) {
        if (r.getDirectory().endsWith("maven-shared-archive-resources")) {
            archiver.getArchiver().addDirectory(new File(r.getDirectory()));
        }
    }
    if (useDefaultManifestFile && defaultManifestFile.exists() && archive.getManifestFile() == null) {
        getLog().info("Adding existing MANIFEST to archive. Found under: " + defaultManifestFile.getPath());
        archive.setManifestFile(defaultManifestFile);
    }
    try {
        archiver.createArchive(session, project, archive);
    } catch (ManifestException e) {
        throw new ArchiverException("ManifestException: " + e.getMessage(), e);
    } catch (DependencyResolutionRequiredException e) {
        throw new ArchiverException("DependencyResolutionRequiredException: " + e.getMessage(), e);
    }
    return javadocJar;
}
Also used : DependencyResolutionRequiredException(org.apache.maven.artifact.DependencyResolutionRequiredException) ArchiverException(org.codehaus.plexus.archiver.ArchiverException) Resource(org.apache.maven.model.Resource) MavenArchiver(org.apache.maven.archiver.MavenArchiver) ManifestException(org.codehaus.plexus.archiver.jar.ManifestException) File(java.io.File)

Example 78 with ArchiverException

use of org.codehaus.plexus.archiver.ArchiverException in project maven-dependency-plugin by apache.

the class AbstractDependencyMojo method unpack.

/**
 * @param artifact {@link Artifact}
 * @param type The type.
 * @param location The location.
 * @param includes includes list.
 * @param excludes excludes list.
 * @param encoding the encoding.
 * @throws MojoExecutionException in case of an error.
 */
protected void unpack(Artifact artifact, String type, File location, String includes, String excludes, String encoding) throws MojoExecutionException {
    File file = artifact.getFile();
    try {
        logUnpack(file, location, includes, excludes);
        location.mkdirs();
        if (!location.exists()) {
            throw new MojoExecutionException("Location to write unpacked files to could not be created: " + location);
        }
        if (file.isDirectory()) {
            // usual case is a future jar packaging, but there are special cases: classifier and other packaging
            throw new MojoExecutionException("Artifact has not been packaged yet. When used on reactor artifact, " + "unpack should be executed after packaging: see MDEP-98.");
        }
        UnArchiver unArchiver;
        try {
            unArchiver = archiverManager.getUnArchiver(type);
            getLog().debug("Found unArchiver by type: " + unArchiver);
        } catch (NoSuchArchiverException e) {
            unArchiver = archiverManager.getUnArchiver(file);
            getLog().debug("Found unArchiver by extension: " + unArchiver);
        }
        if (encoding != null && unArchiver instanceof ZipUnArchiver) {
            ((ZipUnArchiver) unArchiver).setEncoding(encoding);
            getLog().info("Unpacks '" + type + "' with encoding '" + encoding + "'.");
        }
        unArchiver.setUseJvmChmod(useJvmChmod);
        unArchiver.setIgnorePermissions(ignorePermissions);
        unArchiver.setSourceFile(file);
        unArchiver.setDestDirectory(location);
        if (StringUtils.isNotEmpty(excludes) || StringUtils.isNotEmpty(includes)) {
            // Create the selectors that will filter
            // based on include/exclude parameters
            // MDEP-47
            IncludeExcludeFileSelector[] selectors = new IncludeExcludeFileSelector[] { new IncludeExcludeFileSelector() };
            if (StringUtils.isNotEmpty(excludes)) {
                selectors[0].setExcludes(excludes.split(","));
            }
            if (StringUtils.isNotEmpty(includes)) {
                selectors[0].setIncludes(includes.split(","));
            }
            unArchiver.setFileSelectors(selectors);
        }
        if (this.silent) {
            silenceUnarchiver(unArchiver);
        }
        unArchiver.extract();
    } catch (NoSuchArchiverException e) {
        throw new MojoExecutionException("Unknown archiver type", e);
    } catch (ArchiverException e) {
        throw new MojoExecutionException("Error unpacking file: " + file + " to: " + location + "\r\n" + e.toString(), e);
    }
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) IncludeExcludeFileSelector(org.codehaus.plexus.components.io.fileselectors.IncludeExcludeFileSelector) NoSuchArchiverException(org.codehaus.plexus.archiver.manager.NoSuchArchiverException) ArchiverException(org.codehaus.plexus.archiver.ArchiverException) ZipUnArchiver(org.codehaus.plexus.archiver.zip.ZipUnArchiver) File(java.io.File) ZipUnArchiver(org.codehaus.plexus.archiver.zip.ZipUnArchiver) UnArchiver(org.codehaus.plexus.archiver.UnArchiver) NoSuchArchiverException(org.codehaus.plexus.archiver.manager.NoSuchArchiverException)

Example 79 with ArchiverException

use of org.codehaus.plexus.archiver.ArchiverException in project wso2-synapse by wso2.

the class XarMojo method execute.

/**
 * Executes the XarMojo on the current project.
 *
 * @throws MojoExecutionException if an error occurred while building the XAR
 */
public void execute() throws MojoExecutionException {
    File xarFile = new File(outputDirectory, xarName + ".xar");
    // generate xar file
    getLog().info("Generating XAR " + xarFile.getAbsolutePath());
    MavenArchiver archiver = new MavenArchiver();
    archiver.setArchiver(jarArchiver);
    archiver.setOutputFile(xarFile);
    try {
        buildArchive(jarArchiver);
    } catch (ArchiverException e) {
        throw new MojoExecutionException("Unable to build archive", e);
    }
    // create archive
    try {
        archiver.createArchive(project, archive);
    } catch (Exception e) {
        throw new MojoExecutionException("Unable to create archive", e);
    }
    if (classifier != null) {
        projectHelper.attachArtifact(project, "xar", classifier, xarFile);
    } else {
        Artifact artifact = project.getArtifact();
        if (primaryArtifact) {
            artifact.setFile(xarFile);
        } else if (artifact.getFile() == null || artifact.getFile().isDirectory()) {
            artifact.setFile(xarFile);
        } else {
            projectHelper.attachArtifact(project, "xar", xarFile);
        }
    }
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ArchiverException(org.codehaus.plexus.archiver.ArchiverException) MavenArchiver(org.apache.maven.archiver.MavenArchiver) File(java.io.File) ArchiverException(org.codehaus.plexus.archiver.ArchiverException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) Artifact(org.apache.maven.artifact.Artifact)

Example 80 with ArchiverException

use of org.codehaus.plexus.archiver.ArchiverException in project maven-dependency-plugin by apache.

the class AbstractDependencyMojo method unpack.

/**
 * @param artifact {@link Artifact}
 * @param type The type.
 * @param location The location.
 * @param includes includes list.
 * @param excludes excludes list.
 * @param encoding the encoding.
 * @param fileMappers {@link FileMapper}s to be used for rewriting each target path, or {@code null} if no rewriting
 *                    shall happen.
 * @throws MojoExecutionException in case of an error.
 */
protected void unpack(Artifact artifact, String type, File location, String includes, String excludes, String encoding, FileMapper[] fileMappers) throws MojoExecutionException {
    File file = artifact.getFile();
    try {
        logUnpack(file, location, includes, excludes);
        location.mkdirs();
        if (!location.exists()) {
            throw new MojoExecutionException("Location to write unpacked files to could not be created: " + location);
        }
        if (file.isDirectory()) {
            // usual case is a future jar packaging, but there are special cases: classifier and other packaging
            throw new MojoExecutionException("Artifact has not been packaged yet. When used on reactor artifact, " + "unpack should be executed after packaging: see MDEP-98.");
        }
        UnArchiver unArchiver;
        try {
            unArchiver = archiverManager.getUnArchiver(type);
            getLog().debug("Found unArchiver by type: " + unArchiver);
        } catch (NoSuchArchiverException e) {
            unArchiver = archiverManager.getUnArchiver(file);
            getLog().debug("Found unArchiver by extension: " + unArchiver);
        }
        if (encoding != null && unArchiver instanceof ZipUnArchiver) {
            ((ZipUnArchiver) unArchiver).setEncoding(encoding);
            getLog().info("Unpacks '" + type + "' with encoding '" + encoding + "'.");
        }
        unArchiver.setIgnorePermissions(ignorePermissions);
        unArchiver.setSourceFile(file);
        unArchiver.setDestDirectory(location);
        if (StringUtils.isNotEmpty(excludes) || StringUtils.isNotEmpty(includes)) {
            // Create the selectors that will filter
            // based on include/exclude parameters
            // MDEP-47
            IncludeExcludeFileSelector[] selectors = new IncludeExcludeFileSelector[] { new IncludeExcludeFileSelector() };
            if (StringUtils.isNotEmpty(excludes)) {
                selectors[0].setExcludes(excludes.split(","));
            }
            if (StringUtils.isNotEmpty(includes)) {
                selectors[0].setIncludes(includes.split(","));
            }
            unArchiver.setFileSelectors(selectors);
        }
        if (this.silent) {
            silenceUnarchiver(unArchiver);
        }
        unArchiver.setFileMappers(fileMappers);
        unArchiver.extract();
    } catch (NoSuchArchiverException e) {
        throw new MojoExecutionException("Unknown archiver type", e);
    } catch (ArchiverException e) {
        throw new MojoExecutionException("Error unpacking file: " + file + " to: " + location, e);
    }
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) IncludeExcludeFileSelector(org.codehaus.plexus.components.io.fileselectors.IncludeExcludeFileSelector) NoSuchArchiverException(org.codehaus.plexus.archiver.manager.NoSuchArchiverException) ArchiverException(org.codehaus.plexus.archiver.ArchiverException) ZipUnArchiver(org.codehaus.plexus.archiver.zip.ZipUnArchiver) File(java.io.File) ZipUnArchiver(org.codehaus.plexus.archiver.zip.ZipUnArchiver) UnArchiver(org.codehaus.plexus.archiver.UnArchiver) NoSuchArchiverException(org.codehaus.plexus.archiver.manager.NoSuchArchiverException)

Aggregations

ArchiverException (org.codehaus.plexus.archiver.ArchiverException)99 File (java.io.File)69 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)54 IOException (java.io.IOException)48 NoSuchArchiverException (org.codehaus.plexus.archiver.manager.NoSuchArchiverException)28 UnArchiver (org.codehaus.plexus.archiver.UnArchiver)18 ManifestException (org.codehaus.plexus.archiver.jar.ManifestException)15 MavenArchiver (org.apache.maven.archiver.MavenArchiver)14 Artifact (org.apache.maven.artifact.Artifact)14 DependencyResolutionRequiredException (org.apache.maven.artifact.DependencyResolutionRequiredException)14 Archiver (org.codehaus.plexus.archiver.Archiver)8 Resource (org.apache.maven.model.Resource)7 IncludeExcludeFileSelector (org.codehaus.plexus.components.io.fileselectors.IncludeExcludeFileSelector)7 MojoFailureException (org.apache.maven.plugin.MojoFailureException)6 DefaultFileSet (org.codehaus.plexus.archiver.util.DefaultFileSet)6 ArrayList (java.util.ArrayList)5 ArchiveCreationException (org.apache.maven.plugins.assembly.archive.ArchiveCreationException)5 MavenProject (org.apache.maven.project.MavenProject)5 FileInputStream (java.io.FileInputStream)4 FileWriter (java.io.FileWriter)4