use of org.eclipse.aether.resolution.ArtifactResult in project bnd by bndtools.
the class RemotePostProcessor method postProcessRelease.
private ArtifactResult postProcessRelease(ArtifactRequest request, Artifact artifact) throws MojoExecutionException {
for (RemoteRepository repository : request.getRepositories()) {
if (!repository.getPolicy(false).isEnabled()) {
// Skip the repo if it isn't enabled for releases
continue;
}
// Remove the workspace from the session so that we don't use it
DefaultRepositorySystemSession newSession = new DefaultRepositorySystemSession(session);
newSession.setWorkspaceReader(null);
// Find the snapshot metadata for the module
MetadataRequest mr = new MetadataRequest().setRepository(repository).setMetadata(new DefaultMetadata(artifact.getGroupId(), artifact.getArtifactId(), null, "maven-metadata.xml", RELEASE));
for (MetadataResult metadataResult : system.resolveMetadata(newSession, singletonList(mr))) {
if (metadataResult.isResolved()) {
try {
Metadata read = metadataReader.read(metadataResult.getMetadata().getFile(), null);
Versioning versioning = read.getVersioning();
if (versioning == null || versioning.getVersions() == null || versioning.getVersions().isEmpty()) {
continue;
} else if (versioning.getVersions().contains(artifact.getVersion())) {
ArtifactResult result = system.resolveArtifact(newSession, new ArtifactRequest().setArtifact(artifact).addRepository(repository));
if (result.isResolved()) {
File toUse = new File(session.getLocalRepository().getBasedir(), session.getLocalRepositoryManager().getPathForLocalArtifact(artifact));
if (!toUse.exists()) {
logger.warn("The resolved artifact {} does not exist at {}", artifact, toUse);
continue;
} else {
logger.debug("Located snapshot file {} for artifact {}", toUse, artifact);
}
result.getArtifact().setFile(toUse);
return result;
}
}
} catch (Exception e) {
throw new MojoExecutionException("Unable to read project metadata for " + artifact, e);
}
}
}
}
logger.debug("Unable to resolve a remote repository containing {}", artifact);
return null;
}
use of org.eclipse.aether.resolution.ArtifactResult in project fabric8 by jboss-fuse.
the class AetherBasedResolver method resolveFile.
/**
* Resolve maven artifact as file in repository.
*/
public File resolveFile(Artifact artifact, MavenRepositoryURL repositoryURL, Exception previousException) throws IOException {
List<LocalRepository> defaultRepos = selectDefaultRepositories();
List<RemoteRepository> remoteRepos = selectRepositories();
if (repositoryURL != null) {
addRepo(remoteRepos, repositoryURL);
}
if (previousException != null) {
// we'll try using previous repositories, without these that will fail again anyway
List<RemoteRepository> altered = new LinkedList<>();
RepositoryException repositoryException = findAetherException(previousException);
if (repositoryException instanceof ArtifactResolutionException) {
// check only this aggregate exception and assume it's related to current artifact
ArtifactResult result = ((ArtifactResolutionException) repositoryException).getResult();
if (result != null && result.getRequest() != null && result.getRequest().getArtifact().equals(artifact)) {
// - these exceptions contain repository that was checked
for (Exception exception : result.getExceptions()) {
RepositoryException singleException = findAetherException(exception);
if (singleException instanceof ArtifactTransferException) {
RemoteRepository repository = ((ArtifactTransferException) singleException).getRepository();
if (repository != null) {
RetryChance chance = isRetryableException(singleException);
if (chance == RetryChance.NEVER) {
LOG.debug("Removing " + repository + " from list of repositories, previous exception: " + singleException.getClass().getName() + ": " + singleException.getMessage());
} else {
altered.add(repository);
}
}
}
}
// swap list of repos now
remoteRepos = altered;
}
}
}
assignProxyAndMirrors(remoteRepos);
File resolved = resolve(defaultRepos, remoteRepos, artifact);
LOG.debug("Resolved ({}) as {}", artifact.toString(), resolved.getAbsolutePath());
return resolved;
}
use of org.eclipse.aether.resolution.ArtifactResult in project spf4j by zolyfarkas.
the class MavenRepositoryUtils method resolveArtifactAndDependencies.
public static Set<File> resolveArtifactAndDependencies(final String scope, 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 DependencyResolutionException {
Artifact artifact = new DefaultArtifact(groupId, artifactId, classifier, extension, versionExpr);
CollectRequest collectRequest = new CollectRequest();
collectRequest.setRoot(new Dependency(artifact, scope));
collectRequest.setRepositories(repos);
DependencyFilter dependencyFilter = DependencyFilterUtils.classpathFilter(scope);
DependencyRequest dependencyRequest = new DependencyRequest(collectRequest, dependencyFilter);
DependencyResult depresult = repositorySystem.resolveDependencies(session, dependencyRequest);
List<ArtifactResult> artifactResults = depresult.getArtifactResults();
Set<File> result = Sets.newHashSetWithExpectedSize(artifactResults.size());
for (ArtifactResult ar : artifactResults) {
result.add(ar.getArtifact().getFile());
}
return result;
}
use of org.eclipse.aether.resolution.ArtifactResult in project liferay-ide by liferay.
the class AetherUtil method getLatestAvailableArtifact.
public static Artifact getLatestAvailableArtifact(String gavCoords) {
Artifact retval = null;
RepositorySystem system = newRepositorySystem();
RepositorySystemSession session = newRepositorySystemSession(system);
String latestVersion = getLatestVersion(gavCoords, system, session);
String[] gav = gavCoords.split(":");
Artifact defaultArtifact = new DefaultArtifact(gav[0] + ":" + gav[1] + ":" + latestVersion);
ArtifactRequest artifactRequest = new ArtifactRequest();
artifactRequest.setArtifact(defaultArtifact);
artifactRequest.addRepository(newCentralRepository());
try {
ArtifactResult artifactResult = system.resolveArtifact(session, artifactRequest);
retval = artifactResult.getArtifact();
} catch (ArtifactResolutionException e) {
LiferayMavenCore.logError("Unable to get latest Liferay archetype", e);
artifactRequest.setArtifact(new DefaultArtifact(gavCoords));
try {
retval = system.resolveArtifact(session, artifactRequest).getArtifact();
} catch (ArtifactResolutionException e1) {
LiferayMavenCore.logError("Unable to get default Liferay archetype", e1);
}
}
if (retval == null) {
retval = defaultArtifact;
}
return retval;
}
use of org.eclipse.aether.resolution.ArtifactResult in project fabric8-maven-plugin by fabric8io.
the class AbstractArtifactSearchMojo method resolveArtifactFile.
protected File resolveArtifactFile(HelmIndexMojo.ArtifactDTO artifactDTO, String classifier, String extension) {
File file = null;
try {
ArtifactRequest artifactRequest = new ArtifactRequest();
org.eclipse.aether.artifact.Artifact artifact = new DefaultArtifact(artifactDTO.getG(), artifactDTO.getA(), classifier, extension, artifactDTO.getV());
artifactRequest.setArtifact(artifact);
// convert maven remote repositories to Aether repos
List<RemoteRepository> aetherRepoList = new ArrayList<>();
for (MavenArtifactRepository remoteRepository : remoteRepositories) {
RemoteRepository.Builder builder = new RemoteRepository.Builder(remoteRepository.getId(), remoteRepository.getLayout().getId(), remoteRepository.getUrl());
RemoteRepository aetherRepo = builder.build();
aetherRepoList.add(aetherRepo);
}
artifactRequest.setRepositories(aetherRepoList);
ArtifactResult artifactResult = artifactResolver.resolveArtifact(repoSession, artifactRequest);
org.eclipse.aether.artifact.Artifact resolvedArtifact = artifactResult.getArtifact();
if (resolvedArtifact == null) {
getLog().warn("Could not resolve artifact " + artifactDTO.description());
return null;
}
file = resolvedArtifact.getFile();
} catch (Exception e) {
getLog().warn("Failed to resolve manifest manifest for " + artifactDTO.description() + ". " + e, e);
return null;
}
if (file == null) {
getLog().warn("Could not resolve artifact file for " + artifactDTO.description());
return null;
}
if (!file.isFile() || !file.exists()) {
getLog().warn("Resolved artifact file does not exist for " + artifactDTO.description());
return null;
}
return file;
}
Aggregations