use of org.apache.maven.artifact.resolver.ArtifactResolver 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.apache.maven.artifact.resolver.ArtifactResolver in project intellij-community by JetBrains.
the class Maven3ServerEmbedderImpl method reset.
@Override
public void reset() throws RemoteException {
try {
setConsoleAndIndicator(null, null);
final ArtifactFactory artifactFactory = getComponent(ArtifactFactory.class);
if (artifactFactory instanceof CustomMaven3ArtifactFactory) {
((CustomMaven3ArtifactFactory) artifactFactory).reset();
}
final ArtifactResolver artifactResolver = getComponent(ArtifactResolver.class);
if (artifactResolver instanceof CustomMaven3ArtifactResolver) {
((CustomMaven3ArtifactResolver) artifactResolver).reset();
}
final RepositoryMetadataManager repositoryMetadataManager = getComponent(RepositoryMetadataManager.class);
if (repositoryMetadataManager instanceof CustomMaven3RepositoryMetadataManager) {
((CustomMaven3RepositoryMetadataManager) repositoryMetadataManager).reset();
}
//((CustomWagonManager)getComponent(WagonManager.class)).reset();
} catch (Exception e) {
throw rethrowException(e);
}
}
use of org.apache.maven.artifact.resolver.ArtifactResolver in project maven-archetype by apache.
the class ArchetypeTest method getContextClassloader.
// Gets the classloader for this artifact's file.
private ClassLoader getContextClassloader(Artifact archetypeArtifact, ArtifactRepository localRepository, List<ArtifactRepository> remoteRepositories) throws Exception {
ArtifactResolver artifactResolver = (ArtifactResolver) lookup(ArtifactResolver.class.getName());
try {
artifactResolver.resolve(archetypeArtifact, remoteRepositories, localRepository);
} catch (ArtifactResolutionException e) {
throw new ArchetypeDescriptorException("Error attempting to download archetype: " + e.getMessage(), e);
} catch (ArtifactNotFoundException e) {
throw new ArchetypeNotFoundException("OldArchetype does not exist: " + e.getMessage(), e);
}
URLClassLoader archetypeJarLoader;
try {
URL[] urls = new URL[1];
urls[0] = archetypeArtifact.getFile().toURI().toURL();
archetypeJarLoader = new URLClassLoader(urls);
} catch (IOException e) {
throw new ArchetypeDescriptorException("Error reading the " + OldArchetype.ARCHETYPE_DESCRIPTOR + " descriptor.", e);
}
return archetypeJarLoader;
}
Aggregations