Search in sources :

Example 16 with DependencyNode

use of org.apache.maven.shared.dependency.graph.DependencyNode in project maven-plugins by apache.

the class GraphmlDependencyNodeVisitor method endVisit.

/**
 * {@inheritDoc}
 */
@Override
public boolean endVisit(DependencyNode node) {
    if (node.getParent() == null || node.getParent() == node) {
        writer.write(GRAPHML_FOOTER);
    } else {
        DependencyNode p = node.getParent();
        writer.print("<edge source=\"" + generateId(p) + "\" target=\"" + generateId(node) + "\">");
        if (node.getArtifact().getScope() != null) {
            // add Edge label
            writer.print("<data key=\"d1\"><y:PolyLineEdge><y:EdgeLabel>" + node.getArtifact().getScope() + "</y:EdgeLabel></y:PolyLineEdge></data>");
        }
        writer.println("</edge>");
    }
    return true;
}
Also used : DependencyNode(org.apache.maven.shared.dependency.graph.DependencyNode)

Example 17 with DependencyNode

use of org.apache.maven.shared.dependency.graph.DependencyNode in project maven-plugins by apache.

the class Dependencies method addAllChildrenDependencies.

// ----------------------------------------------------------------------
// Private methods
// ----------------------------------------------------------------------
/**
 * Recursive method to get all dependencies from a given <code>dependencyNode</code>
 *
 * @param dependencyNode not null
 */
private void addAllChildrenDependencies(DependencyNode dependencyNode) {
    for (DependencyNode subdependencyNode : dependencyNode.getChildren()) {
        Artifact artifact = subdependencyNode.getArtifact();
        if (artifact.getGroupId().equals(project.getGroupId()) && artifact.getArtifactId().equals(project.getArtifactId()) && artifact.getVersion().equals(project.getVersion())) {
            continue;
        }
        if (!allDependencies.contains(artifact)) {
            allDependencies.add(artifact);
        }
        addAllChildrenDependencies(subdependencyNode);
    }
}
Also used : DependencyNode(org.apache.maven.shared.dependency.graph.DependencyNode) Artifact(org.apache.maven.artifact.Artifact)

Example 18 with DependencyNode

use of org.apache.maven.shared.dependency.graph.DependencyNode in project maven-plugins by apache.

the class DependenciesRenderer method printDependencyListing.

private void printDependencyListing(DependencyNode node) {
    Artifact artifact = node.getArtifact();
    String id = artifact.getId();
    String dependencyDetailId = "_dep" + idCounter++;
    String imgId = "_img" + idCounter++;
    sink.listItem();
    sink.text(id + (StringUtils.isNotEmpty(artifact.getScope()) ? " (" + artifact.getScope() + ") " : " "));
    String javascript = String.format("<img id=\"%s\" src=\"%s\" alt=\"%s\"" + " onclick=\"toggleDependencyDetails( '%s', '%s' );\"" + " style=\"cursor: pointer; vertical-align: text-bottom;\"></img>", imgId, IMG_INFO_URL, getI18nString("graph.icon.information"), dependencyDetailId, imgId);
    sink.rawText(javascript);
    printDescriptionsAndURLs(node, dependencyDetailId);
    if (!node.getChildren().isEmpty()) {
        boolean toBeIncluded = false;
        List<DependencyNode> subList = new ArrayList<DependencyNode>();
        for (DependencyNode dep : node.getChildren()) {
            if (dependencies.getAllDependencies().contains(dep.getArtifact())) {
                subList.add(dep);
                toBeIncluded = true;
            }
        }
        if (toBeIncluded) {
            sink.list();
            for (DependencyNode dep : subList) {
                printDependencyListing(dep);
            }
            sink.list_();
        }
    }
    sink.listItem_();
}
Also used : DependencyNode(org.apache.maven.shared.dependency.graph.DependencyNode) ArrayList(java.util.ArrayList) Artifact(org.apache.maven.artifact.Artifact)

Example 19 with DependencyNode

use of org.apache.maven.shared.dependency.graph.DependencyNode in project maven-plugins by apache.

the class ShadeMojo method updateExcludesInDeps.

public boolean updateExcludesInDeps(MavenProject project, List<Dependency> dependencies, List<Dependency> transitiveDeps) throws DependencyGraphBuilderException {
    DependencyNode node = dependencyGraphBuilder.buildDependencyGraph(project, null);
    boolean modified = false;
    for (DependencyNode n2 : node.getChildren()) {
        for (DependencyNode n3 : n2.getChildren()) {
            // check if it really isn't in the list of original dependencies. Maven
            // prior to 2.0.8 may grab versions from transients instead of
            // from the direct deps in which case they would be marked included
            // instead of OMITTED_FOR_DUPLICATE
            // also, if not promoting the transitives, level 2's would be included
            boolean found = false;
            for (Dependency dep : transitiveDeps) {
                if (dep.getArtifactId().equals(n3.getArtifact().getArtifactId()) && dep.getGroupId().equals(n3.getArtifact().getGroupId()) && (dep.getType() == null || dep.getType().equals(n3.getArtifact().getType()))) {
                    found = true;
                    break;
                }
            }
            if (!found) {
                for (Dependency dep : dependencies) {
                    if (dep.getArtifactId().equals(n2.getArtifact().getArtifactId()) && dep.getGroupId().equals(n2.getArtifact().getGroupId()) && (dep.getType() == null || dep.getType().equals(n2.getArtifact().getType()))) {
                        Exclusion exclusion = new Exclusion();
                        exclusion.setArtifactId(n3.getArtifact().getArtifactId());
                        exclusion.setGroupId(n3.getArtifact().getGroupId());
                        dep.addExclusion(exclusion);
                        modified = true;
                        break;
                    }
                }
            }
        }
    }
    return modified;
}
Also used : DependencyNode(org.apache.maven.shared.dependency.graph.DependencyNode) Exclusion(org.apache.maven.model.Exclusion) Dependency(org.apache.maven.model.Dependency)

Example 20 with DependencyNode

use of org.apache.maven.shared.dependency.graph.DependencyNode in project maven-plugins by apache.

the class TestTreeMojo method assertChildNodeEquals.

// private methods --------------------------------------------------------
private void assertChildNodeEquals(String expectedNode, DependencyNode actualParentNode, int actualChildIndex) {
    DependencyNode actualNode = actualParentNode.getChildren().get(actualChildIndex);
    assertNodeEquals(expectedNode, actualNode);
}
Also used : DependencyNode(org.apache.maven.shared.dependency.graph.DependencyNode)

Aggregations

DependencyNode (org.apache.maven.shared.dependency.graph.DependencyNode)23 MavenProject (org.apache.maven.project.MavenProject)9 Artifact (org.apache.maven.artifact.Artifact)8 DependencyGraphBuilder (org.apache.maven.shared.dependency.graph.DependencyGraphBuilder)8 Builder (aQute.bnd.osgi.Builder)7 HashMap (java.util.HashMap)7 Properties (java.util.Properties)7 LinkedHashSet (java.util.LinkedHashSet)6 Map (java.util.Map)6 Manifest (java.util.jar.Manifest)6 File (java.io.File)5 Set (java.util.Set)5 TreeMap (java.util.TreeMap)5 ArrayList (java.util.ArrayList)4 ArtifactFilter (org.apache.maven.artifact.resolver.filter.ArtifactFilter)3 IOException (java.io.IOException)2 List (java.util.List)2 DefaultArtifact (org.apache.maven.artifact.DefaultArtifact)2 DefaultArtifactHandler (org.apache.maven.artifact.handler.DefaultArtifactHandler)2 AndArtifactFilter (org.apache.maven.artifact.resolver.filter.AndArtifactFilter)2