Search in sources :

Example 1 with DependencyNode

use of org.apache.maven.shared.dependency.tree.DependencyNode in project intellij-community by JetBrains.

the class Maven2ModelConverter method convertDependencyNodes.

public static List<MavenArtifactNode> convertDependencyNodes(MavenArtifactNode parent, Collection<DependencyNode> nodes, Map<Artifact, MavenArtifact> nativeToConvertedMap, File localRepository) {
    List<MavenArtifactNode> result = new ArrayList<MavenArtifactNode>(nodes.size());
    for (DependencyNode each : nodes) {
        Artifact a = each.getArtifact();
        MavenArtifact ma = convertArtifact(a, nativeToConvertedMap, localRepository);
        MavenArtifactState state = MavenArtifactState.ADDED;
        switch(each.getState()) {
            case DependencyNode.INCLUDED:
                break;
            case DependencyNode.OMITTED_FOR_CONFLICT:
                state = MavenArtifactState.CONFLICT;
                break;
            case DependencyNode.OMITTED_FOR_DUPLICATE:
                state = MavenArtifactState.DUPLICATE;
                break;
            case DependencyNode.OMITTED_FOR_CYCLE:
                state = MavenArtifactState.CYCLE;
                break;
            default:
                assert false : "unknown dependency node state: " + each.getState();
        }
        MavenArtifact relatedMA = each.getRelatedArtifact() == null ? null : convertArtifact(each.getRelatedArtifact(), nativeToConvertedMap, localRepository);
        MavenArtifactNode newNode = new MavenArtifactNode(parent, ma, state, relatedMA, each.getOriginalScope(), each.getPremanagedVersion(), each.getPremanagedScope());
        newNode.setDependencies(convertDependencyNodes(newNode, each.getChildren(), nativeToConvertedMap, localRepository));
        result.add(newNode);
    }
    return result;
}
Also used : DependencyNode(org.apache.maven.shared.dependency.tree.DependencyNode) Artifact(org.apache.maven.artifact.Artifact)

Example 2 with DependencyNode

use of org.apache.maven.shared.dependency.tree.DependencyNode in project intellij-community by JetBrains.

the class MavenModelConverter method convertDependencyNodes.

public static List<MavenArtifactNode> convertDependencyNodes(MavenArtifactNode parent, Collection<DependencyNode> nodes, Map<Artifact, MavenArtifact> nativeToConvertedMap, File localRepository) {
    List<MavenArtifactNode> result = new ArrayList<MavenArtifactNode>(nodes.size());
    for (DependencyNode each : nodes) {
        Artifact a = each.getArtifact();
        MavenArtifact ma = convertArtifact(a, nativeToConvertedMap, localRepository);
        MavenArtifactState state = MavenArtifactState.ADDED;
        switch(each.getState()) {
            case DependencyNode.INCLUDED:
                break;
            case DependencyNode.OMITTED_FOR_CONFLICT:
                state = MavenArtifactState.CONFLICT;
                break;
            case DependencyNode.OMITTED_FOR_DUPLICATE:
                state = MavenArtifactState.DUPLICATE;
                break;
            case DependencyNode.OMITTED_FOR_CYCLE:
                state = MavenArtifactState.CYCLE;
                break;
            default:
                assert false : "unknown dependency node state: " + each.getState();
        }
        MavenArtifact relatedMA = each.getRelatedArtifact() == null ? null : convertArtifact(each.getRelatedArtifact(), nativeToConvertedMap, localRepository);
        MavenArtifactNode newNode = new MavenArtifactNode(parent, ma, state, relatedMA, each.getOriginalScope(), each.getPremanagedVersion(), each.getPremanagedScope());
        newNode.setDependencies(convertDependencyNodes(newNode, each.getChildren(), nativeToConvertedMap, localRepository));
        result.add(newNode);
    }
    return result;
}
Also used : DependencyNode(org.apache.maven.shared.dependency.tree.DependencyNode) CustomMaven3Artifact(org.jetbrains.idea.maven.server.embedder.CustomMaven3Artifact) Artifact(org.apache.maven.artifact.Artifact)

Example 3 with DependencyNode

use of org.apache.maven.shared.dependency.tree.DependencyNode in project camel by apache.

the class SpringBootStarterMojo method filterIncludedArtifacts.

private Set<String> filterIncludedArtifacts(Set<String> artifacts) throws DependencyTreeBuilderException {
    Set<String> included = new TreeSet<>();
    ArtifactFilter artifactFilter = new ScopeArtifactFilter(null);
    DependencyNode node = treeBuilder.buildDependencyTree(project, localRepository, artifactFactory, artifactMetadataSource, artifactFilter, artifactCollector);
    CollectingDependencyNodeVisitor visitor = new CollectingDependencyNodeVisitor();
    node.accept(visitor);
    List<DependencyNode> nodes = visitor.getNodes();
    for (DependencyNode dependencyNode : nodes) {
        Artifact artifact = dependencyNode.getArtifact();
        getLog().debug("Found dependency node: " + artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" + artifact.getVersion() + " - scope=" + artifact.getScope());
        if (!Artifact.SCOPE_TEST.equals(artifact.getScope()) && !Artifact.SCOPE_PROVIDED.equals(artifact.getScope())) {
            String canonicalName = artifact.getGroupId() + ":" + artifact.getArtifactId();
            if (artifacts.contains(canonicalName)) {
                getLog().debug(canonicalName + " marked for exclusion");
                included.add(canonicalName);
            }
        }
    }
    return included;
}
Also used : ArtifactFilter(org.apache.maven.artifact.resolver.filter.ArtifactFilter) ScopeArtifactFilter(org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter) CollectingDependencyNodeVisitor(org.apache.maven.shared.dependency.tree.traversal.CollectingDependencyNodeVisitor) ScopeArtifactFilter(org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter) TreeSet(java.util.TreeSet) DependencyNode(org.apache.maven.shared.dependency.tree.DependencyNode) Artifact(org.apache.maven.artifact.Artifact)

Example 4 with DependencyNode

use of org.apache.maven.shared.dependency.tree.DependencyNode in project felix by apache.

the class BundleAllPlugin method bundleAll.

/**
 * Bundle a project and its transitive dependencies up to some depth level
 *
 * @param project
 * @param maxDepth how deep to process the dependency tree
 * @throws MojoExecutionException
 */
protected BundleInfo bundleAll(MavenProject project, int maxDepth) throws MojoExecutionException {
    if (alreadyBundled(project.getArtifact())) {
        getLog().debug("Ignoring project already processed " + project.getArtifact());
        return null;
    }
    if (m_artifactsBeingProcessed.contains(project.getArtifact())) {
        getLog().warn("Ignoring artifact due to dependency cycle " + project.getArtifact());
        return null;
    }
    m_artifactsBeingProcessed.add(project.getArtifact());
    DependencyNode dependencyTree;
    try {
        dependencyTree = m_dependencyTreeBuilder.buildDependencyTree(project, localRepository, m_factory, m_artifactMetadataSource, null, m_collector);
    } catch (DependencyTreeBuilderException e) {
        throw new MojoExecutionException("Unable to build dependency tree", e);
    }
    BundleInfo bundleInfo = new BundleInfo();
    if (!dependencyTree.hasChildren()) {
        /* no need to traverse the tree */
        return bundleRoot(project, bundleInfo);
    }
    getLog().debug("Will bundle the following dependency tree" + LS + dependencyTree);
    for (Iterator it = dependencyTree.inverseIterator(); it.hasNext(); ) {
        DependencyNode node = (DependencyNode) it.next();
        if (!it.hasNext()) {
            /* this is the root, current project */
            break;
        }
        if (node.getState() != DependencyNode.INCLUDED) {
            continue;
        }
        if (Artifact.SCOPE_SYSTEM.equals(node.getArtifact().getScope())) {
            getLog().debug("Ignoring system scoped artifact " + node.getArtifact());
            continue;
        }
        Artifact artifact;
        try {
            artifact = resolveArtifact(node.getArtifact());
        } catch (ArtifactNotFoundException e) {
            if (ignoreMissingArtifacts) {
                continue;
            }
            throw new MojoExecutionException("Artifact was not found in the repo" + node.getArtifact(), e);
        }
        node.getArtifact().setFile(artifact.getFile());
        int nodeDepth = node.getDepth();
        if (nodeDepth > maxDepth) {
            /* node is deeper than we want */
            getLog().debug("Ignoring " + node.getArtifact() + ", depth is " + nodeDepth + ", bigger than " + maxDepth);
            continue;
        }
        MavenProject childProject;
        try {
            childProject = m_mavenProjectBuilder.buildFromRepository(artifact, remoteRepositories, localRepository, true);
            if (childProject.getDependencyArtifacts() == null) {
                childProject.setDependencyArtifacts(childProject.createArtifacts(m_factory, null, null));
            }
        } catch (InvalidDependencyVersionException e) {
            throw new MojoExecutionException("Invalid dependency version for artifact " + artifact);
        } catch (ProjectBuildingException e) {
            throw new MojoExecutionException("Unable to build project object for artifact " + artifact, e);
        }
        childProject.setArtifact(artifact);
        getLog().debug("Child project artifact location: " + childProject.getArtifact().getFile());
        if ((Artifact.SCOPE_COMPILE.equals(artifact.getScope())) || (Artifact.SCOPE_RUNTIME.equals(artifact.getScope()))) {
            BundleInfo subBundleInfo = bundleAll(childProject, maxDepth - 1);
            if (subBundleInfo != null) {
                bundleInfo.merge(subBundleInfo);
            }
        } else {
            getLog().debug("Not processing due to scope (" + childProject.getArtifact().getScope() + "): " + childProject.getArtifact());
        }
    }
    return bundleRoot(project, bundleInfo);
}
Also used : ProjectBuildingException(org.apache.maven.project.ProjectBuildingException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MavenProject(org.apache.maven.project.MavenProject) DependencyNode(org.apache.maven.shared.dependency.tree.DependencyNode) InvalidDependencyVersionException(org.apache.maven.project.artifact.InvalidDependencyVersionException) DependencyTreeBuilderException(org.apache.maven.shared.dependency.tree.DependencyTreeBuilderException) Iterator(java.util.Iterator) ArtifactNotFoundException(org.apache.maven.artifact.resolver.ArtifactNotFoundException) Artifact(org.apache.maven.artifact.Artifact)

Example 5 with DependencyNode

use of org.apache.maven.shared.dependency.tree.DependencyNode in project fabric8 by jboss-fuse.

the class AbstractProfileMojo method walkTree.

protected void walkTree(DependencyNode node, int level) {
    if (node == null) {
        getLog().warn("Null node!");
        return;
    }
    getLog().info(indent(level) + node.getArtifact());
    List children = node.getChildren();
    for (Object child : children) {
        if (child instanceof DependencyNode) {
            walkTree((DependencyNode) child, level + 1);
        } else {
            getLog().warn("Unknown class " + child.getClass());
        }
    }
}
Also used : DependencyNode(org.apache.maven.shared.dependency.tree.DependencyNode) List(java.util.List) ArrayList(java.util.ArrayList)

Aggregations

DependencyNode (org.apache.maven.shared.dependency.tree.DependencyNode)13 Artifact (org.apache.maven.artifact.Artifact)6 ArrayList (java.util.ArrayList)4 List (java.util.List)3 MavenProject (org.apache.maven.project.MavenProject)3 ArtifactFilter (org.apache.maven.artifact.resolver.filter.ArtifactFilter)2 ScopeArtifactFilter (org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter)2 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)2 DependencyTreeBuilderException (org.apache.maven.shared.dependency.tree.DependencyTreeBuilderException)2 DependencyDTO (io.fabric8.deployer.dto.DependencyDTO)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 Iterator (java.util.Iterator)1 TreeMap (java.util.TreeMap)1 TreeSet (java.util.TreeSet)1 JarInputStream (java.util.jar.JarInputStream)1 Manifest (java.util.jar.Manifest)1 ArtifactNotFoundException (org.apache.maven.artifact.resolver.ArtifactNotFoundException)1 ArtifactResolutionRequest (org.apache.maven.artifact.resolver.ArtifactResolutionRequest)1