use of org.apache.maven.artifact.resolver.ArtifactResolutionResult in project fabric8-maven-plugin by fabric8io.
the class ArtifactResolverServiceMavenImpl method resolveArtifact.
@Override
public File resolveArtifact(String groupId, String artifactId, String version, String type) {
String canonicalString = groupId + ":" + artifactId + ":" + type + ":" + version;
Artifact art = repositorySystem.createArtifact(groupId, artifactId, version, type);
ArtifactResolutionRequest request = new ArtifactResolutionRequest().setArtifact(art).setResolveRoot(true).setOffline(false).setRemoteRepositories(project.getRemoteArtifactRepositories()).setResolveTransitively(false);
ArtifactResolutionResult res = repositorySystem.resolve(request);
if (!res.isSuccess()) {
throw new IllegalStateException("Cannot resolve artifact " + canonicalString);
}
for (Artifact artifact : res.getArtifacts()) {
if (artifact.getGroupId().equals(groupId) && artifact.getArtifactId().equals(artifactId) && artifact.getVersion().equals(version) && artifact.getType().equals(type)) {
return artifact.getFile();
}
}
throw new IllegalStateException("Cannot find artifact " + canonicalString + " within the resolved resources");
}
use of org.apache.maven.artifact.resolver.ArtifactResolutionResult in project providence by morimekta.
the class BaseGenerateSourcesMojo method resolveDependency.
private void resolveDependency(Dependency dep, TreeSet<File> includes, File workingDir, Set<Artifact> resolvedArtifacts) throws MojoFailureException, MojoExecutionException {
Artifact artifact = repositorySystem.createDependencyArtifact(dep);
// Avoid resolving stuff we already have resolved.
if (resolvedArtifacts.contains(artifact)) {
return;
}
ArtifactResolutionRequest request = new ArtifactResolutionRequest();
request.setLocalRepository(localRepository);
request.setRemoteRepositories(remoteRepositories);
request.setManagedVersionMap(project.getManagedVersionMap());
request.setResolveTransitively(false);
request.setArtifact(artifact);
ArtifactResolutionResult result = artifactResolver.resolve(request);
boolean found = false;
for (Artifact resolved : result.getArtifacts()) {
if (artifact.equals(resolved)) {
resolvedArtifacts.add(resolved);
addDependencyInclude(workingDir, includes, resolved);
found = true;
break;
}
}
if (!found) {
throw new MojoFailureException("Unable to resolve providence dependency: " + artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" + artifact.getVersion() + ":" + artifact.getClassifier());
}
}
use of org.apache.maven.artifact.resolver.ArtifactResolutionResult in project tycho by eclipse.
the class DevWorkspaceResolver method getBundleInfo.
public DevBundleInfo getBundleInfo(MavenSession session, String groupId, String artifacyId, String version, List<ArtifactRepository> repositories) {
Artifact pomArtifact = repositorySystem.createArtifact(groupId, artifacyId, version, "pom");
ArtifactResolutionRequest request = new ArtifactResolutionRequest();
request.setArtifact(pomArtifact);
request.setResolveRoot(true).setResolveTransitively(false);
request.setLocalRepository(session.getLocalRepository());
request.setRemoteRepositories(repositories);
request.setCache(session.getRepositoryCache());
request.setOffline(session.isOffline());
request.setForceUpdate(session.getRequest().isUpdateSnapshots());
ArtifactResolutionResult result = repositorySystem.resolve(request);
if (result.isSuccess()) {
return getBundleInfo(pomArtifact.getFile().getParentFile());
}
return null;
}
use of org.apache.maven.artifact.resolver.ArtifactResolutionResult in project maven-plugins by apache.
the class DefaultDependencyResolver method resolveTransitively.
private Set<Artifact> resolveTransitively(final Set<Artifact> dependencyArtifacts, final List<ArtifactRepository> repos, final ArtifactFilter filter, final AssemblerConfigurationSource configSource) throws DependencyResolutionException {
final MavenProject project = configSource.getProject();
ArtifactResolutionRequest req = new ArtifactResolutionRequest();
req.setLocalRepository(configSource.getLocalRepository());
req.setResolveRoot(false);
req.setRemoteRepositories(repos);
req.setResolveTransitively(true);
req.setArtifact(project.getArtifact());
req.setArtifactDependencies(dependencyArtifacts);
req.setManagedVersionMap(project.getManagedVersionMap());
req.setCollectionFilter(filter);
req.setOffline(configSource.getMavenSession().isOffline());
req.setForceUpdate(configSource.getMavenSession().getRequest().isUpdateSnapshots());
req.setServers(configSource.getMavenSession().getRequest().getServers());
req.setMirrors(configSource.getMavenSession().getRequest().getMirrors());
req.setProxies(configSource.getMavenSession().getRequest().getProxies());
ArtifactResolutionResult result;
result = resolver.resolve(req);
if (result.hasExceptions()) {
throw new DependencyResolutionException("Failed to resolve dependencies for assembly: ", result.getExceptions().get(0));
}
getLogger().debug("While resolving dependencies of " + project.getId() + ":");
FilterUtils.reportFilteringStatistics(Collections.singleton(filter), getLogger());
return result.getArtifacts();
}
use of org.apache.maven.artifact.resolver.ArtifactResolutionResult 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;
}
Aggregations