use of org.eclipse.aether.resolution.ArtifactResult 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.ArtifactResult in project kie-wb-common by kiegroup.
the class MavenArtifactResolver method internalResolver.
URI internalResolver(final boolean isOffline, final String groupId, final String artifactId, final String version) throws Exception {
try {
if (!isOffline) {
return resolveEmbedded(groupId, artifactId, version);
}
GAV gav = new GAV(groupId, artifactId, version);
org.eclipse.aether.artifact.Artifact jarArtifact = new DefaultArtifact(gav.getGroupId(), gav.getArtifactId(), JAR_ARTIFACT, gav.getVersion());
RepositorySystemSession session = Aether.getAether().getSession();
ArtifactRequest artifactReq = new ArtifactRequest();
artifactReq.setArtifact(jarArtifact);
ArtifactResult result = Aether.getAether().getSystem().resolveArtifact(session, artifactReq);
return result.getArtifact().getFile().toURI();
} catch (Exception e) {
logger.error("Unable to get artifact: " + groupId + ":" + artifactId + ":" + version + " from maven repository", e);
throw new Exception("Unable to get artifact: " + groupId + ":" + artifactId + ":" + version + " from maven repository", e);
}
}
use of org.eclipse.aether.resolution.ArtifactResult 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.ArtifactResult in project spf4j by zolyfarkas.
the class MavenRepositoryUtils method resolveArtifact.
public static File resolveArtifact(final String groupId, final String artifactId, final String classifier, final String extension, final String versionExpr, final List<RemoteRepository> repos, final RepositorySystem repositorySystem, final RepositorySystemSession session) throws ArtifactResolutionException {
Artifact artifact = new DefaultArtifact(groupId, artifactId, classifier, extension, versionExpr);
ArtifactRequest artifactRequest = new ArtifactRequest();
artifactRequest.setArtifact(artifact);
artifactRequest.setRepositories(repos);
ArtifactResult artifactResult = repositorySystem.resolveArtifact(session, artifactRequest);
artifact = artifactResult.getArtifact();
return artifact.getFile();
}
use of org.eclipse.aether.resolution.ArtifactResult in project che by eclipse.
the class CheArtifactResolver method resolveOrig.
private void resolveOrig(Artifact artifact, List<ArtifactRepository> remoteRepositories, RepositorySystemSession session) throws ArtifactResolutionException, ArtifactNotFoundException {
if (artifact == null) {
return;
}
if (Artifact.SCOPE_SYSTEM.equals(artifact.getScope())) {
File systemFile = artifact.getFile();
if (systemFile == null) {
throw new ArtifactNotFoundException("System artifact: " + artifact + " has no file attached", artifact);
}
if (!systemFile.exists()) {
throw new ArtifactNotFoundException("System artifact: " + artifact + " not found in path: " + systemFile, artifact);
}
if (!systemFile.isFile()) {
throw new ArtifactNotFoundException("System artifact: " + artifact + " is not a file: " + systemFile, artifact);
}
artifact.setResolved(true);
return;
}
if (!artifact.isResolved()) {
ArtifactResult result;
try {
ArtifactRequest artifactRequest = new ArtifactRequest();
artifactRequest.setArtifact(RepositoryUtils.toArtifact(artifact));
artifactRequest.setRepositories(RepositoryUtils.toRepos(remoteRepositories));
// Maven 2.x quirk: an artifact always points at the local repo, regardless whether resolved or not
LocalRepositoryManager lrm = session.getLocalRepositoryManager();
String path = lrm.getPathForLocalArtifact(artifactRequest.getArtifact());
artifact.setFile(new File(lrm.getRepository().getBasedir(), path));
result = repoSystem.resolveArtifact(session, artifactRequest);
} catch (org.eclipse.aether.resolution.ArtifactResolutionException e) {
if (e.getCause() instanceof org.eclipse.aether.transfer.ArtifactNotFoundException) {
throw new ArtifactNotFoundException(e.getMessage(), artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), artifact.getType(), artifact.getClassifier(), remoteRepositories, artifact.getDownloadUrl(), artifact.getDependencyTrail(), e);
} else {
throw new ArtifactResolutionException(e.getMessage(), artifact, remoteRepositories, e);
}
}
artifact.selectVersion(result.getArtifact().getVersion());
artifact.setFile(result.getArtifact().getFile());
artifact.setResolved(true);
if (artifact.isSnapshot()) {
Matcher matcher = Artifact.VERSION_FILE_PATTERN.matcher(artifact.getVersion());
if (matcher.matches()) {
Snapshot snapshot = new Snapshot();
snapshot.setTimestamp(matcher.group(2));
try {
snapshot.setBuildNumber(Integer.parseInt(matcher.group(3)));
artifact.addMetadata(new SnapshotArtifactRepositoryMetadata(artifact, snapshot));
} catch (NumberFormatException e) {
logger.warn("Invalid artifact version " + artifact.getVersion() + ": " + e.getMessage());
}
}
}
}
}
Aggregations