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