use of org.eclipse.aether.RepositoryException in project revapi by revapi.
the class Main method convertGavs.
private static ArchivesAndSupplementaryArchives convertGavs(String[] gavs, String errorMessagePrefix, File localRepo) {
RepositorySystem repositorySystem = MavenBootstrap.newRepositorySystem();
DefaultRepositorySystemSession session = MavenBootstrap.newRepositorySystemSession(repositorySystem, localRepo);
session.setDependencySelector(new ScopeDependencySelector("compile", "provided"));
session.setDependencyTraverser(new ScopeDependencyTraverser("compile", "provided"));
RemoteRepository mavenCentral = new RemoteRepository.Builder("@@forced-maven-central@@", "default", "http://repo.maven.apache.org/maven2/").build();
List<RemoteRepository> remoteRepositories = singletonList(mavenCentral);
ArtifactResolver resolver = new ArtifactResolver(repositorySystem, session, remoteRepositories);
List<FileArchive> archives = new ArrayList<>();
List<FileArchive> supplementaryArchives = new ArrayList<>();
for (String gav : gavs) {
try {
archives.add(new FileArchive(resolver.resolveArtifact(gav).getFile()));
ArtifactResolver.CollectionResult res = resolver.collectTransitiveDeps(gav);
res.getResolvedArtifacts().forEach(a -> supplementaryArchives.add(new FileArchive(a.getFile())));
if (!res.getFailures().isEmpty()) {
LOG.warn("Failed to resolve some transitive dependencies: " + res.getFailures().toString());
}
} catch (RepositoryException e) {
throw new IllegalArgumentException(errorMessagePrefix + " " + e.getMessage());
}
}
return new ArchivesAndSupplementaryArchives(archives, supplementaryArchives);
}
use of org.eclipse.aether.RepositoryException in project zeppelin by apache.
the class DependencyResolver method getArtifactsWithDep.
/**
* @param dependency
* @param excludes list of pattern can either be of the form groupId:artifactId
* @return
* @throws Exception
*/
@Override
public List<ArtifactResult> getArtifactsWithDep(String dependency, Collection<String> excludes) throws RepositoryException {
Artifact artifact = new DefaultArtifact(dependency);
DependencyFilter classpathFilter = DependencyFilterUtils.classpathFilter(JavaScopes.COMPILE);
PatternExclusionsDependencyFilter exclusionFilter = new PatternExclusionsDependencyFilter(excludes);
CollectRequest collectRequest = new CollectRequest();
collectRequest.setRoot(new Dependency(artifact, JavaScopes.COMPILE));
synchronized (repos) {
for (RemoteRepository repo : repos) {
collectRequest.addRepository(repo);
}
}
DependencyRequest dependencyRequest = new DependencyRequest(collectRequest, DependencyFilterUtils.andFilter(exclusionFilter, classpathFilter));
try {
return system.resolveDependencies(session, dependencyRequest).getArtifactResults();
} catch (NullPointerException | DependencyResolutionException ex) {
throw new RepositoryException(String.format("Cannot fetch dependencies for %s", dependency), ex);
}
}
use of org.eclipse.aether.RepositoryException 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.RepositoryException in project fabric8 by jboss-fuse.
the class ReplaceConflictingVersionResolver method transformGraph.
public DependencyNode transformGraph(DependencyNode node, DependencyGraphTransformationContext context) throws RepositoryException {
List<?> sortedConflictIds = (List<?>) context.get(TransformationContextKeys.SORTED_CONFLICT_IDS);
if (sortedConflictIds == null) {
ConflictIdSorter sorter = new ConflictIdSorter();
sorter.transformGraph(node, context);
sortedConflictIds = (List<?>) context.get(TransformationContextKeys.SORTED_CONFLICT_IDS);
}
Map<?, ?> conflictIds = (Map<?, ?>) context.get(TransformationContextKeys.CONFLICT_IDS);
if (conflictIds == null) {
throw new RepositoryException("conflict groups have not been identified");
}
Map<DependencyNode, Integer> depths = new TreeMap<DependencyNode, Integer>(DependencyNodeComparator.INSTANCE);
for (Object key : sortedConflictIds) {
ConflictGroup group = new ConflictGroup(key);
depths.clear();
selectVersion(node, null, 0, depths, group, conflictIds);
updateNonSelectedVersions(group, conflictIds);
}
return node;
}
use of org.eclipse.aether.RepositoryException in project zeppelin by apache.
the class InstallInterpreter method install.
public void install(String name, String artifact) {
Proxy proxy = null;
if (proxyUrl != null) {
Authentication auth = new AuthenticationBuilder().addUsername(proxyUser).addPassword(proxyPassword).build();
proxy = new Proxy(proxyUrl.getProtocol(), proxyUrl.getHost(), proxyUrl.getPort(), auth);
}
DependencyResolver depResolver = new DependencyResolver(localRepoDir, proxy);
File installDir = new File(interpreterBaseDir, name);
if (installDir.exists()) {
System.err.println("Directory " + installDir.getAbsolutePath() + " already exists" + "\n\nSkipped");
return;
}
System.out.println("Install " + name + "(" + artifact + ") to " + installDir.getAbsolutePath() + " ... ");
try {
depResolver.load(artifact, installDir);
System.out.println("Interpreter " + name + " installed under " + installDir.getAbsolutePath() + ".");
startTip();
} catch (RepositoryException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
Aggregations