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