use of org.apache.maven.artifact.resolver.ArtifactResolutionRequest in project maven-plugins by apache.
the class DefaultDependencyResolver method resolveNonTransitively.
Set<Artifact> resolveNonTransitively(final Assembly assembly, final Set<Artifact> dependencyArtifacts, final AssemblerConfigurationSource configSource, final List<ArtifactRepository> repos) throws DependencyResolutionException {
final List<Artifact> missing = new ArrayList<Artifact>();
final Set<Artifact> resolved = new LinkedHashSet<Artifact>();
for (final Artifact depArtifact : dependencyArtifacts) {
ArtifactResolutionRequest req = new ArtifactResolutionRequest();
req.setLocalRepository(configSource.getLocalRepository());
req.setRemoteRepositories(repos);
req.setArtifact(depArtifact);
ArtifactResolutionResult resolve = resolver.resolve(req);
if (resolve.hasExceptions()) {
if (getLogger().isDebugEnabled()) {
getLogger().debug("Failed to resolve: " + depArtifact.getId() + " for assembly: " + assembly.getId());
}
missing.add(depArtifact);
} else {
resolved.add(depArtifact);
}
}
if (!missing.isEmpty()) {
final MavenProject project = configSource.getProject();
final Artifact rootArtifact = project.getArtifact();
final Throwable error = new MultipleArtifactsNotFoundException(rootArtifact, new ArrayList<Artifact>(resolved), missing, repos);
throw new DependencyResolutionException("Failed to resolve dependencies for: " + assembly.getId(), error);
}
return resolved;
}
use of org.apache.maven.artifact.resolver.ArtifactResolutionRequest in project intellij-plugins by JetBrains.
the class RepositoryReplicatorMojo method resolveAndCopyArtifact.
private boolean resolveAndCopyArtifact(Artifact artifact) throws MojoExecutionException, IOException {
if (copiedArtifacts.contains(artifact)) {
return true;
}
copiedArtifacts.add(artifact);
File artifactFile = artifact.getFile();
if (artifactFile == null && !artifact.isResolved()) {
ArtifactResolutionRequest request = new ArtifactResolutionRequest();
request.setArtifact(artifact);
request.setLocalRepository(session.getLocalRepository());
request.setRemoteRepositories(remoteRepositories);
ArtifactResolutionResult result = repositorySystem.resolve(request);
artifactFile = artifact.getFile();
if (!result.isSuccess() && artifactFile == null) {
if (getLog().isDebugEnabled()) {
for (Exception e : result.getExceptions()) {
getLog().error(e);
}
}
throw new MojoExecutionException("Failed to resolve artifact " + artifact);
}
}
return copyArtifact(artifactFile, artifactFile.getPath().substring(localRepositoryBasedirLength));
}
use of org.apache.maven.artifact.resolver.ArtifactResolutionRequest in project sling by apache.
the class FsMountMojo method getArtifactFile.
private File getArtifactFile(Bundle bundle, String type) throws MojoExecutionException {
Artifact artifactObject = repository.createArtifact(bundle.getGroupId(), bundle.getArtifactId(), bundle.getVersion(), type);
ArtifactResolutionRequest request = new ArtifactResolutionRequest();
request.setArtifact(artifactObject);
request.setLocalRepository(localRepository);
request.setRemoteRepositories(remoteRepositories);
ArtifactResolutionResult result = repository.resolve(request);
if (result.isSuccess()) {
return artifactObject.getFile();
} else {
throw new MojoExecutionException("Unable to download artifact: " + artifactObject.toString());
}
}
use of org.apache.maven.artifact.resolver.ArtifactResolutionRequest in project che by eclipse.
the class MavenServerImpl method internalResolveProject.
private MavenResult internalResolveProject(File pom, List<String> activeProfiles, List<String> inactiveProfiles, List<ResolutionListener> dependencyTreeResolutionListeners) {
MavenExecutionRequest request = newMavenRequest(pom, activeProfiles, inactiveProfiles, Collections.emptyList());
request.setUpdateSnapshots(updateSnapshots);
AtomicReference<MavenResult> reference = new AtomicReference<>();
runMavenRequest(request, () -> {
try {
ProjectBuilder builder = getMavenComponent(ProjectBuilder.class);
List<ProjectBuildingResult> resultList = builder.build(Collections.singletonList(pom), false, request.getProjectBuildingRequest());
ProjectBuildingResult result = resultList.get(0);
MavenProject mavenProject = result.getProject();
RepositorySystemSession repositorySession = getMavenComponent(LegacySupport.class).getRepositorySession();
if (repositorySession instanceof DefaultRepositorySystemSession) {
((DefaultRepositorySystemSession) repositorySession).setTransferListener(new ArtifactTransferListener(mavenProgressNotifier));
if (workspaceCache != null) {
((DefaultRepositorySystemSession) repositorySession).setWorkspaceReader(new MavenWorkspaceReader(workspaceCache));
}
}
List<Exception> exceptions = new ArrayList<>();
loadExtensions(mavenProject, exceptions);
mavenProject.setDependencyArtifacts(mavenProject.createArtifacts(getMavenComponent(ArtifactFactory.class), null, null));
ArtifactResolutionRequest resolutionRequest = new ArtifactResolutionRequest();
resolutionRequest.setArtifact(mavenProject.getArtifact());
resolutionRequest.setRemoteRepositories(mavenProject.getRemoteArtifactRepositories());
resolutionRequest.setArtifactDependencies(mavenProject.getDependencyArtifacts());
resolutionRequest.setListeners(dependencyTreeResolutionListeners);
resolutionRequest.setLocalRepository(localRepo);
resolutionRequest.setManagedVersionMap(mavenProject.getManagedVersionMap());
resolutionRequest.setResolveTransitively(true);
resolutionRequest.setResolveRoot(false);
ArtifactResolver resolver = getMavenComponent(ArtifactResolver.class);
ArtifactResolutionResult resolve = resolver.resolve(resolutionRequest);
mavenProject.setArtifacts(resolve.getArtifacts());
reference.set(new MavenResult(mavenProject, exceptions));
} catch (Exception e) {
reference.set(new MavenResult(null, null, Collections.singletonList(e)));
}
});
return reference.get();
}
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();
}
Aggregations