Package org.apache.maven.artifact.resolver

Examples of org.apache.maven.artifact.resolver.ResolutionNode


            ArtifactMetadataSource source,
            ArtifactFilter filter,
            List listeners) throws ArtifactResolutionException {
        Map resolvedArtifacts = new HashMap();

        ResolutionNode root = new ResolutionNode(originatingArtifact, remoteRepositories);
        root.addDependencies(artifacts, remoteRepositories, filter);
        recurse(root, resolvedArtifacts, managedVersions, localRepository,
                remoteRepositories, source, filter, listeners);

        Set set = new HashSet();
        for (Iterator i = resolvedArtifacts.values().iterator(); i.hasNext();) {
            List nodes = (List) i.next();
            for (Iterator j = nodes.iterator(); j.hasNext();) {
                ResolutionNode node = (ResolutionNode) j.next();
                Artifact artifact = node.getArtifact();
                if (!node.equals(root) && node.isActive() && node.filterTrail(filter)
                        // If it was optional and not a direct dependency,
                        // we don't add it or its children, just allow the
                        // update of the version and scope
                        && (node.isChildOfRootNode() || !artifact.isOptional())) {
                    artifact.setDependencyTrail(node.getDependencyTrail());
                    set.add(node);
                }
            }
        }
View Full Code Here


        // don't pull in the transitive deps of a system-scoped dependency.
        if (node.isActive() && !Artifact.SCOPE_SYSTEM.equals(node.getArtifact().getScope())) {
            fireEvent(ResolutionListener.PROCESS_CHILDREN, listeners, node);
            for (Iterator i = node.getChildrenIterator(); i.hasNext();) {
                ResolutionNode child = (ResolutionNode) i.next();
                // We leave in optional ones, but don't pick up its dependencies
                if (!child.isResolved()
                        && (!child.getArtifact().isOptional() || child.isChildOfRootNode())) {
                    Artifact artifact = child.getArtifact();
                    try {
                        if (artifact.getVersion() == null) {
                            // set the recommended version
                            // TODO: maybe its better to just pass the range
                            // through to retrieval and use a transformation?
                            ArtifactVersion version;
                            version = getArtifactVersion(localRepository, remoteRepositories, source, artifact);

                            artifact.selectVersion(version.toString());
                            fireEvent(ResolutionListener.SELECT_VERSION_FROM_RANGE,
                                    listeners, child);
                        }

                        ResolutionGroup rGroup = source.retrieve(artifact,
                                localRepository, remoteRepositories);

                        // TODO might be better to have source.retreive() throw
                        // a specific exception for this situation
                        // and catch here rather than have it return null
                        if (rGroup == null) {
                            // relocated dependency artifact is declared
                            // excluded, no need to add and recurse further
                            continue;
                        }

                        child.addDependencies(rGroup.getArtifacts(),
                                rGroup.getResolutionRepositories(), filter);
                    }
                    catch (CyclicDependencyException e) {
                        // would like to throw this, but we have crappy stuff in
                        // the repo

                        fireEvent(ResolutionListener.OMIT_FOR_CYCLE, listeners,
                                new ResolutionNode(e.getArtifact(), remoteRepositories, child));
                    }
                    catch (ArtifactMetadataRetrievalException e) {
                        artifact.setDependencyTrail(node.getDependencyTrail());
                        throw new ArtifactResolutionException(
                                "Unable to get dependency information: "
View Full Code Here

    private ResolutionNode checkPreviousNodes(
            ResolutionNode node,
            List listeners,
            List previousNodes) throws OverConstrainedVersionException {
        for (Iterator i = previousNodes.iterator(); i.hasNext();) {
            ResolutionNode previous = (ResolutionNode) i.next();
            if (previous.isActive()) {
                // Version mediation
                VersionRange previousRange = previous.getArtifact().getVersionRange();
                VersionRange currentRange = node.getArtifact().getVersionRange();
                // TODO: why do we force the version on it? what if they
                // don't match?
                if (previousRange == null) {
                    // version was already resolved
                    node.getArtifact().setVersion(previous.getArtifact().getVersion());
                }
                else if (currentRange == null) {
                    // version was already resolved
                    previous.getArtifact().setVersion(node.getArtifact().getVersion());
                }
                else {
                    // TODO: shouldn't need to double up on this work, only
                    // done for simplicity of handling recommended
                    // version but the restriction is identical
                    VersionRange newRange = previousRange.restrict(currentRange);
                    // TODO: ick. this forces the OCE that should have come
                    // from the previous call. It is still correct
                    if (newRange.isSelectedVersionKnown(previous.getArtifact())) {
                        fireEvent(ResolutionListener.RESTRICT_RANGE,
                                listeners, node, previous.getArtifact(),
                                newRange);
                    }
                    previous.getArtifact().setVersionRange(newRange);
                    node.getArtifact().setVersionRange(
                            currentRange.restrict(previousRange));

                    // Select an appropriate available version from the (now
                    // restricted) range
                    // Note this version was selected before to get the
                    // appropriate POM
                    // But it was reset by the call to setVersionRange on
                    // restricting the version
                    ResolutionNode[] resetNodes = {previous, node};
                    for (int j = 0; j < 2; j++) {
                        Artifact resetArtifact = resetNodes[j]
                                .getArtifact();
                        if (resetArtifact.getVersion() == null
                                && resetArtifact.getVersionRange() != null
                                && resetArtifact.getAvailableVersions() != null) {

                            resetArtifact
                                    .selectVersion(resetArtifact
                                            .getVersionRange()
                                            .matchVersion(
                                                    resetArtifact
                                                            .getAvailableVersions())
                                            .toString());
                            fireEvent(ResolutionListener.SELECT_VERSION_FROM_RANGE,
                                    listeners, resetNodes[j]);
                        }
                    }
                }

                // Conflict Resolution
                // TODO: use as conflict resolver(s), chain

                // TODO: should this be part of mediation?
                // previous one is more dominant
                if (previous.getDepth() <= node.getDepth()) {
                    checkScopeUpdate(node, previous, listeners);
                }
                else {
                    checkScopeUpdate(previous, node, listeners);
                }

                if (previous.getDepth() <= node.getDepth()) {
                    // previous was nearer
                    fireEvent(ResolutionListener.OMIT_FOR_NEARER,
                            listeners, node, previous.getArtifact());
                    node.disable();
                    node = previous;
                }
                else {
                    fireEvent(ResolutionListener.OMIT_FOR_NEARER,
                            listeners, previous, node.getArtifact());
                    previous.disable();
                }
            }
        }
        return node;
    }
View Full Code Here

     * b:1.0 -> a:2.0
     * </pre>
     */
    public void testDepth()
    {
        ResolutionNode a1n = new ResolutionNode( a1, Collections.EMPTY_LIST );
        ResolutionNode b1n = new ResolutionNode( b1, Collections.EMPTY_LIST );
        ResolutionNode a2n = new ResolutionNode( a2, Collections.EMPTY_LIST, b1n );
       
        assertResolveConflict( a1n, a1n, a2n );
    }
View Full Code Here

     * a:1.0
     * </pre>
     */
    public void testDepthReversed()
    {
        ResolutionNode b1n = new ResolutionNode( b1, Collections.EMPTY_LIST );
        ResolutionNode a2n = new ResolutionNode( a2, Collections.EMPTY_LIST, b1n );
        ResolutionNode a1n = new ResolutionNode( a1, Collections.EMPTY_LIST );
       
        assertResolveConflict( a1n, a2n, a1n );
    }
View Full Code Here

     * a:2.0
     * </pre>
     */
    public void testEqual()
    {
        ResolutionNode a1n = new ResolutionNode( a1, Collections.EMPTY_LIST );
        ResolutionNode a2n = new ResolutionNode( a2, Collections.EMPTY_LIST );
       
        assertResolveConflict( a1n, a1n, a2n );
    }
View Full Code Here

     * a:1.0
     * </pre>
     */
    public void testEqualReversed()
    {
        ResolutionNode a2n = new ResolutionNode( a2, Collections.EMPTY_LIST );
        ResolutionNode a1n = new ResolutionNode( a1, Collections.EMPTY_LIST );
       
        assertResolveConflict( a2n, a2n, a1n );
    }
View Full Code Here

        return conflictResolver;
    }
   
    protected void assertResolveConflict( ResolutionNode expectedNode, ResolutionNode actualNode1, ResolutionNode actualNode2 )
    {
        ResolutionNode resolvedNode = getConflictResolver().resolveConflict( actualNode1, actualNode2 );
       
        assertNotNull( "Expected resolvable", resolvedNode );
        assertEquals( "Resolution node", expectedNode, resolvedNode );
    }
View Full Code Here

        assertEquals( "Resolution node", expectedNode, resolvedNode );
    }

    protected void assertUnresolvableConflict( ResolutionNode actualNode1, ResolutionNode actualNode2 )
    {
        ResolutionNode resolvedNode = getConflictResolver().resolveConflict( actualNode1, actualNode2 );
       
        assertNull( "Expected unresolvable", resolvedNode );
    }
View Full Code Here

     * b:1.0 -> a:2.0
     * </pre>
     */
    public void testDepth()
    {
        ResolutionNode a1n = new ResolutionNode( a1, Collections.EMPTY_LIST );
        ResolutionNode b1n = new ResolutionNode( b1, Collections.EMPTY_LIST );
        ResolutionNode a2n = new ResolutionNode( a2, Collections.EMPTY_LIST, b1n );
       
        assertResolveConflict( a1n, a1n, a2n );
    }
View Full Code Here

TOP

Related Classes of org.apache.maven.artifact.resolver.ResolutionNode

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.