diff --git a/its/core-it-suite/src/test/java/org/apache/maven/it/IntegrationTestSuite.java b/its/core-it-suite/src/test/java/org/apache/maven/it/IntegrationTestSuite.java index 2c1f32deea..575eea1263 100644 --- a/its/core-it-suite/src/test/java/org/apache/maven/it/IntegrationTestSuite.java +++ b/its/core-it-suite/src/test/java/org/apache/maven/it/IntegrationTestSuite.java @@ -208,6 +208,7 @@ public static Test suite() suite.addTestSuite( MavenITmng3106ProfileMultipleActivatorsTest.class ); suite.addTestSuite( MavenITmng3099SettingsProfilesWithNoPomTest.class ); suite.addTestSuite( MavenITmng3052DepRepoAggregationTest.class ); + suite.addTestSuite( MavenITmng3023ReactorDependencyResolutionTest.class ); suite.addTestSuite( MavenITmng3012CoreClassImportTest.class ); suite.addTestSuite( MavenITmng2972OverridePluginDependencyTest.class ); suite.addTestSuite( MavenITmng2926PluginPrefixOrderTest.class ); diff --git a/its/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng3023ReactorDependencyResolutionTest.java b/its/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng3023ReactorDependencyResolutionTest.java index 8fcd044e01..5acc4bef46 100644 --- a/its/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng3023ReactorDependencyResolutionTest.java +++ b/its/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng3023ReactorDependencyResolutionTest.java @@ -23,11 +23,14 @@ import org.apache.maven.it.util.ResourceExtractor; import java.io.File; +import java.util.Iterator; +import java.util.List; /** * This is a test set for MNG-3023 * * @author Mark Hobson + * @author jdcasey * @version $Id$ */ public class MavenITmng3023ReactorDependencyResolutionTest @@ -35,20 +38,112 @@ public class MavenITmng3023ReactorDependencyResolutionTest { /** * Test that reactor projects are included in dependency resolution. + * + * In this pass, the dependency artifact should be missing from the local repository, and since + * the 'compile' phase has not been called, the dependency project artifact should not have a + * file associated with it. Therefore, the dependency artifact should fail to resolve, and the + * build should fail. */ - public void testitMNG3023() + public void testitMNG3023A() throws Exception + { + File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-3023" ); + + // First pass. Make sure the dependency cannot be resolved. + Verifier verifier = new Verifier( testDir.getAbsolutePath() ); + + verifier.deleteArtifact( "org.apache.maven.its.mng3023", "dependency", "1", "jar" ); + + try + { + verifier.executeGoal( "initialize" ); + fail( "Expected failure to resolve dependency artifact without at least calling 'compile' phase." ); + } + catch ( VerificationException e ) + { + // expected. + } + finally + { + verifier.resetStreams(); + } + } + + /** + * Test that reactor projects are included in dependency resolution. + * + * I this pass, the dependency artifact should have the file $(basedir)/dependency/target/classes + * (a directory) associated with it, since the 'compile' phase has run. This location should be + * present in the compile classpath output from the maven-it-plugin-dependency-resolution:compile + * mojo execution. + */ + public void testitMNG3023B() throws Exception { - File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-3023/plugin" ); + File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-3023" ); + Verifier verifier = new Verifier( testDir.getAbsolutePath() ); + + verifier.deleteArtifact( "org.apache.maven.its.mng3023", "dependency", "1", "jar" ); + + verifier.executeGoal( "compile" ); + verifier.verifyErrorFreeLog(); + verifier.resetStreams(); + + List compileClassPath = verifier.loadLines( "consumer/target/compile.classpath", "UTF-8" ); + assertTrue( find( "dependency/target/classes", compileClassPath ) ); + assertFalse( find( "dependency-1.jar", compileClassPath ) ); + } + + /** + * Test that reactor projects are included in dependency resolution. + * + * I this pass, the dependency should have been installed, so the dependency artifact should have + * a file of .../dependency-1.jar associated with it, since the 'install' phase has run. This + * location should be present in the compile classpath output from the + * maven-it-plugin-dependency-resolution:compile mojo execution. + * + * Afterwards, the a separate Maven call to the 'initialize' phase should succeed, since the + * dependency artifact has been installed locally. This second execution should use the jar file + * from the local repository in its classpath output. + */ + public void testitMNG3023C() + throws Exception + { + File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-3023" ); + + Verifier verifier = new Verifier( testDir.getAbsolutePath() ); + + verifier.deleteArtifact( "org.apache.maven.its.mng3023", "dependency", "1", "jar" ); + verifier.executeGoal( "install" ); verifier.verifyErrorFreeLog(); verifier.resetStreams(); - testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-3023/project" ); - verifier = new Verifier( testDir.getAbsolutePath() ); - verifier.executeGoal( "org.apache.maven.its.it0122:maven-it-it0122-plugin:1.0:test" ); + List compileClassPath = verifier.loadLines( "consumer/target/compile.classpath", "UTF-8" ); + assertTrue( find( "dependency-1.jar", compileClassPath ) ); + assertFalse( find( "dependency/target/classes", compileClassPath ) ); + + verifier.executeGoal( "initialize" ); verifier.verifyErrorFreeLog(); verifier.resetStreams(); + + compileClassPath = verifier.loadLines( "consumer/target/compile.classpath", "UTF-8" ); + assertTrue( find( "dependency-1.jar", compileClassPath ) ); + assertFalse( find( "dependency/target/classes", compileClassPath ) ); + } + + private boolean find( String pathSubstr, List classPath ) + { + for ( Iterator it = classPath.iterator(); it.hasNext(); ) + { + String path = (String) it.next(); + + if ( path.indexOf( pathSubstr ) > -1 ) + { + return true; + } + } + + return false; } } diff --git a/its/core-it-suite/src/test/resources/mng-3023/consumer/pom.xml b/its/core-it-suite/src/test/resources/mng-3023/consumer/pom.xml new file mode 100644 index 0000000000..5e556e1939 --- /dev/null +++ b/its/core-it-suite/src/test/resources/mng-3023/consumer/pom.xml @@ -0,0 +1,40 @@ + + 4.0.0 + + org.apache.maven.its.mng3023 + parent + 1 + + + consumer + + + + org.apache.maven.its.mng3023 + dependency + 1 + + + + + + + org.apache.maven.its.plugins + maven-it-plugin-dependency-resolution + 2.1-SNAPSHOT + + + compile-classpath + initialize + + compile + + + ${project.build.directory}/compile.classpath + + + + + + + diff --git a/its/core-it-suite/src/test/resources/mng-3023/dependency/pom.xml b/its/core-it-suite/src/test/resources/mng-3023/dependency/pom.xml new file mode 100644 index 0000000000..bfe9865901 --- /dev/null +++ b/its/core-it-suite/src/test/resources/mng-3023/dependency/pom.xml @@ -0,0 +1,10 @@ + + 4.0.0 + + org.apache.maven.its.mng3023 + parent + 1 + + + dependency + diff --git a/its/core-it-suite/src/test/resources/mng-3023/dependency/src/main/java/org/apache/maven/debug/mng2720/App.java b/its/core-it-suite/src/test/resources/mng-3023/dependency/src/main/java/org/apache/maven/debug/mng2720/App.java new file mode 100644 index 0000000000..2f8f544fd8 --- /dev/null +++ b/its/core-it-suite/src/test/resources/mng-3023/dependency/src/main/java/org/apache/maven/debug/mng2720/App.java @@ -0,0 +1,13 @@ +package org.apache.maven.debug.mng2720; + +/** + * Hello world! + * + */ +public class App +{ + public static void main( String[] args ) + { + System.out.println( "Hello World!" ); + } +} diff --git a/its/core-it-suite/src/test/resources/mng-3023/plugin/pom.xml b/its/core-it-suite/src/test/resources/mng-3023/plugin/pom.xml deleted file mode 100644 index 74b54bb400..0000000000 --- a/its/core-it-suite/src/test/resources/mng-3023/plugin/pom.xml +++ /dev/null @@ -1,15 +0,0 @@ - - 4.0.0 - Maven Integration Test :: it0122 :: Plugin - org.apache.maven.its.it0122 - maven-it-it0122-plugin - maven-plugin - 1.0 - - - org.apache.maven - maven-plugin-api - 2.0 - - - diff --git a/its/core-it-suite/src/test/resources/mng-3023/plugin/src/main/java/org/apache/maven/its/it0122/TestMojo.java b/its/core-it-suite/src/test/resources/mng-3023/plugin/src/main/java/org/apache/maven/its/it0122/TestMojo.java deleted file mode 100644 index e153ec11d2..0000000000 --- a/its/core-it-suite/src/test/resources/mng-3023/plugin/src/main/java/org/apache/maven/its/it0122/TestMojo.java +++ /dev/null @@ -1,46 +0,0 @@ -package org.apache.maven.its.it0122; - -/* - * 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.File; -import java.io.IOException; - -import org.apache.maven.plugin.AbstractMojo; -import org.apache.maven.plugin.MojoExecutionException; -import org.apache.maven.plugin.MojoFailureException; - -/** - * Simple Mojo that just requires compile-scope dependency resolution. - * - * @author Mark Hobson - * @version $Id$ - * @goal test - * @requiresDependencyResolution compile - */ -public class TestMojo extends AbstractMojo -{ - /** - * @see org.apache.maven.plugin.Mojo#execute() - */ - public void execute() throws MojoExecutionException, MojoFailureException - { - getLog().info("Test Mojo executed"); - } -} diff --git a/its/core-it-suite/src/test/resources/mng-3023/project/pom.xml b/its/core-it-suite/src/test/resources/mng-3023/pom.xml similarity index 55% rename from its/core-it-suite/src/test/resources/mng-3023/project/pom.xml rename to its/core-it-suite/src/test/resources/mng-3023/pom.xml index 9bcb46b2a4..f21e734f49 100644 --- a/its/core-it-suite/src/test/resources/mng-3023/project/pom.xml +++ b/its/core-it-suite/src/test/resources/mng-3023/pom.xml @@ -1,13 +1,13 @@ 4.0.0 - Maven Integration Test :: it0122 Test that reactor projects are included in dependency resolution. - org.apache.maven.its.it0122 - maven-it-it0122 + org.apache.maven.its.mng3023 + parent + 1 pom - 1.0 + dependency - main + consumer diff --git a/its/core-it-suite/src/test/resources/mng-3023/project/dependency/pom.xml b/its/core-it-suite/src/test/resources/mng-3023/project/dependency/pom.xml deleted file mode 100644 index 6109fbc301..0000000000 --- a/its/core-it-suite/src/test/resources/mng-3023/project/dependency/pom.xml +++ /dev/null @@ -1,7 +0,0 @@ - - 4.0.0 - Maven Integration Test :: it0122 :: Dependency - org.apache.maven.its.it0122 - maven-it-it0122-dependency - 1.0 - diff --git a/its/core-it-suite/src/test/resources/mng-3023/project/main/pom.xml b/its/core-it-suite/src/test/resources/mng-3023/project/main/pom.xml deleted file mode 100644 index 97d90c58d9..0000000000 --- a/its/core-it-suite/src/test/resources/mng-3023/project/main/pom.xml +++ /dev/null @@ -1,14 +0,0 @@ - - 4.0.0 - Maven Integration Test :: it0122 :: Main - org.apache.maven.its.it0122 - maven-it-it0122-main - 1.0 - - - org.apache.maven.its.it0122 - maven-it-it0122-dependency - 1.0 - - -