You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by el...@apache.org on 2020/08/21 11:57:54 UTC
[maven-dependency-plugin] branch master updated: [MDEP-644] Reactor
functionality added for verbose tree (#97)
This is an automated email from the ASF dual-hosted git repository.
elharo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-dependency-plugin.git
The following commit(s) were added to refs/heads/master by this push:
new 52efa14 [MDEP-644] Reactor functionality added for verbose tree (#97)
52efa14 is described below
commit 52efa145585bdcac94d45031854a3749245a9ac5
Author: ian-lavallee <34...@users.noreply.github.com>
AuthorDate: Fri Aug 21 07:57:45 2020 -0400
[MDEP-644] Reactor functionality added for verbose tree (#97)
* Reactor functionality added for verbose tree
---
pom.xml | 3 +
.../projects/tree-verbose-multimodule/expected.txt | 1 +
.../tree-verbose-multimodule/invoker.properties | 18 ++++
.../tree-verbose-multimodule/module-a/expected.txt | 30 +++++++
.../tree-verbose-multimodule/module-a/pom.xml | 48 +++++++++++
.../tree-verbose-multimodule/module-b/expected.txt | 15 ++++
.../tree-verbose-multimodule/module-b/pom.xml | 48 +++++++++++
src/it/projects/tree-verbose-multimodule/pom.xml | 45 ++++++++++
.../tree-verbose-multimodule/test.properties | 18 ++++
.../projects/tree-verbose-multimodule/verify.bsh | 57 +++++++++++++
.../maven/plugins/dependency/tree/ArtifactKey.java | 72 ++++++++++++++++
.../maven/plugins/dependency/tree/TreeMojo.java | 7 +-
.../tree/VerboseDependencyGraphBuilder.java | 98 ++++++++++++++++++++--
.../dependency/tree/VerboseGraphDotSerializer.java | 11 ++-
.../tree/VerboseGraphGraphmlSerializer.java | 6 ++
.../tree/VerboseGraphTextSerializer.java | 12 ++-
.../dependency/tree/VerboseGraphTgfSerializer.java | 11 ++-
17 files changed, 484 insertions(+), 16 deletions(-)
diff --git a/pom.xml b/pom.xml
index 6512557..fca1830 100644
--- a/pom.xml
+++ b/pom.xml
@@ -348,6 +348,9 @@ under the License.
<exclude>src/it/projects/tree-multimodule/expected.txt</exclude>
<exclude>src/it/projects/tree-multimodule/module-a/expected.txt</exclude>
<exclude>src/it/projects/tree-multimodule/module-b/expected.txt</exclude>
+ <exclude>src/it/projects/tree-verbose-multimodule/expected.txt</exclude>
+ <exclude>src/it/projects/tree-verbose-multimodule/module-a/expected.txt</exclude>
+ <exclude>src/it/projects/tree-verbose-multimodule/module-b/expected.txt</exclude>
<exclude>src/it/projects/tree-verbose/expected*.txt</exclude>
<exclude>src/it/projects/tree-verbose-small/expected.txt</exclude>
<!-- These files contain expected versions for unit tests -->
diff --git a/src/it/projects/tree-verbose-multimodule/expected.txt b/src/it/projects/tree-verbose-multimodule/expected.txt
new file mode 100644
index 0000000..d55e3aa
--- /dev/null
+++ b/src/it/projects/tree-verbose-multimodule/expected.txt
@@ -0,0 +1 @@
+org.apache.maven.its.dependency:tree-multimodule:pom:1.0-SNAPSHOT
diff --git a/src/it/projects/tree-verbose-multimodule/invoker.properties b/src/it/projects/tree-verbose-multimodule/invoker.properties
new file mode 100644
index 0000000..01813bd
--- /dev/null
+++ b/src/it/projects/tree-verbose-multimodule/invoker.properties
@@ -0,0 +1,18 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+invoker.goals = ${project.groupId}:${project.artifactId}:${project.version}:tree -Dverbose=true
diff --git a/src/it/projects/tree-verbose-multimodule/module-a/expected.txt b/src/it/projects/tree-verbose-multimodule/module-a/expected.txt
new file mode 100644
index 0000000..b74142d
--- /dev/null
+++ b/src/it/projects/tree-verbose-multimodule/module-a/expected.txt
@@ -0,0 +1,30 @@
+org.apache.maven.its.dependency:tree-multimodule-module-a:jar:1.0-SNAPSHOT
+\- org.apache.maven:maven-project:jar:2.0.6:compile
+ +- org.apache.maven:maven-settings:jar:2.0.6:compile
+ | +- (org.apache.maven:maven-model:jar:2.0.6:compile - omitted for duplicate)
+ | +- (org.codehaus.plexus:plexus-utils:jar:1.4.1:compile - omitted for duplicate)
+ | \- (org.codehaus.plexus:plexus-container-default:jar:1.0-alpha-9-stable-1:compile - omitted for duplicate)
+ +- org.apache.maven:maven-profile:jar:2.0.6:compile
+ | +- (org.apache.maven:maven-model:jar:2.0.6:compile - omitted for duplicate)
+ | +- (org.codehaus.plexus:plexus-utils:jar:1.4.1:compile - omitted for duplicate)
+ | \- (org.codehaus.plexus:plexus-container-default:jar:1.0-alpha-9-stable-1:compile - omitted for duplicate)
+ +- org.apache.maven:maven-model:jar:2.0.6:compile
+ | \- (org.codehaus.plexus:plexus-utils:jar:1.4.1:compile - omitted for duplicate)
+ +- org.apache.maven:maven-artifact-manager:jar:2.0.6:compile
+ | +- org.apache.maven:maven-repository-metadata:jar:2.0.6:compile
+ | | \- (org.codehaus.plexus:plexus-utils:jar:1.4.1:compile - omitted for duplicate)
+ | +- (org.codehaus.plexus:plexus-utils:jar:1.4.1:compile - omitted for duplicate)
+ | +- (org.apache.maven:maven-artifact:jar:2.0.6:compile - omitted for duplicate)
+ | +- (org.codehaus.plexus:plexus-container-default:jar:1.0-alpha-9-stable-1:compile - omitted for duplicate)
+ | \- org.apache.maven.wagon:wagon-provider-api:jar:1.0-beta-2:compile
+ | \- (org.codehaus.plexus:plexus-utils:jar:1.0.4:compile - omitted for duplicate)
+ +- org.apache.maven:maven-plugin-registry:jar:2.0.6:compile
+ | +- (org.codehaus.plexus:plexus-utils:jar:1.4.1:compile - omitted for duplicate)
+ | \- (org.codehaus.plexus:plexus-container-default:jar:1.0-alpha-9-stable-1:compile - omitted for duplicate)
+ +- org.codehaus.plexus:plexus-utils:jar:1.4.1:compile
+ +- org.apache.maven:maven-artifact:jar:2.0.6:compile
+ | \- (org.codehaus.plexus:plexus-utils:jar:1.4.1:compile - omitted for duplicate)
+ \- org.codehaus.plexus:plexus-container-default:jar:1.0-alpha-9-stable-1:compile
+ +- junit:junit:jar:3.8.1:compile
+ +- (org.codehaus.plexus:plexus-utils:jar:1.0.4:compile - omitted for conflict with 1.4.1)
+ \- classworlds:classworlds:jar:1.1-alpha-2:compile
diff --git a/src/it/projects/tree-verbose-multimodule/module-a/pom.xml b/src/it/projects/tree-verbose-multimodule/module-a/pom.xml
new file mode 100644
index 0000000..7c6fe3c
--- /dev/null
+++ b/src/it/projects/tree-verbose-multimodule/module-a/pom.xml
@@ -0,0 +1,48 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one
+ ~ or more contributor license agreements. See the NOTICE file
+ ~ distributed with this work for additional information
+ ~ regarding copyright ownership. The ASF licenses this file
+ ~ to you under the Apache License, Version 2.0 (the
+ ~ "License"); you may not use this file except in compliance
+ ~ with the License. You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing,
+ ~ software distributed under the License is distributed on an
+ ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ ~ KIND, either express or implied. See the License for the
+ ~ specific language governing permissions and limitations
+ ~ under the License.
+ -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.maven.its.dependency</groupId>
+ <artifactId>tree-multimodule</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ </parent>
+
+ <name>MultimoduleTest Module A</name>
+
+ <artifactId>tree-multimodule-module-a</artifactId>
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-project</artifactId>
+ <version>2.0.6</version>
+ </dependency>
+ </dependencies>
+
+</project>
diff --git a/src/it/projects/tree-verbose-multimodule/module-b/expected.txt b/src/it/projects/tree-verbose-multimodule/module-b/expected.txt
new file mode 100644
index 0000000..82331a2
--- /dev/null
+++ b/src/it/projects/tree-verbose-multimodule/module-b/expected.txt
@@ -0,0 +1,15 @@
+org.apache.maven.its.dependency:tree-multimodule-module-b:jar:1.0-SNAPSHOT WARNING: this tree contains a submodule. Once it reaches the submodule will print in nonVerbose fashion, to see the actual submodule verbose output refer to the rest of the output
+\- org.apache.maven.its.dependency:tree-multimodule-module-a:jar:1.0-SNAPSHOT:compile
+ \- org.apache.maven:maven-project:jar:2.0.6:compile
+ +- org.apache.maven:maven-settings:jar:2.0.6:compile
+ +- org.apache.maven:maven-profile:jar:2.0.6:compile
+ +- org.apache.maven:maven-model:jar:2.0.6:compile
+ +- org.apache.maven:maven-artifact-manager:jar:2.0.6:compile
+ | +- org.apache.maven:maven-repository-metadata:jar:2.0.6:compile
+ | \- org.apache.maven.wagon:wagon-provider-api:jar:1.0-beta-2:compile
+ +- org.apache.maven:maven-plugin-registry:jar:2.0.6:compile
+ +- org.codehaus.plexus:plexus-utils:jar:1.4.1:compile
+ +- org.apache.maven:maven-artifact:jar:2.0.6:compile
+ \- org.codehaus.plexus:plexus-container-default:jar:1.0-alpha-9-stable-1:compile
+ +- junit:junit:jar:3.8.1:compile
+ \- classworlds:classworlds:jar:1.1-alpha-2:compile
diff --git a/src/it/projects/tree-verbose-multimodule/module-b/pom.xml b/src/it/projects/tree-verbose-multimodule/module-b/pom.xml
new file mode 100644
index 0000000..bffea42
--- /dev/null
+++ b/src/it/projects/tree-verbose-multimodule/module-b/pom.xml
@@ -0,0 +1,48 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one
+ ~ or more contributor license agreements. See the NOTICE file
+ ~ distributed with this work for additional information
+ ~ regarding copyright ownership. The ASF licenses this file
+ ~ to you under the Apache License, Version 2.0 (the
+ ~ "License"); you may not use this file except in compliance
+ ~ with the License. You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing,
+ ~ software distributed under the License is distributed on an
+ ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ ~ KIND, either express or implied. See the License for the
+ ~ specific language governing permissions and limitations
+ ~ under the License.
+ -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.maven.its.dependency</groupId>
+ <artifactId>tree-multimodule</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ </parent>
+
+ <name>MultimoduleTest Module B</name>
+
+ <artifactId>tree-multimodule-module-b</artifactId>
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.maven.its.dependency</groupId>
+ <artifactId>tree-multimodule-module-a</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ </dependencies>
+
+</project>
diff --git a/src/it/projects/tree-verbose-multimodule/pom.xml b/src/it/projects/tree-verbose-multimodule/pom.xml
new file mode 100644
index 0000000..062e10d
--- /dev/null
+++ b/src/it/projects/tree-verbose-multimodule/pom.xml
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one
+ ~ or more contributor license agreements. See the NOTICE file
+ ~ distributed with this work for additional information
+ ~ regarding copyright ownership. The ASF licenses this file
+ ~ to you under the Apache License, Version 2.0 (the
+ ~ "License"); you may not use this file except in compliance
+ ~ with the License. You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing,
+ ~ software distributed under the License is distributed on an
+ ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ ~ KIND, either express or implied. See the License for the
+ ~ specific language governing permissions and limitations
+ ~ under the License.
+ -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>org.apache.maven.its.dependency</groupId>
+ <artifactId>tree-multimodule</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <packaging>pom</packaging>
+
+ <name>MultimoduleTest</name>
+ <description>
+ Test dependency:tree on multimodule project
+ </description>
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ </properties>
+
+ <modules>
+ <module>module-a</module>
+ <module>module-b</module>
+ </modules>
+
+</project>
diff --git a/src/it/projects/tree-verbose-multimodule/test.properties b/src/it/projects/tree-verbose-multimodule/test.properties
new file mode 100644
index 0000000..2a312e2
--- /dev/null
+++ b/src/it/projects/tree-verbose-multimodule/test.properties
@@ -0,0 +1,18 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+outputFile = target/tree.txt
diff --git a/src/it/projects/tree-verbose-multimodule/verify.bsh b/src/it/projects/tree-verbose-multimodule/verify.bsh
new file mode 100644
index 0000000..fcbece7
--- /dev/null
+++ b/src/it/projects/tree-verbose-multimodule/verify.bsh
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.io.*;
+
+import org.codehaus.plexus.util.*;
+
+String actual = FileUtils.fileRead( new File( basedir, "target/tree.txt" ) );
+String expected = FileUtils.fileRead( new File( basedir, "expected.txt" ) );
+
+actual = actual.replaceAll( "[\n\r]+", "\n" );
+expected = expected.replaceAll( "[\n\r]+", "\n" );
+
+if ( !actual.equals( expected ) )
+{
+ throw new Exception( "Unexpected root dependency tree" );
+}
+
+actual = FileUtils.fileRead( new File( basedir, "module-a/target/tree.txt" ) );
+expected = FileUtils.fileRead( new File( basedir, "module-a/expected.txt" ) );
+
+actual = actual.replaceAll( "[\n\r]+", "\n" );
+expected = expected.replaceAll( "[\n\r]+", "\n" );
+
+if ( !actual.equals( expected ) )
+{
+ throw new Exception( "Unexpected module-a dependency tree" );
+}
+
+actual = FileUtils.fileRead( new File( basedir, "module-b/target/tree.txt" ) );
+expected = FileUtils.fileRead( new File( basedir, "module-b/expected.txt" ) );
+
+actual = actual.replaceAll( "[\n\r]+", "\n" );
+expected = expected.replaceAll( "[\n\r]+", "\n" );
+
+if ( !actual.equals( expected ) )
+{
+ throw new Exception( "Unexpected module-b dependency tree" );
+}
+
+return true;
diff --git a/src/main/java/org/apache/maven/plugins/dependency/tree/ArtifactKey.java b/src/main/java/org/apache/maven/plugins/dependency/tree/ArtifactKey.java
new file mode 100644
index 0000000..f9346eb
--- /dev/null
+++ b/src/main/java/org/apache/maven/plugins/dependency/tree/ArtifactKey.java
@@ -0,0 +1,72 @@
+package org.apache.maven.plugins.dependency.tree;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.maven.project.MavenProject;
+
+/**
+ * Uniquely defines an artifact by groupId, artifactId and version.
+ */
+final class ArtifactKey
+{
+ private final String groupId;
+ private final String artifactId;
+ private final String version;
+
+ ArtifactKey( String groupId, String artifactId, String version )
+ {
+ this.groupId = groupId;
+ this.artifactId = artifactId;
+ this.version = version;
+ }
+
+ ArtifactKey( MavenProject project )
+ {
+ this( project.getGroupId(), project.getArtifactId(), project.getVersion() );
+ }
+
+ @Override
+ public boolean equals( Object o )
+ {
+ if ( this == o )
+ {
+ return true;
+ }
+
+ if ( !( o instanceof ArtifactKey ) )
+ {
+ return false;
+ }
+
+ ArtifactKey that = (ArtifactKey) o;
+
+ return artifactId.equals( that.artifactId ) && groupId.equals( that.groupId ) && version.equals( that.version );
+ }
+
+ @Override
+ public int hashCode()
+ {
+ final int hashPrime = 31;
+ int result = groupId.hashCode();
+ result = hashPrime * result + artifactId.hashCode();
+ result = hashPrime * result + version.hashCode();
+ return result;
+ }
+}
diff --git a/src/main/java/org/apache/maven/plugins/dependency/tree/TreeMojo.java b/src/main/java/org/apache/maven/plugins/dependency/tree/TreeMojo.java
index 1eb35b0..5f030c5 100644
--- a/src/main/java/org/apache/maven/plugins/dependency/tree/TreeMojo.java
+++ b/src/main/java/org/apache/maven/plugins/dependency/tree/TreeMojo.java
@@ -37,7 +37,6 @@ import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.plugins.annotations.ResolutionScope;
import org.apache.maven.plugins.dependency.utils.DependencyUtil;
import org.apache.maven.project.DefaultProjectBuildingRequest;
-import org.apache.maven.project.DependencyResolutionException;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.ProjectBuildingRequest;
import org.apache.maven.project.ProjectDependenciesResolver;
@@ -271,7 +270,7 @@ public class TreeMojo
AbstractVerboseGraphSerializer serializer = getSerializer();
org.eclipse.aether.graph.DependencyNode verboseRootNode = builder.buildVerboseGraph(
- project, resolver, repoSession );
+ project, resolver, repoSession, reactorProjects, buildingRequest );
dependencyTreeString = serializer.serialize( verboseRootNode );
rootNode = convertToCustomDependencyNode( verboseRootNode );
}
@@ -304,10 +303,6 @@ public class TreeMojo
{
throw new MojoExecutionException( "Cannot serialise project dependency graph", exception );
}
- catch ( DependencyResolutionException exception )
- {
- throw new MojoExecutionException( "Cannot resolve dependencies", exception );
- }
}
// public methods ---------------------------------------------------------
diff --git a/src/main/java/org/apache/maven/plugins/dependency/tree/VerboseDependencyGraphBuilder.java b/src/main/java/org/apache/maven/plugins/dependency/tree/VerboseDependencyGraphBuilder.java
index 192c941..44881cc 100644
--- a/src/main/java/org/apache/maven/plugins/dependency/tree/VerboseDependencyGraphBuilder.java
+++ b/src/main/java/org/apache/maven/plugins/dependency/tree/VerboseDependencyGraphBuilder.java
@@ -24,9 +24,12 @@ import org.apache.maven.model.Model;
import org.apache.maven.project.DefaultDependencyResolutionRequest;
import org.apache.maven.project.DependencyResolutionException;
import org.apache.maven.project.DependencyResolutionRequest;
+import org.apache.maven.project.DependencyResolutionResult;
import org.apache.maven.project.MavenProject;
+import org.apache.maven.project.ProjectBuildingRequest;
import org.apache.maven.project.ProjectDependenciesResolver;
import org.apache.maven.repository.internal.MavenRepositorySystemUtils;
+import org.apache.maven.shared.dependency.graph.DependencyGraphBuilderException;
import org.eclipse.aether.DefaultRepositorySystemSession;
import org.eclipse.aether.RepositorySystemSession;
import org.eclipse.aether.artifact.Artifact;
@@ -42,9 +45,11 @@ import org.eclipse.aether.util.graph.transformer.ChainedDependencyGraphTransform
import org.eclipse.aether.util.graph.transformer.JavaDependencyContextRefiner;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
+import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -57,8 +62,10 @@ class VerboseDependencyGraphBuilder
MANAGED_SCOPE = "managedScope";
public DependencyNode buildVerboseGraph( MavenProject project, ProjectDependenciesResolver resolver,
- RepositorySystemSession repositorySystemSession )
- throws DependencyResolutionException
+ RepositorySystemSession repositorySystemSession,
+ Collection<MavenProject> reactorProjects,
+ ProjectBuildingRequest buildingRequest )
+ throws DependencyGraphBuilderException
{
DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession();
session.setLocalRepositoryManager( repositorySystemSession.getLocalRepositoryManager() );
@@ -75,14 +82,48 @@ class VerboseDependencyGraphBuilder
session.setDependencyManager( null );
DependencyResolutionRequest request = new DefaultDependencyResolutionRequest();
- request.setMavenProject( project );
- request.setRepositorySession( session );
- request.setResolutionFilter( null );
+ request.setMavenProject( buildingRequest.getProject() );
+ request.setRepositorySession( session ) ;
+ DependencyNode rootNode;
+ boolean reactor = false;
+
+ try
+ {
+ rootNode = resolver.resolve( request ).getDependencyGraph();
+ }
+ catch ( DependencyResolutionException e )
+ {
+ // cannot properly resolve reactor dependencies with verbose RepositorySystemSession
+ // this should be fixed in the future
+ DependencyResolutionRequest reactorRequest = new DefaultDependencyResolutionRequest();
+ reactorRequest.setMavenProject( buildingRequest.getProject() );
+ reactorRequest.setRepositorySession( buildingRequest.getRepositorySession() ) ;
+ try
+ {
+ rootNode = resolver.resolve( reactorRequest ).getDependencyGraph();
+ }
+ catch ( DependencyResolutionException exception )
+ {
+ if ( reactorProjects == null )
+ {
+ throw new DependencyGraphBuilderException( "Could not resolve following dependencies: "
+ + exception.getResult().getUnresolvedDependencies(), exception );
+ }
+ reactor = true;
+ // try collecting from reactor
+ rootNode = collectDependenciesFromReactor( exception, reactorProjects ).getDependencyGraph();
+ rootNode.setData( "ContainsModule", "True" );
+ // rootNode.setArtifact( rootArtifact.setProperties( artifactProperties ) );
+ }
+ }
- DependencyNode rootNode = resolver.resolve( request ).getDependencyGraph();
// Don't want transitive test dependencies included in analysis
DependencyNode prunedRoot = pruneTransitiveTestDependencies( rootNode, project );
applyDependencyManagement( project, prunedRoot );
+ if ( reactor )
+ {
+ prunedRoot.setData( "ContainsModule", "True" );
+ }
return prunedRoot;
}
@@ -219,4 +260,49 @@ class VerboseDependencyGraphBuilder
}
}
}
+
+ private DependencyResolutionResult collectDependenciesFromReactor( DependencyResolutionException e,
+ Collection<MavenProject> reactorProjects )
+ throws DependencyGraphBuilderException
+ {
+ DependencyResolutionResult result = e.getResult();
+
+ List<Dependency> reactorDeps = getReactorDependencies( reactorProjects, result.getUnresolvedDependencies() );
+ result.getUnresolvedDependencies().removeAll( reactorDeps );
+ result.getResolvedDependencies().addAll( reactorDeps );
+
+ if ( !result.getUnresolvedDependencies().isEmpty() )
+ {
+ throw new DependencyGraphBuilderException( "Could not resolve nor collect following dependencies: "
+ + result.getUnresolvedDependencies(), e );
+ }
+
+ return result;
+ }
+
+ private List<Dependency> getReactorDependencies( Collection<MavenProject> reactorProjects, List<?> dependencies )
+ {
+ Set<ArtifactKey> reactorProjectsIds = new HashSet<ArtifactKey>();
+ for ( MavenProject project : reactorProjects )
+ {
+ reactorProjectsIds.add( new ArtifactKey( project ) );
+ }
+
+ List<Dependency> reactorDeps = new ArrayList<Dependency>();
+ for ( Object untypedDependency : dependencies )
+ {
+ Dependency dependency = (Dependency) untypedDependency;
+ org.eclipse.aether.artifact.Artifact depArtifact = dependency.getArtifact();
+
+ ArtifactKey key =
+ new ArtifactKey( depArtifact.getGroupId(), depArtifact.getArtifactId(), depArtifact.getVersion() );
+
+ if ( reactorProjectsIds.contains( key ) )
+ {
+ reactorDeps.add( dependency );
+ }
+ }
+
+ return reactorDeps;
+ }
}
diff --git a/src/main/java/org/apache/maven/plugins/dependency/tree/VerboseGraphDotSerializer.java b/src/main/java/org/apache/maven/plugins/dependency/tree/VerboseGraphDotSerializer.java
index fce1b4d..e2f6b3e 100644
--- a/src/main/java/org/apache/maven/plugins/dependency/tree/VerboseGraphDotSerializer.java
+++ b/src/main/java/org/apache/maven/plugins/dependency/tree/VerboseGraphDotSerializer.java
@@ -49,7 +49,16 @@ class VerboseGraphDotSerializer extends AbstractVerboseGraphSerializer
StringBuilder result = new StringBuilder( "digraph" );
result.append( " \"" ).append( rootArtifact.getGroupId() ).append( ":" ).append(
rootArtifact.getArtifactId() ).append( ":" ).append( rootArtifact.getExtension() ).append( ":" ).append(
- rootArtifact.getVersion() ).append( "\" {" ).append( "\n" );
+ rootArtifact.getVersion() );
+
+ if ( root.getData().containsKey( "ContainsModule" ) )
+ {
+ result.append( " WARNING: this tree contains a submodule. Once it reaches the submodule will print "
+ + "in nonVerbose fashion, to see the actual submodule verbose output refer to the "
+ + "rest of the output" );
+ }
+
+ result.append( "\" {" ).append( "\n" );
while ( !queue.isEmpty() )
{
diff --git a/src/main/java/org/apache/maven/plugins/dependency/tree/VerboseGraphGraphmlSerializer.java b/src/main/java/org/apache/maven/plugins/dependency/tree/VerboseGraphGraphmlSerializer.java
index 6f6e7e9..79ab9b9 100644
--- a/src/main/java/org/apache/maven/plugins/dependency/tree/VerboseGraphGraphmlSerializer.java
+++ b/src/main/java/org/apache/maven/plugins/dependency/tree/VerboseGraphGraphmlSerializer.java
@@ -152,6 +152,12 @@ public class VerboseGraphGraphmlSerializer extends AbstractVerboseGraphSerialize
"scope managed from " + node.getArtifact().getProperties().get( PRE_MANAGED_SCOPE );
}
builder.append( getDependencyCoordinate( node ) ).append( coordString );
+ if ( node.getData().containsKey( "ContainsModule" ) )
+ {
+ builder.append( " WARNING: this tree contains a submodule. Once it reaches the submodule will print "
+ + "in nonVerbose fashion, to see the actual submodule "
+ + "verbose output refer to the rest of the output" );
+ }
if ( node.getArtifact().getProperties().containsKey( "Cycle" ) )
{
if ( !messageAdded )
diff --git a/src/main/java/org/apache/maven/plugins/dependency/tree/VerboseGraphTextSerializer.java b/src/main/java/org/apache/maven/plugins/dependency/tree/VerboseGraphTextSerializer.java
index 70e41ee..b8a5143 100644
--- a/src/main/java/org/apache/maven/plugins/dependency/tree/VerboseGraphTextSerializer.java
+++ b/src/main/java/org/apache/maven/plugins/dependency/tree/VerboseGraphTextSerializer.java
@@ -45,8 +45,16 @@ class VerboseGraphTextSerializer extends AbstractVerboseGraphSerializer
// deal with root first
Artifact rootArtifact = root.getArtifact();
builder.append( rootArtifact.getGroupId() ).append( ":" ).append( rootArtifact.getArtifactId() ).append(
- ":" ).append( rootArtifact.getExtension() ).append( ":" ).append( rootArtifact.getVersion() ).append(
- "\n" );
+ ":" ).append( rootArtifact.getExtension() ).append( ":" ).append( rootArtifact.getVersion() );
+
+ if ( root.getData().containsKey( "ContainsModule" ) )
+ {
+ builder.append( " WARNING: this tree contains a submodule. Once it reaches the submodule will print "
+ + "in nonVerbose fashion, to see the actual submodule verbose output refer to "
+ + "the rest of the output" );
+ }
+
+ builder.append( "\n" );
for ( int i = 0; i < root.getChildren().size(); i++ )
{
diff --git a/src/main/java/org/apache/maven/plugins/dependency/tree/VerboseGraphTgfSerializer.java b/src/main/java/org/apache/maven/plugins/dependency/tree/VerboseGraphTgfSerializer.java
index f44cfe6..5fef91b 100644
--- a/src/main/java/org/apache/maven/plugins/dependency/tree/VerboseGraphTgfSerializer.java
+++ b/src/main/java/org/apache/maven/plugins/dependency/tree/VerboseGraphTgfSerializer.java
@@ -49,7 +49,16 @@ class VerboseGraphTgfSerializer extends AbstractVerboseGraphSerializer
Artifact rootArtifact = root.getArtifact();
nodes.append( root.hashCode() ).append( " " ).append( rootArtifact.getGroupId() ).append( ":" ).append(
rootArtifact.getArtifactId() ).append( ":" ).append( rootArtifact.getExtension() ).append( ":" ).append(
- rootArtifact.getVersion() ).append( "\n" );
+ rootArtifact.getVersion() );
+
+ if ( root.getData().containsKey( "ContainsModule" ) )
+ {
+ nodes.append( " WARNING: this tree contains a submodule. Once it reaches the submodule will print "
+ + "in nonVerbose fashion, to see the actual submodule "
+ + "verbose output refer to the rest of the output" );
+ }
+
+ nodes.append( "\n" );
for ( DependencyNode child : root.getChildren() )
{