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.util.ResourceExtractor;
23  
24  import java.io.File;
25  import java.io.IOException;
26  import java.util.HashMap;
27  import java.util.Map;
28  
29  /**
30   * This is a collection of test cases for <a href="https://issues.apache.org/jira/browse/MNG-6118">MNG-6118</a>,
31   * invoking Maven in a submodule of a multi-module project.
32   *
33   * The test uses a multi-module project with two modules:
34   * <ul>
35   *     <li>app (depends on lib)</li>
36   *     <li>lib</li>
37   * </ul>
38   *
39   * @author Maarten Mulders
40   * @author Martin Kanters
41   */
42  public class MavenITmng6118SubmoduleInvocation extends AbstractMavenIntegrationTestCase
43  {
44      private static final String RESOURCE_PATH = "/mng-6118-submodule-invocation-full-reactor";
45      private final File testDir;
46      private final Map<String, String> envVars = new HashMap<>();
47  
48      public MavenITmng6118SubmoduleInvocation() throws IOException
49      {
50          super( "[4.0.0-alpha-1,)" );
51          testDir = ResourceExtractor.simpleExtractResources( getClass(), RESOURCE_PATH );
52      }
53  
54      /**
55       * Performs a {@code cd app && mvn compile} invocation. Verifies that inter-module dependencies are resolved.
56       *
57       * @throws Exception in case of failure
58       */
59      public void testInSubModule() throws Exception
60      {
61          // Compile the whole project first.
62          Verifier verifier = newVerifier( testDir.getAbsolutePath() );
63          verifier.executeGoal( "compile", envVars );
64  
65          final File submoduleDirectory = new File( testDir, "app" );
66          verifier = newVerifier( submoduleDirectory.getAbsolutePath() );
67          verifier.setAutoclean( false );
68          verifier.setLogFileName( "log-insubmodule.txt" );
69          verifier.executeGoal( "compile", envVars );
70      }
71  
72      /**
73       * Performs a {@code mvn -f app/pom.xml compile} invocation. Verifies that inter-module dependencies are resolved.
74       *
75       * @throws Exception in case of failure
76       */
77      public void testWithFile() throws Exception
78      {
79          // Compile the whole project first.
80          Verifier verifier = newVerifier( testDir.getAbsolutePath() );
81          verifier.executeGoal( "compile" );
82  
83          verifier = newVerifier( testDir.getAbsolutePath() );
84          verifier.setAutoclean( false );
85          verifier.setLogFileName( "log-withfile.txt" );
86          verifier.addCliOption( "-f app/pom.xml" );
87          verifier.executeGoal( "compile", envVars );
88      }
89  
90      /**
91       * Performs a {@code mvn -f app/pom.xml -am compile} invocation. Verifies that dependent modules are also built.
92       *
93       * @throws Exception in case of failure
94       */
95      public void testWithFileAndAlsoMake() throws Exception
96      {
97          Verifier verifier = newVerifier( testDir.getAbsolutePath() );
98          verifier.addCliOption( "-am" );
99          verifier.addCliOption( "-f app/pom.xml" );
100         verifier.setLogFileName( "log-withfilealsomake.txt" );
101         verifier.executeGoal( "compile", envVars );
102         verifier.verifyTextInLog( "Building Maven Integration Test :: MNG-6118 :: Library 1.0" );
103     }
104 
105     /**
106      * Performs a {@code cd app && mvn compile -am} invocation. Verifies that dependent modules are also built.
107      *
108      * @throws Exception in case of failure
109      */
110     public void testInSubModuleWithAlsoMake() throws Exception
111     {
112         File submoduleDirectory = new File( testDir, "app" );
113         Verifier verifier = newVerifier( submoduleDirectory.getAbsolutePath() );
114         verifier.addCliOption( "-am" );
115         verifier.setLogFileName( "log-insubmodulealsomake.txt" );
116         verifier.executeGoal( "compile", envVars );
117         verifier.verifyTextInLog( "Building Maven Integration Test :: MNG-6118 :: Library 1.0" );
118     }
119 }