Search in sources :

Example 26 with ArtifactResolutionResult

use of org.apache.maven.artifact.resolver.ArtifactResolutionResult 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

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