use of org.eclipse.aether.resolution.ArtifactRequest 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.ArtifactRequest in project gate-core by GateNLP.
the class SimpleMavenCache method cacheParents.
private void cacheParents(File pom, RepositorySystem repoSystem, RepositorySystemSession repoSession, List<RemoteRepository> repos) throws ModelBuildingException, IOException, ArtifactResolutionException {
ModelBuildingRequest req = new DefaultModelBuildingRequest();
req.setProcessPlugins(false);
req.setPomFile(pom);
req.setModelResolver(new SimpleModelResolver(repoSystem, repoSession, repos));
req.setValidationLevel(ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL);
ModelBuilder modelBuilder = new DefaultModelBuilderFactory().newInstance();
Model model = modelBuilder.build(req).getEffectiveModel();
Parent parent = model.getParent();
if (parent == null)
return;
Artifact pomArtifact = new DefaultArtifact(parent.getGroupId(), parent.getArtifactId(), "pom", parent.getVersion());
ArtifactRequest artifactRequest = new ArtifactRequest(pomArtifact, repos, null);
ArtifactResult artifactResult = repoSystem.resolveArtifact(repoSession, artifactRequest);
// but copy it to a file named for the original requested version number
File file = getArtifactFile(artifactRequest.getArtifact());
FileUtils.copyFile(artifactResult.getArtifact().getFile(), file);
cacheParents(artifactResult.getArtifact().getFile(), repoSystem, repoSession, repos);
}
use of org.eclipse.aether.resolution.ArtifactRequest in project spring-cloud-deployer by spring-cloud.
the class MavenArtifactResolver method resolve.
/**
* Resolve an artifact and return its location in the local repository. Aether performs the normal
* Maven resolution process ensuring that the latest update is cached to the local repository.
* In addition, if the {@link MavenProperties#resolvePom} flag is <code>true</code>,
* the POM is also resolved and cached.
* @param resource the {@link MavenResource} representing the artifact
* @return a {@link FileSystemResource} representing the resolved artifact in the local repository
* @throws IllegalStateException if the artifact does not exist or the resolution fails
*/
Resource resolve(MavenResource resource) {
Assert.notNull(resource, "MavenResource must not be null");
validateCoordinates(resource);
RepositorySystemSession session = newRepositorySystemSession(this.repositorySystem, this.properties.getLocalRepository());
ArtifactResult resolvedArtifact;
try {
List<ArtifactRequest> artifactRequests = new ArrayList<>(2);
if (properties.isResolvePom()) {
artifactRequests.add(new ArtifactRequest(toPomArtifact(resource), this.remoteRepositories, JavaScopes.RUNTIME));
}
artifactRequests.add(new ArtifactRequest(toJarArtifact(resource), this.remoteRepositories, JavaScopes.RUNTIME));
List<ArtifactResult> results = this.repositorySystem.resolveArtifacts(session, artifactRequests);
resolvedArtifact = results.get(results.size() - 1);
} catch (ArtifactResolutionException e) {
ChoiceFormat pluralizer = new ChoiceFormat(new double[] { 0d, 1d, ChoiceFormat.nextDouble(1d) }, new String[] { "repositories: ", "repository: ", "repositories: " });
MessageFormat messageFormat = new MessageFormat("Failed to resolve MavenResource: {0}. Configured remote {1}: {2}");
messageFormat.setFormat(1, pluralizer);
String repos = properties.getRemoteRepositories().isEmpty() ? "none" : StringUtils.collectionToDelimitedString(properties.getRemoteRepositories().keySet(), ",", "[", "]");
throw new IllegalStateException(messageFormat.format(new Object[] { resource, properties.getRemoteRepositories().size(), repos }), e);
}
return toResource(resolvedArtifact);
}
use of org.eclipse.aether.resolution.ArtifactRequest in project mule by mulesoft.
the class DefaultRepositoryService method lookupBundle.
@Override
public File lookupBundle(BundleDependency bundleDependency) {
try {
if (remoteRepositories.isEmpty()) {
throw new RepositoryServiceDisabledException("Repository service has not been configured so it's disabled. " + "To enable it you must configure the set of repositories to use using the system property: " + MULE_REMOTE_REPOSITORIES_PROPERTY);
}
DefaultArtifact artifact = toArtifact(bundleDependency);
ArtifactRequest getArtifactRequest = new ArtifactRequest();
getArtifactRequest.setRepositories(remoteRepositories);
getArtifactRequest.setArtifact(artifact);
ArtifactResult artifactResult = repositorySystem.resolveArtifact(repositorySystemSession, getArtifactRequest);
return artifactResult.getArtifact().getFile();
} catch (ArtifactResolutionException e) {
if (e.getCause() instanceof ArtifactNotFoundException) {
throw new BundleNotFoundException(e);
} else {
throw new RepositoryConnectionException("There was a problem connecting to one of the repositories", e);
}
}
}
use of org.eclipse.aether.resolution.ArtifactRequest in project mule by mulesoft.
the class DependencyResolver method resolveArtifact.
/**
* Resolves the path for an artifact.
*
* @param artifact the {@link Artifact} requested, must not be {@code null}
* @return The resolution result, never {@code null}.
* @throws {@link ArtifactResolutionException} if the artifact could not be resolved.
*/
public ArtifactResult resolveArtifact(Artifact artifact) throws ArtifactResolutionException {
checkNotNull(artifact, "artifact cannot be null");
final ArtifactRequest request = new ArtifactRequest(artifact, resolutionContext.getRemoteRepositories(), null);
return repositoryState.getSystem().resolveArtifact(repositoryState.getSession(), request);
}
Aggregations