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  import org.apache.maven.shared.utils.Os;
24  
25  import java.io.File;
26  import java.util.HashMap;
27  import java.util.Map;
28  import java.util.Properties;
29  
30  /**
31   * This is a test set for <a href="https://issues.apache.org/jira/browse/MNG-3940">MNG-3940</a>.
32   *
33   * @author Benjamin Bentmann
34   *
35   */
36  public class MavenITmng3940EnvVarInterpolationTest
37      extends AbstractMavenIntegrationTestCase
38  {
39  
40      public MavenITmng3940EnvVarInterpolationTest()
41      {
42          super( "(2.0.10,2.1.0-M1),(2.1.0-M1,)" );
43      }
44  
45      /**
46       * Test that interpolation of environment variables respects the casing rules of the underlying OS (especially
47       * Windows).
48       *
49       * @throws Exception in case of failure
50       */
51      public void testitMNG3940()
52          throws Exception
53      {
54          File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-3940" );
55  
56          Map<String, String> envVars = new HashMap<>();
57          /*
58           * NOTE: The POM is using MAVEN_MNG_3940 to reference the var (just as one would refer to PATH). On Windows,
59           * this must resolve case-insensitively so we use different character casing for the variable here.
60           */
61          if ( Os.isFamily( Os.FAMILY_WINDOWS ) )
62          {
63              envVars.put( "Maven_mng_3940", "PASSED" );
64          }
65          else
66          {
67              envVars.put( "MAVEN_MNG_3940", "PASSED" );
68          }
69  
70          Verifier verifier = newVerifier( testDir.getAbsolutePath() );
71          verifier.setAutoclean( false );
72          verifier.deleteDirectory( "target" );
73          verifier.executeGoal( "validate", envVars );
74          verifier.verifyErrorFreeLog();
75          verifier.resetStreams();
76  
77          verifier.assertFilePresent( "target/PASSED.properties" );
78          Properties props = verifier.loadProperties( "target/PASSED.properties" );
79          assertEquals( "PASSED", props.getProperty( "project.properties.envTest" ) );
80      }
81  
82  }