Search in sources :

Example 1 with DependencyGraphTransformer

use of org.eclipse.aether.collection.DependencyGraphTransformer in project fabric8 by jboss-fuse.

the class AetherBasedResolver method collectDependencies.

protected DependencyNode collectDependencies(Artifact root, String pomVersion, final Filter<Dependency> excludeDependencyFilter) throws RepositoryException, IOException {
    final DefaultRepositorySystemSession session = newSession();
    try {
        List<RemoteRepository> repos = selectRepositories();
        assignProxyAndMirrors(repos);
        ArtifactDescriptorResult artifactDescriptorResult = m_repoSystem.readArtifactDescriptor(session, new ArtifactDescriptorRequest(root, repos, null));
        repos.addAll(artifactDescriptorResult.getRepositories());
        Dependency rootDependency = new Dependency(root, null);
        List<Dependency> dependencies = artifactDescriptorResult.getDependencies();
        final DefaultDependencyNode rootNode = new DefaultDependencyNode(rootDependency);
        GenericVersionScheme versionScheme = new GenericVersionScheme();
        rootNode.setVersion(versionScheme.parseVersion(pomVersion));
        rootNode.setVersionConstraint(versionScheme.parseVersionConstraint(pomVersion));
        DependencyNode pomNode = rootNode;
        // final Filter<Dependency> shouldExclude = Filters.or(DependencyFilters.testScopeFilter, excludeDependencyFilter, new NewerVersionExistsFilter(rootNode));
        final Filter<Dependency> shouldExclude = Filters.or(Arrays.asList(DependencyFilters.testScopeFilter, excludeDependencyFilter));
        DependencySelector dependencySelector = new AndDependencySelector(new ScopeDependencySelector("test"), new ExclusionDependencySelector(), new DependencySelector() {

            @Override
            public DependencySelector deriveChildSelector(DependencyCollectionContext context) {
                return this;
            }

            @Override
            public boolean selectDependency(Dependency dependency) {
                try {
                    return !DependencyFilters.matches(dependency, shouldExclude);
                } catch (Exception e) {
                    failedToMakeDependencyTree(dependency, e);
                    return false;
                }
            }
        });
        session.setDependencySelector(dependencySelector);
        // work on the root dependency directly?
        if (true) {
            for (Dependency dependency : dependencies) {
                DependencyNode node = resolveDependencies(session, repos, pomNode, dependency, shouldExclude);
                if (node != null) {
                    pomNode.getChildren().add(node);
                }
            }
        } else {
            DependencyNode node = resolveDependencies(session, repos, pomNode, rootDependency, shouldExclude);
            if (node != null) {
                pomNode = node;
            }
        }
        // now lets transform the dependency tree to remove different versions for the same artifact
        final DependencyGraphTransformationContext tranformContext = new DependencyGraphTransformationContext() {

            Map<Object, Object> map = new HashMap<>();

            public RepositorySystemSession getSession() {
                return session;
            }

            public Object get(Object key) {
                return map.get(key);
            }

            public Object put(Object key, Object value) {
                return map.put(key, value);
            }
        };
        DependencyGraphTransformer transformer = new ReplaceConflictingVersionResolver();
        pomNode = transformer.transformGraph(pomNode, tranformContext);
        transformer = new DuplicateTransformer();
        pomNode = transformer.transformGraph(pomNode, tranformContext);
        return pomNode;
    } finally {
        releaseSession(session);
    }
}
Also used : DependencyGraphTransformationContext(org.eclipse.aether.collection.DependencyGraphTransformationContext) ReplaceConflictingVersionResolver(io.fabric8.maven.ReplaceConflictingVersionResolver) RemoteRepository(org.eclipse.aether.repository.RemoteRepository) DuplicateTransformer(io.fabric8.maven.DuplicateTransformer) DefaultRepositorySystemSession(org.eclipse.aether.DefaultRepositorySystemSession) DefaultDependencyNode(org.eclipse.aether.graph.DefaultDependencyNode) DependencyNode(org.eclipse.aether.graph.DependencyNode) ChainedDependencyGraphTransformer(org.eclipse.aether.util.graph.transformer.ChainedDependencyGraphTransformer) DependencyGraphTransformer(org.eclipse.aether.collection.DependencyGraphTransformer) ArtifactDescriptorRequest(org.eclipse.aether.resolution.ArtifactDescriptorRequest) ScopeDependencySelector(org.eclipse.aether.util.graph.selector.ScopeDependencySelector) ExclusionDependencySelector(org.eclipse.aether.util.graph.selector.ExclusionDependencySelector) DependencyCollectionContext(org.eclipse.aether.collection.DependencyCollectionContext) AndDependencySelector(org.eclipse.aether.util.graph.selector.AndDependencySelector) Dependency(org.eclipse.aether.graph.Dependency) FailedToResolveDependency(io.fabric8.maven.FailedToResolveDependency) DependencyCollectionException(org.eclipse.aether.collection.DependencyCollectionException) SocketTimeoutException(java.net.SocketTimeoutException) ConnectException(java.net.ConnectException) IOException(java.io.IOException) ArtifactNotFoundException(org.eclipse.aether.transfer.ArtifactNotFoundException) RepositoryException(org.eclipse.aether.RepositoryException) VersionRangeResolutionException(org.eclipse.aether.resolution.VersionRangeResolutionException) MetadataTransferException(org.eclipse.aether.transfer.MetadataTransferException) NoRouteToHostException(java.net.NoRouteToHostException) ArtifactTransferException(org.eclipse.aether.transfer.ArtifactTransferException) ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) DependencyResolutionException(org.eclipse.aether.resolution.DependencyResolutionException) MalformedURLException(java.net.MalformedURLException) MetadataNotFoundException(org.eclipse.aether.transfer.MetadataNotFoundException) InvalidVersionSpecificationException(org.eclipse.aether.version.InvalidVersionSpecificationException) 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) DefaultDependencyNode(org.eclipse.aether.graph.DefaultDependencyNode) GenericVersionScheme(org.eclipse.aether.util.version.GenericVersionScheme) ArtifactDescriptorResult(org.eclipse.aether.resolution.ArtifactDescriptorResult) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap)

Example 2 with DependencyGraphTransformer

use of org.eclipse.aether.collection.DependencyGraphTransformer 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)

Aggregations

DefaultRepositorySystemSession (org.eclipse.aether.DefaultRepositorySystemSession)2 DependencyGraphTransformer (org.eclipse.aether.collection.DependencyGraphTransformer)2 DependencySelector (org.eclipse.aether.collection.DependencySelector)2 AndDependencySelector (org.eclipse.aether.util.graph.selector.AndDependencySelector)2 ExclusionDependencySelector (org.eclipse.aether.util.graph.selector.ExclusionDependencySelector)2 OptionalDependencySelector (org.eclipse.aether.util.graph.selector.OptionalDependencySelector)2 ScopeDependencySelector (org.eclipse.aether.util.graph.selector.ScopeDependencySelector)2 ChainedDependencyGraphTransformer (org.eclipse.aether.util.graph.transformer.ChainedDependencyGraphTransformer)2 DuplicateTransformer (io.fabric8.maven.DuplicateTransformer)1 FailedToResolveDependency (io.fabric8.maven.FailedToResolveDependency)1 ReplaceConflictingVersionResolver (io.fabric8.maven.ReplaceConflictingVersionResolver)1 IOException (java.io.IOException)1 ConnectException (java.net.ConnectException)1 MalformedURLException (java.net.MalformedURLException)1 NoRouteToHostException (java.net.NoRouteToHostException)1 SocketTimeoutException (java.net.SocketTimeoutException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Properties (java.util.Properties)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1