use of org.eclipse.aether.util.filter.ScopeDependencyFilter 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;
}
use of org.eclipse.aether.util.filter.ScopeDependencyFilter in project grails-maven by grails.
the class AbstractGrailsMojo method resolveArtifacts.
protected List<File> resolveArtifacts(MavenProject mavenProject, Collection<String> scopes, DependencyFilter filter) throws MojoExecutionException {
try {
DefaultDependencyResolutionRequest request = new DefaultDependencyResolutionRequest(mavenProject, repoSession);
if (filter != null) {
request.setResolutionFilter(new AndDependencyFilter(new ScopeDependencyFilter(scopes, Collections.<String>emptyList()), filter));
} else {
request.setResolutionFilter(new ScopeDependencyFilter(scopes, Collections.<String>emptyList()));
}
DependencyResolutionResult result = projectDependenciesResolver.resolve(request);
List<org.eclipse.aether.graph.Dependency> dependencies = result.getDependencies();
final List<File> files = new ArrayList<File>();
for (org.eclipse.aether.graph.Dependency d : dependencies) {
org.eclipse.aether.artifact.Artifact artifact = d.getArtifact();
File file = artifact.getFile();
if (file != null) {
String name = file.getName();
if (!name.contains("xml-apis") && !name.contains("commons-logging"))
files.add(file);
}
}
return files;
} catch (DependencyResolutionException e) {
throw new MojoExecutionException("Dependency resolution failure: " + e.getMessage(), e);
}
}
Aggregations