use of org.eclipse.aether.resolution.ArtifactResult in project spring-boot by spring-projects.
the class ModifiedClassPathClassLoader method resolveCoordinates.
private static List<URL> resolveCoordinates(String[] coordinates) {
Exception latestFailure = null;
DefaultServiceLocator serviceLocator = MavenRepositorySystemUtils.newServiceLocator();
serviceLocator.addService(RepositoryConnectorFactory.class, BasicRepositoryConnectorFactory.class);
serviceLocator.addService(TransporterFactory.class, HttpTransporterFactory.class);
RepositorySystem repositorySystem = serviceLocator.getService(RepositorySystem.class);
DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession();
LocalRepository localRepository = new LocalRepository(System.getProperty("user.home") + "/.m2/repository");
RemoteRepository remoteRepository = new RemoteRepository.Builder("central", "default", "https://repo.maven.apache.org/maven2").build();
session.setLocalRepositoryManager(repositorySystem.newLocalRepositoryManager(session, localRepository));
for (int i = 0; i < MAX_RESOLUTION_ATTEMPTS; i++) {
CollectRequest collectRequest = new CollectRequest(null, Arrays.asList(remoteRepository));
collectRequest.setDependencies(createDependencies(coordinates));
DependencyRequest dependencyRequest = new DependencyRequest(collectRequest, null);
try {
DependencyResult result = repositorySystem.resolveDependencies(session, dependencyRequest);
List<URL> resolvedArtifacts = new ArrayList<>();
for (ArtifactResult artifact : result.getArtifactResults()) {
resolvedArtifacts.add(artifact.getArtifact().getFile().toURI().toURL());
}
return resolvedArtifacts;
} catch (Exception ex) {
latestFailure = ex;
}
}
throw new IllegalStateException("Resolution failed after " + MAX_RESOLUTION_ATTEMPTS + " attempts", latestFailure);
}
use of org.eclipse.aether.resolution.ArtifactResult in project grails-maven by grails.
the class AbstractGrailsMojo method resolveArtifact.
protected File resolveArtifact(String artifactId) throws MojoExecutionException {
ArtifactRequest request = new ArtifactRequest();
request.setArtifact(new DefaultArtifact(artifactId));
request.setRepositories(remoteRepos);
getLog().debug("Resolving artifact " + artifactId + " from " + remoteRepos);
ArtifactResult result;
File file;
try {
result = repoSystem.resolveArtifact(repoSession, request);
file = result.getArtifact().getFile();
} catch (ArtifactResolutionException e) {
throw new MojoExecutionException(e.getMessage(), e);
}
getLog().debug("Resolved artifact " + artifactId + " to " + file + " from " + result.getRepository());
return file;
}
use of org.eclipse.aether.resolution.ArtifactResult in project drools by kiegroup.
the class MavenProjectLoader method resolve.
private static boolean resolve(final RepositorySystemSession session, final Artifact artifact) {
final ArtifactRequest artifactRequest = new ArtifactRequest();
final org.eclipse.aether.artifact.Artifact jarArtifact = new org.eclipse.aether.artifact.DefaultArtifact(artifact.getGroupId(), artifact.getArtifactId(), artifact.getClassifier(), "jar", artifact.getVersion());
artifactRequest.setArtifact(jarArtifact);
try {
ArtifactResult result = Aether.getAether().getSystem().resolveArtifact(session, artifactRequest);
return result != null && result.isResolved();
} catch (final Exception are) {
log.info(are.getMessage(), are);
return false;
}
}
use of org.eclipse.aether.resolution.ArtifactResult in project drools by kiegroup.
the class MavenRepository method resolveArtifact.
public Artifact resolveArtifact(String artifactName, boolean logUnresolvedArtifact) {
Artifact artifact = new DefaultArtifact(artifactName);
ArtifactRequest artifactRequest = new ArtifactRequest();
artifactRequest.setArtifact(artifact);
for (RemoteRepository repo : remoteRepositoriesForRequest) {
artifactRequest.addRepository(repo);
}
RepositorySystemSession session = aether.getSession();
Object sessionChecks = null;
boolean isSnapshot = artifactName.endsWith("-SNAPSHOT");
if (artifactName.endsWith("-SNAPSHOT")) {
// ensure to always update snapshots
sessionChecks = session.getData().get(SESSION_CHECKS);
session.getData().set(SESSION_CHECKS, null);
}
try {
ArtifactResult artifactResult = aether.getSystem().resolveArtifact(session, artifactRequest);
return artifactResult.getArtifact();
} catch (ArtifactResolutionException e) {
if (logUnresolvedArtifact) {
if (log.isDebugEnabled()) {
log.debug("Unable to resolve artifact: " + artifactName, e);
} else {
log.warn("Unable to resolve artifact: " + artifactName);
}
}
return null;
} finally {
if (sessionChecks != null) {
session.getData().set(SESSION_CHECKS, sessionChecks);
}
}
}
use of org.eclipse.aether.resolution.ArtifactResult in project meecrowave by apache.
the class MeecrowaveBundleMojo method resolve.
private File resolve(final String group, final String artifact, final String version, final String classifier) {
final DefaultArtifact art = new DefaultArtifact(group, artifact, classifier, "jar", version);
final ArtifactRequest artifactRequest = new ArtifactRequest().setArtifact(art).setRepositories(remoteRepositories);
final LocalRepositoryManager lrm = session.getLocalRepositoryManager();
art.setFile(new File(lrm.getRepository().getBasedir(), lrm.getPathForLocalArtifact(artifactRequest.getArtifact())));
try {
final ArtifactResult result = repositorySystem.resolveArtifact(session, artifactRequest);
if (result.isMissing()) {
throw new IllegalStateException("Can't find commons-cli, please add it to the pom.");
}
return result.getArtifact().getFile();
} catch (final ArtifactResolutionException e) {
throw new IllegalStateException(e.getMessage(), e);
}
}
Aggregations