use of org.eclipse.aether.artifact.Artifact 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.artifact.Artifact in project druid by druid-io.
the class PullDependencies method run.
@Override
public void run() {
if (aether == null) {
aether = getAetherClient();
}
final File extensionsDir = new File(extensionsConfig.getDirectory());
final File hadoopDependenciesDir = new File(extensionsConfig.getHadoopDependenciesDir());
try {
if (clean) {
FileUtils.deleteDirectory(extensionsDir);
FileUtils.deleteDirectory(hadoopDependenciesDir);
}
FileUtils.forceMkdir(extensionsDir);
FileUtils.forceMkdir(hadoopDependenciesDir);
} catch (IOException e) {
log.error(e, "Unable to clear or create extension directory at [%s]", extensionsDir);
throw Throwables.propagate(e);
}
log.info("Start pull-deps with local repository [%s] and remote repositories [%s]", localRepository, remoteRepositories);
try {
log.info("Start downloading dependencies for extension coordinates: [%s]", coordinates);
for (String coordinate : coordinates) {
coordinate = coordinate.trim();
final Artifact versionedArtifact = getArtifact(coordinate);
File currExtensionDir = new File(extensionsDir, versionedArtifact.getArtifactId());
createExtensionDirectory(coordinate, currExtensionDir);
downloadExtension(versionedArtifact, currExtensionDir);
}
log.info("Finish downloading dependencies for extension coordinates: [%s]", coordinates);
if (!noDefaultHadoop && hadoopCoordinates.isEmpty()) {
hadoopCoordinates.addAll(TaskConfig.DEFAULT_DEFAULT_HADOOP_COORDINATES);
}
log.info("Start downloading dependencies for hadoop extension coordinates: [%s]", hadoopCoordinates);
for (final String hadoopCoordinate : hadoopCoordinates) {
final Artifact versionedArtifact = getArtifact(hadoopCoordinate);
File currExtensionDir = new File(hadoopDependenciesDir, versionedArtifact.getArtifactId());
createExtensionDirectory(hadoopCoordinate, currExtensionDir);
// add a version folder for hadoop dependency directory
currExtensionDir = new File(currExtensionDir, versionedArtifact.getVersion());
createExtensionDirectory(hadoopCoordinate, currExtensionDir);
downloadExtension(versionedArtifact, currExtensionDir);
}
log.info("Finish downloading dependencies for hadoop extension coordinates: [%s]", hadoopCoordinates);
} catch (Exception e) {
throw Throwables.propagate(e);
}
}
use of org.eclipse.aether.artifact.Artifact 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.artifact.Artifact in project druid by druid-io.
the class PullDependenciesTest method getArtifactsForExtension.
private List<Artifact> getArtifactsForExtension(Artifact artifact) {
final List<String> jarNames = extensionToJars.get(artifact);
final List<Artifact> artifacts = Lists.newArrayList();
for (String jarName : jarNames) {
final File jarFile = new File(localRepo, jarName);
try {
jarFile.createNewFile();
} catch (IOException e) {
Throwables.propagate(e);
}
artifacts.add(new DefaultArtifact(null, jarName, null, "jar", "1.0", null, jarFile));
}
return artifacts;
}
use of org.eclipse.aether.artifact.Artifact in project bnd by bndtools.
the class AetherRepository method get.
@Override
public File get(String bsn, Version version, Map<String, String> properties, DownloadListener... listeners) throws Exception {
init();
// Use the index by preference
if (indexedRepo != null)
return indexedRepo.get(ConversionUtils.maybeMavenCoordsToBsn(bsn), version, properties, listeners);
File file = null;
boolean getSource = false;
try {
// Setup the Aether repo session and request
DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession();
session.setLocalRepositoryManager(repoSystem.newLocalRepositoryManager(session, localRepo));
if (bsn.endsWith(".source")) {
String originalBsn = properties.get("bsn");
if (originalBsn != null) {
bsn = originalBsn;
getSource = true;
}
}
String[] coords = ConversionUtils.getGroupAndArtifactForBsn(bsn);
MavenVersion mvnVersion = new MavenVersion(version);
String versionStr = null;
if ("exact".equals(properties.get("strategy")) || getSource) {
versionStr = properties.get("version");
} else {
versionStr = mvnVersion.toString();
}
Artifact artifact = null;
if (getSource) {
artifact = new DefaultArtifact(coords[0], coords[1], "sources", "jar", versionStr);
} else {
artifact = new DefaultArtifact(coords[0], coords[1], "jar", versionStr);
}
ArtifactRequest request = new ArtifactRequest();
request.setArtifact(artifact);
request.setRepositories(Collections.singletonList(remoteRepo));
// Log the transfer
session.setTransferListener(new AbstractTransferListener() {
@Override
public void transferStarted(TransferEvent event) throws TransferCancelledException {
System.err.println(event);
}
@Override
public void transferSucceeded(TransferEvent event) {
System.err.println(event);
}
@Override
public void transferFailed(TransferEvent event) {
System.err.println(event);
}
});
try {
// Resolve the version
ArtifactResult artifactResult = repoSystem.resolveArtifact(session, request);
artifact = artifactResult.getArtifact();
file = artifact.getFile();
} catch (ArtifactResolutionException ex) {
// could not download artifact, simply return null
}
return file;
} finally {
for (DownloadListener dl : listeners) {
if (file != null)
dl.success(file);
else
dl.failure(null, "Download failed");
}
}
}
Aggregations