Search in sources :

Example 36 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 37 with ArchiverException

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

the class AddArtifactTaskTest method testShouldAddArchiveFileWithUnpack.

public void testShouldAddArchiveFileWithUnpack() throws ArchiveCreationException, AssemblyFormattingException, IOException {
    mac.expectModeChange(-1, -1, -1, -1, 1);
    mac.expectInterpolators();
    ArtifactMock artifactMock = new ArtifactMock(mockManager, "group", "artifact", "version", "jar", false);
    artifactMock.setNewFile();
    mac.expectGetDestFile(new File("junk"));
    try {
        //            mac.archiver.addArchivedFileSet( artifactFile, outputLocation, AddArtifactTask.DEFAULT_INCLUDES_ARRAY,
        // null );
        mac.archiver.addArchivedFileSet((ArchivedFileSet) anyObject(), (Charset) anyObject());
    } catch (ArchiverException e) {
        fail("Should never happen.");
    }
    mockManager.replayAll();
    AddArtifactTask task = createTask(artifactMock.getArtifact());
    task.setUnpack(true);
    task.execute(mac.archiver, mac.configSource);
    mockManager.verifyAll();
}
Also used : ArchiverException(org.codehaus.plexus.archiver.ArchiverException) MockAndControlForAddArtifactTask(org.apache.maven.plugins.assembly.archive.task.testutils.MockAndControlForAddArtifactTask) ArtifactMock(org.apache.maven.plugins.assembly.archive.task.testutils.ArtifactMock) File(java.io.File)

Example 38 with ArchiverException

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

the class AddDirectoryTaskTest method testAddDirectory_ShouldAddDirectoryWithDirMode.

public void testAddDirectory_ShouldAddDirectoryWithDirMode() throws ArchiveCreationException {
    File dir = fileManager.createTempDir();
    try {
        archiver.addFileSet((FileSet) anyObject());
    } catch (ArchiverException e) {
        fail("Should never happen.");
    }
    int dirMode = Integer.parseInt("777", 8);
    int fileMode = Integer.parseInt("777", 8);
    configureModeExpectations(-1, -1, dirMode, fileMode, true);
    mockManager.replayAll();
    AddDirectoryTask task = new AddDirectoryTask(dir);
    task.setDirectoryMode(dirMode);
    task.setFileMode(fileMode);
    task.setOutputDirectory("dir");
    task.execute(archiver);
    mockManager.verifyAll();
}
Also used : ArchiverException(org.codehaus.plexus.archiver.ArchiverException) File(java.io.File)

Example 39 with ArchiverException

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

the class AddDirectoryTaskTest method testAddDirectory_ShouldAddDirectoryWithIncludesAndExcludes.

public void testAddDirectory_ShouldAddDirectoryWithIncludesAndExcludes() throws ArchiveCreationException {
    File dir = fileManager.createTempDir();
    try {
        archiver.addFileSet((FileSet) anyObject());
    } catch (ArchiverException e) {
        fail("Should never happen.");
    }
    configureModeExpectations(-1, -1, -1, -1, false);
    mockManager.replayAll();
    AddDirectoryTask task = new AddDirectoryTask(dir);
    task.setIncludes(Collections.singletonList("**/*.txt"));
    task.setExcludes(Collections.singletonList("**/README.txt"));
    task.setOutputDirectory("dir");
    task.execute(archiver);
    mockManager.verifyAll();
}
Also used : ArchiverException(org.codehaus.plexus.archiver.ArchiverException) File(java.io.File)

Example 40 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)

Aggregations

ArchiverException (org.codehaus.plexus.archiver.ArchiverException)51 File (java.io.File)33 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)26 IOException (java.io.IOException)25 NoSuchArchiverException (org.codehaus.plexus.archiver.manager.NoSuchArchiverException)17 UnArchiver (org.codehaus.plexus.archiver.UnArchiver)9 Artifact (org.apache.maven.artifact.Artifact)8 ManifestException (org.codehaus.plexus.archiver.jar.ManifestException)8 DependencyResolutionRequiredException (org.apache.maven.artifact.DependencyResolutionRequiredException)7 MavenArchiver (org.apache.maven.archiver.MavenArchiver)6 ArchiveCreationException (org.apache.maven.plugins.assembly.archive.ArchiveCreationException)5 ArrayList (java.util.ArrayList)3 MojoFailureException (org.apache.maven.plugin.MojoFailureException)3 Archiver (org.codehaus.plexus.archiver.Archiver)3 JarArchiver (org.codehaus.plexus.archiver.jar.JarArchiver)3 FileInputStream (java.io.FileInputStream)2 FileOutputStream (java.io.FileOutputStream)2 FileWriter (java.io.FileWriter)2 OutputStreamWriter (java.io.OutputStreamWriter)2 PrintWriter (java.io.PrintWriter)2