use of org.apache.maven.artifact.resolver.ArtifactResolutionResult in project cxf by apache.
the class AbstractCodegenMojo method resolveArbitraryWsdl.
private Artifact resolveArbitraryWsdl(Artifact artifact) {
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;
}
use of org.apache.maven.artifact.resolver.ArtifactResolutionResult 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.ArtifactResolutionResult in project che by eclipse.
the class CheArtifactResolver method resolveWithExceptions.
public ArtifactResolutionResult resolveWithExceptions(ArtifactResolutionRequest request) throws ArtifactResolutionException, ArtifactNotFoundException {
ArtifactResolutionResult result = resolve(request);
// We have collected all the problems so let's mimic the way the old code worked and just blow up right here.
// That's right lets just let it rip right here and send a big incomprehensible blob of text at unsuspecting
// users. Bad dog!
resolutionErrorHandler.throwErrors(request, result);
return result;
}
use of org.apache.maven.artifact.resolver.ArtifactResolutionResult in project camel by apache.
the class RunMojo method resolveExecutableDependencies.
private Set<Artifact> resolveExecutableDependencies(Artifact executablePomArtifact) throws MojoExecutionException {
Set<Artifact> executableDependencies;
try {
MavenProject executableProject = this.projectBuilder.buildFromRepository(executablePomArtifact, this.remoteRepositories, this.localRepository);
// get all of the dependencies for the executable project
List<Artifact> dependencies = CastUtils.cast(executableProject.getDependencies());
// make Artifacts of all the dependencies
Set<Artifact> dependencyArtifacts = CastUtils.cast(MavenMetadataSource.createArtifacts(this.artifactFactory, dependencies, null, null, null));
// not forgetting the Artifact of the project itself
dependencyArtifacts.add(executableProject.getArtifact());
// resolve all dependencies transitively to obtain a comprehensive
// list of assemblies
ArtifactResolutionResult result = artifactResolver.resolveTransitively(dependencyArtifacts, executablePomArtifact, Collections.emptyMap(), this.localRepository, this.remoteRepositories, metadataSource, null, Collections.emptyList());
executableDependencies = CastUtils.cast(result.getArtifacts());
} catch (Exception ex) {
throw new MojoExecutionException("Encountered problems resolving dependencies of the executable " + "in preparation for its execution.", ex);
}
return executableDependencies;
}
use of org.apache.maven.artifact.resolver.ArtifactResolutionResult in project maven-plugins by apache.
the class AbstractJavadocMojo method getClasspath.
/**
* Method that sets the classpath elements that will be specified in the javadoc <code>-classpath</code>
* parameter. Since we have all the sources of the current reactor, it is sufficient to consider the
* dependencies of the reactor modules, excluding the module artifacts which may not yet be available
* when the reactor project is built for the first time.
*
* @return a String that contains the concatenated classpath elements, separated by the System pathSeparator
* string (colon (<code>:</code>) on Solaris or semi-colon (<code>;</code>) on Windows).
* @throws MavenReportException if any.
* @see File#pathSeparator
*/
private String getClasspath() throws MavenReportException {
List<String> classpathElements = new ArrayList<String>();
Map<String, Artifact> compileArtifactMap = new HashMap<String, Artifact>();
if (isTest()) {
classpathElements.addAll(getProjectBuildOutputDirs(project));
}
populateCompileArtifactMap(compileArtifactMap, getProjectArtifacts(project));
if (isAggregator() && project.isExecutionRoot()) {
List<Artifact> reactorArtifacts = new ArrayList<Artifact>();
for (MavenProject p : reactorProjects) {
reactorArtifacts.add(p.getArtifact());
}
try {
for (MavenProject subProject : reactorProjects) {
if (subProject != project) {
classpathElements.addAll(getProjectBuildOutputDirs(subProject));
Set<Artifact> dependencyArtifacts = subProject.createArtifacts(factory, null, null);
// do not attempt to resolve artifacts of the current reactor which may not exist yet
dependencyArtifacts.removeAll(reactorArtifacts);
if (!dependencyArtifacts.isEmpty()) {
ArtifactResolutionResult result = null;
try {
result = resolver.resolveTransitively(dependencyArtifacts, subProject.getArtifact(), subProject.getManagedVersionMap(), localRepository, subProject.getRemoteArtifactRepositories(), artifactMetadataSource);
} catch (ArtifactNotFoundException e) {
throw new MavenReportException(e.getMessage(), e);
} catch (ArtifactResolutionException e) {
throw new MavenReportException(e.getMessage(), e);
}
if (result == null) {
continue;
}
populateCompileArtifactMap(compileArtifactMap, getCompileArtifacts(result.getArtifacts()));
if (getLog().isDebugEnabled()) {
StringBuilder sb = new StringBuilder();
sb.append("Compiled artifacts for ");
sb.append(subProject.getGroupId()).append(":");
sb.append(subProject.getArtifactId()).append(":");
sb.append(subProject.getVersion()).append('\n');
for (Artifact a : compileArtifactMap.values()) {
sb.append(a.getFile()).append('\n');
}
getLog().debug(sb.toString());
}
}
}
}
} catch (InvalidDependencyVersionException e) {
throw new MavenReportException(e.getMessage(), e);
}
}
for (Artifact a : compileArtifactMap.values()) {
classpathElements.add(a.getFile().toString());
}
if (additionalDependencies != null) {
for (Dependency dependency : additionalDependencies) {
Artifact artifact = resolveDependency(dependency);
String path = artifact.getFile().toString();
getLog().debug("add additional artifact with path " + path);
classpathElements.add(path);
}
}
return StringUtils.join(classpathElements.iterator(), File.pathSeparator);
}
Aggregations