use of org.eclipse.aether.graph.DependencyFilter in project buck by facebook.
the class Resolver method getRunTimeTransitiveDeps.
private ImmutableMap<String, Artifact> getRunTimeTransitiveDeps(Iterable<Dependency> mavenCoords) throws RepositoryException {
CollectRequest collectRequest = new CollectRequest();
collectRequest.setRequestContext(JavaScopes.RUNTIME);
collectRequest.setRepositories(repos);
for (Dependency dep : mavenCoords) {
collectRequest.addDependency(dep);
}
DependencyFilter filter = DependencyFilterUtils.classpathFilter(JavaScopes.RUNTIME);
DependencyRequest dependencyRequest = new DependencyRequest(collectRequest, filter);
DependencyResult dependencyResult = repoSys.resolveDependencies(session, dependencyRequest);
ImmutableSortedMap.Builder<String, Artifact> knownDeps = ImmutableSortedMap.naturalOrder();
for (ArtifactResult artifactResult : dependencyResult.getArtifactResults()) {
Artifact node = artifactResult.getArtifact();
knownDeps.put(buildKey(node), node);
}
return knownDeps.build();
}
use of org.eclipse.aether.graph.DependencyFilter in project druid by druid-io.
the class PullDependencies method downloadExtension.
/**
* Download the extension given its maven coordinate
*
* @param versionedArtifact The maven artifact of the extension
* @param toLocation The location where this extension will be downloaded to
*/
private void downloadExtension(Artifact versionedArtifact, File toLocation) {
final CollectRequest collectRequest = new CollectRequest();
collectRequest.setRoot(new Dependency(versionedArtifact, JavaScopes.RUNTIME));
final DependencyRequest dependencyRequest = new DependencyRequest(collectRequest, DependencyFilterUtils.andFilter(DependencyFilterUtils.classpathFilter(JavaScopes.RUNTIME), new DependencyFilter() {
@Override
public boolean accept(DependencyNode node, List<DependencyNode> parents) {
String scope = node.getDependency().getScope();
if (scope != null) {
scope = scope.toLowerCase();
if (scope.equals("provided")) {
return false;
}
if (scope.equals("test")) {
return false;
}
if (scope.equals("system")) {
return false;
}
}
if (accept(node.getArtifact())) {
return false;
}
for (DependencyNode parent : parents) {
if (accept(parent.getArtifact())) {
return false;
}
}
return true;
}
private boolean accept(final Artifact artifact) {
return exclusions.contains(artifact.getGroupId());
}
}));
try {
log.info("Start downloading extension [%s]", versionedArtifact);
final List<Artifact> artifacts = aether.resolveArtifacts(dependencyRequest);
for (Artifact artifact : artifacts) {
if (!exclusions.contains(artifact.getGroupId())) {
log.info("Adding file [%s] at [%s]", artifact.getFile().getName(), toLocation.getAbsolutePath());
FileUtils.copyFileToDirectory(artifact.getFile(), toLocation);
} else {
log.debug("Skipped Artifact[%s]", artifact);
}
}
} catch (Exception e) {
log.error(e, "Unable to resolve artifacts for [%s].", dependencyRequest);
throw Throwables.propagate(e);
}
log.info("Finish downloading extension [%s]", versionedArtifact);
}
use of org.eclipse.aether.graph.DependencyFilter in project launcher by runelite.
the class ArtifactResolver method resolveArtifacts.
public List<ArtifactResult> resolveArtifacts(Artifact artifact) throws DependencyResolutionException {
RepositorySystem system = newRepositorySystem();
RepositorySystemSession session = newRepositorySystemSession(system);
DependencyFilter classpathFlter = DependencyFilterUtils.classpathFilter(JavaScopes.COMPILE, JavaScopes.RUNTIME);
CollectRequest collectRequest = new CollectRequest();
collectRequest.setRoot(new Dependency(artifact, JavaScopes.COMPILE));
collectRequest.setRepositories(repositories);
DependencyRequest dependencyRequest = new DependencyRequest(collectRequest, classpathFlter);
List<ArtifactResult> results = system.resolveDependencies(session, dependencyRequest).getArtifactResults();
// check to see if they're from the right repository
validate(results);
return results;
}
use of org.eclipse.aether.graph.DependencyFilter in project mule by mulesoft.
the class AetherClassPathClassifier method buildPluginUrlClassification.
/**
* Classifies an {@link Artifact} recursively. {@value org.eclipse.aether.util.artifact.JavaScopes#COMPILE} dependencies will be
* resolved for building the {@link URL}'s for the class loader. Once classified the node is added to {@link Map} of
* artifactsClassified.
*
* @param artifactToClassify {@link Artifact} that represents the artifact to be classified
* @param context {@link ClassPathClassifierContext} with settings for the classification process
* @param artifactsClassified {@link Map} that contains already classified plugins
* @param rootArtifactRemoteRepositories remote repositories defined at the root artifact.
*/
private void buildPluginUrlClassification(Artifact artifactToClassify, ClassPathClassifierContext context, Predicate<Dependency> directDependenciesFilter, Set<ArtifactClassificationNode> artifactsClassified, List<RemoteRepository> rootArtifactRemoteRepositories) {
List<URL> urls;
try {
final DependencyFilter dependencyFilter = andFilter(classpathFilter(COMPILE), new PatternExclusionsDependencyFilter(context.getExcludedArtifacts()), orFilter(new PatternExclusionsDependencyFilter("*:*:*:" + MULE_PLUGIN_CLASSIFIER + ":*"), new PatternInclusionsDependencyFilter(toId(artifactToClassify))));
urls = toUrl(dependencyResolver.resolveDependencies(new Dependency(artifactToClassify, COMPILE), emptyList(), emptyList(), dependencyFilter, rootArtifactRemoteRepositories));
} catch (Exception e) {
throw new IllegalStateException("Couldn't resolve dependencies for artifact: '" + artifactToClassify + "' classification", e);
}
List<Dependency> directDependencies;
List<ArtifactClassificationNode> artifactDependencies = newArrayList();
try {
directDependencies = dependencyResolver.getDirectDependencies(artifactToClassify, rootArtifactRemoteRepositories);
} catch (ArtifactDescriptorException e) {
throw new IllegalStateException("Couldn't get direct dependencies for artifact: '" + artifactToClassify + "'", e);
}
logger.debug("Searching for dependencies on direct dependencies of artifact {}", artifactToClassify);
List<Artifact> pluginArtifactDependencies = filterArtifacts(directDependencies, directDependenciesFilter);
logger.debug("Artifacts {} identified a plugin dependencies for plugin {}", pluginArtifactDependencies, artifactToClassify);
pluginArtifactDependencies.stream().map(artifact -> {
Optional<ArtifactClassificationNode> artifactClassificationNodeOptional = findArtifactClassified(artifactsClassified, artifact);
if (!artifactClassificationNodeOptional.isPresent()) {
buildPluginUrlClassification(artifact, context, directDependenciesFilter, artifactsClassified, rootArtifactRemoteRepositories);
} else {
if (!areCompatibleVersions(artifactClassificationNodeOptional.get().getArtifact().getVersion(), artifact.getVersion())) {
throw new IllegalStateException(format("Incompatible version of artifacts found: %s and %s", toId(artifactClassificationNodeOptional.get().getArtifact()), toId(artifact)));
}
logger.debug("Checking for highest version of artifact, already discovered: '{}' versus: '{}'", toId(artifactClassificationNodeOptional.get().getArtifact()), toId(artifact));
if (isHighestVersion(artifact.getVersion(), artifactClassificationNodeOptional.get().getArtifact().getVersion())) {
artifactsClassified.remove(artifactClassificationNodeOptional.get());
buildPluginUrlClassification(artifact, context, directDependenciesFilter, artifactsClassified, rootArtifactRemoteRepositories);
logger.warn("Replacing artifact: '{}' for highest version: '{}'", toId(artifactClassificationNodeOptional.get().getArtifact()), toId(artifact));
}
}
return findArtifactClassified(artifactsClassified, artifact).orElseThrow(() -> new IllegalStateException(format("Should %s be already added to the list of artifacts classified", toId(artifact))));
}).forEach(artifactDependencies::add);
final List<Class> exportClasses = getArtifactExportedClasses(artifactToClassify, context, rootArtifactRemoteRepositories);
resolveSnapshotVersionsToTimestampedFromClassPath(urls, context.getClassPathURLs());
ArtifactClassificationNode artifactUrlClassification = new ArtifactClassificationNode(artifactToClassify, urls, exportClasses, artifactDependencies);
logger.debug("Artifact discovered: {}", toId(artifactUrlClassification.getArtifact()));
artifactsClassified.add(artifactUrlClassification);
}
use of org.eclipse.aether.graph.DependencyFilter 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);
}
}
Aggregations