use of org.eclipse.aether.graph.DependencyNode 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.DependencyNode in project intellij-community by JetBrains.
the class Maven3AetherModelConverter method convertAetherDependencyNodes.
public static List<MavenArtifactNode> convertAetherDependencyNodes(MavenArtifactNode parent, Collection<DependencyNode> nodes, Map<Artifact, MavenArtifact> nativeToConvertedMap, File localRepository) {
List<MavenArtifactNode> result = new ArrayList<MavenArtifactNode>(nodes.size());
for (DependencyNode each : nodes) {
Artifact a = toArtifact(each.getDependency());
MavenArtifact ma = convertArtifact(a, nativeToConvertedMap, localRepository);
Map<?, ?> data = each.getData();
String premanagedVersion = DependencyManagerUtils.getPremanagedVersion(each);
String premanagedScope = DependencyManagerUtils.getPremanagedScope(each);
MavenArtifactState state = MavenArtifactState.ADDED;
MavenArtifact relatedArtifact = null;
String scope = each.getDependency().getScope();
Object winner = data.get(ConflictResolver.NODE_DATA_WINNER);
if (winner instanceof DependencyNode) {
DependencyNode winnerNode = (DependencyNode) winner;
scope = winnerNode.getDependency().getScope();
Artifact winnerArtifact = toArtifact(winnerNode.getDependency());
relatedArtifact = convertArtifact(winnerArtifact, nativeToConvertedMap, localRepository);
nativeToConvertedMap.put(a, relatedArtifact);
if (!StringUtil.equals(each.getVersion().toString(), winnerNode.getVersion().toString())) {
state = MavenArtifactState.CONFLICT;
} else {
state = MavenArtifactState.DUPLICATE;
}
}
ma.setScope(scope);
MavenArtifactNode newNode = new MavenArtifactNode(parent, ma, state, relatedArtifact, each.getDependency().getScope(), premanagedVersion, premanagedScope);
newNode.setDependencies(convertAetherDependencyNodes(newNode, each.getChildren(), nativeToConvertedMap, localRepository));
result.add(newNode);
}
return result;
}
use of org.eclipse.aether.graph.DependencyNode in project karaf by apache.
the class Dependency31Helper method getDependencies.
@Override
public void getDependencies(MavenProject project, boolean useTransitiveDependencies) throws MojoExecutionException {
DependencyNode rootNode = getDependencyTree(toArtifact(project.getArtifact()));
Scanner scanner = new Scanner();
scanner.scan(rootNode, useTransitiveDependencies);
localDependencies = scanner.localDependencies;
treeListing = scanner.getLog();
}
use of org.eclipse.aether.graph.DependencyNode in project BIMserver by opensourceBIM.
the class PluginManager method loadDependencies.
private PublicFindClassClassLoader loadDependencies(Set<org.bimserver.plugins.Dependency> bimServerDependencies, Model model, PublicFindClassClassLoader previous) throws FileNotFoundException, IOException {
List<org.apache.maven.model.Dependency> dependencies = model.getDependencies();
Iterator<org.apache.maven.model.Dependency> it = dependencies.iterator();
Path workspaceDir = Paths.get("..");
bimServerDependencies.add(new org.bimserver.plugins.Dependency(workspaceDir.resolve("PluginBase/target/classes")));
bimServerDependencies.add(new org.bimserver.plugins.Dependency(workspaceDir.resolve("Shared/target/classes")));
while (it.hasNext()) {
org.apache.maven.model.Dependency depend = it.next();
try {
if (depend.getGroupId().equals("org.opensourcebim") && (depend.getArtifactId().equals("shared") || depend.getArtifactId().equals("pluginbase"))) {
// TODO we might want to check the version though
continue;
}
if (depend.isOptional() || "test".equals(depend.getScope())) {
continue;
}
Dependency dependency2 = new Dependency(new DefaultArtifact(depend.getGroupId() + ":" + depend.getArtifactId() + ":jar:" + depend.getVersion()), "compile");
DelegatingClassLoader depDelLoader = new DelegatingClassLoader(previous);
if (!dependency2.getArtifact().isSnapshot()) {
if (dependency2.getArtifact().getFile() != null) {
bimServerDependencies.add(new org.bimserver.plugins.Dependency(dependency2.getArtifact().getFile().toPath()));
loadDependencies(dependency2.getArtifact().getFile().toPath(), depDelLoader);
} else {
ArtifactRequest request = new ArtifactRequest();
request.setArtifact(dependency2.getArtifact());
request.setRepositories(mavenPluginRepository.getRepositories());
try {
ArtifactResult resolveArtifact = mavenPluginRepository.getSystem().resolveArtifact(mavenPluginRepository.getSession(), request);
if (resolveArtifact.getArtifact().getFile() != null) {
bimServerDependencies.add(new org.bimserver.plugins.Dependency(resolveArtifact.getArtifact().getFile().toPath()));
loadDependencies(resolveArtifact.getArtifact().getFile().toPath(), depDelLoader);
} else {
// TODO error?
}
} catch (ArtifactResolutionException e) {
e.printStackTrace();
}
}
} else {
// Snapshot projects linked in Eclipse
ArtifactRequest request = new ArtifactRequest();
if ((!"test".equals(dependency2.getScope()) && !dependency2.getArtifact().isSnapshot())) {
request.setArtifact(dependency2.getArtifact());
request.setRepositories(mavenPluginRepository.getLocalRepositories());
try {
ArtifactResult resolveArtifact = mavenPluginRepository.getSystem().resolveArtifact(mavenPluginRepository.getSession(), request);
if (resolveArtifact.getArtifact().getFile() != null) {
bimServerDependencies.add(new org.bimserver.plugins.Dependency(resolveArtifact.getArtifact().getFile().toPath()));
loadDependencies(resolveArtifact.getArtifact().getFile().toPath(), depDelLoader);
} else {
// TODO error?
}
} catch (Exception e) {
LOGGER.info(dependency2.getArtifact().toString());
e.printStackTrace();
}
// bimServerDependencies.add(new
// org.bimserver.plugins.Dependency(resolveArtifact.getArtifact().getFile().toPath()));
}
}
ArtifactDescriptorRequest descriptorRequest = new ArtifactDescriptorRequest();
descriptorRequest.setArtifact(dependency2.getArtifact());
descriptorRequest.setRepositories(mavenPluginRepository.getRepositories());
ArtifactDescriptorResult descriptorResult = mavenPluginRepository.getSystem().readArtifactDescriptor(mavenPluginRepository.getSession(), descriptorRequest);
CollectRequest collectRequest = new CollectRequest();
collectRequest.setRootArtifact(descriptorResult.getArtifact());
collectRequest.setDependencies(descriptorResult.getDependencies());
collectRequest.setManagedDependencies(descriptorResult.getManagedDependencies());
collectRequest.setRepositories(descriptorResult.getRepositories());
DependencyNode node = mavenPluginRepository.getSystem().collectDependencies(mavenPluginRepository.getSession(), collectRequest).getRoot();
DependencyRequest dependencyRequest = new DependencyRequest();
dependencyRequest.setRoot(node);
CollectResult collectResult = mavenPluginRepository.getSystem().collectDependencies(mavenPluginRepository.getSession(), collectRequest);
PreorderNodeListGenerator nlg = new PreorderNodeListGenerator();
// collectResult.getRoot().accept(new
// ConsoleDependencyGraphDumper());
collectResult.getRoot().accept(nlg);
try {
mavenPluginRepository.getSystem().resolveDependencies(mavenPluginRepository.getSession(), dependencyRequest);
} catch (DependencyResolutionException e) {
// Ignore
}
for (DependencyNode dependencyNode : nlg.getNodes()) {
ArtifactRequest newRequest = new ArtifactRequest(dependencyNode);
newRequest.setRepositories(mavenPluginRepository.getRepositories());
ArtifactResult resolveArtifact = mavenPluginRepository.getSystem().resolveArtifact(mavenPluginRepository.getSession(), newRequest);
Artifact artifact = resolveArtifact.getArtifact();
Path jarFile = Paths.get(artifact.getFile().getAbsolutePath());
loadDependencies(jarFile, depDelLoader);
Artifact versionArtifact = new DefaultArtifact(artifact.getGroupId(), artifact.getArtifactId(), "pom", artifact.getVersion());
ArtifactRequest request = new ArtifactRequest();
request.setArtifact(versionArtifact);
request.setRepositories(mavenPluginRepository.getRepositories());
// try {
// ArtifactResult resolveArtifact =
// mavenPluginRepository.getSystem().resolveArtifact(mavenPluginRepository.getSession(),
// request);
// File depPomFile =
// resolveArtifact.getArtifact().getFile();
// if (depPomFile != null) {
// MavenXpp3Reader mavenreader = new MavenXpp3Reader();
// Model depModel = null;
// try (FileReader reader = new FileReader(depPomFile)) {
// try {
// depModel = mavenreader.read(reader);
// } catch (XmlPullParserException e) {
// e.printStackTrace();
// }
// }
// previous = loadDependencies(bimServerDependencies,
// depModel, previous);
// } else {
// LOGGER.info("Artifact not found " + versionArtifact);
// }
// } catch (ArtifactResolutionException e1) {
// LOGGER.error(e1.getMessage());
// }
// EclipsePluginClassloader depLoader = new
// EclipsePluginClassloader(depDelLoader, projectRoot);
bimServerDependencies.add(new org.bimserver.plugins.Dependency(jarFile));
}
previous = depDelLoader;
} catch (DependencyCollectionException e) {
e.printStackTrace();
} catch (ArtifactDescriptorException e2) {
e2.printStackTrace();
} catch (ArtifactResolutionException e) {
e.printStackTrace();
}
}
return previous;
}
use of org.eclipse.aether.graph.DependencyNode in project bnd by bndtools.
the class DependencyResolver method discoverArtifacts.
private void discoverArtifacts(Map<File, ArtifactResult> files, List<DependencyNode> nodes, String parent, List<RemoteRepository> remoteRepositories) throws MojoExecutionException {
for (DependencyNode node : nodes) {
// Ensure that the file is downloaded so we can index it
try {
ArtifactResult resolvedArtifact = postProcessor.postProcessResult(system.resolveArtifact(session, new ArtifactRequest(node.getArtifact(), remoteRepositories, parent)));
logger.debug("Located file: {} for artifact {}", resolvedArtifact.getArtifact().getFile(), resolvedArtifact);
files.put(resolvedArtifact.getArtifact().getFile(), resolvedArtifact);
} catch (ArtifactResolutionException e) {
throw new MojoExecutionException("Failed to resolve the dependency " + node.getArtifact().toString(), e);
}
if (includeTransitive) {
discoverArtifacts(files, node.getChildren(), node.getRequestContext(), remoteRepositories);
} else {
logger.debug("Ignoring transitive dependencies of {}", node.getDependency());
}
}
}
Aggregations