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.Properties;
24  
25  import org.apache.maven.it.util.ResourceExtractor;
26  
27  /**
28   * This is a test set for <a href="https://issues.apache.org/jira/browse/MNG-5889">MNG-5889</a>:
29   * check that extensions in <code>.mvn/</code> are found when Maven is run with <code>-f path/to/pom.xml</code>.
30   */
31  public class MavenITmng5889FindBasedir
32      extends AbstractMavenIntegrationTestCase
33  {
34      public MavenITmng5889FindBasedir()
35      {
36          super( "[3.5.0,3.5.1)" );
37      }
38  
39      protected MavenITmng5889FindBasedir( String constraint )
40      {
41          super( constraint );
42      }
43  
44      /**
45       * check that <code>path/to/.mvn/</code> is found when path to POM set by <code>--file path/to/pom.xml</code>
46       *
47       * @throws Exception in case of failure
48       */
49      public void testMvnFileLongOption()
50          throws Exception
51      {
52          runCoreExtensionWithOption( "--file", null );
53      }
54  
55      /**
56       * check that <code>path/to/.mvn/</code> is found when path to POM set by <code>-f path/to/pom.xml</code>
57       *
58       * @throws Exception in case of failure
59       */
60      public void testMvnFileShortOption()
61          throws Exception
62      {
63          runCoreExtensionWithOption( "-f", null );
64      }
65  
66      /**
67       * check that <code>path/to/.mvn/</code> is found when path to POM set by <code>--file path/to/module/pom.xml</code>
68       *
69       * @throws Exception in case of failure
70       */
71      public void testMvnFileLongOptionModule()
72          throws Exception
73      {
74          runCoreExtensionWithOption( "--file", "module" );
75      }
76  
77      /**
78       * check that <code>path/to/.mvn/</code> is found when path to POM set by <code>-f path/to/module/pom.xml</code>
79       *
80       * @throws Exception in case of failure
81       */
82      public void testMvnFileShortOptionModule()
83          throws Exception
84      {
85          runCoreExtensionWithOption( "-f", "module" );
86      }
87  
88      private void runCoreExtensionWithOption( String option, String subdir )
89          throws Exception
90      {
91          runCoreExtensionWithOption( option, subdir, true );
92      }
93  
94      protected void runCoreExtensionWithOption( String option, String subdir, boolean pom )
95          throws Exception
96      {
97          File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-5889-find.mvn" );
98  
99          File basedir = new File( testDir, "../mng-" + ( pom ? "5889" : "6223" ) + "-find.mvn" + option + ( pom ? "Pom" : "Dir" ) );
100         basedir.mkdir();
101 
102         if ( subdir != null )
103         {
104             testDir = new File( testDir, subdir );
105             basedir = new File( basedir, subdir );
106             basedir.mkdirs();
107         }
108 
109         Verifier verifier = newVerifier( basedir.getAbsolutePath() );
110         verifier.getCliOptions().add( "-Dexpression.outputFile=" + new File( basedir, "expression.properties" ).getAbsolutePath() );
111         verifier.getCliOptions().add( option ); // -f/--file client/pom.xml
112         verifier.getCliOptions().add( ( pom ? new File( testDir, "pom.xml" ) : testDir ).getAbsolutePath() );
113         verifier.setForkJvm( true ); // force forked JVM since we need the shell script to detect .mvn/ location
114         verifier.executeGoal( "validate" );
115         verifier.verifyErrorFreeLog();
116         verifier.resetStreams();
117 
118         Properties props = verifier.loadProperties( "expression.properties" );
119         assertEquals( "ok", props.getProperty( "project.properties.jvm-config" ) );
120         assertEquals( "ok", props.getProperty( "project.properties.maven-config" ) );
121     }
122 }