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.Collections;
24  import java.util.Properties;
25  
26  import org.apache.maven.it.util.ResourceExtractor;
27  import org.apache.maven.shared.utils.Os;
28  
29  /**
30   * This is a test set for <a href="https://issues.apache.org/jira/browse/MNG-3933">MNG-3933</a>.
31   *
32   * @author Benjamin Bentmann
33   *
34   */
35  public class MavenITmng3933ProfilesXmlActivationTest
36      extends AbstractMavenIntegrationTestCase
37  {
38  
39      public MavenITmng3933ProfilesXmlActivationTest()
40      {
41          // support for profiles.xml removed from 3.x (see MNG-4060)
42          super( "[2.0,3.0-alpha-1)" );
43      }
44  
45      /**
46       * Test that profiles from an external profiles.xml are properly activated. This is really a different story
47       * than profiles in the settings.xml or the POM.
48       *
49       * @throws Exception in case of failure
50       */
51      public void testitMNG3933()
52          throws Exception
53      {
54          File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-3933" );
55  
56          Verifier verifier = newVerifier( testDir.getAbsolutePath() );
57          verifier.setAutoclean( false );
58          verifier.deleteDirectory( "target" );
59          verifier.getSystemProperties().setProperty( "maven.profile.activator", "test" );
60          verifier.executeGoal( "validate", Collections.singletonMap( "MAVEN_PROFILE", "test" ) );
61          verifier.verifyErrorFreeLog();
62          verifier.resetStreams();
63  
64          Properties props = verifier.loadProperties( "target/profile.properties" );
65  
66          assertEquals( "DEFAULT-ACTIVATION", props.getProperty( "project.properties.defaultProperty" ) );
67  
68          assertEquals( "SYS-PROP-ACTIVATION", props.getProperty( "project.properties.sysProperty" ) );
69  
70          if ( matchesVersionRange( "(2.0.8,)" ) )
71          {
72              // MNG-2848
73              assertEquals( "ENV-PROP-ACTIVATION", props.getProperty( "project.properties.envProperty" ) );
74          }
75  
76          assertEquals( "MISSING-FILE-ACTIVATION", props.getProperty( "project.properties.fileProperty" ) );
77  
78          assertEquals( "JDK-ACTIVATION", props.getProperty( "project.properties.jdkProperty" ) );
79  
80          if ( matchesVersionRange( "(2.0.10,2.1.0-M1),(2.1.0-M1,)" ) )
81          {
82              // MNG-3933
83              if ( Os.isFamily( Os.FAMILY_WINDOWS ) || Os.isFamily( Os.FAMILY_MAC ) || Os.isFamily( Os.FAMILY_UNIX ) )
84              {
85                  assertEquals( "OS-FAMILY-ACTIVATION", props.getProperty( "project.properties.osFamilyProperty" ) );
86              }
87              else
88              {
89                  System.out.println();
90                  System.out.println( "[WARNING] Skipping OS activation test on unrecognized OS: " + Os.OS_NAME );
91                  System.out.println();
92              }
93          }
94  
95          assertNull( props.getProperty( "project.properties.sysPropertyMissing" ) );
96          assertNull( props.getProperty( "project.properties.envPropertyMissing" ) );
97          assertNull( props.getProperty( "project.properties.filePropertyMissing" ) );
98      }
99  
100 }