Search in sources :

Example 71 with ArchiverException

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

the class SimpleAggregatingDescriptorHandler method writePropertiesFile.

private File writePropertiesFile() {
    File f;
    Writer writer = null;
    try {
        f = File.createTempFile("maven-assembly-plugin", "tmp");
        f.deleteOnExit();
        writer = AssemblyFileUtils.isPropertyFile(f) ? new OutputStreamWriter(new FileOutputStream(f), "ISO-8859-1") : // Still platform encoding
        new OutputStreamWriter(new FileOutputStream(f));
        writer.write(commentChars + " Aggregated on " + new Date() + " from: ");
        for (final String filename : filenames) {
            writer.write("\n" + commentChars + " " + filename);
        }
        writer.write("\n\n");
        writer.write(aggregateWriter.toString());
        writer.close();
        writer = null;
    } catch (final IOException e) {
        throw new ArchiverException("Error adding aggregated properties to finalize archive creation. Reason: " + e.getMessage(), e);
    } finally {
        IOUtil.close(writer);
    }
    return f;
}
Also used : ArchiverException(org.codehaus.plexus.archiver.ArchiverException) FileOutputStream(java.io.FileOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) IOException(java.io.IOException) File(java.io.File) StringWriter(java.io.StringWriter) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter) Date(java.util.Date)

Example 72 with ArchiverException

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

the class AddDependencySetsTask method addNonArchiveDependency.

private void addNonArchiveDependency(final Artifact depArtifact, final MavenProject depProject, final DependencySet dependencySet, final Archiver archiver, final AssemblerConfigurationSource configSource) throws AssemblyFormattingException, ArchiveCreationException {
    final File source = depArtifact.getFile();
    String outputDirectory = dependencySet.getOutputDirectory();
    FixedStringSearchInterpolator moduleProjectInterpolator = AssemblyFormatUtils.moduleProjectInterpolator(moduleProject);
    FixedStringSearchInterpolator artifactProjectInterpolator = AssemblyFormatUtils.artifactProjectInterpolator(depProject);
    outputDirectory = AssemblyFormatUtils.getOutputDirectory(outputDirectory, depProject.getBuild().getFinalName(), configSource, moduleProjectInterpolator, artifactProjectInterpolator);
    final String destName = AssemblyFormatUtils.evaluateFileNameMapping(dependencySet.getOutputFileNameMapping(), depArtifact, configSource.getProject(), moduleArtifact, configSource, moduleProjectInterpolator, artifactProjectInterpolator);
    String target;
    // omit the last char if ends with / or \\
    if (outputDirectory.endsWith("/") || outputDirectory.endsWith("\\")) {
        target = outputDirectory + destName;
    } else {
        target = outputDirectory + "/" + destName;
    }
    try {
        final int mode = TypeConversionUtils.modeToInt(dependencySet.getFileMode(), logger);
        if (mode > -1) {
            archiver.addFile(source, target, mode);
        } else {
            archiver.addFile(source, target);
        }
    } catch (final ArchiverException e) {
        throw new ArchiveCreationException("Error adding file to archive: " + e.getMessage(), e);
    }
}
Also used : FixedStringSearchInterpolator(org.codehaus.plexus.interpolation.fixed.FixedStringSearchInterpolator) ArchiverException(org.codehaus.plexus.archiver.ArchiverException) ArchiveCreationException(org.apache.maven.plugins.assembly.archive.ArchiveCreationException) File(java.io.File)

Example 73 with ArchiverException

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

the class AbstractDependencyMojo method unpack.

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 74 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 75 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)

Aggregations

ArchiverException (org.codehaus.plexus.archiver.ArchiverException)91 File (java.io.File)63 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)49 IOException (java.io.IOException)45 NoSuchArchiverException (org.codehaus.plexus.archiver.manager.NoSuchArchiverException)27 UnArchiver (org.codehaus.plexus.archiver.UnArchiver)17 Artifact (org.apache.maven.artifact.Artifact)14 ManifestException (org.codehaus.plexus.archiver.jar.ManifestException)12 MavenArchiver (org.apache.maven.archiver.MavenArchiver)11 DependencyResolutionRequiredException (org.apache.maven.artifact.DependencyResolutionRequiredException)11 Archiver (org.codehaus.plexus.archiver.Archiver)8 ArrayList (java.util.ArrayList)6 MojoFailureException (org.apache.maven.plugin.MojoFailureException)6 DefaultFileSet (org.codehaus.plexus.archiver.util.DefaultFileSet)6 IncludeExcludeFileSelector (org.codehaus.plexus.components.io.fileselectors.IncludeExcludeFileSelector)6 Resource (org.apache.maven.model.Resource)5 ArchiveCreationException (org.apache.maven.plugins.assembly.archive.ArchiveCreationException)5 MavenProject (org.apache.maven.project.MavenProject)5 FileInputStream (java.io.FileInputStream)4 ZipFile (org.apache.commons.compress.archivers.zip.ZipFile)4