Search in sources :

Example 1 with JavaScopeDeriver

use of org.eclipse.aether.util.graph.transformer.JavaScopeDeriver 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)

Example 2 with JavaScopeDeriver

use of org.eclipse.aether.util.graph.transformer.JavaScopeDeriver in project fabric8 by jboss-fuse.

the class AetherBasedResolver method newRepositorySystemSession.

private static DefaultRepositorySystemSession newRepositorySystemSession() {
    DefaultRepositorySystemSession session = new DefaultRepositorySystemSession();
    DependencyTraverser depTraverser = new FatArtifactTraverser();
    session.setDependencyTraverser(depTraverser);
    DependencyManager depManager = new ClassicDependencyManager();
    session.setDependencyManager(depManager);
    DependencySelector depFilter = new AndDependencySelector(new ScopeDependencySelector("test", "provided"), new OptionalDependencySelector(), new ExclusionDependencySelector());
    session.setDependencySelector(depFilter);
    DependencyGraphTransformer transformer = new ConflictResolver(new NearestVersionSelector(), new JavaScopeSelector(), new SimpleOptionalitySelector(), new JavaScopeDeriver());
    new ChainedDependencyGraphTransformer(transformer, new JavaDependencyContextRefiner());
    session.setDependencyGraphTransformer(transformer);
    DefaultArtifactTypeRegistry stereotypes = new DefaultArtifactTypeRegistry();
    stereotypes.add(new DefaultArtifactType("pom"));
    stereotypes.add(new DefaultArtifactType("maven-plugin", "jar", "", "java"));
    stereotypes.add(new DefaultArtifactType("jar", "jar", "", "java"));
    stereotypes.add(new DefaultArtifactType("ejb", "jar", "", "java"));
    stereotypes.add(new DefaultArtifactType("ejb-client", "jar", "client", "java"));
    stereotypes.add(new DefaultArtifactType("test-jar", "jar", "tests", "java"));
    stereotypes.add(new DefaultArtifactType("javadoc", "jar", "javadoc", "java"));
    stereotypes.add(new DefaultArtifactType("java-source", "jar", "sources", "java", false, false));
    stereotypes.add(new DefaultArtifactType("war", "war", "", "java", false, true));
    stereotypes.add(new DefaultArtifactType("ear", "ear", "", "java", false, true));
    stereotypes.add(new DefaultArtifactType("rar", "rar", "", "java", false, true));
    stereotypes.add(new DefaultArtifactType("par", "par", "", "java", false, true));
    session.setArtifactTypeRegistry(stereotypes);
    session.setArtifactDescriptorPolicy(new SimpleArtifactDescriptorPolicy(true, true));
    Properties sysProps = (Properties) System.getProperties().clone();
    session.setSystemProperties(sysProps);
    session.setConfigProperties(sysProps);
    // set timeout smaller than 30 minutes by default
    session.setConfigProperty(ConfigurationProperties.REQUEST_TIMEOUT, TimeUnit.MINUTES.toMillis(5));
    return session;
}
Also used : JavaDependencyContextRefiner(org.eclipse.aether.util.graph.transformer.JavaDependencyContextRefiner) ConflictResolver(org.eclipse.aether.util.graph.transformer.ConflictResolver) ClassicDependencyManager(org.eclipse.aether.util.graph.manager.ClassicDependencyManager) DependencyManager(org.eclipse.aether.collection.DependencyManager) JavaScopeDeriver(org.eclipse.aether.util.graph.transformer.JavaScopeDeriver) AndDependencySelector(org.eclipse.aether.util.graph.selector.AndDependencySelector) DependencyTraverser(org.eclipse.aether.collection.DependencyTraverser) ConfigurationProperties(org.eclipse.aether.ConfigurationProperties) ArtifactProperties(org.eclipse.aether.artifact.ArtifactProperties) Properties(java.util.Properties) FatArtifactTraverser(org.eclipse.aether.util.graph.traverser.FatArtifactTraverser) ChainedDependencyGraphTransformer(org.eclipse.aether.util.graph.transformer.ChainedDependencyGraphTransformer) OptionalDependencySelector(org.eclipse.aether.util.graph.selector.OptionalDependencySelector) SimpleOptionalitySelector(org.eclipse.aether.util.graph.transformer.SimpleOptionalitySelector) NearestVersionSelector(org.eclipse.aether.util.graph.transformer.NearestVersionSelector) ClassicDependencyManager(org.eclipse.aether.util.graph.manager.ClassicDependencyManager) DefaultRepositorySystemSession(org.eclipse.aether.DefaultRepositorySystemSession) DefaultArtifactTypeRegistry(org.eclipse.aether.util.artifact.DefaultArtifactTypeRegistry) JavaScopeSelector(org.eclipse.aether.util.graph.transformer.JavaScopeSelector) AndDependencySelector(org.eclipse.aether.util.graph.selector.AndDependencySelector) ScopeDependencySelector(org.eclipse.aether.util.graph.selector.ScopeDependencySelector) OptionalDependencySelector(org.eclipse.aether.util.graph.selector.OptionalDependencySelector) ExclusionDependencySelector(org.eclipse.aether.util.graph.selector.ExclusionDependencySelector) DependencySelector(org.eclipse.aether.collection.DependencySelector) ChainedDependencyGraphTransformer(org.eclipse.aether.util.graph.transformer.ChainedDependencyGraphTransformer) DependencyGraphTransformer(org.eclipse.aether.collection.DependencyGraphTransformer) DefaultArtifactType(org.eclipse.aether.artifact.DefaultArtifactType) SimpleArtifactDescriptorPolicy(org.eclipse.aether.util.repository.SimpleArtifactDescriptorPolicy) ScopeDependencySelector(org.eclipse.aether.util.graph.selector.ScopeDependencySelector) ExclusionDependencySelector(org.eclipse.aether.util.graph.selector.ExclusionDependencySelector)

Example 3 with JavaScopeDeriver

use of org.eclipse.aether.util.graph.transformer.JavaScopeDeriver in project wildfly-swarm by wildfly-swarm.

the class MavenArtifactResolvingHelper method resolveAll.

@Override
public Set<ArtifactSpec> resolveAll(Collection<ArtifactSpec> specs, boolean transitive, boolean defaultExcludes) throws Exception {
    if (specs.isEmpty()) {
        return Collections.emptySet();
    }
    List<DependencyNode> nodes;
    if (transitive) {
        final CollectRequest request = new CollectRequest();
        request.setRepositories(this.remoteRepositories);
        // SWARM-1031
        if (this.dependencyManagement != null) {
            List<Dependency> managedDependencies = this.dependencyManagement.getDependencies().stream().map(mavenDep -> {
                DefaultArtifact artifact = new DefaultArtifact(mavenDep.getGroupId(), mavenDep.getArtifactId(), mavenDep.getType(), mavenDep.getVersion());
                return new Dependency(artifact, mavenDep.getScope());
            }).collect(Collectors.toList());
            request.setManagedDependencies(managedDependencies);
        }
        specs.forEach(spec -> request.addDependency(new Dependency(new DefaultArtifact(spec.groupId(), spec.artifactId(), spec.classifier(), spec.type(), spec.version()), "compile")));
        RepositorySystemSession tempSession = new RepositorySystemSessionWrapper(this.session, new ConflictResolver(new NearestVersionSelector(), new JavaScopeSelector(), new SimpleOptionalitySelector(), new JavaScopeDeriver()), defaultExcludes);
        CollectResult result = this.system.collectDependencies(tempSession, request);
        PreorderNodeListGenerator gen = new PreorderNodeListGenerator();
        result.getRoot().accept(gen);
        nodes = gen.getNodes();
    } else {
        nodes = new ArrayList<>();
        for (ArtifactSpec spec : specs) {
            Dependency dependency = new Dependency(new DefaultArtifact(spec.groupId(), spec.artifactId(), spec.classifier(), spec.type(), spec.version()), "compile");
            DefaultDependencyNode node = new DefaultDependencyNode(dependency);
            nodes.add(node);
        }
    }
    List<DependencyNode> extraDependencies = ExtraArtifactsHandler.getExtraDependencies(nodes);
    nodes.addAll(extraDependencies);
    resolveDependenciesInParallel(nodes);
    return nodes.stream().filter(node -> !"system".equals(node.getDependency().getScope())).map(node -> {
        final Artifact artifact = node.getArtifact();
        return new ArtifactSpec(node.getDependency().getScope(), artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), artifact.getExtension(), artifact.getClassifier(), null);
    }).map(this::resolve).filter(Objects::nonNull).collect(Collectors.toSet());
}
Also used : LocalArtifactRequest(org.eclipse.aether.repository.LocalArtifactRequest) Proxy(org.eclipse.aether.repository.Proxy) Dependency(org.eclipse.aether.graph.Dependency) DependencyManagement(org.apache.maven.model.DependencyManagement) SimpleOptionalitySelector(org.eclipse.aether.util.graph.transformer.SimpleOptionalitySelector) RepositorySystemSession(org.eclipse.aether.RepositorySystemSession) ArtifactRepositoryPolicy(org.apache.maven.artifact.repository.ArtifactRepositoryPolicy) ArrayList(java.util.ArrayList) ArtifactRepository(org.apache.maven.artifact.repository.ArtifactRepository) ConflictResolver(org.eclipse.aether.util.graph.transformer.ConflictResolver) JavaScopeSelector(org.eclipse.aether.util.graph.transformer.JavaScopeSelector) NearestVersionSelector(org.eclipse.aether.util.graph.transformer.NearestVersionSelector) ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) CollectRequest(org.eclipse.aether.collection.CollectRequest) CollectResult(org.eclipse.aether.collection.CollectResult) DependencyNode(org.eclipse.aether.graph.DependencyNode) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) RepositoryPolicy(org.eclipse.aether.repository.RepositoryPolicy) Collection(java.util.Collection) Authentication(org.apache.maven.artifact.repository.Authentication) Artifact(org.eclipse.aether.artifact.Artifact) JavaScopeDeriver(org.eclipse.aether.util.graph.transformer.JavaScopeDeriver) PreorderNodeListGenerator(org.eclipse.aether.util.graph.visitor.PreorderNodeListGenerator) Set(java.util.Set) LocalArtifactResult(org.eclipse.aether.repository.LocalArtifactResult) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult) DefaultDependencyNode(org.eclipse.aether.graph.DefaultDependencyNode) Collectors(java.util.stream.Collectors) ArtifactResolvingHelper(org.wildfly.swarm.tools.ArtifactResolvingHelper) Objects(java.util.Objects) RemoteRepository(org.eclipse.aether.repository.RemoteRepository) AuthenticationBuilder(org.eclipse.aether.util.repository.AuthenticationBuilder) List(java.util.List) ArtifactResolver(org.eclipse.aether.impl.ArtifactResolver) ArtifactRequest(org.eclipse.aether.resolution.ArtifactRequest) Collections(java.util.Collections) RepositorySystem(org.eclipse.aether.RepositorySystem) ArtifactSpec(org.wildfly.swarm.tools.ArtifactSpec) RepositorySystemSession(org.eclipse.aether.RepositorySystemSession) ConflictResolver(org.eclipse.aether.util.graph.transformer.ConflictResolver) CollectResult(org.eclipse.aether.collection.CollectResult) JavaScopeDeriver(org.eclipse.aether.util.graph.transformer.JavaScopeDeriver) Dependency(org.eclipse.aether.graph.Dependency) CollectRequest(org.eclipse.aether.collection.CollectRequest) PreorderNodeListGenerator(org.eclipse.aether.util.graph.visitor.PreorderNodeListGenerator) SimpleOptionalitySelector(org.eclipse.aether.util.graph.transformer.SimpleOptionalitySelector) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Artifact(org.eclipse.aether.artifact.Artifact) NearestVersionSelector(org.eclipse.aether.util.graph.transformer.NearestVersionSelector) ArtifactSpec(org.wildfly.swarm.tools.ArtifactSpec) JavaScopeSelector(org.eclipse.aether.util.graph.transformer.JavaScopeSelector) DependencyNode(org.eclipse.aether.graph.DependencyNode) DefaultDependencyNode(org.eclipse.aether.graph.DefaultDependencyNode) DefaultDependencyNode(org.eclipse.aether.graph.DefaultDependencyNode) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact)

Aggregations

ConflictResolver (org.eclipse.aether.util.graph.transformer.ConflictResolver)3 JavaScopeDeriver (org.eclipse.aether.util.graph.transformer.JavaScopeDeriver)3 JavaScopeSelector (org.eclipse.aether.util.graph.transformer.JavaScopeSelector)3 NearestVersionSelector (org.eclipse.aether.util.graph.transformer.NearestVersionSelector)3 SimpleOptionalitySelector (org.eclipse.aether.util.graph.transformer.SimpleOptionalitySelector)3 DependencyManagement (org.apache.maven.model.DependencyManagement)2 DefaultRepositorySystemSession (org.eclipse.aether.DefaultRepositorySystemSession)2 CollectRequest (org.eclipse.aether.collection.CollectRequest)2 DependencyNode (org.eclipse.aether.graph.DependencyNode)2 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 List (java.util.List)1 Objects (java.util.Objects)1 Properties (java.util.Properties)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 ArtifactRepository (org.apache.maven.artifact.repository.ArtifactRepository)1