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-3545">MNG-3545</a>:
28   * it tests activation and deactivation of profiles.
29   *
30   */
31  public class MavenITmng3545ProfileDeactivationTest
32      extends AbstractMavenIntegrationTestCase
33  {
34  
35      public MavenITmng3545ProfileDeactivationTest()
36      {
37          super( "(2.0.9,)" );
38      }
39  
40      /**
41       * Test build with two active by default profiles
42       *
43       * @throws Exception in case of failure
44       */
45      public void testBasicBuildWithDefaultProfiles()
46          throws Exception
47      {
48          File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-3545" );
49  
50          Verifier verifier = newVerifier( testDir.getAbsolutePath() );
51          verifier.setAutoclean( false );
52          verifier.deleteDirectory( "target" );
53          verifier.setLogFileName( "log1.txt" );
54  
55          verifier.executeGoal( "validate" );
56  
57          verifier.verifyErrorFreeLog();
58          // profile 1 and 2 are active by default
59          verifier.assertFilePresent( "target/profile1/touch.txt" );
60          verifier.assertFilePresent( "target/profile2/touch.txt" );
61          verifier.assertFileNotPresent( "target/profile3/touch.txt" );
62          verifier.assertFileNotPresent( "target/profile4/touch.txt" );
63          verifier.assertFileNotPresent( "target/profile5/touch.txt" );
64          verifier.resetStreams();
65      }
66  
67      /**
68       * Test command line deactivation of active by default profiles.
69       *
70       * @throws Exception in case of failure
71       */
72      public void testDeactivateDefaultProfilesHyphen()
73          throws Exception
74      {
75          File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-3545" );
76  
77          Verifier verifier = newVerifier( testDir.getAbsolutePath() );
78          verifier.setAutoclean( false );
79          verifier.deleteDirectory( "target" );
80          verifier.setLogFileName( "log2.txt" );
81  
82          // Deactivate active by default profiles
83          verifier.addCliOption( "-P-profile1" );
84          verifier.addCliOption( "-P -profile2" );
85  
86          verifier.executeGoal( "validate" );
87  
88          verifier.verifyErrorFreeLog();
89          verifier.assertFileNotPresent( "target/profile1/touch.txt" );
90          verifier.assertFileNotPresent( "target/profile2/touch.txt" );
91          verifier.resetStreams();
92      }
93  
94      public void testDeactivateDefaultProfilesExclamation()
95          throws Exception
96      {
97          File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-3545" );
98  
99          Verifier verifier = newVerifier( testDir.getAbsolutePath() );
100         verifier.setAutoclean( false );
101         verifier.deleteDirectory( "target" );
102         verifier.setLogFileName( "log3.txt" );
103 
104         // Deactivate active by default profiles
105         verifier.addCliOption( "-P!profile1" );
106         verifier.addCliOption( "-P !profile2" );
107 
108         verifier.executeGoal( "validate" );
109 
110         verifier.verifyErrorFreeLog();
111         verifier.assertFileNotPresent( "target/profile1/touch.txt" );
112         verifier.assertFileNotPresent( "target/profile2/touch.txt" );
113         verifier.resetStreams();
114     }
115 
116     /**
117      * Test command line deactivation of a profile that was activated
118      * by a property
119      *
120      * @throws Exception in case of failure
121      */
122     public void testDeactivateActivatedByProp()
123         throws Exception
124     {
125         File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-3545" );
126 
127         Verifier verifier = newVerifier( testDir.getAbsolutePath() );
128         verifier.setAutoclean( false );
129         verifier.deleteDirectory( "target" );
130         verifier.setLogFileName( "log4.txt" );
131 
132         // Activate with a prop, then deactivate
133         verifier.addCliOption( "-Dprofile3-active-by-property=true" );
134         verifier.addCliOption( "-P-profile3" );
135 
136         verifier.executeGoal( "validate" );
137 
138         verifier.verifyErrorFreeLog();
139         verifier.assertFilePresent( "target/profile1/touch.txt" );
140         verifier.assertFilePresent( "target/profile2/touch.txt" );
141         verifier.assertFileNotPresent( "target/profile3/touch.txt" );
142         verifier.assertFileNotPresent( "target/profile4/touch.txt" );
143         verifier.assertFileNotPresent( "target/profile5/touch.txt" );
144         verifier.resetStreams();
145     }
146 
147     /**
148      * Test that deactivating from the command line takes priority over
149      * activating from the command line.
150      *
151      * @throws Exception in case of failure
152      */
153     public void testActivateThenDeactivate()
154         throws Exception
155     {
156         File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-3545" );
157 
158         Verifier verifier = newVerifier( testDir.getAbsolutePath() );
159         verifier.setAutoclean( false );
160         verifier.deleteDirectory( "target" );
161         verifier.setLogFileName( "log5.txt" );
162 
163         // Activate then deactivate
164         verifier.addCliOption( "-Pprofile4" );
165         verifier.addCliOption( "-P-profile4" );
166 
167         verifier.executeGoal( "validate" );
168 
169         verifier.verifyErrorFreeLog();
170         verifier.assertFilePresent( "target/profile1/touch.txt" );
171         verifier.assertFilePresent( "target/profile2/touch.txt" );
172         verifier.assertFileNotPresent( "target/profile3/touch.txt" );
173         verifier.assertFileNotPresent( "target/profile4/touch.txt" );
174         verifier.assertFileNotPresent( "target/profile5/touch.txt" );
175         verifier.resetStreams();
176     }
177 
178     /**
179      * Test that default profiles are deactivated when another profile is
180      * activated.
181      *
182      * @throws Exception in case of failure
183      */
184     public void testDefaultProfileAutoDeactivation()
185         throws Exception
186     {
187         File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-3545" );
188 
189         Verifier verifier = newVerifier( testDir.getAbsolutePath() );
190         verifier.setAutoclean( false );
191         verifier.deleteDirectory( "target" );
192         verifier.setLogFileName( "log6.txt" );
193 
194         // Activate
195         verifier.addCliOption( "-Pprofile4" );
196 
197         verifier.executeGoal( "validate" );
198 
199         verifier.verifyErrorFreeLog();
200         verifier.assertFileNotPresent( "target/profile1/touch.txt" );
201         verifier.assertFileNotPresent( "target/profile2/touch.txt" );
202         verifier.assertFileNotPresent( "target/profile3/touch.txt" );
203         verifier.assertFilePresent( "target/profile4/touch.txt" );
204         verifier.assertFileNotPresent( "target/profile5/touch.txt" );
205         verifier.resetStreams();
206     }
207 
208 }