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.List;
26  
27  /**
28   * This is a test set for <a href="https://issues.apache.org/jira/browse/MNG-2720">MNG-2720</a>.
29   *
30   * This test will ensure that running the 'package' phase on a multimodule build with child
31   * interdependency will result in one child using the JAR of the other child in its compile
32   * classpath, NOT the target/classes directory. This is critical, since sibling projects might
33   * use literally ANY artifact produced by another module project, and limiting to target/classes
34   * and target/test-classes eliminates many of the options that would be possible if the dependent
35   * sibling were built on its own.
36   *
37   * @author jdcasey
38   *
39   */
40  public class MavenITmng2720SiblingClasspathArtifactsTest
41      extends AbstractMavenIntegrationTestCase
42  {
43  
44      public MavenITmng2720SiblingClasspathArtifactsTest()
45      {
46          super( "[2.1.0,)" );
47      }
48  
49      public void testIT()
50          throws Exception
51      {
52          File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-2720" );
53  
54          Verifier verifier = newVerifier( testDir.getAbsolutePath() );
55          verifier.setAutoclean( false );
56          verifier.deleteDirectory( "child2/target" );
57          verifier.deleteDirectory( "child3/target" );
58          verifier.executeGoal( "initialize" );
59          verifier.verifyErrorFreeLog();
60          verifier.resetStreams();
61  
62          List<String> classPath;
63  
64          classPath = verifier.loadLines( "child2/target/compile.txt", "UTF-8" );
65          assertMainJar( classPath );
66  
67          classPath = verifier.loadLines( "child2/target/runtime.txt", "UTF-8" );
68          assertMainJar( classPath );
69  
70          classPath = verifier.loadLines( "child2/target/test.txt", "UTF-8" );
71          assertMainJar( classPath );
72  
73          classPath = verifier.loadLines( "child3/target/compile.txt", "UTF-8" );
74          assertTestJar( classPath );
75  
76          classPath = verifier.loadLines( "child3/target/runtime.txt", "UTF-8" );
77          assertTestJar( classPath );
78  
79          classPath = verifier.loadLines( "child3/target/test.txt", "UTF-8" );
80          assertTestJar( classPath );
81      }
82  
83      private void assertMainJar( List<String> classPath )
84      {
85          assertTrue( classPath.toString(), classPath.contains( "main.jar" ) );
86          assertFalse( classPath.toString(), classPath.contains( "main" ) );
87          assertFalse( classPath.toString(), classPath.contains( "test.jar" ) );
88          assertFalse( classPath.toString(), classPath.contains( "test" ) );
89      }
90  
91      private void assertTestJar( List<String> classPath )
92      {
93          assertFalse( classPath.toString(), classPath.contains( "main.jar" ) );
94          assertFalse( classPath.toString(), classPath.contains( "main" ) );
95          assertTrue( classPath.toString(), classPath.contains( "test.jar" ) );
96          assertFalse( classPath.toString(), classPath.contains( "test" ) );
97      }
98  
99  }