View Javadoc
1   package org.apache.maven.it;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import java.io.File;
23  import java.util.List;
24  
25  import org.apache.maven.it.util.ResourceExtractor;
26  
27  /**
28   * This is a test set for <a href="https://issues.apache.org/jira/browse/MNG-3023">MNG-3023</a>
29   *
30   * @author Mark Hobson
31   * @author jdcasey
32   *
33   */
34  public class MavenITmng3023ReactorDependencyResolutionTest
35      extends AbstractMavenIntegrationTestCase
36  {
37  
38      public MavenITmng3023ReactorDependencyResolutionTest()
39      {
40          super( "(2.1.0-M1,)" );
41      }
42  
43      /**
44       * Test that reactor projects are included in dependency resolution.
45       *
46       * In this pass, the dependency artifact should be missing from the local repository, and since the 'compile' phase
47       * has not been called, i.e. the output directory for the compiled classes has not been created yet, the
48       * dependency project artifact should not have a file associated with it. Therefore, the dependency artifact
49       * should fail to resolve, and the build should fail.
50       *
51       * @throws Exception in case of failure
52       */
53      public void testitMNG3023A() throws Exception
54      {
55          File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-3023" );
56  
57          // First pass. Make sure the dependency cannot be resolved.
58          Verifier verifier = newVerifier( testDir.getAbsolutePath() );
59          verifier.setAutoclean( false );
60          verifier.setLogFileName( "log-a.txt" );
61  
62          verifier.deleteDirectory( "dependency/dependency-classes" );
63          verifier.deleteArtifacts( "org.apache.maven.its.mng3023" );
64  
65          try
66          {
67              verifier.executeGoal( "validate" );
68              fail( "Expected failure to resolve dependency artifact without at least calling 'compile' phase." );
69          }
70          catch ( VerificationException e )
71          {
72              // expected.
73          }
74          finally
75          {
76              verifier.resetStreams();
77          }
78      }
79  
80      /**
81       * Test that reactor projects are included in dependency resolution.
82       *
83       * I this pass, the dependency artifact should have the file $(basedir)/dependency/dependency-classes
84       * (a directory) associated with it, since the 'compile' phase has run. This location should be
85       * present in the compile classpath output from the maven-it-plugin-dependency-resolution:compile
86       * mojo execution.
87       *
88       * @throws Exception in case of failure
89       */
90      public void testitMNG3023B()
91          throws Exception
92      {
93          File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-3023" );
94  
95          Verifier verifier = newVerifier( testDir.getAbsolutePath() );
96          verifier.setAutoclean( false );
97          verifier.setLogFileName( "log-b.txt" );
98          // The IT doesn't actually run the compiler but merely mimics its effect, i.e. the creation of the output dir
99          new File( testDir, "dependency/dependency-classes" ).mkdirs();
100         verifier.deleteDirectory( "consumer/target" );
101         verifier.deleteArtifacts( "org.apache.maven.its.mng3023" );
102 
103         verifier.executeGoal( "initialize" );
104         verifier.verifyErrorFreeLog();
105         verifier.resetStreams();
106 
107         List<String> compileClassPath = verifier.loadLines( "consumer/target/compile.classpath", "UTF-8" );
108         assertTrue( compileClassPath.toString(), compileClassPath.contains( "dependency-classes" ) );
109         assertFalse( compileClassPath.toString(), compileClassPath.contains( "dependency-1.jar" ) );
110     }
111 
112     /**
113      * Test that reactor projects are included in dependency resolution.
114      *
115      * I this pass, the dependency should have been installed, so the dependency artifact should have
116      * a file of .../dependency-1.jar associated with it, since the 'install' phase has run. This
117      * location should be present in the compile classpath output from the
118      * maven-it-plugin-dependency-resolution:compile mojo execution.
119      *
120      * Afterwards, the projects are cleaned and a separate Maven call to the 'initialize' phase should succeed, since
121      * the dependency artifact has been installed locally. This second execution should use the jar file
122      * from the local repository in its classpath output.
123      *
124      * @throws Exception in case of failure
125      */
126     public void testitMNG3023C()
127         throws Exception
128     {
129         File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-3023" );
130 
131         Verifier verifier = newVerifier( testDir.getAbsolutePath() );
132         verifier.setAutoclean( false );
133 
134         verifier.deleteArtifacts( "org.apache.maven.its.mng3023" );
135 
136         verifier.deleteDirectory( "consumer/target" );
137         verifier.setLogFileName( "log-c-1.txt" );
138         verifier.executeGoal( "generate-sources" );
139         verifier.verifyErrorFreeLog();
140         verifier.resetStreams();
141 
142         List<String> compileClassPath = verifier.loadLines( "consumer/target/compile.classpath", "UTF-8" );
143         assertTrue( compileClassPath.toString(), compileClassPath.contains( "dependency-1.jar" ) );
144         assertFalse( compileClassPath.toString(), compileClassPath.contains( "dependency-classes" ) );
145 
146         verifier.deleteDirectory( "dependency/dependency-classes" );
147         verifier.deleteDirectory( "consumer/target" );
148         verifier.setLogFileName( "log-c-2.txt" );
149         verifier.executeGoal( "validate" );
150         verifier.verifyErrorFreeLog();
151         verifier.resetStreams();
152 
153         compileClassPath = verifier.loadLines( "consumer/target/compile.classpath", "UTF-8" );
154         assertTrue( compileClassPath.toString(), compileClassPath.contains( "dependency-1.jar" ) );
155         assertFalse( compileClassPath.toString(), compileClassPath.contains( "dependency-classes" ) );
156     }
157 
158 }