use of org.apache.maven.artifact.resolver.ArtifactResolutionResult in project asterixdb by apache.
the class SourcePointerResolver method ensureCDDLSourcesPointer.
private void ensureCDDLSourcesPointer(Collection<Project> projects, ArtifactRepository central, ArtifactResolutionRequest request) throws ProjectBuildingException, IOException {
for (Project p : projects) {
if (p.getSourcePointer() != null) {
continue;
}
mojo.getLog().debug("finding sources for artifact: " + p);
Artifact sourcesArtifact = new DefaultArtifact(p.getGroupId(), p.getArtifactId(), p.getVersion(), Artifact.SCOPE_COMPILE, "jar", "sources", null);
MavenProject mavenProject = mojo.resolveDependency(sourcesArtifact);
sourcesArtifact.setArtifactHandler(mavenProject.getArtifact().getArtifactHandler());
final ArtifactRepository localRepo = mojo.getSession().getLocalRepository();
final File marker = new File(localRepo.getBasedir(), localRepo.pathOf(sourcesArtifact) + ".oncentral");
final File antimarker = new File(localRepo.getBasedir(), localRepo.pathOf(sourcesArtifact) + ".nocentral");
boolean onCentral;
if (marker.exists() || antimarker.exists()) {
onCentral = marker.exists();
} else {
request.setArtifact(sourcesArtifact);
ArtifactResolutionResult result = mojo.getArtifactResolver().resolve(request);
mojo.getLog().debug("result: " + result);
onCentral = result.isSuccess();
if (onCentral) {
FileUtils.touch(marker);
} else {
FileUtils.touch(antimarker);
}
}
StringBuilder noticeBuilder = new StringBuilder("You may obtain ");
noticeBuilder.append(p.getName()).append(" in Source Code form code here:\n");
if (onCentral) {
noticeBuilder.append(central.getUrl()).append("/").append(central.pathOf(sourcesArtifact));
} else {
mojo.getLog().warn("Unable to find sources in 'central' for " + p + ", falling back to project url: " + p.getUrl());
noticeBuilder.append(p.getUrl() != null ? p.getUrl() : "MISSING SOURCE POINTER");
}
p.setSourcePointer(noticeBuilder.toString());
}
}
use of org.apache.maven.artifact.resolver.ArtifactResolutionResult in project tycho by eclipse.
the class TychoOsgiRuntimeLocator method resolveDependency.
public Artifact resolveDependency(MavenSession session, Dependency dependency) throws MavenExecutionException {
Artifact artifact = repositorySystem.createArtifact(dependency.getGroupId(), dependency.getArtifactId(), dependency.getVersion(), dependency.getType());
ArtifactResolutionRequest request = new ArtifactResolutionRequest();
request.setArtifact(artifact);
request.setResolveRoot(true).setResolveTransitively(false);
request.setLocalRepository(session.getLocalRepository());
request.setRemoteRepositories(getPluginRepositories(session));
request.setCache(session.getRepositoryCache());
request.setOffline(session.isOffline());
request.setProxies(session.getSettings().getProxies());
request.setForceUpdate(session.getRequest().isUpdateSnapshots());
ArtifactResolutionResult result = repositorySystem.resolve(request);
try {
resolutionErrorHandler.throwErrors(request, result);
} catch (ArtifactResolutionException e) {
throw new MavenExecutionException("Could not resolve artifact for Tycho's OSGi runtime", e);
}
return artifact;
}
use of org.apache.maven.artifact.resolver.ArtifactResolutionResult in project tycho by eclipse.
the class TestMojo method getFrameworkExtensions.
private List<File> getFrameworkExtensions() throws MojoExecutionException {
List<File> files = new ArrayList<>();
if (frameworkExtensions != null) {
for (Dependency frameworkExtension : frameworkExtensions) {
Artifact artifact = repositorySystem.createDependencyArtifact(frameworkExtension);
ArtifactResolutionRequest request = new ArtifactResolutionRequest();
request.setArtifact(artifact);
request.setResolveRoot(true).setResolveTransitively(false);
request.setLocalRepository(session.getLocalRepository());
// XXX wrong repositories -- these are user artifacts, not plugin artifacts
request.setRemoteRepositories(project.getPluginArtifactRepositories());
request.setOffline(session.isOffline());
request.setForceUpdate(session.getRequest().isUpdateSnapshots());
ArtifactResolutionResult result = repositorySystem.resolve(request);
try {
resolutionErrorHandler.throwErrors(request, result);
} catch (ArtifactResolutionException e) {
throw new MojoExecutionException("Failed to resolve framework extension " + frameworkExtension.getManagementKey(), e);
}
files.add(artifact.getFile());
}
}
return files;
}
use of org.apache.maven.artifact.resolver.ArtifactResolutionResult 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.ArtifactResolutionResult in project tycho by eclipse.
the class AbstractOsgiCompilerMojo method getClasspath.
@Override
public List<ClasspathEntry> getClasspath() throws MojoExecutionException {
TychoProject projectType = getBundleProject();
ArrayList<ClasspathEntry> classpath = new ArrayList<>(((BundleProject) projectType).getClasspath(project));
if (extraClasspathElements != null) {
ArtifactRepository localRepository = session.getLocalRepository();
List<ArtifactRepository> remoteRepositories = project.getRemoteArtifactRepositories();
for (Dependency extraDependency : extraClasspathElements) {
Artifact artifact = repositorySystem.createDependencyArtifact(extraDependency);
ArtifactResolutionRequest request = new ArtifactResolutionRequest();
request.setArtifact(artifact);
request.setLocalRepository(localRepository);
request.setRemoteRepositories(remoteRepositories);
request.setResolveRoot(true);
request.setResolveTransitively(true);
ArtifactResolutionResult result = repositorySystem.resolve(request);
if (result.hasExceptions()) {
throw new MojoExecutionException("Could not resolve extra classpath entry", result.getExceptions().get(0));
}
for (Artifact b : result.getArtifacts()) {
MavenProject bProject = null;
if (b instanceof ProjectArtifact) {
bProject = ((ProjectArtifact) b).getProject();
}
ArrayList<File> bLocations = new ArrayList<>();
// TODO properly handle multiple project locations maybe
bLocations.add(b.getFile());
classpath.add(new DefaultClasspathEntry(DefaultReactorProject.adapt(bProject), null, bLocations, null));
}
}
}
return classpath;
}
Aggregations