Search in sources :

Example 11 with ArtifactResolutionRequest

use of org.apache.maven.artifact.resolver.ArtifactResolutionRequest in project aries by apache.

the class VersionCheckerMojo method resolve.

private File resolve(String artifactDescriptor) {
    String[] s = artifactDescriptor.split(":");
    String type = (s.length >= 4 ? s[3] : "jar");
    Artifact artifact = repository.createArtifact(s[0], s[1], s[2], type);
    ArtifactResolutionRequest request = new ArtifactResolutionRequest();
    request.setArtifact(artifact);
    request.setResolveRoot(true).setResolveTransitively(false);
    request.setServers(session.getRequest().getServers());
    request.setMirrors(session.getRequest().getMirrors());
    request.setProxies(session.getRequest().getProxies());
    request.setLocalRepository(session.getLocalRepository());
    request.setRemoteRepositories(session.getRequest().getRemoteRepositories());
    repository.resolve(request);
    return artifact.getFile();
}
Also used : ArtifactResolutionRequest(org.apache.maven.artifact.resolver.ArtifactResolutionRequest) Artifact(org.apache.maven.artifact.Artifact)

Example 12 with ArtifactResolutionRequest

use of org.apache.maven.artifact.resolver.ArtifactResolutionRequest in project asterixdb by apache.

the class SourcePointerResolver method collectSourcePointers.

private void collectSourcePointers() throws ProjectBuildingException, IOException {
    try (StubArtifactRepository stubRepo = new StubArtifactRepository()) {
        DefaultRepositoryRequest rr = new DefaultRepositoryRequest();
        rr.setLocalRepository(stubRepo);
        ArtifactRepository central = getCentralRepository();
        rr.setRemoteRepositories(Collections.singletonList(central));
        ArtifactResolutionRequest request = new ArtifactResolutionRequest(rr);
        for (LicensedProjects lp : mojo.getLicenseMap().values()) {
            if (lp.getLicense().getDisplayName() != null && lp.getLicense().getDisplayName().toLowerCase().contains("cddl")) {
                ensureCDDLSourcesPointer(lp.getProjects(), central, request);
            }
        }
    }
}
Also used : LicensedProjects(org.apache.hyracks.maven.license.project.LicensedProjects) ArtifactResolutionRequest(org.apache.maven.artifact.resolver.ArtifactResolutionRequest) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) DefaultRepositoryRequest(org.apache.maven.artifact.repository.DefaultRepositoryRequest)

Example 13 with ArtifactResolutionRequest

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

the class AbstractCompilerMojo method resolveProcessorPathEntries.

private List<String> resolveProcessorPathEntries() throws MojoExecutionException {
    if (annotationProcessorPaths == null || annotationProcessorPaths.isEmpty()) {
        return null;
    }
    try {
        Set<Artifact> requiredArtifacts = new LinkedHashSet<Artifact>();
        for (DependencyCoordinate coord : annotationProcessorPaths) {
            ArtifactHandler handler = artifactHandlerManager.getArtifactHandler(coord.getType());
            Artifact artifact = new DefaultArtifact(coord.getGroupId(), coord.getArtifactId(), VersionRange.createFromVersionSpec(coord.getVersion()), Artifact.SCOPE_RUNTIME, coord.getType(), coord.getClassifier(), handler, false);
            requiredArtifacts.add(artifact);
        }
        ArtifactResolutionRequest request = new ArtifactResolutionRequest().setArtifact(requiredArtifacts.iterator().next()).setResolveRoot(true).setResolveTransitively(true).setArtifactDependencies(requiredArtifacts).setLocalRepository(session.getLocalRepository()).setRemoteRepositories(project.getRemoteArtifactRepositories());
        ArtifactResolutionResult resolutionResult = repositorySystem.resolve(request);
        resolutionErrorHandler.throwErrors(request, resolutionResult);
        List<String> elements = new ArrayList<String>(resolutionResult.getArtifacts().size());
        for (Object resolved : resolutionResult.getArtifacts()) {
            elements.add(((Artifact) resolved).getFile().getAbsolutePath());
        }
        return elements;
    } catch (Exception e) {
        throw new MojoExecutionException("Resolution of annotationProcessorPath dependencies failed: " + e.getLocalizedMessage(), e);
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ArrayList(java.util.ArrayList) Artifact(org.apache.maven.artifact.Artifact) DefaultArtifact(org.apache.maven.artifact.DefaultArtifact) NoSuchCompilerException(org.codehaus.plexus.compiler.manager.NoSuchCompilerException) CompilerException(org.codehaus.plexus.compiler.CompilerException) InclusionScanException(org.codehaus.plexus.compiler.util.scan.InclusionScanException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) InvocationTargetException(java.lang.reflect.InvocationTargetException) CompilerNotImplementedException(org.codehaus.plexus.compiler.CompilerNotImplementedException) ArtifactHandler(org.apache.maven.artifact.handler.ArtifactHandler) ArtifactResolutionRequest(org.apache.maven.artifact.resolver.ArtifactResolutionRequest) ArtifactResolutionResult(org.apache.maven.artifact.resolver.ArtifactResolutionResult) DefaultArtifact(org.apache.maven.artifact.DefaultArtifact)

Example 14 with ArtifactResolutionRequest

use of org.apache.maven.artifact.resolver.ArtifactResolutionRequest in project cxf by apache.

the class AbstractCodeGeneratorMojo method resolveRemoteWadlArtifact.

private Artifact resolveRemoteWadlArtifact(Artifact artifact) throws MojoExecutionException {
    /**
     * First try to find the artifact in the reactor projects of the maven session.
     * So an artifact that is not yet built can be resolved
     */
    List<MavenProject> rProjects = mavenSession.getProjects();
    for (MavenProject rProject : rProjects) {
        if (artifact.getGroupId().equals(rProject.getGroupId()) && artifact.getArtifactId().equals(rProject.getArtifactId()) && artifact.getVersion().equals(rProject.getVersion())) {
            Set<Artifact> artifacts = rProject.getArtifacts();
            for (Artifact pArtifact : artifacts) {
                if ("wadl".equals(pArtifact.getType())) {
                    return pArtifact;
                }
            }
        }
    }
    ArtifactResolutionRequest request = new ArtifactResolutionRequest();
    request.setArtifact(artifact);
    request.setResolveRoot(true).setResolveTransitively(false);
    request.setServers(mavenSession.getRequest().getServers());
    request.setMirrors(mavenSession.getRequest().getMirrors());
    request.setProxies(mavenSession.getRequest().getProxies());
    request.setLocalRepository(mavenSession.getLocalRepository());
    request.setRemoteRepositories(mavenSession.getRequest().getRemoteRepositories());
    ArtifactResolutionResult result = repositorySystem.resolve(request);
    Artifact resolvedArtifact = result.getOriginatingArtifact();
    if (resolvedArtifact == null && !CollectionUtils.isEmpty(result.getArtifacts())) {
        resolvedArtifact = result.getArtifacts().iterator().next();
    }
    return resolvedArtifact;
}
Also used : MavenProject(org.apache.maven.project.MavenProject) ArtifactResolutionRequest(org.apache.maven.artifact.resolver.ArtifactResolutionRequest) ArtifactResolutionResult(org.apache.maven.artifact.resolver.ArtifactResolutionResult) DocumentArtifact(org.apache.cxf.maven_plugin.common.DocumentArtifact) Artifact(org.apache.maven.artifact.Artifact)

Aggregations

ArtifactResolutionRequest (org.apache.maven.artifact.resolver.ArtifactResolutionRequest)14 ArtifactResolutionResult (org.apache.maven.artifact.resolver.ArtifactResolutionResult)11 Artifact (org.apache.maven.artifact.Artifact)8 ArrayList (java.util.ArrayList)4 MavenProject (org.apache.maven.project.MavenProject)4 LinkedHashSet (java.util.LinkedHashSet)3 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)3 File (java.io.File)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 ArtifactResolver (org.apache.maven.artifact.resolver.ArtifactResolver)2 ComponentLookupException (org.codehaus.plexus.component.repository.exception.ComponentLookupException)2 RepositorySystemSession (org.eclipse.aether.RepositorySystemSession)2 IOException (java.io.IOException)1 RemoteException (java.rmi.RemoteException)1 LinkedHashMap (java.util.LinkedHashMap)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 DocumentArtifact (org.apache.cxf.maven_plugin.common.DocumentArtifact)1 LicensedProjects (org.apache.hyracks.maven.license.project.LicensedProjects)1 MavenExecutionException (org.apache.maven.MavenExecutionException)1