Search in sources :

Example 1 with NoSuchArchiverException

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

the class AbstractJavadocMojo method copyAdditionalJavadocResources.

/**
     * Method that copy additional Javadoc resources from given artifacts.
     *
     * @param anOutputDirectory the output directory
     * @throws MavenReportException if any
     * @see #resourcesArtifacts
     */
private void copyAdditionalJavadocResources(File anOutputDirectory) throws MavenReportException {
    Set<ResourcesArtifact> resourcesArtifacts = collectResourcesArtifacts();
    if (isEmpty(resourcesArtifacts)) {
        return;
    }
    UnArchiver unArchiver;
    try {
        unArchiver = archiverManager.getUnArchiver("jar");
    } catch (NoSuchArchiverException e) {
        throw new MavenReportException("Unable to extract resources artifact. " + "No archiver for 'jar' available.", e);
    }
    for (ResourcesArtifact item : resourcesArtifacts) {
        Artifact artifact;
        try {
            artifact = createAndResolveArtifact(item);
        } catch (ArtifactResolverException e) {
            throw new MavenReportException("Unable to resolve artifact:" + item, e);
        }
        unArchiver.setSourceFile(artifact.getFile());
        unArchiver.setDestDirectory(anOutputDirectory);
        // remove the META-INF directory from resource artifact
        IncludeExcludeFileSelector[] selectors = new IncludeExcludeFileSelector[] { new IncludeExcludeFileSelector() };
        selectors[0].setExcludes(new String[] { "META-INF/**" });
        unArchiver.setFileSelectors(selectors);
        getLog().info("Extracting contents of resources artifact: " + artifact.getArtifactId());
        try {
            unArchiver.extract();
        } catch (ArchiverException e) {
            throw new MavenReportException("Extraction of resources failed. Artifact that failed was: " + artifact.getArtifactId(), e);
        }
    }
}
Also used : ArtifactResolverException(org.apache.maven.shared.artifact.resolve.ArtifactResolverException) ResourcesArtifact(org.apache.maven.plugin.javadoc.options.ResourcesArtifact) IncludeExcludeFileSelector(org.codehaus.plexus.components.io.fileselectors.IncludeExcludeFileSelector) ArchiverException(org.codehaus.plexus.archiver.ArchiverException) NoSuchArchiverException(org.codehaus.plexus.archiver.manager.NoSuchArchiverException) UnArchiver(org.codehaus.plexus.archiver.UnArchiver) NoSuchArchiverException(org.codehaus.plexus.archiver.manager.NoSuchArchiverException) JavadocPathArtifact(org.apache.maven.plugin.javadoc.options.JavadocPathArtifact) Artifact(org.apache.maven.artifact.Artifact) DocletArtifact(org.apache.maven.plugin.javadoc.options.DocletArtifact) BootclasspathArtifact(org.apache.maven.plugin.javadoc.options.BootclasspathArtifact) ResourcesArtifact(org.apache.maven.plugin.javadoc.options.ResourcesArtifact) TagletArtifact(org.apache.maven.plugin.javadoc.options.TagletArtifact) MavenReportException(org.apache.maven.reporting.MavenReportException)

Example 2 with NoSuchArchiverException

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

the class ResourceResolver method resolveAndUnpack.

private List<String> resolveAndUnpack(final List<Artifact> artifacts, final SourceResolverConfig config, final List<String> validClassifiers, final boolean propagateErrors) throws ArtifactResolutionException, ArtifactNotFoundException {
    // NOTE: Since these are '-sources' and '-test-sources' artifacts, they won't actually 
    // resolve transitively...this is just used to aggregate resolution failures into a single 
    // exception.
    final Set<Artifact> artifactSet = new LinkedHashSet<Artifact>(artifacts);
    final Artifact pomArtifact = config.project().getArtifact();
    final ArtifactRepository localRepo = config.localRepository();
    final List<ArtifactRepository> remoteRepos = config.project().getRemoteArtifactRepositories();
    final ArtifactFilter filter;
    if (config.filter() != null) {
        filter = new ArtifactIncludeFilterTransformer().transform(config.filter());
    } else {
        filter = null;
    }
    ArtifactFilter resolutionFilter = null;
    if (filter != null) {
        // Wrap the filter in a ProjectArtifactFilter in order to always include the pomArtifact for resolution.
        // NOTE that this is necessary, b/c the -sources artifacts are added dynamically to the pomArtifact
        // and the resolver also checks the dependency trail with the given filter, thus the pomArtifact has
        // to be explicitly included by the filter, otherwise the -sources artifacts won't be resolved.
        resolutionFilter = new ProjectArtifactFilter(pomArtifact, filter);
    }
    Map<String, Artifact> managed = config.project().getManagedVersionMap();
    final ArtifactResolutionResult resolutionResult = resolver.resolveTransitively(artifactSet, pomArtifact, managed, localRepo, remoteRepos, artifactMetadataSource, resolutionFilter);
    final List<String> result = new ArrayList<String>(artifacts.size());
    for (final Artifact a : (Collection<Artifact>) resolutionResult.getArtifacts()) {
        if (!validClassifiers.contains(a.getClassifier()) || (filter != null && !filter.include(a))) {
            continue;
        }
        final File d = new File(config.outputBasedir(), a.getArtifactId() + "-" + a.getVersion() + "-" + a.getClassifier());
        if (!d.exists()) {
            d.mkdirs();
        }
        try {
            final UnArchiver unArchiver = archiverManager.getUnArchiver(a.getType());
            unArchiver.setDestDirectory(d);
            unArchiver.setSourceFile(a.getFile());
            unArchiver.extract();
            result.add(d.getAbsolutePath());
        } catch (final NoSuchArchiverException e) {
            if (propagateErrors) {
                throw new ArtifactResolutionException("Failed to retrieve valid un-archiver component: " + a.getType(), a, e);
            }
        } catch (final ArchiverException e) {
            if (propagateErrors) {
                throw new ArtifactResolutionException("Failed to unpack: " + a.getId(), a, e);
            }
        }
    }
    return result;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) NoSuchArchiverException(org.codehaus.plexus.archiver.manager.NoSuchArchiverException) ArchiverException(org.codehaus.plexus.archiver.ArchiverException) ArtifactIncludeFilterTransformer(org.apache.maven.shared.artifact.filter.resolve.transform.ArtifactIncludeFilterTransformer) ArrayList(java.util.ArrayList) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) Artifact(org.apache.maven.artifact.Artifact) DefaultArtifact(org.apache.maven.artifact.DefaultArtifact) ArtifactFilter(org.apache.maven.artifact.resolver.filter.ArtifactFilter) ArtifactResolutionException(org.apache.maven.artifact.resolver.ArtifactResolutionException) ArtifactResolutionResult(org.apache.maven.artifact.resolver.ArtifactResolutionResult) Collection(java.util.Collection) File(java.io.File) UnArchiver(org.codehaus.plexus.archiver.UnArchiver) NoSuchArchiverException(org.codehaus.plexus.archiver.manager.NoSuchArchiverException)

Example 3 with NoSuchArchiverException

use of org.codehaus.plexus.archiver.manager.NoSuchArchiverException in project sofa-ark by alipay.

the class ArkPluginMojo method execute.

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    Archiver archiver;
    try {
        archiver = getArchiver();
    } catch (NoSuchArchiverException e) {
        throw new MojoExecutionException(e.getMessage());
    }
    if (!outputDirectory.exists()) {
        outputDirectory.mkdirs();
    }
    String fileName = getFileName();
    File destination = new File(outputDirectory, fileName);
    if (destination.exists()) {
        destination.delete();
    }
    archiver.setDestFile(destination);
    Set<Artifact> artifacts = project.getArtifacts();
    artifacts = filterExcludeArtifacts(artifacts);
    Set<Artifact> conflictArtifacts = filterConflictArtifacts(artifacts);
    addArkPluginArtifact(archiver, artifacts, conflictArtifacts);
    addArkPluginConfig(archiver);
    try {
        archiver.createArchive();
    } catch (ArchiverException e) {
        throw new MojoExecutionException(e.getMessage());
    } catch (IOException e) {
        throw new MojoExecutionException(e.getMessage());
    }
    if (isAttach()) {
        projectHelper.attachArtifact(project, destination, getClassifier());
    }
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) NoSuchArchiverException(org.codehaus.plexus.archiver.manager.NoSuchArchiverException) ArchiverException(org.codehaus.plexus.archiver.ArchiverException) AbstractZipArchiver(org.codehaus.plexus.archiver.zip.AbstractZipArchiver) Archiver(org.codehaus.plexus.archiver.Archiver) NoSuchArchiverException(org.codehaus.plexus.archiver.manager.NoSuchArchiverException) Artifact(org.apache.maven.artifact.Artifact)

Example 4 with NoSuchArchiverException

use of org.codehaus.plexus.archiver.manager.NoSuchArchiverException in project midpoint by Evolveum.

the class SchemaDistMojo method unpack.

private void unpack(ArtifactItem artifactItem, File destDir) throws MojoExecutionException {
    Artifact artifact = artifactItem.getArtifact();
    File file = artifact.getFile();
    if (file == null) {
        throw new MojoExecutionException("No file for artifact " + artifact);
    }
    if (file.isDirectory()) {
        try {
            FileUtils.copyDirectory(file, destDir);
        } catch (IOException e) {
            throw new MojoExecutionException("Error copying directory " + file + " to " + destDir + ": " + e.getMessage(), e);
        }
    } else {
        try {
            UnArchiver unArchiver = archiverManager.getUnArchiver(artifact.getType());
            unArchiver.setSourceFile(file);
            unArchiver.setDestDirectory(destDir);
            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);
            }
            unArchiver.extract();
        } catch (ArchiverException | NoSuchArchiverException e) {
            throw new MojoExecutionException("Error unpacking file: " + file + " to: " + destDir + "\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) Artifact(org.apache.maven.artifact.Artifact) UnArchiver(org.codehaus.plexus.archiver.UnArchiver) NoSuchArchiverException(org.codehaus.plexus.archiver.manager.NoSuchArchiverException)

Example 5 with NoSuchArchiverException

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

the class DockerAssemblyManager method createChangedFilesTarBall.

private File createChangedFilesTarBall(File archive, File archiveDir) throws MojoExecutionException {
    try {
        TarArchiver archiver = (TarArchiver) archiverManager.getArchiver("tar");
        archiver.setLongfile(TarLongFileMode.posix);
        archiver.addFileSet(DefaultFileSet.fileSet(archiveDir));
        archiver.setDestFile(archive);
        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);
    } catch (RuntimeException e) {
        e.printStackTrace();
        throw e;
    }
}
Also used : TarArchiver(org.codehaus.plexus.archiver.tar.TarArchiver) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) IOException(java.io.IOException) NoSuchArchiverException(org.codehaus.plexus.archiver.manager.NoSuchArchiverException)

Aggregations

NoSuchArchiverException (org.codehaus.plexus.archiver.manager.NoSuchArchiverException)21 ArchiverException (org.codehaus.plexus.archiver.ArchiverException)18 UnArchiver (org.codehaus.plexus.archiver.UnArchiver)14 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)13 File (java.io.File)12 Artifact (org.apache.maven.artifact.Artifact)7 IOException (java.io.IOException)6 IncludeExcludeFileSelector (org.codehaus.plexus.components.io.fileselectors.IncludeExcludeFileSelector)5 Archiver (org.codehaus.plexus.archiver.Archiver)4 ArtifactResolverException (org.apache.maven.shared.artifact.resolve.ArtifactResolverException)3 TarArchiver (org.codehaus.plexus.archiver.tar.TarArchiver)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