From 2b728af9b738710293d9b22d8ccbbaa48b29e73c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9da=20Housni=20Alaoui?= Date: Fri, 14 Apr 2017 00:22:15 +0200 Subject: [PATCH] MDEP-409 dependency:tree fails for a multi-module project where one module depends on another and "mvn install" not run yet --- maven-dependency-plugin/pom.xml | 3 + .../it/projects/tree-multimodule/expected.txt | 1 + .../tree-multimodule/invoker.properties | 18 ++++++ .../tree-multimodule/module-a/expected.txt | 14 +++++ .../tree-multimodule/module-a/pom.xml | 48 ++++++++++++++ .../tree-multimodule/module-b/expected.txt | 15 +++++ .../tree-multimodule/module-b/pom.xml | 48 ++++++++++++++ .../src/it/projects/tree-multimodule/pom.xml | 45 +++++++++++++ .../projects/tree-multimodule/test.properties | 18 ++++++ .../it/projects/tree-multimodule/verify.bsh | 63 +++++++++++++++++++ .../plugins/dependency/tree/TreeMojo.java | 10 ++- 11 files changed, 281 insertions(+), 2 deletions(-) create mode 100644 maven-dependency-plugin/src/it/projects/tree-multimodule/expected.txt create mode 100644 maven-dependency-plugin/src/it/projects/tree-multimodule/invoker.properties create mode 100644 maven-dependency-plugin/src/it/projects/tree-multimodule/module-a/expected.txt create mode 100644 maven-dependency-plugin/src/it/projects/tree-multimodule/module-a/pom.xml create mode 100644 maven-dependency-plugin/src/it/projects/tree-multimodule/module-b/expected.txt create mode 100644 maven-dependency-plugin/src/it/projects/tree-multimodule/module-b/pom.xml create mode 100644 maven-dependency-plugin/src/it/projects/tree-multimodule/pom.xml create mode 100644 maven-dependency-plugin/src/it/projects/tree-multimodule/test.properties create mode 100644 maven-dependency-plugin/src/it/projects/tree-multimodule/verify.bsh diff --git a/maven-dependency-plugin/pom.xml b/maven-dependency-plugin/pom.xml index 06bbdf09a1..d28437f458 100644 --- a/maven-dependency-plugin/pom.xml +++ b/maven-dependency-plugin/pom.xml @@ -305,6 +305,9 @@ under the License. --> src/it/projects/tree/expected.txt src/it/projects/tree-includes/expected.txt + src/it/projects/tree-multimodule/expected.txt + src/it/projects/tree-multimodule/module-a/expected.txt + src/it/projects/tree-multimodule/module-b/expected.txt src/it/projects/tree-verbose/expected.txt diff --git a/maven-dependency-plugin/src/it/projects/tree-multimodule/expected.txt b/maven-dependency-plugin/src/it/projects/tree-multimodule/expected.txt new file mode 100644 index 0000000000..d55e3aae76 --- /dev/null +++ b/maven-dependency-plugin/src/it/projects/tree-multimodule/expected.txt @@ -0,0 +1 @@ +org.apache.maven.its.dependency:tree-multimodule:pom:1.0-SNAPSHOT diff --git a/maven-dependency-plugin/src/it/projects/tree-multimodule/invoker.properties b/maven-dependency-plugin/src/it/projects/tree-multimodule/invoker.properties new file mode 100644 index 0000000000..b803f42285 --- /dev/null +++ b/maven-dependency-plugin/src/it/projects/tree-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 \ No newline at end of file diff --git a/maven-dependency-plugin/src/it/projects/tree-multimodule/module-a/expected.txt b/maven-dependency-plugin/src/it/projects/tree-multimodule/module-a/expected.txt new file mode 100644 index 0000000000..5864693a0d --- /dev/null +++ b/maven-dependency-plugin/src/it/projects/tree-multimodule/module-a/expected.txt @@ -0,0 +1,14 @@ +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-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/maven-dependency-plugin/src/it/projects/tree-multimodule/module-a/pom.xml b/maven-dependency-plugin/src/it/projects/tree-multimodule/module-a/pom.xml new file mode 100644 index 0000000000..7c6fe3c1d4 --- /dev/null +++ b/maven-dependency-plugin/src/it/projects/tree-multimodule/module-a/pom.xml @@ -0,0 +1,48 @@ + + + + + 4.0.0 + + + org.apache.maven.its.dependency + tree-multimodule + 1.0-SNAPSHOT + + + MultimoduleTest Module A + + tree-multimodule-module-a + + + UTF-8 + + + + + org.apache.maven + maven-project + 2.0.6 + + + + diff --git a/maven-dependency-plugin/src/it/projects/tree-multimodule/module-b/expected.txt b/maven-dependency-plugin/src/it/projects/tree-multimodule/module-b/expected.txt new file mode 100644 index 0000000000..70d2df7975 --- /dev/null +++ b/maven-dependency-plugin/src/it/projects/tree-multimodule/module-b/expected.txt @@ -0,0 +1,15 @@ +org.apache.maven.its.dependency:tree-multimodule-module-b:jar:1.0-SNAPSHOT +\- 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/maven-dependency-plugin/src/it/projects/tree-multimodule/module-b/pom.xml b/maven-dependency-plugin/src/it/projects/tree-multimodule/module-b/pom.xml new file mode 100644 index 0000000000..bffea42af0 --- /dev/null +++ b/maven-dependency-plugin/src/it/projects/tree-multimodule/module-b/pom.xml @@ -0,0 +1,48 @@ + + + + + 4.0.0 + + + org.apache.maven.its.dependency + tree-multimodule + 1.0-SNAPSHOT + + + MultimoduleTest Module B + + tree-multimodule-module-b + + + UTF-8 + + + + + org.apache.maven.its.dependency + tree-multimodule-module-a + ${project.version} + + + + diff --git a/maven-dependency-plugin/src/it/projects/tree-multimodule/pom.xml b/maven-dependency-plugin/src/it/projects/tree-multimodule/pom.xml new file mode 100644 index 0000000000..062e10d433 --- /dev/null +++ b/maven-dependency-plugin/src/it/projects/tree-multimodule/pom.xml @@ -0,0 +1,45 @@ + + + + + 4.0.0 + + org.apache.maven.its.dependency + tree-multimodule + 1.0-SNAPSHOT + pom + + MultimoduleTest + + Test dependency:tree on multimodule project + + + + UTF-8 + + + + module-a + module-b + + + diff --git a/maven-dependency-plugin/src/it/projects/tree-multimodule/test.properties b/maven-dependency-plugin/src/it/projects/tree-multimodule/test.properties new file mode 100644 index 0000000000..2a312e22e2 --- /dev/null +++ b/maven-dependency-plugin/src/it/projects/tree-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/maven-dependency-plugin/src/it/projects/tree-multimodule/verify.bsh b/maven-dependency-plugin/src/it/projects/tree-multimodule/verify.bsh new file mode 100644 index 0000000000..a4fce7eda5 --- /dev/null +++ b/maven-dependency-plugin/src/it/projects/tree-multimodule/verify.bsh @@ -0,0 +1,63 @@ +/* + * 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" ); + +System.out.println( "Checking root dependency tree..." ); + +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" ); + +System.out.println( "Checking module-a dependency tree..." ); + +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" ); + +System.out.println( "Checking module-b dependency tree..." ); + +if ( !actual.equals( expected ) ) +{ + throw new Exception( "Unexpected module-b dependency tree" ); +} + +return true; diff --git a/maven-dependency-plugin/src/main/java/org/apache/maven/plugins/dependency/tree/TreeMojo.java b/maven-dependency-plugin/src/main/java/org/apache/maven/plugins/dependency/tree/TreeMojo.java index 678653d142..a83c08dcaf 100644 --- a/maven-dependency-plugin/src/main/java/org/apache/maven/plugins/dependency/tree/TreeMojo.java +++ b/maven-dependency-plugin/src/main/java/org/apache/maven/plugins/dependency/tree/TreeMojo.java @@ -67,7 +67,7 @@ * @version $Id$ * @since 2.0-alpha-5 */ -@Mojo( name = "tree", requiresDependencyResolution = ResolutionScope.TEST, threadSafe = true ) +@Mojo( name = "tree", requiresDependencyCollection = ResolutionScope.TEST, threadSafe = true ) public class TreeMojo extends AbstractMojo { @@ -82,6 +82,12 @@ public class TreeMojo @Parameter( defaultValue = "${session}", readonly = true, required = true ) private MavenSession session; + /** + * Contains the full list of projects in the reactor. + */ + @Parameter( defaultValue = "${reactorProjects}", readonly = true, required = true ) + private List reactorProjects; + /** * The dependency tree builder to use. */ @@ -234,7 +240,7 @@ public void execute() // non-verbose mode use dependency graph component, which gives consistent results with Maven version // running - rootNode = dependencyGraphBuilder.buildDependencyGraph( buildingRequest, artifactFilter ); + rootNode = dependencyGraphBuilder.buildDependencyGraph( buildingRequest, artifactFilter, reactorProjects ); dependencyTreeString = serializeDependencyTree( rootNode );