Search in sources :

Example 6 with DependencyNode

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

the class AbstractProfileMojo method loadRootDependency.

protected DependencyDTO loadRootDependency() throws DependencyTreeBuilderException {
    ArtifactFilter artifactFilter = createResolvingArtifactFilter();
    DependencyNode dependencyNode = dependencyTreeBuilder.buildDependencyTree(project, localRepository, artifactFactory, metadataSource, artifactFilter, artifactCollector);
    return buildFrom(dependencyNode);
}
Also used : ArtifactFilter(org.apache.maven.artifact.resolver.filter.ArtifactFilter) ScopeArtifactFilter(org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter) DependencyNode(org.apache.maven.shared.dependency.tree.DependencyNode)

Example 7 with DependencyNode

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

the class AbstractProfileMojo method buildFrom.

private DependencyDTO buildFrom(DependencyNode node) {
    Artifact artifact = node.getArtifact();
    if (artifact != null) {
        DependencyDTO answer = new DependencyDTO();
        answer.setGroupId(artifact.getGroupId());
        answer.setArtifactId(artifact.getArtifactId());
        if (artifact.isSnapshot() && !uniqueVersion) {
            answer.setVersion(artifact.getBaseVersion());
        } else {
            answer.setVersion(artifact.getVersion());
        }
        answer.setClassifier(artifact.getClassifier());
        String scope = artifact.getScope();
        answer.setScope(scope);
        answer.setType(artifact.getType());
        // so lets ignore this for the maven project's artifact
        if (artifact.getClassifier() == null && "jar".equals(artifact.getType())) {
            if (project.getArtifact().equals(artifact)) {
                getLog().debug("Ignoring bundle check on the maven project artifact: " + artifact + " as this causes issues with the maven-install-plugin and we can assume the project packaging is accurate");
            } else {
                try {
                    ArtifactResolutionRequest request = new ArtifactResolutionRequest();
                    request.setArtifact(artifact);
                    request.setRemoteRepositories(remoteRepositories);
                    request.setLocalRepository(localRepository);
                    resolver.resolve(request);
                    JarInputStream jis = new JarInputStream(new FileInputStream(artifact.getFile()));
                    Manifest man = jis.getManifest();
                    String bsn = man.getMainAttributes().getValue(Constants.BUNDLE_SYMBOLICNAME);
                    if (bsn != null) {
                        answer.setType("bundle");
                    } else {
                    // Try to find a matching servicemix bundle for it
                    /*
                        Map<String, String> bundles = getAllServiceMixBundles();
                        getLog().debug("Trying to find a matching bundle for " + artifact);
                        String match = bundles.get(artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" + artifact.getVersion());
                        if (match != null) {
                            String[] parts = match.split(":");
                            answer.setGroupId(parts[0]);
                            answer.setArtifactId(parts[1]);
                            answer.setVersion(parts[2]);
                            getLog().info("Replacing artifact " + artifact + " with servicemix bundle " + match);
                        }
                        */
                    }
                } catch (Exception e) {
                    getLog().debug("Error checking artifact type for " + artifact, e);
                }
            }
        }
        answer.setOptional(artifact.isOptional());
        String type = answer.getType();
        if (type != null && type.equals("pom")) {
            getLog().debug("Ignoring pom.xml for " + answer);
            return null;
        }
        int state = node.getState();
        if (state != DependencyNode.INCLUDED) {
            getLog().debug("Ignoring " + node);
            return null;
        }
        if (isWarProject()) {
            if (scope != null && !scope.equals("provided")) {
                getLog().debug("WAR packaging so ignoring non-provided scope " + scope + " for " + node);
                return null;
            }
        }
        List children = node.getChildren();
        for (Object child : children) {
            if (child instanceof DependencyNode) {
                DependencyNode childNode = (DependencyNode) child;
                if (childNode.getState() == DependencyNode.INCLUDED) {
                    String childScope = childNode.getArtifact().getScope();
                    if (!"test".equals(childScope) && !"provided".equals(childScope)) {
                        DependencyDTO childDTO = buildFrom(childNode);
                        if (childDTO != null) {
                            answer.addChild(childDTO);
                        }
                    } else {
                        getLog().debug("Ignoring artifact " + childNode.getArtifact() + " with scope " + childScope);
                    }
                }
            }
        }
        return answer;
    }
    return null;
}
Also used : JarInputStream(java.util.jar.JarInputStream) ArtifactResolutionRequest(org.apache.maven.artifact.resolver.ArtifactResolutionRequest) DependencyNode(org.apache.maven.shared.dependency.tree.DependencyNode) DependencyDTO(io.fabric8.deployer.dto.DependencyDTO) List(java.util.List) ArrayList(java.util.ArrayList) Manifest(java.util.jar.Manifest) Artifact(org.apache.maven.artifact.Artifact) FileInputStream(java.io.FileInputStream) DependencyTreeBuilderException(org.apache.maven.shared.dependency.tree.DependencyTreeBuilderException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException)

Example 8 with DependencyNode

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

the class DependencyConvergenceReport method getProjectNodes.

private List<DependencyNode> getProjectNodes(List<ReverseDependencyLink> depList) {
    List<DependencyNode> projectNodes = new ArrayList<DependencyNode>();
    for (ReverseDependencyLink depLink : depList) {
        MavenProject project = depLink.getProject();
        DependencyNode projectNode = this.projectMap.get(project);
        if (projectNode != null && !projectNodes.contains(projectNode)) {
            projectNodes.add(projectNode);
        }
    }
    return projectNodes;
}
Also used : MavenProject(org.apache.maven.project.MavenProject) DependencyNode(org.apache.maven.shared.dependency.tree.DependencyNode) ArrayList(java.util.ArrayList)

Example 9 with DependencyNode

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

the class DependencyConvergenceReport method analyzeDependencyTree.

/**
 * Produce a DependencyAnalyzeResult, it contains conflicting dependencies map, snapshot dependencies map and all
 * dependencies map. Map structure is the relationships between dependencies (its groupId:artifactId) and reactor
 * projects. This is the structure of the Map:
 *
 * <pre>
 * +--------------------+----------------------------------+---------------|
 * | key                | value                                            |
 * +--------------------+----------------------------------+---------------|
 * | groupId:artifactId | A List of ReverseDependencyLinks                 |
 * | of a dependency    | which each look like this:                       |
 * |                    | +------------+-----------------+-----------------|
 * |                    | | dependency | reactor project | dependency node |
 * |                    | +------------+-----------------+-----------------|
 * +--------------------+--------------------------------------------------|
 * </pre>
 *
 * @return DependencyAnalyzeResult contains conflicting dependencies map, snapshot dependencies map and all
 *         dependencies map.
 * @throws MavenReportException
 */
private DependencyAnalyzeResult analyzeDependencyTree() throws MavenReportException {
    Map<String, List<ReverseDependencyLink>> conflictingDependencyMap = new TreeMap<String, List<ReverseDependencyLink>>();
    Map<String, List<ReverseDependencyLink>> allDependencies = new TreeMap<String, List<ReverseDependencyLink>>();
    for (MavenProject reactorProject : reactorProjects) {
        DependencyNode node = getNode(reactorProject);
        this.projectMap.put(reactorProject, node);
        getConflictingDependencyMap(conflictingDependencyMap, reactorProject, node);
        getAllDependencyMap(allDependencies, reactorProject, node);
    }
    return populateDependencyAnalyzeResult(conflictingDependencyMap, allDependencies);
}
Also used : MavenProject(org.apache.maven.project.MavenProject) DependencyNode(org.apache.maven.shared.dependency.tree.DependencyNode) ArrayList(java.util.ArrayList) List(java.util.List) TreeMap(java.util.TreeMap)

Example 10 with DependencyNode

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

the class SinkSerializingDependencyNodeVisitor method isLast.

/**
 * Gets whether the specified dependency node is the last of its siblings.
 *
 * @param node the dependency node to check
 * @return <code>true</code> if the specified dependency node is the last of its last siblings
 */
private boolean isLast(DependencyNode node) {
    // TODO: remove node argument and calculate from visitor calls only
    DependencyNode parent = node.getParent();
    boolean last;
    if (parent == null) {
        last = true;
    } else {
        List<DependencyNode> siblings = parent.getChildren();
        last = (siblings.indexOf(node) == siblings.size() - 1);
    }
    return last;
}
Also used : DependencyNode(org.apache.maven.shared.dependency.tree.DependencyNode)

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