Search in sources :

Example 21 with ArtifactResolverException

use of org.apache.maven.shared.artifact.resolve.ArtifactResolverException in project maven-plugins by apache.

the class ResourceResolver method resolveAndUnpack.

/**
 * @param artifacts the artifacts to resolve
 * @param config the configuration
 * @param validClassifiers
 * @param propagateErrors
 * @return list of <dependencyConflictId, absolutePath>
 * @throws ArtifactResolutionException if an exception occurs
 * @throws ArtifactNotFoundException if an exception occurs
 */
private Collection<Map.Entry<String, 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<>(artifacts);
    final ArtifactFilter filter;
    if (config.filter() != null) {
        filter = new ArtifactIncludeFilterTransformer().transform(config.filter());
    } else {
        filter = null;
    }
    final List<Map.Entry<String, String>> result = new ArrayList<>(artifacts.size());
    for (final Artifact a : artifactSet) {
        if (!validClassifiers.contains(a.getClassifier()) || (filter != null && !filter.include(a))) {
            continue;
        }
        Artifact resolvedArtifact;
        try {
            resolvedArtifact = resolver.resolveArtifact(config.getBuildingRequest(), a).getArtifact();
        } catch (ArtifactResolverException e1) {
            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(resolvedArtifact.getFile());
            unArchiver.extract();
            result.add(new AbstractMap.SimpleEntry<String, String>(a.getDependencyConflictId(), 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) ArtifactResolverException(org.apache.maven.shared.artifact.resolve.ArtifactResolverException) 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) Artifact(org.apache.maven.artifact.Artifact) DefaultArtifact(org.apache.maven.artifact.DefaultArtifact) AbstractMap(java.util.AbstractMap) ArtifactFilter(org.apache.maven.artifact.resolver.filter.ArtifactFilter) ArtifactResolutionException(org.apache.maven.artifact.resolver.ArtifactResolutionException) Entry(java.util.Map.Entry) File(java.io.File) UnArchiver(org.codehaus.plexus.archiver.UnArchiver) NoSuchArchiverException(org.codehaus.plexus.archiver.manager.NoSuchArchiverException)

Example 22 with ArtifactResolverException

use of org.apache.maven.shared.artifact.resolve.ArtifactResolverException in project maven-plugins by apache.

the class AbstractJavadocMojo method getArtifactsAbsolutePath.

/**
     * Return the Javadoc artifact path and its transitive dependencies path from the local repository
     *
     * @param javadocArtifact not null
     * @return a list of locale artifacts absolute path
     * @throws MavenReportException if any
     */
private List<String> getArtifactsAbsolutePath(JavadocPathArtifact javadocArtifact) throws MavenReportException {
    if ((StringUtils.isEmpty(javadocArtifact.getGroupId())) && (StringUtils.isEmpty(javadocArtifact.getArtifactId())) && (StringUtils.isEmpty(javadocArtifact.getVersion()))) {
        return Collections.emptyList();
    }
    List<String> path = new ArrayList<String>();
    try {
        Artifact artifact = createAndResolveArtifact(javadocArtifact);
        path.add(artifact.getFile().getAbsolutePath());
        DefaultDependableCoordinate coordinate = new DefaultDependableCoordinate();
        coordinate.setGroupId(javadocArtifact.getGroupId());
        coordinate.setArtifactId(javadocArtifact.getArtifactId());
        coordinate.setVersion(javadocArtifact.getVersion());
        Iterable<ArtifactResult> deps = dependencyResolver.resolveDependencies(session.getProjectBuildingRequest(), coordinate, ScopeFilter.including("compile", "provided"));
        for (ArtifactResult a : deps) {
            path.add(a.getArtifact().getFile().getAbsolutePath());
        }
        return path;
    } catch (ArtifactResolverException e) {
        throw new MavenReportException("Unable to resolve artifact:" + javadocArtifact, e);
    } catch (DependencyResolverException e) {
        throw new MavenReportException("Unable to resolve dependencies for:" + javadocArtifact, e);
    }
}
Also used : ArtifactResolverException(org.apache.maven.shared.artifact.resolve.ArtifactResolverException) DefaultDependableCoordinate(org.apache.maven.shared.dependencies.DefaultDependableCoordinate) ArrayList(java.util.ArrayList) DependencyResolverException(org.apache.maven.shared.dependencies.resolve.DependencyResolverException) 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) ArtifactResult(org.apache.maven.shared.artifact.resolve.ArtifactResult) MavenReportException(org.apache.maven.reporting.MavenReportException)

Example 23 with ArtifactResolverException

use of org.apache.maven.shared.artifact.resolve.ArtifactResolverException in project maven-plugins by apache.

the class PurgeLocalRepositoryMojo method getFilteredResolvedArtifacts.

private Set<Artifact> getFilteredResolvedArtifacts(MavenProject project, Set<Artifact> artifacts, TransformableFilter filter) {
    try {
        Iterable<ArtifactResult> results = dependencyResolver.resolveDependencies(session.getProjectBuildingRequest(), project.getModel(), filter);
        Set<Artifact> resolvedArtifacts = new LinkedHashSet<Artifact>();
        for (ArtifactResult artResult : results) {
            resolvedArtifacts.add(artResult.getArtifact());
        }
        return resolvedArtifacts;
    } catch (DependencyResolverException e) {
        getLog().info("Unable to resolve all dependencies for : " + project.getGroupId() + ":" + project.getArtifactId() + ":" + project.getVersion() + ". Falling back to non-transitive mode for initial artifact resolution.");
    }
    Set<Artifact> resolvedArtifacts = new LinkedHashSet<Artifact>();
    ArtifactFilter artifactFilter = filter.transform(new ArtifactIncludeFilterTransformer());
    // purge anyway
    for (Artifact artifact : artifacts) {
        if (artifactFilter.include(artifact)) {
            try {
                ArtifactResult artifactResult = artifactResolver.resolveArtifact(session.getProjectBuildingRequest(), artifact);
                resolvedArtifacts.add(artifactResult.getArtifact());
            } catch (ArtifactResolverException e) {
                getLog().debug("Unable to resolve artifact: " + artifact);
            }
        }
    }
    return resolvedArtifacts;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ArtifactFilter(org.apache.maven.artifact.resolver.filter.ArtifactFilter) ArtifactResolverException(org.apache.maven.shared.artifact.resolve.ArtifactResolverException) ArtifactIncludeFilterTransformer(org.apache.maven.shared.artifact.filter.resolve.transform.ArtifactIncludeFilterTransformer) DependencyResolverException(org.apache.maven.shared.dependencies.resolve.DependencyResolverException) Artifact(org.apache.maven.artifact.Artifact) ArtifactResult(org.apache.maven.shared.artifact.resolve.ArtifactResult)

Example 24 with ArtifactResolverException

use of org.apache.maven.shared.artifact.resolve.ArtifactResolverException in project maven-dependency-plugin by apache.

the class AbstractDependencyFilterMojo method addParentArtifacts.

private void addParentArtifacts(MavenProject project, Set<Artifact> artifacts) throws MojoExecutionException {
    while (project.hasParent()) {
        project = project.getParent();
        if (artifacts.contains(project.getArtifact())) {
            // artifact already in the set
            break;
        }
        try {
            ProjectBuildingRequest buildingRequest = newResolveArtifactProjectBuildingRequest();
            Artifact resolvedArtifact = artifactResolver.resolveArtifact(buildingRequest, project.getArtifact()).getArtifact();
            artifacts.add(resolvedArtifact);
        } catch (ArtifactResolverException e) {
            throw new MojoExecutionException(e.getMessage(), e);
        }
    }
}
Also used : ProjectBuildingRequest(org.apache.maven.project.ProjectBuildingRequest) ArtifactResolverException(org.apache.maven.shared.artifact.resolve.ArtifactResolverException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) Artifact(org.apache.maven.artifact.Artifact)

Example 25 with ArtifactResolverException

use of org.apache.maven.shared.artifact.resolve.ArtifactResolverException in project maven-dependency-plugin by apache.

the class AbstractDependencyFilterMojo method resolve.

/**
 * @param coordinates The set of artifact coordinates{@link ArtifactCoordinate}.
 * @param stopOnFailure <code>true</code> if we should fail with exception if an artifact couldn't be resolved
 *            <code>false</code> otherwise.
 * @return the resolved artifacts. {@link Artifact}.
 * @throws MojoExecutionException in case of error.
 */
protected Set<Artifact> resolve(Set<ArtifactCoordinate> coordinates, boolean stopOnFailure) throws MojoExecutionException {
    ProjectBuildingRequest buildingRequest = newResolveArtifactProjectBuildingRequest();
    Set<Artifact> resolvedArtifacts = new LinkedHashSet<Artifact>();
    for (ArtifactCoordinate coordinate : coordinates) {
        try {
            Artifact artifact = artifactResolver.resolveArtifact(buildingRequest, coordinate).getArtifact();
            resolvedArtifacts.add(artifact);
        } catch (ArtifactResolverException ex) {
            // an error occurred during resolution, log it an continue
            getLog().debug("error resolving: " + coordinate);
            getLog().debug(ex);
            if (stopOnFailure) {
                throw new MojoExecutionException("error resolving: " + coordinate, ex);
            }
        }
    }
    return resolvedArtifacts;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ProjectBuildingRequest(org.apache.maven.project.ProjectBuildingRequest) ArtifactCoordinate(org.apache.maven.shared.artifact.ArtifactCoordinate) ArtifactResolverException(org.apache.maven.shared.artifact.resolve.ArtifactResolverException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) Artifact(org.apache.maven.artifact.Artifact)

Aggregations

ArtifactResolverException (org.apache.maven.shared.artifact.resolve.ArtifactResolverException)35 Artifact (org.apache.maven.artifact.Artifact)28 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)14 DefaultArtifactCoordinate (org.apache.maven.shared.artifact.DefaultArtifactCoordinate)13 ProjectBuildingRequest (org.apache.maven.project.ProjectBuildingRequest)12 ArrayList (java.util.ArrayList)11 DependencyResolverException (org.apache.maven.shared.dependencies.resolve.DependencyResolverException)9 IOException (java.io.IOException)8 LinkedHashSet (java.util.LinkedHashSet)8 MavenReportException (org.apache.maven.reporting.MavenReportException)8 File (java.io.File)7 ArtifactResult (org.apache.maven.shared.artifact.resolve.ArtifactResult)7 ArtifactFilter (org.apache.maven.artifact.resolver.filter.ArtifactFilter)6 DefaultProjectBuildingRequest (org.apache.maven.project.DefaultProjectBuildingRequest)5 ArtifactIncludeFilterTransformer (org.apache.maven.shared.artifact.filter.resolve.transform.ArtifactIncludeFilterTransformer)4 DefaultDependableCoordinate (org.apache.maven.shared.dependencies.DefaultDependableCoordinate)4 ArtifactRepository (org.apache.maven.artifact.repository.ArtifactRepository)3 BootclasspathArtifact (org.apache.maven.plugin.javadoc.options.BootclasspathArtifact)3 DocletArtifact (org.apache.maven.plugin.javadoc.options.DocletArtifact)3 JavadocPathArtifact (org.apache.maven.plugin.javadoc.options.JavadocPathArtifact)3