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  import java.util.List;
24  import java.util.regex.Pattern;
25  
26  import org.apache.maven.it.util.ResourceExtractor;
27  
28  /**
29   * This is a test set for <a href="https://issues.apache.org/jira/browse/MNG-3641">MNG-3641</a>:
30   * Profile activation warning test
31   */
32  public class MavenITmng3641ProfileActivationWarningTest
33      extends AbstractMavenIntegrationTestCase
34  {
35  
36      public MavenITmng3641ProfileActivationWarningTest()
37      {
38          super( "[2.0.11,2.1.0-M1),[2.1.0,4.0.0-alpha-1)" ); // only test in 2.0.11+, 2.1.0+
39      }
40  
41      public void testitMNG3641()
42          throws Exception
43      {
44          // (0) Initialize.
45          File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-3641" );
46  
47          Verifier verifier = newVerifier( testDir.getAbsolutePath() );
48          verifier.setAutoclean( false );
49  
50          // Delete this artifact. Just in case.
51          verifier.deleteArtifact( "org.apache.maven.its.mng3641", "parent", "1.0", "pom" );
52  
53          // (1) make sure the profile is found. Must not contain a warning.
54          verifier.addCliOption( "-P mng-3641-it-provided-profile" );
55          verifier.setLogFileName( "log-1.txt" );
56          verifier.executeGoal( "validate" );
57          verifier.verifyErrorFreeLog();
58          verifier.resetStreams();
59  
60          List<String> logFile = verifier.loadFile( verifier.getBasedir(), verifier.getLogFileName(), false );
61          assertNull( findWarning( logFile, "mng-3641-it-provided-profile" ) );
62  
63          // (2) make sure the profile was not found and a warning was printed.
64          verifier = newVerifier( testDir.getAbsolutePath() );
65          verifier.addCliOption( "-P mng-3641-TWlzdGVyIFQgd2FzIGhlcmUuICheX14p" );
66          verifier.setLogFileName( "log-2.txt" );
67          verifier.executeGoal( "validate" );
68          verifier.verifyErrorFreeLog();
69          verifier.resetStreams();
70  
71          logFile = verifier.loadFile( verifier.getBasedir(), verifier.getLogFileName(), false );
72          assertNotNull( findWarning( logFile, "mng-3641-TWlzdGVyIFQgd2FzIGhlcmUuICheX14p" ) );
73  
74          // (3) make sure the first profile is found while the other is not and a warning was printed
75          // accordingly.
76          verifier = newVerifier( testDir.getAbsolutePath() );
77          verifier.addCliOption( "-P mng-3641-it-provided-profile,mng-3641-TWlzdGVyIFQgd2FzIGhlcmUuICheX14p" );
78          verifier.setLogFileName( "log-3.txt" );
79          verifier.executeGoal( "validate" );
80          verifier.verifyErrorFreeLog();
81          verifier.resetStreams();
82  
83          logFile = verifier.loadFile( verifier.getBasedir(), verifier.getLogFileName(), false );
84          assertNull( findWarning( logFile, "mng-3641-it-provided-profile" ) );
85          assertNotNull( findWarning( logFile, "mng-3641-TWlzdGVyIFQgd2FzIGhlcmUuICheX14p" ) );
86  
87          // (4) make sure the warning is only printed when the profile is missing in all projects
88          verifier = newVerifier( testDir.getAbsolutePath() );
89          verifier.addCliOption( "-P mng-3641-it-provided-profile-child" );
90          verifier.setLogFileName( "log-4.txt" );
91          verifier.executeGoal( "validate" );
92          verifier.verifyErrorFreeLog();
93          verifier.resetStreams();
94  
95          logFile = verifier.loadFile( verifier.getBasedir(), verifier.getLogFileName(), false );
96          assertNull( findWarning( logFile, "mng-3641-it-provided-profile-child" ) );
97  
98          // (5) make sure the profile is found in subproject. Must not contain a warning.
99          verifier = newVerifier( new File( testDir, "child1" ).getAbsolutePath() );
100         verifier.addCliOption( "-P mng-3641-it-provided-profile-child" );
101         verifier.setLogFileName( "log-5.txt" );
102         verifier.executeGoal( "validate" );
103         verifier.verifyErrorFreeLog();
104         verifier.resetStreams();
105 
106         logFile = verifier.loadFile( verifier.getBasedir(), verifier.getLogFileName(), false );
107         assertNull( findWarning( logFile, "mng-3641-it-provided-profile-child" ) );
108 
109         // (6) make sure the profile is found from parent in subproject. Must not contain a warning.
110         verifier = newVerifier( new File( testDir, "child1" ).getAbsolutePath() );
111         verifier.addCliOption( "-P mng-3641-it-provided-profile" );
112         verifier.setLogFileName( "log-6.txt" );
113         verifier.executeGoal( "validate" );
114         verifier.verifyErrorFreeLog();
115         verifier.resetStreams();
116 
117         logFile = verifier.loadFile( verifier.getBasedir(), verifier.getLogFileName(), false );
118         assertNull( findWarning( logFile, "mng-3641-it-provided-profile" ) );
119     }
120 
121     private String findWarning( List<String> logLines, String profileId )
122     {
123         Pattern pattern = Pattern.compile( "(?i).*profile\\s.*\\Q" + profileId + "\\E.*\\snot\\s.*activated.*" );
124 
125         for ( String logLine : logLines )
126         {
127             if ( pattern.matcher( logLine ).matches() )
128             {
129                 return logLine;
130             }
131         }
132 
133         return null;
134     }
135 
136 }