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  
26  /**
27   * Test case adapted from MNG-2576
28   * @author Luuk van den Broek
29   */
30  public class MavenITmng5230MakeReactorWithExcludesTest
31      extends AbstractMavenIntegrationTestCase
32  {
33  
34      public MavenITmng5230MakeReactorWithExcludesTest()
35      {
36          super( "[3.2,)" );
37      }
38  
39       private void clean( Verifier verifier )
40          throws Exception
41      {
42          verifier.deleteDirectory( "target" );
43          verifier.deleteDirectory( "mod-a/target" );
44          verifier.deleteDirectory( "mod-b/target" );
45          verifier.deleteDirectory( "mod-c/target" );
46          verifier.deleteDirectory( "mod-d/target" );
47      }
48  
49      /**
50       * Verify that project list exclusion by itself is not built
51       *
52       * @throws Exception in case of failure
53       */
54      public void testitMakeWithExclude()
55          throws Exception
56      {
57          File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-5230-make-reactor-with-excludes" );
58  
59          Verifier verifier = newVerifier( testDir.getAbsolutePath(), true );
60          verifier.setMavenDebug( true );
61          verifier.setAutoclean( false );
62          clean( verifier );
63          verifier.addCliOption( "-pl" );
64          verifier.addCliOption( "!mod-b" );
65          verifier.setLogFileName( "log-only.txt" );
66          verifier.executeGoal( "validate" );
67          verifier.verifyErrorFreeLog();
68          verifier.resetStreams();
69  
70          verifier.assertFilePresent( "target/touch.txt" );
71          verifier.assertFilePresent( "mod-a/target/touch.txt" );
72          verifier.assertFileNotPresent( "mod-b/target/touch.txt" );
73          verifier.assertFilePresent( "mod-c/target/touch.txt" );
74          verifier.assertFilePresent( "mod-d/target/touch.txt" );
75      }
76  
77      /**
78       * Verify that that exclusion happens on upstream projects.
79       *
80       * @throws Exception in case of failure
81       */
82      public void testitMakeUpstreamExclude()
83          throws Exception
84      {
85          File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-5230-make-reactor-with-excludes" );
86  
87          Verifier verifier = newVerifier( testDir.getAbsolutePath() );
88          verifier.setAutoclean( false );
89          clean( verifier );
90          verifier.addCliOption( "-pl" );
91          verifier.addCliOption( "mod-b,!mod-a" );
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.assertFileNotPresent( "mod-a/target/touch.txt" );
100         verifier.assertFilePresent( "mod-b/target/touch.txt" );
101         verifier.assertFileNotPresent( "mod-c/target/touch.txt" );
102         verifier.assertFileNotPresent( "mod-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 testitMakeDownstreamExclude()
111         throws Exception
112     {
113         File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-5230-make-reactor-with-excludes" );
114 
115         Verifier verifier = newVerifier( testDir.getAbsolutePath() );
116         verifier.setAutoclean( false );
117         clean( verifier );
118         verifier.addCliOption( "-pl" );
119         verifier.addCliOption( "mod-b,!mod-c" );
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( "mod-a/target/touch.txt" );
128         verifier.assertFilePresent( "mod-b/target/touch.txt" );
129         verifier.assertFileNotPresent( "mod-c/target/touch.txt" );
130         verifier.assertFileNotPresent( "mod-d/target/touch.txt" );
131     }
132 
133     /**
134      * Verify  project exclusion when also building upstream and downstream projects are built.
135      *
136      * @throws Exception in case of failure
137      */
138     public void testitMakeBothExclude()
139         throws Exception
140     {
141         File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-5230-make-reactor-with-excludes" );
142 
143         Verifier verifier = newVerifier( testDir.getAbsolutePath() );
144         verifier.setAutoclean( false );
145         clean( verifier );
146         verifier.addCliOption( "-pl" );
147         verifier.addCliOption( "mod-b,!mod-a" );
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.assertFileNotPresent( "mod-a/target/touch.txt" );
157         verifier.assertFilePresent( "mod-b/target/touch.txt" );
158         verifier.assertFilePresent( "mod-c/target/touch.txt" );
159         verifier.assertFileNotPresent( "mod-d/target/touch.txt" );
160     }
161 
162     /**
163      * Verify that using the basedir for exclusion with an exclemation in the project list matches projects with non-default POM files.
164      *
165      * @throws Exception in case of failure
166      */
167     public void testitMatchesByBasedirExclamationExclude()
168         throws Exception
169     {
170         File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-5230-make-reactor-with-excludes" );
171 
172         Verifier verifier = newVerifier( testDir.getAbsolutePath() );
173         verifier.setAutoclean( false );
174         clean( verifier );
175         verifier.assertFileNotPresent( "mod-d/pom.xml" );
176         verifier.addCliOption( "-pl" );
177         verifier.addCliOption( "!mod-d" );
178         verifier.setLogFileName( "log-basedir-exclamation.txt" );
179         verifier.executeGoal( "validate" );
180         verifier.verifyErrorFreeLog();
181         verifier.resetStreams();
182 
183         verifier.assertFilePresent( "target/touch.txt" );
184         verifier.assertFilePresent( "mod-a/target/touch.txt" );
185         verifier.assertFilePresent( "mod-b/target/touch.txt" );
186         verifier.assertFilePresent( "mod-c/target/touch.txt" );
187         verifier.assertFileNotPresent( "mod-d/target/touch.txt" );
188     }
189 
190     /**
191      * Verify that using the basedir for exclusion with a minus in the project list matches projects with non-default POM files.
192      *
193      * @throws Exception in case of failure
194      */
195     public void testitMatchesByBasedirMinusExclude()
196         throws Exception
197     {
198         File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-5230-make-reactor-with-excludes" );
199 
200         Verifier verifier = newVerifier( testDir.getAbsolutePath() );
201         verifier.setAutoclean( false );
202         clean( verifier );
203         verifier.assertFileNotPresent( "mod-d/pom.xml" );
204         verifier.addCliOption( "-pl" );
205         verifier.addCliOption( "-mod-d" );
206         verifier.setLogFileName( "log-basedir-minus.txt" );
207         verifier.executeGoal( "validate" );
208         verifier.verifyErrorFreeLog();
209         verifier.resetStreams();
210 
211         verifier.assertFilePresent( "target/touch.txt" );
212         verifier.assertFilePresent( "mod-a/target/touch.txt" );
213         verifier.assertFilePresent( "mod-b/target/touch.txt" );
214         verifier.assertFilePresent( "mod-c/target/touch.txt" );
215         verifier.assertFileNotPresent( "mod-d/target/touch.txt" );
216     }
217 
218 
219     /**
220      * Verify that the project list can also specify project ids for exclusion
221      *
222      * @throws Exception in case of failure
223      */
224     public void testitMatchesByIdExclude()
225         throws Exception
226     {
227         File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-5230-make-reactor-with-excludes" );
228 
229         Verifier verifier = newVerifier( testDir.getAbsolutePath() );
230         verifier.setAutoclean( false );
231         clean( verifier );
232         verifier.addCliOption( "-pl" );
233         verifier.addCliOption( "!org.apache.maven.its.mng5230:mod-b" );
234         verifier.setLogFileName( "log-id.txt" );
235         verifier.executeGoal( "validate" );
236         verifier.verifyErrorFreeLog();
237         verifier.resetStreams();
238 
239         verifier.assertFilePresent( "target/touch.txt" );
240         verifier.assertFilePresent( "mod-a/target/touch.txt" );
241         verifier.assertFileNotPresent( "mod-b/target/touch.txt" );
242         verifier.assertFilePresent( "mod-c/target/touch.txt" );
243         verifier.assertFilePresent( "mod-d/target/touch.txt" );
244     }
245 
246     /**
247      * Verify that the project list exclude can also specify artifact ids.
248      *
249      * @throws Exception in case of failure
250      */
251     public void testitMatchesByArtifactIdExclude()
252         throws Exception
253     {
254         File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-5230-make-reactor-with-excludes" );
255 
256         Verifier verifier = newVerifier( testDir.getAbsolutePath() );
257         verifier.setAutoclean( false );
258         clean( verifier );
259         verifier.addCliOption( "-pl" );
260         verifier.addCliOption( "!:mod-b" );
261         verifier.setLogFileName( "log-artifact-id.txt" );
262         verifier.executeGoal( "validate" );
263         verifier.verifyErrorFreeLog();
264         verifier.resetStreams();
265 
266         verifier.assertFilePresent( "target/touch.txt" );
267         verifier.assertFilePresent( "mod-a/target/touch.txt" );
268         verifier.assertFileNotPresent( "mod-b/target/touch.txt" );
269         verifier.assertFilePresent( "mod-c/target/touch.txt" );
270         verifier.assertFilePresent( "mod-d/target/touch.txt" );
271     }
272 
273      /**
274      * Verify that reactor is resumed from specified project with exclude
275      *
276      * @throws Exception in case of failure
277      */
278     public void testitResumeFromExclude()
279         throws Exception
280     {
281         File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-5230-make-reactor-with-excludes" );
282 
283         Verifier verifier = newVerifier( testDir.getAbsolutePath() );
284         verifier.setAutoclean( false );
285         clean( verifier );
286         verifier.addCliOption( "-rf" );
287         verifier.addCliOption( "mod-b" );
288         verifier.addCliOption( "-pl" );
289         verifier.addCliOption( "!mod-c" );
290         verifier.setLogFileName( "log-resume.txt" );
291         verifier.executeGoal( "validate" );
292         verifier.verifyErrorFreeLog();
293         verifier.resetStreams();
294 
295         verifier.assertFileNotPresent( "target/touch.txt" );
296         verifier.assertFileNotPresent( "mod-a/target/touch.txt" );
297         verifier.assertFilePresent( "mod-b/target/touch.txt" );
298         verifier.assertFileNotPresent( "mod-c/target/touch.txt" );
299         verifier.assertFilePresent( "mod-d/target/touch.txt" );
300     }
301 }