Search in sources :

Example 1 with ArtifactTypeRegistry

use of org.eclipse.aether.artifact.ArtifactTypeRegistry 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;
}
Also used : DependencyCollectionException(org.eclipse.aether.collection.DependencyCollectionException) CloningDependencyVisitor(org.eclipse.aether.util.graph.visitor.CloningDependencyVisitor) FilteringDependencyVisitor(org.eclipse.aether.util.graph.visitor.FilteringDependencyVisitor) ConflictResolver(org.eclipse.aether.util.graph.transformer.ConflictResolver) JavaScopeDeriver(org.eclipse.aether.util.graph.transformer.JavaScopeDeriver) CollectRequest(org.eclipse.aether.collection.CollectRequest) SimpleOptionalitySelector(org.eclipse.aether.util.graph.transformer.SimpleOptionalitySelector) NearestVersionSelector(org.eclipse.aether.util.graph.transformer.NearestVersionSelector) DefaultRepositorySystemSession(org.eclipse.aether.DefaultRepositorySystemSession) ArtifactTypeRegistry(org.eclipse.aether.artifact.ArtifactTypeRegistry) JavaScopeSelector(org.eclipse.aether.util.graph.transformer.JavaScopeSelector) DependencyNode(org.eclipse.aether.graph.DependencyNode) ScopeDependencyFilter(org.eclipse.aether.util.filter.ScopeDependencyFilter) DependencyManagement(org.apache.maven.model.DependencyManagement) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Aggregations

HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 DependencyManagement (org.apache.maven.model.DependencyManagement)1 DefaultRepositorySystemSession (org.eclipse.aether.DefaultRepositorySystemSession)1 ArtifactTypeRegistry (org.eclipse.aether.artifact.ArtifactTypeRegistry)1 CollectRequest (org.eclipse.aether.collection.CollectRequest)1 DependencyCollectionException (org.eclipse.aether.collection.DependencyCollectionException)1 DependencyNode (org.eclipse.aether.graph.DependencyNode)1 ScopeDependencyFilter (org.eclipse.aether.util.filter.ScopeDependencyFilter)1 ConflictResolver (org.eclipse.aether.util.graph.transformer.ConflictResolver)1 JavaScopeDeriver (org.eclipse.aether.util.graph.transformer.JavaScopeDeriver)1 JavaScopeSelector (org.eclipse.aether.util.graph.transformer.JavaScopeSelector)1 NearestVersionSelector (org.eclipse.aether.util.graph.transformer.NearestVersionSelector)1 SimpleOptionalitySelector (org.eclipse.aether.util.graph.transformer.SimpleOptionalitySelector)1 CloningDependencyVisitor (org.eclipse.aether.util.graph.visitor.CloningDependencyVisitor)1 FilteringDependencyVisitor (org.eclipse.aether.util.graph.visitor.FilteringDependencyVisitor)1