use of org.eclipse.aether.resolution.ArtifactResolutionException 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);
}
}
use of org.eclipse.aether.resolution.ArtifactResolutionException in project kie-wb-common by kiegroup.
the class MavenArtifactResolverTest method resolveArtifactOffline.
@Test
public void resolveArtifactOffline() throws Exception {
final boolean[] executedOffline = { true };
RepositorySystemSession session = Aether.getAether().getSession();
assertThat(checksIfArtifactIsPresent(session)).isFalse();
File file = new File("target/test-classes/fake-uberfire-m2repo-editor-backend-100-SNAPSHOT.jar");
assertThat(file).exists();
Artifact artifact = getArtifact();
artifact = artifact.setFile(file);
ArtifactRequest artifactRequest = new ArtifactRequest();
artifactRequest.setArtifact(artifact);
ArtifactResult result;
try {
Aether.getAether().getSystem().resolveArtifact(session, artifactRequest);
} catch (ArtifactResolutionException ex) {
assertThat(ex).isNotNull();
}
deployTestJar(artifact, session);
MavenArtifactResolver resolver = new MavenArtifactResolver() {
public URI resolve(final String groupId, final String artifactId, final String version) throws Exception {
return internalResolver(true, groupId, artifactId, version);
}
URI resolveEmbedded(final String groupId, final String artifactId, final String version) throws IOException {
executedOffline[0] = false;
return super.resolveEmbedded(groupId, artifactId, version);
}
};
URI uri = resolver.resolve(artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion());
assertThat(uri).isNotNull();
assertThat(uri.getPath()).endsWith(File.separator + "fake-uberfire-m2repo-editor-backend" + File.separator + "100-SNAPSHOT" + File.separator + "fake-uberfire-m2repo-editor-backend-100-SNAPSHOT.jar");
result = Aether.getAether().getSystem().resolveArtifact(session, artifactRequest);
assertThat(result.isMissing()).isFalse();
assertThat(result.isResolved()).isTrue();
assertThat(executedOffline[0]).isTrue();
}
use of org.eclipse.aether.resolution.ArtifactResolutionException in project kie-wb-common by kiegroup.
the class MavenArtifactResolverTest method checksIfArtifactIsPresent.
private boolean checksIfArtifactIsPresent(RepositorySystemSession session) {
try {
ArtifactRequest artifactRequest = new ArtifactRequest();
artifactRequest.setArtifact(getArtifact());
Aether.getAether().getSystem().resolveArtifact(session, artifactRequest);
return true;
} catch (ArtifactResolutionException e) {
return false;
}
}
use of org.eclipse.aether.resolution.ArtifactResolutionException in project karaf by apache.
the class Dependency31Helper method resolveById.
@Override
public File resolveById(String id, Log log) throws MojoFailureException {
if (id.startsWith("mvn:")) {
if (id.contains("!")) {
id = id.substring(0, "mvn:".length()) + id.substring(id.indexOf("!") + 1);
}
if (id.endsWith("/")) {
id = id.substring(0, id.length() - 1);
}
}
id = MavenUtil.mvnToAether(id);
if (log.isDebugEnabled()) {
log.debug("Resolving artifact " + id + " from " + projectRepositories);
}
ArtifactResult result;
try {
result = resolveArtifact(MavenUtil.aetherToArtifact(id));
} catch (ArtifactResolutionException e) {
log.warn("Could not resolve " + id, e);
throw new MojoFailureException(format("Couldn't resolve artifact %s", id), e);
}
if (log.isDebugEnabled()) {
log.debug("Resolved artifact " + id + " to " + result.getArtifact().getFile() + " from " + result.getRepository());
}
return result.getArtifact().getFile();
}
use of org.eclipse.aether.resolution.ArtifactResolutionException in project che by eclipse.
the class MavenServerImpl method resolveArtifact.
@Override
public MavenArtifact resolveArtifact(MavenArtifactKey artifactKey, List<MavenRemoteRepository> repositories) throws RemoteException {
Artifact artifact = getMavenComponent(ArtifactFactory.class).createArtifactWithClassifier(artifactKey.getGroupId(), artifactKey.getArtifactId(), artifactKey.getVersion(), artifactKey.getPackaging(), artifactKey.getClassifier());
List<ArtifactRepository> repos = new ArrayList<>();
ArtifactRepositoryFactory factory = getMavenComponent(ArtifactRepositoryFactory.class);
for (MavenRemoteRepository repository : repositories) {
try {
ArtifactRepository artifactRepository = ProjectUtils.buildArtifactRepository(MavenModelUtil.convertToMavenRepository(repository), factory, container);
repos.add(artifactRepository);
} catch (InvalidRepositoryException e) {
MavenServerContext.getLogger().error(e);
}
}
MavenExecutionRequest request = newMavenRequest(null, Collections.emptyList(), Collections.emptyList(), Collections.emptyList());
repos.forEach(request::addRemoteRepository);
DefaultMaven maven = (DefaultMaven) getMavenComponent(Maven.class);
RepositorySystemSession repositorySystemSession = maven.newRepositorySession(request);
org.eclipse.aether.impl.ArtifactResolver artifactResolver = getMavenComponent(org.eclipse.aether.impl.ArtifactResolver.class);
InternalLoggerFactory loggerFactory = new InternalLoggerFactory();
if (artifactResolver instanceof DefaultArtifactResolver) {
((DefaultArtifactResolver) artifactResolver).setLoggerFactory(loggerFactory);
}
org.eclipse.aether.RepositorySystem repositorySystem = getMavenComponent(org.eclipse.aether.RepositorySystem.class);
if (repositorySystem instanceof DefaultRepositorySystem) {
((DefaultRepositorySystem) repositorySystem).setLoggerFactory(loggerFactory);
}
List<RemoteRepository> remoteRepositories = RepositoryUtils.toRepos(request.getRemoteRepositories());
remoteRepositories = repositorySystem.newResolutionRepositories(repositorySystemSession, remoteRepositories);
try {
ArtifactResult artifactResult = repositorySystem.resolveArtifact(repositorySystemSession, new ArtifactRequest(RepositoryUtils.toArtifact(artifact), remoteRepositories, null));
return MavenModelUtil.convertArtifact(RepositoryUtils.toArtifact(artifactResult.getArtifact()), localRepository);
} catch (ArtifactResolutionException e) {
MavenServerContext.getLogger().info(e);
}
return MavenModelUtil.convertArtifact(artifact, localRepository);
}
Aggregations