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  
27  /**
28   * This is a collection of test cases for <a href="https://issues.apache.org/jira/browse/MNG-6511">MNG-6511</a>,
29   * selecting and deselecting optional projects.
30   *
31   * @author Maarten Mulders
32   * @author Martin Kanters
33   */
34  public class MavenITmng6511OptionalProjectSelectionTest extends AbstractMavenIntegrationTestCase
35  {
36      private static final String RESOURCE_PATH = "/mng-6511-optional-project-selection";
37      private final File testDir;
38  
39      public MavenITmng6511OptionalProjectSelectionTest() throws IOException
40      {
41          super( "[4.0.0-alpha-1,)" );
42          testDir = ResourceExtractor.simpleExtractResources( getClass(), RESOURCE_PATH );
43      }
44  
45      public void testSelectExistingOptionalProfile() throws VerificationException
46      {
47          newVerifier( testDir.getAbsolutePath() ).executeGoal( "clean" );
48  
49          Verifier verifier = newVerifier( testDir.getAbsolutePath() );
50          verifier.setLogFileName( "log-select-existing.txt" );
51          verifier.addCliOption( "-pl ?existing-module" );
52          verifier.executeGoal( "validate" );
53          verifier.verifyErrorFreeLog();
54          verifier.assertFilePresent( "existing-module/target/touch.txt" ); // existing-module should have been built.
55      }
56  
57      public void testSelectExistingOptionalProfileByArtifactId() throws VerificationException
58      {
59          newVerifier( testDir.getAbsolutePath() ).executeGoal( "clean" );
60  
61          Verifier verifier = newVerifier( testDir.getAbsolutePath() );
62          verifier.setLogFileName( "log-select-existing-artifact-id.txt" );
63          verifier.addCliOption( "-pl ?:existing-module" );
64          verifier.executeGoal( "validate" );
65          verifier.verifyErrorFreeLog();
66          verifier.assertFilePresent( "existing-module/target/touch.txt" ); // existing-module should have been built.
67      }
68  
69      public void testSelectNonExistingOptionalProfile() throws VerificationException
70      {
71          newVerifier( testDir.getAbsolutePath() ).executeGoal( "clean" );
72  
73          Verifier verifier = newVerifier( testDir.getAbsolutePath() );
74          verifier.setLogFileName( "log-select-non-existing.txt" );
75          verifier.addCliOption( "-pl ?non-existing-module" );
76          verifier.executeGoal( "validate" );
77          verifier.verifyErrorFreeLog();
78          verifier.assertFilePresent( "existing-module/target/touch.txt" ); // existing-module should have been built.
79      }
80  
81      public void testDeselectExistingOptionalProfile() throws VerificationException
82      {
83          newVerifier( testDir.getAbsolutePath() ).executeGoal( "clean" );
84  
85          Verifier verifier = newVerifier( testDir.getAbsolutePath() );
86          verifier.setLogFileName( "log-deselect-existing.txt" );
87          verifier.addCliOption( "-pl !?existing-module" );
88          verifier.executeGoal( "validate" );
89          verifier.verifyErrorFreeLog();
90          verifier.assertFileNotPresent( "existing-module/target/touch.txt" ); // existing-module should not have been built.
91      }
92  
93      public void testDeselectNonExistingOptionalProfile() throws VerificationException
94      {
95          newVerifier( testDir.getAbsolutePath() ).executeGoal( "clean" );
96  
97          Verifier verifier = newVerifier( testDir.getAbsolutePath() );
98          verifier.setLogFileName( "log-deselect-non-existing.txt" );
99          verifier.addCliOption( "-pl !?non-existing-module" );
100         verifier.executeGoal( "validate" );
101         verifier.verifyErrorFreeLog();
102         verifier.assertFilePresent( "existing-module/target/touch.txt" ); // existing-module should have been built.
103     }
104 }