Search in sources :

Example 11 with ArtifactResolverException

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

the class DefaultDownloader method downloadOld.

public File downloadOld(String groupId, String artifactId, String version, ArtifactRepository archetypeRepository, ArtifactRepository localRepository, List<ArtifactRepository> remoteRepositories, ProjectBuildingRequest buildingRequest) throws DownloadException, DownloadNotFoundException {
    DefaultArtifactCoordinate jarCoordinate = new DefaultArtifactCoordinate();
    jarCoordinate.setGroupId(groupId);
    jarCoordinate.setArtifactId(artifactId);
    jarCoordinate.setVersion(version);
    try {
        return artifactResolver.resolveArtifact(buildingRequest, jarCoordinate).getArtifact().getFile();
    } catch (ArtifactResolverException e) {
        throw new DownloadException("Error downloading " + jarCoordinate + ".", e);
    }
}
Also used : ArtifactResolverException(org.apache.maven.shared.artifact.resolve.ArtifactResolverException) DefaultArtifactCoordinate(org.apache.maven.shared.artifact.DefaultArtifactCoordinate)

Example 12 with ArtifactResolverException

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

the class AbstractChangesReport method getSkinArtifactFile.

private File getSkinArtifactFile() throws MojoExecutionException {
    Skin skin = Skin.getDefaultSkin();
    DefaultArtifactCoordinate coordinate = new DefaultArtifactCoordinate();
    coordinate.setGroupId(skin.getGroupId());
    coordinate.setArtifactId(skin.getArtifactId());
    coordinate.setVersion(skin.getVersion());
    ProjectBuildingRequest pbr = new DefaultProjectBuildingRequest(mavenSession.getProjectBuildingRequest());
    pbr.setRemoteRepositories(project.getRemoteArtifactRepositories());
    try {
        return resolver.resolveArtifact(pbr, coordinate).getArtifact().getFile();
    } catch (ArtifactResolverException e) {
        throw new MojoExecutionException("Couldn't resolve the skin.", e);
    }
}
Also used : ProjectBuildingRequest(org.apache.maven.project.ProjectBuildingRequest) DefaultProjectBuildingRequest(org.apache.maven.project.DefaultProjectBuildingRequest) ArtifactResolverException(org.apache.maven.shared.artifact.resolve.ArtifactResolverException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) DefaultArtifactCoordinate(org.apache.maven.shared.artifact.DefaultArtifactCoordinate) Skin(org.apache.maven.doxia.site.decoration.Skin) DefaultProjectBuildingRequest(org.apache.maven.project.DefaultProjectBuildingRequest)

Example 13 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, List<Dependency> dependencies, 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());
    for (Dependency dependency : dependencies) {
        DefaultArtifactCoordinate coordinate = new DefaultArtifactCoordinate();
        coordinate.setGroupId(dependency.getGroupId());
        coordinate.setArtifactId(dependency.getArtifactId());
        coordinate.setVersion(dependency.getVersion());
        coordinate.setExtension(artifactHandlerManager.getArtifactHandler(dependency.getType()).getExtension());
        try {
            Artifact artifact = artifactResolver.resolveArtifact(session.getProjectBuildingRequest(), coordinate).getArtifact();
            if (artifactFilter.include(artifact)) {
                resolvedArtifacts.add(artifact);
            }
        } catch (ArtifactResolverException e) {
            getLog().debug("Unable to resolve artifact: " + coordinate);
        }
    }
    return resolvedArtifacts;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ArtifactFilter(org.apache.maven.artifact.resolver.filter.ArtifactFilter) ArtifactResolverException(org.apache.maven.shared.artifact.resolve.ArtifactResolverException) DefaultArtifactCoordinate(org.apache.maven.shared.artifact.DefaultArtifactCoordinate) ArtifactIncludeFilterTransformer(org.apache.maven.shared.artifact.filter.resolve.transform.ArtifactIncludeFilterTransformer) DependencyResolverException(org.apache.maven.shared.dependencies.resolve.DependencyResolverException) Dependency(org.apache.maven.model.Dependency) Artifact(org.apache.maven.artifact.Artifact) ArtifactResult(org.apache.maven.shared.artifact.resolve.ArtifactResult)

Example 14 with ArtifactResolverException

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

the class AbstractFromConfigurationMojo method getArtifact.

/**
 * Resolves the Artifact from the remote repository if necessary. If no version is specified, it will be retrieved
 * from the dependency list or from the DependencyManagement section of the pom.
 *
 * @param artifactItem containing information about artifact from plugin configuration.
 * @return Artifact object representing the specified file.
 * @throws MojoExecutionException with a message if the version can't be found in DependencyManagement.
 */
protected Artifact getArtifact(ArtifactItem artifactItem) throws MojoExecutionException {
    Artifact artifact;
    try {
        // mdep-50 - rolledback for now because it's breaking some functionality.
        /*
             * List listeners = new ArrayList(); Set theSet = new HashSet(); theSet.add( artifact );
             * ArtifactResolutionResult artifactResolutionResult = artifactCollector.collect( theSet, project
             * .getArtifact(), managedVersions, this.local, project.getRemoteArtifactRepositories(),
             * artifactMetadataSource, null, listeners ); Iterator iter =
             * artifactResolutionResult.getArtifactResolutionNodes().iterator(); while ( iter.hasNext() ) {
             * ResolutionNode node = (ResolutionNode) iter.next(); artifact = node.getArtifact(); }
             */
        ProjectBuildingRequest buildingRequest = newResolveArtifactProjectBuildingRequest();
        if (localRepositoryDirectory != null) {
            buildingRequest = repositoryManager.setLocalRepositoryBasedir(buildingRequest, localRepositoryDirectory);
        }
        // Map dependency to artifact coordinate
        DefaultArtifactCoordinate coordinate = new DefaultArtifactCoordinate();
        coordinate.setGroupId(artifactItem.getGroupId());
        coordinate.setArtifactId(artifactItem.getArtifactId());
        coordinate.setVersion(artifactItem.getVersion());
        coordinate.setClassifier(artifactItem.getClassifier());
        final String extension;
        ArtifactHandler artifactHandler = artifactHandlerManager.getArtifactHandler(artifactItem.getType());
        if (artifactHandler != null) {
            extension = artifactHandler.getExtension();
        } else {
            extension = artifactItem.getType();
        }
        coordinate.setExtension(extension);
        artifact = artifactResolver.resolveArtifact(buildingRequest, coordinate).getArtifact();
    } catch (ArtifactResolverException e) {
        throw new MojoExecutionException("Unable to find/resolve artifact.", e);
    }
    return artifact;
}
Also used : ProjectBuildingRequest(org.apache.maven.project.ProjectBuildingRequest) ArtifactResolverException(org.apache.maven.shared.artifact.resolve.ArtifactResolverException) ArtifactHandler(org.apache.maven.artifact.handler.ArtifactHandler) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) DefaultArtifactCoordinate(org.apache.maven.shared.artifact.DefaultArtifactCoordinate) Artifact(org.apache.maven.artifact.Artifact)

Example 15 with ArtifactResolverException

use of org.apache.maven.shared.artifact.resolve.ArtifactResolverException in project maven-plugins 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