Search in sources :

Example 16 with NoSuchArchiverException

use of org.codehaus.plexus.archiver.manager.NoSuchArchiverException in project docker-maven-plugin by fabric8io.

the class DockerAssemblyManager method createBuildTarBall.

// Create final tar-ball to be used for building the archive to send to the Docker daemon
private File createBuildTarBall(BuildDirs buildDirs, List<ArchiverCustomizer> archiverCustomizers, AssemblyConfiguration assemblyConfig, ArchiveCompression compression) throws MojoExecutionException {
    File archive = new File(buildDirs.getTemporaryRootDirectory(), "docker-build." + compression.getFileSuffix());
    try {
        TarArchiver archiver = createBuildArchiver(buildDirs.getOutputDirectory(), archive, assemblyConfig);
        for (ArchiverCustomizer customizer : archiverCustomizers) {
            if (customizer != null) {
                archiver = customizer.customize(archiver);
            }
        }
        archiver.setCompression(compression.getTarCompressionMethod());
        archiver.createArchive();
        return archive;
    } catch (NoSuchArchiverException e) {
        throw new MojoExecutionException("No archiver for type 'tar' found", e);
    } catch (IOException e) {
        throw new MojoExecutionException("Cannot create archive " + archive, e);
    }
}
Also used : TarArchiver(org.codehaus.plexus.archiver.tar.TarArchiver) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) IOException(java.io.IOException) File(java.io.File) NoSuchArchiverException(org.codehaus.plexus.archiver.manager.NoSuchArchiverException)

Example 17 with NoSuchArchiverException

use of org.codehaus.plexus.archiver.manager.NoSuchArchiverException in project felix by apache.

the class CheckMojo method extract.

private File extract(final File file) throws IOException, MojoExecutionException {
    final File rootDir = Files.createTempDirectory("osgicheck").toFile();
    UnArchiver zipUnarchiver = null;
    try {
        zipUnarchiver = archiverManager.getUnArchiver(file);
    } catch (NoSuchArchiverException e) {
        // should not happen
        throw new MojoExecutionException("Impossible to unarchive the '" + file + "' file: " + e.getMessage());
    }
    zipUnarchiver.setDestDirectory(rootDir);
    zipUnarchiver.setSourceFile(file);
    zipUnarchiver.extract();
    return rootDir;
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) File(java.io.File) UnArchiver(org.codehaus.plexus.archiver.UnArchiver) NoSuchArchiverException(org.codehaus.plexus.archiver.manager.NoSuchArchiverException)

Example 18 with NoSuchArchiverException

use of org.codehaus.plexus.archiver.manager.NoSuchArchiverException 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 19 with NoSuchArchiverException

use of org.codehaus.plexus.archiver.manager.NoSuchArchiverException in project docker-maven-plugin by fabric8io.

the class DockerAssemblyManager method extractDockerTarArchive.

/**
 * Extract a docker tar archive into the given directory.
 *
 * @param archiveFile a tar archive to extract
 * @param destinationDirectory directory where to place extracted content
 * @throws MojoExecutionException if an error occurs during extracting.
 */
public void extractDockerTarArchive(File archiveFile, File destinationDirectory) throws MojoExecutionException {
    try {
        TarUnArchiver unArchiver = (TarUnArchiver) archiverManager.getUnArchiver(TAR_ARCHIVER_TYPE);
        unArchiver.setCompression(UntarCompressionMethod.NONE);
        unArchiver.setSourceFile(archiveFile);
        unArchiver.setDestDirectory(destinationDirectory);
        unArchiver.extract();
    } catch (NoSuchArchiverException e) {
        throw new MojoExecutionException("No archiver found for file " + archiveFile, e);
    } catch (ArchiverException e) {
        throw new MojoExecutionException("Cannot extract archive " + archiveFile, e);
    }
}
Also used : TarUnArchiver(org.codehaus.plexus.archiver.tar.TarUnArchiver) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) NoSuchArchiverException(org.codehaus.plexus.archiver.manager.NoSuchArchiverException) ArchiverException(org.codehaus.plexus.archiver.ArchiverException) NoSuchArchiverException(org.codehaus.plexus.archiver.manager.NoSuchArchiverException)

Example 20 with NoSuchArchiverException

use of org.codehaus.plexus.archiver.manager.NoSuchArchiverException in project jbehave-core by jbehave.

the class EmbedderMojoBehaviour method shouldNotIgnoreFailureInUnpackingViewResources.

@Test(expected = MojoExecutionException.class)
public void shouldNotIgnoreFailureInUnpackingViewResources() throws MojoExecutionException, MojoFailureException, NoSuchArchiverException, ArchiverException {
    // Given
    UnpackViewResources mojo = new UnpackViewResources() {

        @Override
        protected Embedder newEmbedder() {
            return new Embedder();
        }
    };
    ArchiverManager archiveManager = mock(ArchiverManager.class);
    MavenProject project = mock(MavenProject.class);
    File coreFile = new File("core");
    Artifact coreResources = mock(Artifact.class);
    when(coreResources.getArtifactId()).thenReturn("jbehave-core");
    when(coreResources.getType()).thenReturn("zip");
    when(coreResources.getFile()).thenReturn(coreFile);
    File siteFile = new File("site");
    Artifact siteResources = mock(Artifact.class);
    when(siteResources.getArtifactId()).thenReturn("jbehave-site-resources");
    when(siteResources.getType()).thenReturn("zip");
    when(siteResources.getFile()).thenReturn(siteFile);
    Set<Artifact> allArtifacts = new HashSet<>();
    allArtifacts.add(coreResources);
    allArtifacts.add(siteResources);
    String buildDirectory = "target";
    Build build = new Build();
    build.setDirectory(buildDirectory);
    UnArchiver coreArchiver = mock(UnArchiver.class);
    UnArchiver siteArchiver = mock(UnArchiver.class);
    // When
    mojo.project = project;
    mojo.archiverManager = archiveManager;
    when(project.getArtifacts()).thenReturn(allArtifacts);
    when(project.getBuild()).thenReturn(build);
    when(archiveManager.getUnArchiver(coreFile)).thenReturn(coreArchiver);
    when(archiveManager.getUnArchiver(siteFile)).thenReturn(siteArchiver);
    Mockito.doThrow(new ArchiverException("bum")).when(siteArchiver).extract();
    mojo.execute();
    // Then
    verify(coreArchiver).extract();
// and fail as expected ...
}
Also used : ArchiverManager(org.codehaus.plexus.archiver.manager.ArchiverManager) MavenProject(org.apache.maven.project.MavenProject) NoSuchArchiverException(org.codehaus.plexus.archiver.manager.NoSuchArchiverException) ArchiverException(org.codehaus.plexus.archiver.ArchiverException) Build(org.apache.maven.model.Build) Embedder(org.jbehave.core.embedder.Embedder) InjectableEmbedder(org.jbehave.core.InjectableEmbedder) Matchers.containsString(org.hamcrest.Matchers.containsString) File(java.io.File) Artifact(org.apache.maven.artifact.Artifact) UnArchiver(org.codehaus.plexus.archiver.UnArchiver) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

NoSuchArchiverException (org.codehaus.plexus.archiver.manager.NoSuchArchiverException)23 ArchiverException (org.codehaus.plexus.archiver.ArchiverException)19 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)15 File (java.io.File)14 UnArchiver (org.codehaus.plexus.archiver.UnArchiver)14 IOException (java.io.IOException)8 Artifact (org.apache.maven.artifact.Artifact)7 IncludeExcludeFileSelector (org.codehaus.plexus.components.io.fileselectors.IncludeExcludeFileSelector)5 Archiver (org.codehaus.plexus.archiver.Archiver)4 TarArchiver (org.codehaus.plexus.archiver.tar.TarArchiver)4 ArtifactResolverException (org.apache.maven.shared.artifact.resolve.ArtifactResolverException)3 ArrayList (java.util.ArrayList)2 LinkedHashSet (java.util.LinkedHashSet)2 DefaultArtifact (org.apache.maven.artifact.DefaultArtifact)2 ArtifactResolutionException (org.apache.maven.artifact.resolver.ArtifactResolutionException)2 ArtifactFilter (org.apache.maven.artifact.resolver.filter.ArtifactFilter)2 MavenReportException (org.apache.maven.reporting.MavenReportException)2 ArtifactIncludeFilterTransformer (org.apache.maven.shared.artifact.filter.resolve.transform.ArtifactIncludeFilterTransformer)2 ArchiverManager (org.codehaus.plexus.archiver.manager.ArchiverManager)2 AbstractZipArchiver (org.codehaus.plexus.archiver.zip.AbstractZipArchiver)2