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 org.apache.maven.it.Verifier;
23  import org.apache.maven.it.util.ResourceExtractor;
24  
25  import java.io.File;
26  import java.util.List;
27  
28  /**
29   * This is a test set for <a href="http://jira.codehaus.org/browse/MNG-3043">MNG-3043</a>.
30   * 
31   * @author Benjamin Bentmann
32   */
33  public class MavenITmng3043BestEffortReactorResolutionTest
34      extends AbstractMavenIntegrationTestCase
35  {
36  
37      public MavenITmng3043BestEffortReactorResolutionTest()
38      {
39          super( "[3.0-alpha-3,)" );
40      }
41  
42      /**
43       * Test that dependencies on attached artifacts like a test JAR or an EJB client JAR which have not been built
44       * yet, i.e. in build phases prior to "package" like "test", are satisfied from the output directories of the
45       * projects in the reactor. This is meant as a best effort to provide a class path for compilation or testing.
46       */
47      public void testitTestPhase()
48          throws Exception
49      {
50          File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-3043" );
51  
52          Verifier verifier = newVerifier( testDir.getAbsolutePath() );
53          verifier.setAutoclean( false );
54          verifier.deleteDirectory( "consumer-a/target" );
55          verifier.deleteDirectory( "consumer-b/target" );
56          verifier.deleteDirectory( "consumer-c/target" );
57          verifier.deleteArtifacts( "org.apache.maven.its.mng3043" );
58          verifier.setLogFileName( "log-test.txt" );
59          verifier.executeGoal( "test" );
60          verifier.verifyErrorFreeLog();
61          verifier.resetStreams();
62  
63          List classpath;
64  
65          classpath = verifier.loadLines( "consumer-a/target/compile.txt", "UTF-8" );
66          assertContains( classpath, new String[] { "classes-test" } );
67          assertNotContains( classpath, new String[] { "classes-main" } );
68          classpath = verifier.loadLines( "consumer-a/target/runtime.txt", "UTF-8" );
69          assertContains( classpath, new String[] { "classes-test" } );
70          assertNotContains( classpath, new String[] { "classes-main" } );
71          classpath = verifier.loadLines( "consumer-a/target/test.txt", "UTF-8" );
72          assertContains( classpath, new String[] { "classes-test" } );
73          assertNotContains( classpath, new String[] { "classes-main" } );
74  
75          classpath = verifier.loadLines( "consumer-b/target/compile.txt", "UTF-8" );
76          assertContains( classpath, new String[] { "classes-main" } );
77          assertNotContains( classpath, new String[] { "classes-test" } );
78          classpath = verifier.loadLines( "consumer-b/target/runtime.txt", "UTF-8" );
79          assertContains( classpath, new String[] { "classes-main" } );
80          assertNotContains( classpath, new String[] { "classes-test" } );
81          classpath = verifier.loadLines( "consumer-b/target/test.txt", "UTF-8" );
82          assertContains( classpath, new String[] { "classes-main" } );
83          assertNotContains( classpath, new String[] { "classes-test" } );
84  
85          classpath = verifier.loadLines( "consumer-c/target/compile.txt", "UTF-8" );
86          assertContains( classpath, new String[] { "classes-main" } );
87          assertContains( classpath, new String[] { "classes-test" } );
88          classpath = verifier.loadLines( "consumer-c/target/runtime.txt", "UTF-8" );
89          assertContains( classpath, new String[] { "classes-main" } );
90          assertContains( classpath, new String[] { "classes-test" } );
91          classpath = verifier.loadLines( "consumer-c/target/test.txt", "UTF-8" );
92          assertContains( classpath, new String[] { "classes-main" } );
93          assertContains( classpath, new String[] { "classes-test" } );
94      }
95  
96      /**
97       * Test that dependency resolution still uses the actual artifact files once these have been
98       * assembled/attached in the "package" phase. This ensures the class path is accurate and not locked to
99       * the output directories of the best effort model from above.
100      */
101     public void testitPackagePhase()
102         throws Exception
103     {
104         File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-3043" );
105 
106         Verifier verifier = newVerifier( testDir.getAbsolutePath() );
107         verifier.setAutoclean( false );
108         verifier.deleteDirectory( "consumer-a/target" );
109         verifier.deleteDirectory( "consumer-b/target" );
110         verifier.deleteDirectory( "consumer-c/target" );
111         verifier.deleteArtifacts( "org.apache.maven.its.mng3043" );
112         verifier.setLogFileName( "log-package.txt" );
113         verifier.executeGoal( "package" );
114         verifier.verifyErrorFreeLog();
115         verifier.resetStreams();
116 
117         List classpath;
118 
119         classpath = verifier.loadLines( "consumer-a/target/compile.txt", "UTF-8" );
120         assertContains( classpath, new String[] { "tests.jar" } );
121         assertNotContains( classpath, new String[] { "client.jar" } );
122         classpath = verifier.loadLines( "consumer-a/target/runtime.txt", "UTF-8" );
123         assertContains( classpath, new String[] { "tests.jar" } );
124         assertNotContains( classpath, new String[] { "client.jar" } );
125         classpath = verifier.loadLines( "consumer-a/target/test.txt", "UTF-8" );
126         assertContains( classpath, new String[] { "tests.jar" } );
127         assertNotContains( classpath, new String[] { "client.jar" } );
128 
129         classpath = verifier.loadLines( "consumer-b/target/compile.txt", "UTF-8" );
130         assertContains( classpath, new String[] { "client.jar" } );
131         assertNotContains( classpath, new String[] { "tests.jar" } );
132         classpath = verifier.loadLines( "consumer-b/target/runtime.txt", "UTF-8" );
133         assertContains( classpath, new String[] { "client.jar" } );
134         assertNotContains( classpath, new String[] { "tests.jar" } );
135         classpath = verifier.loadLines( "consumer-b/target/test.txt", "UTF-8" );
136         assertContains( classpath, new String[] { "client.jar" } );
137         assertNotContains( classpath, new String[] { "tests.jar" } );
138 
139         classpath = verifier.loadLines( "consumer-c/target/compile.txt", "UTF-8" );
140         assertContains( classpath, new String[] { "client.jar" } );
141         assertContains( classpath, new String[] { "tests.jar" } );
142         classpath = verifier.loadLines( "consumer-c/target/runtime.txt", "UTF-8" );
143         assertContains( classpath, new String[] { "client.jar" } );
144         assertContains( classpath, new String[] { "tests.jar" } );
145         classpath = verifier.loadLines( "consumer-c/target/test.txt", "UTF-8" );
146         assertContains( classpath, new String[] { "client.jar" } );
147         assertContains( classpath, new String[] { "tests.jar" } );
148     }
149 
150     private void assertContains( List collection, Object[] items )
151     {
152         for ( int i = 0; i < items.length; i++ )
153         {
154             assertContains( collection, items[i] );
155         }
156     }
157 
158     private void assertContains( List collection, Object item )
159     {
160         assertTrue( item + " missing in " + collection, collection.contains( item ) );
161     }
162 
163     private void assertNotContains( List collection, Object[] items )
164     {
165         for ( int i = 0; i < items.length; i++ )
166         {
167             assertNotContains( collection, items[i] );
168         }
169     }
170 
171     private void assertNotContains( List collection, Object item )
172     {
173         assertFalse( item + " present in " + collection, collection.contains( item ) );
174     }
175 
176 }