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.util.List;
26  import java.util.regex.Pattern;
27  
28  /**
29   * This is a test set for <a href="https://issues.apache.org/jira/browse/MNG-5608">MNG-5608</a>:
30   * Profile activation warning test when file specification contains <code>${project.basedir}</code>
31   * instead of <code>${basedir}</code>
32   */
33  public class MavenITmng5608ProfileActivationWarningTest
34      extends AbstractMavenIntegrationTestCase
35  {
36  
37      public MavenITmng5608ProfileActivationWarningTest()
38      {
39          super( "(3.2.1,)" );
40      }
41  
42      public void testitMNG5608()
43          throws Exception
44      {
45          File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-5608-profile-activation-warning" );
46  
47          Verifier verifier = newVerifier( testDir.getAbsolutePath() );
48          verifier.executeGoal( "validate" );
49          verifier.verifyErrorFreeLog();
50          verifier.resetStreams();
51  
52          // check expected profiles activated, just for sanity (or build should have failed, given other profiles)
53          assertFileExists( testDir, "target/exists-basedir" );
54          assertFileExists( testDir, "target/mng-5608-missing-project.basedir" );
55  
56          // check that the 2 profiles using ${project.basedir} caused warnings
57          List<String> logFile = verifier.loadFile( verifier.getBasedir(), verifier.getLogFileName(), false );
58          assertNotNull( findWarning( logFile, "mng-5608-exists-project.basedir" ) );
59          assertNotNull( findWarning( logFile, "mng-5608-missing-project.basedir" ) );
60      }
61  
62      private void assertFileExists( File dir, String filename )
63      {
64          File file = new File( dir, filename );
65          assertTrue( "expected file: " + file, file.exists() );
66      }
67  
68      private String findWarning( List<String> logLines, String profileId )
69      {
70          Pattern pattern = Pattern.compile(
71              "(?i).*Failed to interpolate file location ..project.basedir./pom.xml for profile " + profileId + ": .*" );
72  
73          for ( String logLine : logLines )
74          {
75              if ( pattern.matcher( logLine ).matches() )
76              {
77                  return logLine;
78              }
79          }
80  
81          return null;
82      }
83  
84  }