use of org.eclipse.aether.resolution.ArtifactResult 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);
}
use of org.eclipse.aether.resolution.ArtifactResult in project intellij-community by JetBrains.
the class Maven3ServerEmbedderImpl method resolve.
private Artifact resolve(@NotNull final Artifact artifact, @NotNull final List<ArtifactRepository> repos) throws ArtifactResolutionException, ArtifactNotFoundException, RemoteException, org.eclipse.aether.resolution.ArtifactResolutionException {
final String mavenVersion = getMavenVersion();
// see https://youtrack.jetbrains.com/issue/IDEA-140208 for details
if (USE_MVN2_COMPATIBLE_DEPENDENCY_RESOLVING || StringUtil.compareVersionNumbers(mavenVersion, "3.2.5") < 0) {
MavenExecutionRequest request = new DefaultMavenExecutionRequest();
request.setRemoteRepositories(repos);
try {
getComponent(MavenExecutionRequestPopulator.class).populateFromSettings(request, myMavenSettings);
getComponent(MavenExecutionRequestPopulator.class).populateDefaults(request);
} catch (MavenExecutionRequestPopulationException e) {
throw new RuntimeException(e);
}
getComponent(ArtifactResolver.class).resolve(artifact, request.getRemoteRepositories(), myLocalRepository);
return artifact;
} else {
final MavenExecutionRequest request = createRequest(null, Collections.<String>emptyList(), Collections.<String>emptyList(), Collections.<String>emptyList());
for (ArtifactRepository artifactRepository : repos) {
request.addRemoteRepository(artifactRepository);
}
DefaultMaven maven = (DefaultMaven) getComponent(Maven.class);
RepositorySystemSession repositorySystemSession = maven.newRepositorySession(request);
final org.eclipse.aether.impl.ArtifactResolver artifactResolver = getComponent(org.eclipse.aether.impl.ArtifactResolver.class);
final MyLoggerFactory loggerFactory = new MyLoggerFactory();
if (artifactResolver instanceof DefaultArtifactResolver) {
((DefaultArtifactResolver) artifactResolver).setLoggerFactory(loggerFactory);
}
final org.eclipse.aether.RepositorySystem repositorySystem = getComponent(org.eclipse.aether.RepositorySystem.class);
if (repositorySystem instanceof DefaultRepositorySystem) {
((DefaultRepositorySystem) repositorySystem).setLoggerFactory(loggerFactory);
}
List<RemoteRepository> repositories = RepositoryUtils.toRepos(request.getRemoteRepositories());
repositories = repositorySystem.newResolutionRepositories(repositorySystemSession, repositories);
final ArtifactResult artifactResult = repositorySystem.resolveArtifact(repositorySystemSession, new ArtifactRequest(RepositoryUtils.toArtifact(artifact), repositories, null));
return RepositoryUtils.toArtifact(artifactResult.getArtifact());
}
}
use of org.eclipse.aether.resolution.ArtifactResult in project intellij-community by JetBrains.
the class CustomMaven3ArtifactResolver method resolveOld.
private void resolveOld(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());
}
}
}
}
}
use of org.eclipse.aether.resolution.ArtifactResult in project intellij-community by JetBrains.
the class ArtifactRepositoryManager method resolveDependency.
public Collection<File> resolveDependency(String groupId, String artifactId, String version) throws Exception {
final DependencyRequest dependencyRequest = new DependencyRequest(createCollectRequest(groupId, artifactId, toVersion(version)), DependencyFilterUtils.classpathFilter(JavaScopes.COMPILE));
final DependencyResult result = ourSystem.resolveDependencies(mySession, dependencyRequest);
final List<File> files = new ArrayList<>();
for (ArtifactResult artifactResult : result.getArtifactResults()) {
files.add(artifactResult.getArtifact().getFile());
}
return files;
}
use of org.eclipse.aether.resolution.ArtifactResult in project bnd by bndtools.
the class DependencyResolver method resolve.
public Map<File, ArtifactResult> resolve() throws MojoExecutionException {
if (resolvedDependencies != null) {
return resolvedDependencies;
}
DependencyResolutionRequest request = new DefaultDependencyResolutionRequest(project, session);
request.setResolutionFilter(new DependencyFilter() {
@Override
public boolean accept(DependencyNode node, List<DependencyNode> parents) {
if (node.getDependency() != null) {
return scopes.contains(node.getDependency().getScope());
}
return false;
}
});
DependencyResolutionResult result;
try {
result = resolver.resolve(request);
} catch (DependencyResolutionException e) {
throw new MojoExecutionException(e.getMessage(), e);
}
Map<File, ArtifactResult> dependencies = new HashMap<>();
DependencyNode dependencyGraph = result.getDependencyGraph();
if (dependencyGraph != null && !dependencyGraph.getChildren().isEmpty()) {
List<RemoteRepository> remoteRepositories = new ArrayList<>(project.getRemoteProjectRepositories());
ArtifactRepository deployRepo = project.getDistributionManagementArtifactRepository();
if (deployRepo != null) {
remoteRepositories.add(RepositoryUtils.toRepo(deployRepo));
}
discoverArtifacts(dependencies, dependencyGraph.getChildren(), project.getArtifact().getId(), remoteRepositories);
}
return resolvedDependencies = dependencies;
}
Aggregations