use of org.eclipse.aether.util.graph.visitor.FilteringDependencyVisitor in project sts4 by spring-projects.
the class MavenCore method readDependencyTree.
/**
* Taken from M2E same named method from MavenModelManager
*
* @param repositorySystem
* @param repositorySession
* @param mavenProject
* @param scope
* @return
*/
private DependencyNode readDependencyTree(org.eclipse.aether.RepositorySystem repositorySystem, RepositorySystemSession repositorySession, MavenProject mavenProject, String scope) {
DefaultRepositorySystemSession session = new DefaultRepositorySystemSession(repositorySession);
ConflictResolver transformer = new ConflictResolver(new NearestVersionSelector(), new JavaScopeSelector(), new SimpleOptionalitySelector(), new JavaScopeDeriver());
session.setDependencyGraphTransformer(transformer);
session.setConfigProperty(ConflictResolver.CONFIG_PROP_VERBOSE, Boolean.toString(true));
session.setConfigProperty(DependencyManagerUtils.CONFIG_PROP_VERBOSE, true);
ArtifactTypeRegistry stereotypes = session.getArtifactTypeRegistry();
CollectRequest request = new CollectRequest();
// $NON-NLS-1$
request.setRequestContext("project");
request.setRepositories(mavenProject.getRemoteProjectRepositories());
for (org.apache.maven.model.Dependency dependency : mavenProject.getDependencies()) {
request.addDependency(RepositoryUtils.toDependency(dependency, stereotypes));
}
DependencyManagement depMngt = mavenProject.getDependencyManagement();
if (depMngt != null) {
for (org.apache.maven.model.Dependency dependency : depMngt.getDependencies()) {
request.addManagedDependency(RepositoryUtils.toDependency(dependency, stereotypes));
}
}
DependencyNode node;
try {
node = repositorySystem.collectDependencies(session, request).getRoot();
} catch (DependencyCollectionException ex) {
node = ex.getResult().getRoot();
}
Collection<String> scopes = new HashSet<String>();
Collections.addAll(scopes, Artifact.SCOPE_SYSTEM, Artifact.SCOPE_COMPILE, Artifact.SCOPE_PROVIDED, Artifact.SCOPE_RUNTIME, Artifact.SCOPE_TEST);
if (Artifact.SCOPE_COMPILE.equals(scope)) {
scopes.remove(Artifact.SCOPE_COMPILE);
scopes.remove(Artifact.SCOPE_SYSTEM);
scopes.remove(Artifact.SCOPE_PROVIDED);
} else if (Artifact.SCOPE_RUNTIME.equals(scope)) {
scopes.remove(Artifact.SCOPE_COMPILE);
scopes.remove(Artifact.SCOPE_RUNTIME);
} else if (Artifact.SCOPE_COMPILE_PLUS_RUNTIME.equals(scope)) {
scopes.remove(Artifact.SCOPE_COMPILE);
scopes.remove(Artifact.SCOPE_SYSTEM);
scopes.remove(Artifact.SCOPE_PROVIDED);
scopes.remove(Artifact.SCOPE_RUNTIME);
} else {
scopes.clear();
}
CloningDependencyVisitor cloner = new CloningDependencyVisitor();
node.accept(new FilteringDependencyVisitor(cloner, new ScopeDependencyFilter(null, scopes)));
node = cloner.getRootNode();
return node;
}
Aggregations