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;
}
Aggregations