use of org.eclipse.aether.resolution.DependencyRequest 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.resolution.DependencyRequest in project druid by druid-io.
the class PullDependenciesTest method setUp.
@Before
public void setUp() throws Exception {
localRepo = temporaryFolder.newFolder();
extensionToJars = new HashMap<>();
extensionToJars.put(extension_A, ImmutableList.of("a.jar", "b.jar", "c.jar"));
extensionToJars.put(extension_B, ImmutableList.of("d.jar", "e.jar"));
extensionToJars.put(hadoop_client_2_3_0, ImmutableList.of("f.jar", "g.jar"));
extensionToJars.put(hadoop_client_2_4_0, ImmutableList.of("h.jar", "i.jar"));
rootExtensionsDir = new File(temporaryFolder.getRoot(), "extensions");
rootHadoopDependenciesDir = new File(temporaryFolder.getRoot(), "druid_hadoop_dependencies");
pullDependencies = new PullDependencies(new DefaultTeslaAether() {
@Override
public List<Artifact> resolveArtifacts(DependencyRequest request) throws DependencyResolutionException {
return getArtifactsForExtension(request.getCollectRequest().getRoot().getArtifact());
}
}, new ExtensionsConfig() {
@Override
public String getDirectory() {
return rootExtensionsDir.getAbsolutePath();
}
@Override
public String getHadoopDependenciesDir() {
return rootHadoopDependenciesDir.getAbsolutePath();
}
});
pullDependencies.coordinates = ImmutableList.of(EXTENSION_A_COORDINATE, EXTENSION_B_COORDINATE);
pullDependencies.hadoopCoordinates = ImmutableList.of(HADOOP_CLIENT_2_3_0_COORDINATE, HADOOP_CLIENT_2_4_0_COORDINATE);
}
use of org.eclipse.aether.resolution.DependencyRequest 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.resolution.DependencyRequest in project byte-buddy by raphw.
the class ClassLoaderResolverTest method testResolutionFailure.
@Test(expected = MojoExecutionException.class)
public void testResolutionFailure() throws Exception {
when(repositorySystem.resolveDependencies(eq(repositorySystemSession), any(DependencyRequest.class))).thenThrow(new DependencyResolutionException(new DependencyResult(new DependencyRequest(root, mock(DependencyFilter.class))), new Throwable()));
classLoaderResolver.resolve(new MavenCoordinate(FOO, BAR, QUX));
}
use of org.eclipse.aether.resolution.DependencyRequest in project spring-boot by spring-projects.
the class AetherGrapeEngine method resolve.
private List<File> resolve(List<Dependency> dependencies) throws ArtifactResolutionException {
try {
CollectRequest collectRequest = getCollectRequest(dependencies);
DependencyRequest dependencyRequest = getDependencyRequest(collectRequest);
DependencyResult result = this.repositorySystem.resolveDependencies(this.session, dependencyRequest);
addManagedDependencies(result);
return getFiles(result);
} catch (Exception ex) {
throw new DependencyResolutionFailedException(ex);
} finally {
this.progressReporter.finished();
}
}
Aggregations