Search in sources :

Example 11 with ArtifactResolutionResult

use of org.apache.maven.artifact.resolver.ArtifactResolutionResult in project fabric8-maven-plugin by fabric8io.

the class ArtifactResolverServiceMavenImpl method resolveArtifact.

@Override
public File resolveArtifact(String groupId, String artifactId, String version, String type) {
    String canonicalString = groupId + ":" + artifactId + ":" + type + ":" + version;
    Artifact art = repositorySystem.createArtifact(groupId, artifactId, version, type);
    ArtifactResolutionRequest request = new ArtifactResolutionRequest().setArtifact(art).setResolveRoot(true).setOffline(false).setRemoteRepositories(project.getRemoteArtifactRepositories()).setResolveTransitively(false);
    ArtifactResolutionResult res = repositorySystem.resolve(request);
    if (!res.isSuccess()) {
        throw new IllegalStateException("Cannot resolve artifact " + canonicalString);
    }
    for (Artifact artifact : res.getArtifacts()) {
        if (artifact.getGroupId().equals(groupId) && artifact.getArtifactId().equals(artifactId) && artifact.getVersion().equals(version) && artifact.getType().equals(type)) {
            return artifact.getFile();
        }
    }
    throw new IllegalStateException("Cannot find artifact " + canonicalString + " within the resolved resources");
}
Also used : ArtifactResolutionRequest(org.apache.maven.artifact.resolver.ArtifactResolutionRequest) ArtifactResolutionResult(org.apache.maven.artifact.resolver.ArtifactResolutionResult) Artifact(org.apache.maven.artifact.Artifact)

Example 12 with ArtifactResolutionResult

use of org.apache.maven.artifact.resolver.ArtifactResolutionResult in project providence by morimekta.

the class BaseGenerateSourcesMojo method resolveDependency.

private void resolveDependency(Dependency dep, TreeSet<File> includes, File workingDir, Set<Artifact> resolvedArtifacts) throws MojoFailureException, MojoExecutionException {
    Artifact artifact = repositorySystem.createDependencyArtifact(dep);
    // Avoid resolving stuff we already have resolved.
    if (resolvedArtifacts.contains(artifact)) {
        return;
    }
    ArtifactResolutionRequest request = new ArtifactResolutionRequest();
    request.setLocalRepository(localRepository);
    request.setRemoteRepositories(remoteRepositories);
    request.setManagedVersionMap(project.getManagedVersionMap());
    request.setResolveTransitively(false);
    request.setArtifact(artifact);
    ArtifactResolutionResult result = artifactResolver.resolve(request);
    boolean found = false;
    for (Artifact resolved : result.getArtifacts()) {
        if (artifact.equals(resolved)) {
            resolvedArtifacts.add(resolved);
            addDependencyInclude(workingDir, includes, resolved);
            found = true;
            break;
        }
    }
    if (!found) {
        throw new MojoFailureException("Unable to resolve providence dependency: " + artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" + artifact.getVersion() + ":" + artifact.getClassifier());
    }
}
Also used : ArtifactResolutionRequest(org.apache.maven.artifact.resolver.ArtifactResolutionRequest) ArtifactResolutionResult(org.apache.maven.artifact.resolver.ArtifactResolutionResult) MojoFailureException(org.apache.maven.plugin.MojoFailureException) Artifact(org.apache.maven.artifact.Artifact)

Example 13 with ArtifactResolutionResult

use of org.apache.maven.artifact.resolver.ArtifactResolutionResult in project tycho by eclipse.

the class DevWorkspaceResolver method getBundleInfo.

public DevBundleInfo getBundleInfo(MavenSession session, String groupId, String artifacyId, String version, List<ArtifactRepository> repositories) {
    Artifact pomArtifact = repositorySystem.createArtifact(groupId, artifacyId, version, "pom");
    ArtifactResolutionRequest request = new ArtifactResolutionRequest();
    request.setArtifact(pomArtifact);
    request.setResolveRoot(true).setResolveTransitively(false);
    request.setLocalRepository(session.getLocalRepository());
    request.setRemoteRepositories(repositories);
    request.setCache(session.getRepositoryCache());
    request.setOffline(session.isOffline());
    request.setForceUpdate(session.getRequest().isUpdateSnapshots());
    ArtifactResolutionResult result = repositorySystem.resolve(request);
    if (result.isSuccess()) {
        return getBundleInfo(pomArtifact.getFile().getParentFile());
    }
    return null;
}
Also used : ArtifactResolutionRequest(org.apache.maven.artifact.resolver.ArtifactResolutionRequest) ArtifactResolutionResult(org.apache.maven.artifact.resolver.ArtifactResolutionResult) Artifact(org.apache.maven.artifact.Artifact)

Example 14 with ArtifactResolutionResult

use of org.apache.maven.artifact.resolver.ArtifactResolutionResult in project maven-plugins by apache.

the class DefaultDependencyResolver method resolveTransitively.

private Set<Artifact> resolveTransitively(final Set<Artifact> dependencyArtifacts, final List<ArtifactRepository> repos, final ArtifactFilter filter, final AssemblerConfigurationSource configSource) throws DependencyResolutionException {
    final MavenProject project = configSource.getProject();
    ArtifactResolutionRequest req = new ArtifactResolutionRequest();
    req.setLocalRepository(configSource.getLocalRepository());
    req.setResolveRoot(false);
    req.setRemoteRepositories(repos);
    req.setResolveTransitively(true);
    req.setArtifact(project.getArtifact());
    req.setArtifactDependencies(dependencyArtifacts);
    req.setManagedVersionMap(project.getManagedVersionMap());
    req.setCollectionFilter(filter);
    req.setOffline(configSource.getMavenSession().isOffline());
    req.setForceUpdate(configSource.getMavenSession().getRequest().isUpdateSnapshots());
    req.setServers(configSource.getMavenSession().getRequest().getServers());
    req.setMirrors(configSource.getMavenSession().getRequest().getMirrors());
    req.setProxies(configSource.getMavenSession().getRequest().getProxies());
    ArtifactResolutionResult result;
    result = resolver.resolve(req);
    if (result.hasExceptions()) {
        throw new DependencyResolutionException("Failed to resolve dependencies for assembly: ", result.getExceptions().get(0));
    }
    getLogger().debug("While resolving dependencies of " + project.getId() + ":");
    FilterUtils.reportFilteringStatistics(Collections.singleton(filter), getLogger());
    return result.getArtifacts();
}
Also used : MavenProject(org.apache.maven.project.MavenProject) ArtifactResolutionRequest(org.apache.maven.artifact.resolver.ArtifactResolutionRequest) ArtifactResolutionResult(org.apache.maven.artifact.resolver.ArtifactResolutionResult)

Example 15 with ArtifactResolutionResult

use of org.apache.maven.artifact.resolver.ArtifactResolutionResult in project maven-plugins by apache.

the class DefaultDependencyResolver method resolveNonTransitively.

Set<Artifact> resolveNonTransitively(final Assembly assembly, final Set<Artifact> dependencyArtifacts, final AssemblerConfigurationSource configSource, final List<ArtifactRepository> repos) throws DependencyResolutionException {
    final List<Artifact> missing = new ArrayList<Artifact>();
    final Set<Artifact> resolved = new LinkedHashSet<Artifact>();
    for (final Artifact depArtifact : dependencyArtifacts) {
        ArtifactResolutionRequest req = new ArtifactResolutionRequest();
        req.setLocalRepository(configSource.getLocalRepository());
        req.setRemoteRepositories(repos);
        req.setArtifact(depArtifact);
        ArtifactResolutionResult resolve = resolver.resolve(req);
        if (resolve.hasExceptions()) {
            if (getLogger().isDebugEnabled()) {
                getLogger().debug("Failed to resolve: " + depArtifact.getId() + " for assembly: " + assembly.getId());
            }
            missing.add(depArtifact);
        } else {
            resolved.add(depArtifact);
        }
    }
    if (!missing.isEmpty()) {
        final MavenProject project = configSource.getProject();
        final Artifact rootArtifact = project.getArtifact();
        final Throwable error = new MultipleArtifactsNotFoundException(rootArtifact, new ArrayList<Artifact>(resolved), missing, repos);
        throw new DependencyResolutionException("Failed to resolve dependencies for: " + assembly.getId(), error);
    }
    return resolved;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) MavenProject(org.apache.maven.project.MavenProject) ArtifactResolutionRequest(org.apache.maven.artifact.resolver.ArtifactResolutionRequest) ArtifactResolutionResult(org.apache.maven.artifact.resolver.ArtifactResolutionResult) ArrayList(java.util.ArrayList) MultipleArtifactsNotFoundException(org.apache.maven.artifact.resolver.MultipleArtifactsNotFoundException) Artifact(org.apache.maven.artifact.Artifact)

Aggregations

ArtifactResolutionResult (org.apache.maven.artifact.resolver.ArtifactResolutionResult)26 ArtifactResolutionRequest (org.apache.maven.artifact.resolver.ArtifactResolutionRequest)20 Artifact (org.apache.maven.artifact.Artifact)19 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)9 MavenProject (org.apache.maven.project.MavenProject)9 ArrayList (java.util.ArrayList)8 File (java.io.File)6 ArtifactResolutionException (org.apache.maven.artifact.resolver.ArtifactResolutionException)5 LinkedHashSet (java.util.LinkedHashSet)4 Dependency (org.apache.maven.model.Dependency)4 MojoFailureException (org.apache.maven.plugin.MojoFailureException)4 DefaultArtifact (org.apache.maven.artifact.DefaultArtifact)3 ArtifactRepository (org.apache.maven.artifact.repository.ArtifactRepository)3 IOException (java.io.IOException)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 MalformedURLException (java.net.MalformedURLException)2 MavenExecutionException (org.apache.maven.MavenExecutionException)2 ArtifactNotFoundException (org.apache.maven.artifact.resolver.ArtifactNotFoundException)2 ArtifactResolver (org.apache.maven.artifact.resolver.ArtifactResolver)2 ArtifactFilter (org.apache.maven.artifact.resolver.filter.ArtifactFilter)2