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  
24  import org.apache.maven.it.util.ResourceExtractor;
25  
26  /**
27   * This is a test set for <a href="https://issues.apache.org/jira/browse/MNG-2576">MNG-2576</a>.
28   *
29   * @author Benjamin Bentmann
30   */
31  public class MavenITmng2576MakeLikeReactorTest
32      extends AbstractMavenIntegrationTestCase
33  {
34  
35      public MavenITmng2576MakeLikeReactorTest()
36      {
37          super( "[2.1.0,)" );
38      }
39  
40      private void clean( Verifier verifier )
41          throws Exception
42      {
43          verifier.deleteDirectory( "target" );
44          verifier.deleteDirectory( "sub-a/target" );
45          verifier.deleteDirectory( "sub-b/target" );
46          verifier.deleteDirectory( "sub-c/target" );
47          verifier.deleteDirectory( "sub-d/target" );
48      }
49  
50      /**
51       * Verify that project list by itself only builds specified projects.
52       *
53       * @throws Exception in case of failure
54       */
55      public void testitMakeOnlyList()
56          throws Exception
57      {
58          File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-2576" );
59  
60          Verifier verifier = newVerifier( testDir.getAbsolutePath() );
61          verifier.setAutoclean( false );
62          clean( verifier );
63          verifier.addCliOption( "-pl" );
64          verifier.addCliOption( "sub-b" );
65          verifier.setLogFileName( "log-only.txt" );
66          verifier.executeGoal( "validate" );
67          verifier.verifyErrorFreeLog();
68          verifier.resetStreams();
69  
70          verifier.assertFileNotPresent( "target/touch.txt" );
71          verifier.assertFileNotPresent( "sub-a/target/touch.txt" );
72          verifier.assertFilePresent( "sub-b/target/touch.txt" );
73          verifier.assertFileNotPresent( "sub-c/target/touch.txt" );
74          verifier.assertFileNotPresent( "sub-d/target/touch.txt" );
75      }
76  
77      /**
78       * Verify that project list and all their upstream projects are built.
79       *
80       * @throws Exception in case of failure
81       */
82      public void testitMakeUpstream()
83          throws Exception
84      {
85          File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-2576" );
86  
87          Verifier verifier = newVerifier( testDir.getAbsolutePath() );
88          verifier.setAutoclean( false );
89          clean( verifier );
90          verifier.addCliOption( "-pl" );
91          verifier.addCliOption( "sub-b" );
92          verifier.addCliOption( "-am" );
93          verifier.setLogFileName( "log-upstream.txt" );
94          verifier.executeGoal( "validate" );
95          verifier.verifyErrorFreeLog();
96          verifier.resetStreams();
97  
98          verifier.assertFilePresent( "target/touch.txt" );
99          verifier.assertFilePresent( "sub-a/target/touch.txt" );
100         verifier.assertFilePresent( "sub-b/target/touch.txt" );
101         verifier.assertFileNotPresent( "sub-c/target/touch.txt" );
102         verifier.assertFileNotPresent( "sub-d/target/touch.txt" );
103     }
104 
105     /**
106      * Verify that project list and all their downstream projects are built.
107      *
108      * @throws Exception in case of failure
109      */
110     public void testitMakeDownstream()
111         throws Exception
112     {
113         File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-2576" );
114 
115         Verifier verifier = newVerifier( testDir.getAbsolutePath() );
116         verifier.setAutoclean( false );
117         clean( verifier );
118         verifier.addCliOption( "-pl" );
119         verifier.addCliOption( "sub-b" );
120         verifier.addCliOption( "-amd" );
121         verifier.setLogFileName( "log-downstream.txt" );
122         verifier.executeGoal( "validate" );
123         verifier.verifyErrorFreeLog();
124         verifier.resetStreams();
125 
126         verifier.assertFileNotPresent( "target/touch.txt" );
127         verifier.assertFileNotPresent( "sub-a/target/touch.txt" );
128         verifier.assertFilePresent( "sub-b/target/touch.txt" );
129         verifier.assertFilePresent( "sub-c/target/touch.txt" );
130         verifier.assertFileNotPresent( "sub-d/target/touch.txt" );
131     }
132 
133     /**
134      * Verify that project list and all their upstream and downstream projects are built.
135      *
136      * @throws Exception in case of failure
137      */
138     public void testitMakeBoth()
139         throws Exception
140     {
141         File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-2576" );
142 
143         Verifier verifier = newVerifier( testDir.getAbsolutePath() );
144         verifier.setAutoclean( false );
145         clean( verifier );
146         verifier.addCliOption( "-pl" );
147         verifier.addCliOption( "sub-b" );
148         verifier.addCliOption( "-am" );
149         verifier.addCliOption( "-amd" );
150         verifier.setLogFileName( "log-both.txt" );
151         verifier.executeGoal( "validate" );
152         verifier.verifyErrorFreeLog();
153         verifier.resetStreams();
154 
155         verifier.assertFilePresent( "target/touch.txt" );
156         verifier.assertFilePresent( "sub-a/target/touch.txt" );
157         verifier.assertFilePresent( "sub-b/target/touch.txt" );
158         verifier.assertFilePresent( "sub-c/target/touch.txt" );
159         verifier.assertFileNotPresent( "sub-d/target/touch.txt" );
160     }
161 
162     /**
163      * Verify that using the mere basedir in the project list properly matches projects with non-default POM files.
164      *
165      * @throws Exception in case of failure
166      */
167     public void testitMatchesByBasedir()
168         throws Exception
169     {
170         File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-2576" );
171 
172         Verifier verifier = newVerifier( testDir.getAbsolutePath() );
173         verifier.setAutoclean( false );
174         clean( verifier );
175         verifier.assertFileNotPresent( "sub-d/pom.xml" );
176         verifier.addCliOption( "-pl" );
177         verifier.addCliOption( "sub-d" );
178         verifier.setLogFileName( "log-basedir.txt" );
179         verifier.executeGoal( "validate" );
180         verifier.verifyErrorFreeLog();
181         verifier.resetStreams();
182 
183         verifier.assertFileNotPresent( "target/touch.txt" );
184         verifier.assertFileNotPresent( "sub-a/target/touch.txt" );
185         verifier.assertFileNotPresent( "sub-b/target/touch.txt" );
186         verifier.assertFileNotPresent( "sub-c/target/touch.txt" );
187         verifier.assertFilePresent( "sub-d/target/touch.txt" );
188     }
189 
190     /**
191      * Verify that using the mere basedir in the project list properly matches projects with non-default POM files.
192      *
193      * @throws Exception in case of failure
194      */
195     public void testitMatchesByBasedirPlus()
196         throws Exception
197     {
198         // as per MNG-5230
199         requiresMavenVersion( "[3.2,)" );
200 
201         File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-2576" );
202 
203         Verifier verifier = newVerifier( testDir.getAbsolutePath() );
204         verifier.setAutoclean( false );
205         clean( verifier );
206         verifier.assertFileNotPresent( "sub-d/pom.xml" );
207         verifier.addCliOption( "-pl" );
208         verifier.addCliOption( "+sub-d" );
209         verifier.setLogFileName( "log-basedir-plus.txt" );
210         verifier.executeGoal( "validate" );
211         verifier.verifyErrorFreeLog();
212         verifier.resetStreams();
213 
214         verifier.assertFileNotPresent( "target/touch.txt" );
215         verifier.assertFileNotPresent( "sub-a/target/touch.txt" );
216         verifier.assertFileNotPresent( "sub-b/target/touch.txt" );
217         verifier.assertFileNotPresent( "sub-c/target/touch.txt" );
218         verifier.assertFilePresent( "sub-d/target/touch.txt" );
219     }
220     /**
221      * Verify that the project list can also specify project ids.
222      *
223      * @throws Exception in case of failure
224      */
225     public void testitMatchesById()
226         throws Exception
227     {
228         File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-2576" );
229 
230         Verifier verifier = newVerifier( testDir.getAbsolutePath() );
231         verifier.setAutoclean( false );
232         clean( verifier );
233         verifier.addCliOption( "-pl" );
234         verifier.addCliOption( "org.apache.maven.its.mng2576:sub-b" );
235         verifier.setLogFileName( "log-id.txt" );
236         verifier.executeGoal( "validate" );
237         verifier.verifyErrorFreeLog();
238         verifier.resetStreams();
239 
240         verifier.assertFileNotPresent( "target/touch.txt" );
241         verifier.assertFileNotPresent( "sub-a/target/touch.txt" );
242         verifier.assertFilePresent( "sub-b/target/touch.txt" );
243         verifier.assertFileNotPresent( "sub-c/target/touch.txt" );
244         verifier.assertFileNotPresent( "sub-d/target/touch.txt" );
245     }
246 
247     /**
248      * Verify that the project list can also specify artifact ids.
249      *
250      * @throws Exception in case of failure
251      */
252     public void testitMatchesByArtifactId()
253         throws Exception
254     {
255         // as per MNG-4244
256         requiresMavenVersion( "[3.0-alpha-3,)" );
257 
258         File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-2576" );
259 
260         Verifier verifier = newVerifier( testDir.getAbsolutePath() );
261         verifier.setAutoclean( false );
262         clean( verifier );
263         verifier.addCliOption( "-pl" );
264         verifier.addCliOption( ":sub-b" );
265         verifier.setLogFileName( "log-artifact-id.txt" );
266         verifier.executeGoal( "validate" );
267         verifier.verifyErrorFreeLog();
268         verifier.resetStreams();
269 
270         verifier.assertFileNotPresent( "target/touch.txt" );
271         verifier.assertFileNotPresent( "sub-a/target/touch.txt" );
272         verifier.assertFilePresent( "sub-b/target/touch.txt" );
273         verifier.assertFileNotPresent( "sub-c/target/touch.txt" );
274         verifier.assertFileNotPresent( "sub-d/target/touch.txt" );
275     }
276 
277     /**
278      * Verify that reactor is resumed from specified project.
279      *
280      * @throws Exception in case of failure
281      */
282     public void testitResumeFrom()
283         throws Exception
284     {
285         File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-2576" );
286 
287         Verifier verifier = newVerifier( testDir.getAbsolutePath() );
288         verifier.setAutoclean( false );
289         clean( verifier );
290         verifier.addCliOption( "-rf" );
291         verifier.addCliOption( "sub-b" );
292         verifier.setLogFileName( "log-resume.txt" );
293         verifier.executeGoal( "validate" );
294         verifier.verifyErrorFreeLog();
295         verifier.resetStreams();
296 
297         verifier.assertFileNotPresent( "target/touch.txt" );
298         verifier.assertFileNotPresent( "sub-a/target/touch.txt" );
299         verifier.assertFilePresent( "sub-b/target/touch.txt" );
300         verifier.assertFilePresent( "sub-c/target/touch.txt" );
301     }
302 
303 }