Example usage for org.apache.maven.artifact.resolver ResolutionNode getKey

List of usage examples for org.apache.maven.artifact.resolver ResolutionNode getKey

Introduction

In this page you can find the example usage for org.apache.maven.artifact.resolver ResolutionNode getKey.

Prototype

public Object getKey() 

Source Link

Usage

From source file:com.adviser.maven.GraphArtifactCollector.java

License:Apache License

private void recurse(ResolutionNode node, Map resolvedArtifacts, Map managedVersions,
        ArtifactRepository localRepository, List remoteRepositories, ArtifactMetadataSource source,
        ArtifactFilter filter, List listeners)
        throws CyclicDependencyException, ArtifactResolutionException, OverConstrainedVersionException {
    fireEvent(ResolutionListener.TEST_ARTIFACT, listeners, node);

    // TODO: use as a conflict resolver
    Object key = node.getKey();
    if (managedVersions.containsKey(key)) {
        Artifact artifact = (Artifact) managedVersions.get(key);
        fireEvent(ResolutionListener.MANAGE_ARTIFACT, listeners, node, artifact);
        if (artifact.getVersion() != null) {
            node.getArtifact().setVersion(artifact.getVersion());
        }//from w  ww.j av a 2 s  . c o m
        if (artifact.getScope() != null) {
            node.getArtifact().setScope(artifact.getScope());
        }
    }

    List previousNodes = (List) resolvedArtifacts.get(key);
    if (previousNodes != null) {
        node = checkPreviousNodes(node, listeners, previousNodes);
    } else {
        previousNodes = new ArrayList();
        resolvedArtifacts.put(key, previousNodes);
    }
    previousNodes.add(node);

    if (node.isActive()) {
        fireEvent(ResolutionListener.INCLUDE_ARTIFACT, listeners, node);
    }

    // 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: " + e.getMessage(), artifact, e);
                }

                recurse(child, resolvedArtifacts, managedVersions, localRepository, remoteRepositories, source,
                        filter, listeners);
            }
        }
        fireEvent(ResolutionListener.FINISH_PROCESSING_CHILDREN, listeners, node);
    }
}

From source file:org.codehaus.mojo.pomtools.console.screens.custom.TransitiveStartPointDetailScreen.java

License:Apache License

public ConsoleScreenDisplay getDisplay() throws ConsoleExecutionException {
    StringBuffer sb = new StringBuffer(getHeader(TITLE));

    sb.append(NEWLINE);/*w w  w  .  j  a v  a  2s  . com*/

    TreeNode tree = new TreeNode(null, new Comparator() {

        public int compare(Object arg0, Object arg1) {
            ResolutionNode n0 = (ResolutionNode) arg0;
            ResolutionNode n1 = (ResolutionNode) arg1;

            return ((Comparable) n0.getKey()).compareTo(n1.getKey());
        }

    });

    TransitiveDependencyInfo resolutionInfo = (TransitiveDependencyInfo) getEditorObject();

    recurseNode(tree, resolutionInfo.getSelectedNode());

    String treeOutput = tree.getSingleChild().toString(new TreeNode.Stringifier() {

        public String getNodeLabel(TreeNode treeNode) {
            ResolutionNode node = (ResolutionNode) treeNode.getId();
            StringBuffer sb = new StringBuffer();

            Artifact artifact = node.getArtifact();

            // Only print bold if we are also showing inactive
            if (node.isActive() && showInactive) {
                sb.append(getTerminal().bold(artifact.toString()));
            } else {
                sb.append(artifact.toString());

                if (!getTerminal().supportsFormatting()) {
                    sb.append(" (inactive)");
                }
            }

            return sb.toString();
        }

    });

    sb.append(treeOutput);

    OptionsPane options = getOptionsPane(false);

    options.add(KEY_OPTIONAL_TOGGLE,
            "Toggle display of inactive dependencies. currently: " + (showInactive ? "ON" : "OFF"));

    sb.append(options.getOutput());

    return createDisplay(sb.toString(), PRESS_ENTER_TO_CONTINUE);
}

From source file:org.codehaus.mojo.pomtools.helpers.MetadataHelper.java

License:Apache License

protected void recurseNode(Map dependencyMap, Set seen, Iterator nodeIter, int depth) throws PomToolsException {
    while (nodeIter.hasNext()) {
        ResolutionNode node = (ResolutionNode) nodeIter.next();

        if (!seen.contains(node)) {
            seen.add(node);/*w w w .  j ava2s.  c  o  m*/

            TransitiveDependencyInfo info = (TransitiveDependencyInfo) dependencyMap.get(node.getKey());

            // if we couldn't find the info in the map, then its not a dependency that we should 
            // care about because it wasn't returned to the top level dependency resolution.
            if (info != null) {
                info.addResolutionNode(node);

                if (node.isResolved()) {
                    recurseNode(dependencyMap, seen, node.getChildrenIterator(), depth + 1);
                }
            }
        }
    }
}

From source file:org.codehaus.mojo.pomtools.helpers.TransitiveDependencyInfo.java

License:Apache License

/** Returns a sorted list of distinct versions from all of the ResolutionNodes
 * and the number of occurances./*from ww  w .  ja  v a2  s. c o m*/
 * 
 * @return a list of {@link VersionCount} objects
 */
public List getDistinctVersionCounts() {
    List infoList = new ArrayList();
    List unparsedList = new ArrayList();
    CountMap countMap = new CountMap();

    // Create a list of VersionInfo objects so we can sort them.
    for (Iterator i = resolutionNodes.iterator(); i.hasNext();) {
        ResolutionNode node = (ResolutionNode) i.next();

        ModelVersionRange vRange = new ModelVersionRange(node.getArtifact().getVersionRange());

        if (vRange.hasRestrictions()) {
            if (countMap.increment(vRange.toString())) {
                unparsedList.add(vRange.toString());
            }
        } else {
            VersionInfo vInfo = new DefaultVersionInfo(
                    StringUtils.defaultString(vRange.toString(), "(unknown)"));

            if (vInfo.isParsed()) {
                // Add it to our parsed list
                if (countMap.increment(vInfo.getVersionString())) {
                    infoList.add(vInfo);
                }
            } else {
                // Add it to the unparsed list
                if (countMap.increment(vRange.toString())) {
                    unparsedList.add(vRange.toString());

                    PomToolsPluginContext.getInstance().getLog().warn("Dependency contained an unparsable "
                            + "version: \"" + node.getArtifact().getVersion() + "\" " + node.getKey());
                }
            }
        }
    }

    List result = new ArrayList(infoList.size());

    // Add all the unparsed versions 
    for (Iterator iter = unparsedList.iterator(); iter.hasNext();) {
        String version = (String) iter.next();

        result.add(new VersionCount(version, countMap.get(version)));
    }

    // Add the sorted parsed versions
    Collections.sort(infoList);
    for (Iterator iter = infoList.iterator(); iter.hasNext();) {
        VersionInfo info = (VersionInfo) iter.next();

        result.add(new VersionCount(info.getVersionString(), countMap.get(info.getVersionString())));
    }

    return result;
}

From source file:org.codehaus.mojo.pomtools.helpers.TransitiveDependencyInfo.java

License:Apache License

/** Returns an object tree of all of the possible paths which can transitively include
 * this artifact. The root immediate children of the root node of the resulting tree will
 * be the directly included dependencies which lead to this artifact.
 * //from   ww w  .  j  ava2s  . c  o m
 * @return
 * @throws PomToolsException
 */
public TreeNode getInclusionTree() throws PomToolsException {
    TreeNode tree = new TreeNode(null, new Comparator() {
        public int compare(Object arg0, Object arg1) {
            ResolutionNode n0 = (ResolutionNode) arg0;
            ResolutionNode n1 = (ResolutionNode) arg1;

            return ((Comparable) n0.getKey()).compareTo(n1.getKey());
        }
    });

    for (Iterator iter = getResolutionNodes().iterator(); iter.hasNext();) {
        ResolutionNode node = (ResolutionNode) iter.next();

        List depTrail = APIWorkaroundHelper.getNodeLineage(node);

        TreeNode currentTree = tree;

        for (Iterator trailIter = depTrail.iterator(); trailIter.hasNext();) {
            // currentTree is reassigned each time to the tree of the newly added child
            currentTree = currentTree.addChild(trailIter.next());
        }
    }

    if (!tree.hasChildren()) {
        // this shouldn't happen
        throw new PomToolsException("Unable to determine lineage of transitive dependency");
    }

    return tree.getSingleChild();
}

From source file:org.universAAL.maven.treebuilder.DependencyTreeBuilder.java

License:Apache License

/**
 * Updates node's scope and version according to the dependency management
 * information./*from  w  ww .j  a va 2s.c o  m*/
 * 
 * @param node
 *            Node which scope will be updated.
 * @param managedVersions
 *            Map containing all managed versions.
 */
private void manageArtifact(final ResolutionNode node, final ManagedVersionMap managedVersions) {
    Artifact artifact = (Artifact) managedVersions.get(node.getKey());

    // Before we update the version of the artifact, we need to know
    // whether we are working on a transitive dependency or not. This
    // allows depMgmt to always override transitive dependencies, while
    // explicit child override depMgmt (viz. depMgmt should only
    // provide defaults to children, but should override transitives).
    // We can do this by calling isChildOfRootNode on the current node.

    if (artifact.getVersion() != null
            && (node.isChildOfRootNode() ? node.getArtifact().getVersion() == null : true)) {
        if (!"org.apache.felix:org.osgi.compendium:jar".equals(node.getKey())) {
            node.getArtifact().setVersion(artifact.getVersion());
        }
    }

    if (artifact.getScope() != null
            && (node.isChildOfRootNode() ? node.getArtifact().getScope() == null : true)) {
        if (!"org.apache.felix:org.osgi.compendium:jar".equals(node.getKey())) {
            node.getArtifact().setScope(artifact.getScope());
        }
    }
}

From source file:org.universAAL.maven.treebuilder.DependencyTreeBuilder.java

License:Apache License

/**
 * Method resolves provided node with the use of provided
 * ArtifactMetadataSource and taking into account ManagedVersionMap. Output
 * is passed to listeners, passed as argument, which are notified about all
 * events related to dependencies detected in the tree.
 * //from w  w  w  .j  av a  2  s  .c o m
 * @param parentNode
 *            Parent node
 * @param child
 *            Child node
 * @param filter
 *            Filter for filtering artifacts for the resolving process.
 * @param managedVersions
 *            Map of managed versions.
 * @param listener
 *            Listener to be notified about events related to resolution
 *            process.
 * @param source
 *            ArtifactMetadataSource object passed by maven.
 * @param parentArtifact
 *            Parent artifact
 * @return returns true if the child should be recursively resolved.
 * @throws OverConstrainedVersionException
 *             Occurs when ranges exclude each other and no valid value
 *             remains.
 * @throws ArtifactMetadataRetrievalException
 *             Error while retrieving repository metadata from the
 *             repository
 */
private boolean resolveChildNode(final ResolutionNode parentNode, final ResolutionNode child,
        final ArtifactFilter filter, final ManagedVersionMap managedVersions,
        final DependencyTreeResolutionListener listener, final ArtifactMetadataSource source,
        final Artifact parentArtifact)
        throws OverConstrainedVersionException, ArtifactMetadataRetrievalException {
    // We leave in optional ones, but don't pick up its dependencies
    if (!child.isResolved() && (!child.getArtifact().isOptional() || child.isChildOfRootNode())) {
        Artifact artifact = child.getArtifact();
        artifact.setDependencyTrail(parentNode.getDependencyTrail());

        List childRemoteRepositories = child.getRemoteRepositories();
        try {
            Object childKey;
            do {
                childKey = child.getKey();

                if (managedVersions.containsKey(childKey)) {
                    // If this child node is a managed dependency,
                    // ensure
                    // we are using the dependency management
                    // version
                    // of this child if applicable b/c we want to
                    // use the
                    // managed version's POM, *not* any other
                    // version's POM.
                    // We retrieve the POM below in the retrieval
                    // step.
                    manageArtifact(child, managedVersions);

                    // Also, we need to ensure that any exclusions
                    // it presents are
                    // added to the artifact before we retrieve the
                    // metadata
                    // for the artifact; otherwise we may end up
                    // with unwanted
                    // dependencies.
                    Artifact ma = (Artifact) managedVersions.get(childKey);
                    ArtifactFilter managedExclusionFilter = ma.getDependencyFilter();
                    if (null != managedExclusionFilter) {
                        if (null != artifact.getDependencyFilter()) {
                            AndArtifactFilter aaf = new AndArtifactFilter();
                            aaf.add(artifact.getDependencyFilter());
                            aaf.add(managedExclusionFilter);
                            artifact.setDependencyFilter(aaf);
                        } else {
                            artifact.setDependencyFilter(managedExclusionFilter);
                        }
                    }
                }

                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;
                    if (artifact.isSelectedVersionKnown()) {
                        version = artifact.getSelectedVersion();
                    } else {
                        // go find the version
                        List versions = artifact.getAvailableVersions();
                        if (versions == null) {
                            versions = source.retrieveAvailableVersions(artifact, localRepository,
                                    childRemoteRepositories);
                            artifact.setAvailableVersions(versions);
                        }

                        Collections.sort(versions);

                        VersionRange versionRange = artifact.getVersionRange();

                        version = versionRange.matchVersion(versions);

                        if (version == null) {
                            if (versions.isEmpty()) {
                                throw new OverConstrainedVersionException(
                                        "No versions are present in the repository for the artifact with a range "
                                                + versionRange,
                                        artifact, childRemoteRepositories);
                            }

                            throw new OverConstrainedVersionException("Couldn't find a version in " + versions
                                    + " to match range " + versionRange, artifact, childRemoteRepositories);
                        }
                    }

                    // this is dangerous because
                    // artifact.getSelectedVersion() can
                    // return null. However it is ok here because we
                    // first check if the
                    // selected version is known. As currently coded
                    // we can't get a null here.
                    artifact.selectVersion(version.toString());
                    fireEvent(ResolutionListener.SELECT_VERSION_FROM_RANGE, listener, child);
                }

                // rotgier: it is not compatible with maven 3
                // Artifact relocated = source.retrieveRelocatedArtifact(
                // artifact, localRepository, childRemoteRepositories);
                // if (relocated != null && !artifact.equals(relocated)) {
                // relocated.setDependencyFilter(artifact
                // .getDependencyFilter());
                // artifact = relocated;
                // child.setArtifact(artifact);
                // }
            } while (!childKey.equals(child.getKey()));

            if (parentArtifact != null && parentArtifact.getDependencyFilter() != null
                    && !parentArtifact.getDependencyFilter().include(artifact)) {
                // MNG-3769: the [probably relocated] artifact is
                // excluded.
                // We could process exclusions on relocated artifact
                // details in the
                // MavenMetadataSource.createArtifacts(..) step, BUT
                // that would
                // require resolving the POM from the repository
                // very early on in
                // the build.
                return true;
            }

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

            // TODO might be better to have source.retrieve() 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
                return true;
            }
            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, listener,
                    new ResolutionNode(e.getArtifact(), childRemoteRepositories, child));
        } catch (ArtifactMetadataRetrievalException e) {
            artifact.setDependencyTrail(parentNode.getDependencyTrail());
            throw e;
        }
    } else {
        return true;
    }
    return false;
}

From source file:org.universAAL.maven.treebuilder.DependencyTreeBuilder.java

License:Apache License

/**
 * The heart of the tree builder. Recursively resolves provided artifact.
 * Output is passed to listeners, passed as argument, which are notified
 * about all dependencies detected in the tree. Resolving of each child node
 * is delegated to resolveChildNode method.
 * //from ww  w .  j  av a2 s  . c o m
 * @param originatingArtifact
 *            Rootnode of recursed subtree.
 * @param node
 *            Current node which is resolved.
 * @param resolvedArtifacts
 *            Map which is used for remembering already resolved artifacts.
 *            Artifacts are indexed by a key which calculation algorithm is
 *            the same as the one present in calculateDepKey method. Thanks
 *            to this map, duplicates and conflicts are detected and
 *            resolved.
 * @param managedVersions
 *            Information about dependency management extracted from the
 *            subtree rootnode - a maven project.
 * @param localRepository
 *            Local maven repository.
 * @param remoteRepositories
 *            Remote repositories provided by maven.
 * @param source
 *            ArtifactMetadataSource provided by maven.
 * @param filter
 *            Filter used for unfiltering artifacts which should not be
 *            included in the dependency tree.
 * @param listener
 *            Listener used for providing the output of the resolve process.
 * @param transitive
 *            If this parameter is false than the children of current node
 *            are not resolved.
 * 
 * @throws CyclicDependencyException
 *             Exception thrown when cyclic dependency detected.
 * @throws ArtifactResolutionException
 *             Exception thrown when a problem with artifact resolution
 *             occurs.
 * @throws OverConstrainedVersionException
 *             Occurs when ranges exclude each other and no valid value
 *             remains.
 * @throws ArtifactMetadataRetrievalException
 *             Error while retrieving repository metadata from the
 *             repository.
 * @throws NoSuchFieldException
 *             Signals that the class doesn't have a field of a specified
 *             name.
 * @throws SecurityException
 *             Thrown by the security manager to indicate a security
 *             violation.
 * @throws IllegalAccessException
 *             When illegal access is performed in the curse of java
 *             reflection operations.
 * @throws IllegalArgumentException
 *             Thrown to indicate that an illegal or inappropriate argument
 *             has been passed.
 */
private void recurse(final Artifact originatingArtifact, final ResolutionNode node, final Map resolvedArtifacts,
        final ManagedVersionMap managedVersions, final ArtifactRepository localRepository,
        final List remoteRepositories, final ArtifactMetadataSource source, final ArtifactFilter filter,
        final DependencyTreeResolutionListener listener, final boolean transitive,
        final Set<String> separatedGroupIds) throws CyclicDependencyException, ArtifactResolutionException,
        OverConstrainedVersionException, ArtifactMetadataRetrievalException, SecurityException,
        NoSuchFieldException, IllegalArgumentException, IllegalAccessException {
    try {

        fireEvent(ResolutionListener.TEST_ARTIFACT, listener, node);
        Object key = node.getKey();

        // TODO: Does this check need to happen here? Had to add the same
        // call
        // below when we iterate on child nodes -- will that suffice?
        if (managedVersions.containsKey(key)) {
            manageArtifact(node, managedVersions);
        }

        List previousNodes = (List) resolvedArtifacts.get(key);
        if (previousNodes != null) {
            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();

                    if (previousRange != null && currentRange != null) {
                        // 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, listener, node, previous, 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();

                            // MNG-2123: if the previous node was not a
                            // range,
                            // then it wouldn't have any available
                            // versions. We just clobbered the selected
                            // version
                            // above. (why? i have no idea.)
                            // So since we are here and this is ranges we
                            // must
                            // go figure out the version (for a third
                            // time...)
                            if (resetArtifact.getVersion() == null && resetArtifact.getVersionRange() != null) {

                                // go find the version. This is a total
                                // hack.
                                // See previous comment.
                                List versions = resetArtifact.getAvailableVersions();
                                if (versions == null) {
                                    try {
                                        versions = source.retrieveAvailableVersions(resetArtifact,
                                                localRepository, remoteRepositories);
                                        resetArtifact.setAvailableVersions(versions);
                                    } catch (ArtifactMetadataRetrievalException e) {
                                        resetArtifact.setDependencyTrail(node.getDependencyTrail());
                                        throw e;
                                    }
                                }
                                // end hack

                                // MNG-2861: match version can return null
                                ArtifactVersion selectedVersion = resetArtifact.getVersionRange()
                                        .matchVersion(resetArtifact.getAvailableVersions());
                                if (selectedVersion != null) {
                                    resetArtifact.selectVersion(selectedVersion.toString());
                                } else {
                                    throw new OverConstrainedVersionException(
                                            " Unable to find a version in "
                                                    + resetArtifact.getAvailableVersions()
                                                    + " to match the range " + resetArtifact.getVersionRange(),
                                            resetArtifact);
                                }
                                fireEvent(ResolutionListener.SELECT_VERSION_FROM_RANGE, listener,
                                        resetNodes[j]);
                            }
                        }
                    }

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

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

                    if (checkScopeUpdate(farthest, nearest)) {
                        // if we need to update scope of nearest to use
                        // farthest
                        // scope, use the nearest version, but farthest
                        // scope
                        nearest.disable();
                        farthest.getArtifact().setVersion(nearest.getArtifact().getVersion());
                        fireEvent(ResolutionListener.OMIT_FOR_NEARER, listener, nearest, farthest);
                    } else {
                        farthest.disable();
                        fireEvent(ResolutionListener.OMIT_FOR_NEARER, listener, farthest, nearest);
                    }
                }
            }
        } else {
            previousNodes = new ArrayList();
            resolvedArtifacts.put(key, previousNodes);
        }
        previousNodes.add(node);

        if (node.isActive()) {
            fireEvent(ResolutionListener.INCLUDE_ARTIFACT, listener, node);
        }

        // 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, listener, node);
            if (transitive) {
                Artifact parentArtifact = node.getArtifact();
                for (Iterator i = node.getChildrenIterator(); i.hasNext();) {
                    ResolutionNode child = (ResolutionNode) i.next();
                    if (!filter.include(child.getArtifact())) {
                        continue;
                    }
                    /*
                     * rotgier: In case of regular dependencies provided
                     * scope is simply ignored (artifact versions specified
                     * there conflict with the ones of runtime deps)
                     */
                    if (Artifact.SCOPE_PROVIDED.equals(child.getArtifact().getScope())) {
                        continue;
                    }
                    changeArtifactCoreToOsgi(node, child, separatedGroupIds, listener);
                    boolean isContinue = resolveChildNode(node, child, filter, managedVersions, listener,
                            source, parentArtifact);
                    if (isContinue) {
                        continue;
                    }
                    List<String> extractedSeparatedGroupIds = extractSeparatedGroupIds(child.getArtifact(),
                            remoteRepositories);
                    Set<String> combinedSeparatedGroupIds = new HashSet<String>(separatedGroupIds);
                    combinedSeparatedGroupIds.addAll(extractedSeparatedGroupIds);
                    recurse(originatingArtifact, child, resolvedArtifacts, managedVersions, localRepository,
                            child.getRemoteRepositories(), source, filter, listener, true,
                            combinedSeparatedGroupIds);
                }
                List runtimeDeps = getRuntimeDeps(node.getArtifact(), managedVersions, remoteRepositories);
                Field childrenField = node.getClass().getDeclaredField("children");
                childrenField.setAccessible(true);
                List nodesChildren = (List) childrenField.get(node);
                /* nodesChildren can be empty when dealing with parent POMs */
                if (nodesChildren == Collections.EMPTY_LIST) {
                    nodesChildren = new ArrayList();
                    childrenField.set(node, nodesChildren);
                }
                for (Object runtimeDepObj : runtimeDeps) {
                    DependencyNode runtimeDep = (DependencyNode) runtimeDepObj;
                    Artifact artifact = runtimeDep.getArtifact();
                    ResolutionNode childRuntime = new ResolutionNode(artifact, node.getRemoteRepositories(),
                            node);
                    /*
                     * rotgier: In case of runtime dependencies provided
                     * scope should be allowed
                     */
                    if (!filter.include(childRuntime.getArtifact())) {

                        if (!Artifact.SCOPE_PROVIDED.equals(artifact.getScope())) {
                            continue;
                        }
                    }
                    changeArtifactCoreToOsgi(node, childRuntime, separatedGroupIds, listener);
                    boolean isContinue = resolveChildNode(node, childRuntime, filter, managedVersions, listener,
                            source, parentArtifact);
                    if (isContinue) {
                        continue;
                    }
                    List<String> extractedSeparatedGroupIds = extractSeparatedGroupIds(
                            childRuntime.getArtifact(), remoteRepositories);
                    Set<String> combinedSeparatedGroupIds = new HashSet<String>(separatedGroupIds);
                    combinedSeparatedGroupIds.addAll(extractedSeparatedGroupIds);
                    recurse(originatingArtifact, childRuntime, resolvedArtifacts, managedVersions,
                            localRepository, childRuntime.getRemoteRepositories(), source, filter, listener,
                            true, combinedSeparatedGroupIds);
                    nodesChildren.add(childRuntime);
                }
            }
            fireEvent(ResolutionListener.FINISH_PROCESSING_CHILDREN, listener, node);
        }
    } catch (Exception ex) {
        StringBuilder msg = new StringBuilder();
        msg.append(String.format("\nUnpredicted exception during dependency tree recursion at node %s",
                FilteringVisitorSupport.stringify(node.getArtifact())));
        msg.append("\nNode's parent tree:\n");
        msg.append(printNodeParentsTree(node));
        throw new IllegalStateException(msg.toString(), ex);
    }
}