View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *  http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  
20  package org.apache.maven.it;
21  
22  import org.apache.maven.it.util.ResourceExtractor;
23  
24  import java.io.File;
25  import java.util.Iterator;
26  import java.util.List;
27  
28  /**
29   * This is a test set for <a href="http://jira.codehaus.org/browse/MNG-2720">MNG-2720</a>.
30   * 
31   * This test will ensure that running the 'package' phase on a multimodule build with child
32   * interdependency will result in one child using the JAR of the other child in its compile
33   * classpath, NOT the target/classes directory. This is critical, since sibling projects might
34   * use literally ANY artifact produced by another module project, and limiting to target/classes
35   * and target/test-classes eliminates many of the options that would be possible if the dependent
36   * sibling were built on its own.
37   *
38   * @author jdcasey
39   * 
40   */
41  public class MavenITmng2720SiblingClasspathArtifactsTest
42      extends AbstractMavenIntegrationTestCase
43  {
44  
45      public MavenITmng2720SiblingClasspathArtifactsTest()
46      {
47          super( "[2.1.0,)" );
48      }
49  
50      public void testIT()
51          throws Exception
52      {
53          File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-2720" );
54  
55          Verifier verifier = newVerifier( testDir.getAbsolutePath() );
56          verifier.setAutoclean( false );
57          verifier.deleteDirectory( "child2/target" );
58          verifier.deleteDirectory( "child3/target" );
59          verifier.executeGoal( "initialize" );
60          verifier.verifyErrorFreeLog();
61          verifier.resetStreams();
62          
63          List classPath;
64  
65          classPath = verifier.loadLines( "child2/target/compile.txt", "UTF-8" );
66          assertMainJar( classPath );
67  
68          classPath = verifier.loadLines( "child2/target/runtime.txt", "UTF-8" );
69          assertMainJar( classPath );
70  
71          classPath = verifier.loadLines( "child2/target/test.txt", "UTF-8" );
72          assertMainJar( classPath );
73          
74          classPath = verifier.loadLines( "child3/target/compile.txt", "UTF-8" );
75          assertTestJar( classPath );
76  
77          classPath = verifier.loadLines( "child3/target/runtime.txt", "UTF-8" );
78          assertTestJar( classPath );
79  
80          classPath = verifier.loadLines( "child3/target/test.txt", "UTF-8" );
81          assertTestJar( classPath );
82      }
83  
84      private void assertMainJar( List classPath )
85      {
86          assertTrue( classPath.toString(), classPath.contains( "main.jar" ) );
87          assertFalse( classPath.toString(), classPath.contains( "main" ) );
88          assertFalse( classPath.toString(), classPath.contains( "test.jar" ) );
89          assertFalse( classPath.toString(), classPath.contains( "test" ) );
90      }
91  
92      private void assertTestJar( List classPath )
93      {
94          assertFalse( classPath.toString(), classPath.contains( "main.jar" ) );
95          assertFalse( classPath.toString(), classPath.contains( "main" ) );
96          assertTrue( classPath.toString(), classPath.contains( "test.jar" ) );
97          assertFalse( classPath.toString(), classPath.contains( "test" ) );
98      }
99  
100 }