diff --git a/src/main/java/org/apache/maven/shared/invoker/InvocationRequest.java b/src/main/java/org/apache/maven/shared/invoker/InvocationRequest.java index fd603a2..3db994d 100644 --- a/src/main/java/org/apache/maven/shared/invoker/InvocationRequest.java +++ b/src/main/java/org/apache/maven/shared/invoker/InvocationRequest.java @@ -776,7 +776,7 @@ enum CheckSumPolicy /** * Sets the path to the base directory of the Maven installation used to invoke Maven. This parameter may be left * unspecified to use the default Maven installation which will be discovered by evaluating the system property - * maven.home and the environment variable M2_HOME. + * maven.home. * * @param mavenHome The path to the base directory of the Maven installation, may be null to use the * default Maven installation. diff --git a/src/main/java/org/apache/maven/shared/invoker/Invoker.java b/src/main/java/org/apache/maven/shared/invoker/Invoker.java index 869d29e..4349a0a 100644 --- a/src/main/java/org/apache/maven/shared/invoker/Invoker.java +++ b/src/main/java/org/apache/maven/shared/invoker/Invoker.java @@ -80,7 +80,7 @@ InvocationResult execute( InvocationRequest request ) /** * Sets the path to the base directory of the Maven installation used to invoke Maven. This parameter may be left * unspecified to use the default Maven installation which will be discovered by evaluating the system property - * maven.home and the environment variable M2_HOME. + * maven.home. * * @param mavenHome The path to the base directory of the Maven installation, may be null to use the * default Maven installation. diff --git a/src/main/java/org/apache/maven/shared/invoker/MavenCommandLineBuilder.java b/src/main/java/org/apache/maven/shared/invoker/MavenCommandLineBuilder.java index 5767a4b..186da75 100644 --- a/src/main/java/org/apache/maven/shared/invoker/MavenCommandLineBuilder.java +++ b/src/main/java/org/apache/maven/shared/invoker/MavenCommandLineBuilder.java @@ -31,7 +31,6 @@ import org.apache.maven.shared.utils.Os; import org.apache.maven.shared.utils.StringUtils; import org.apache.maven.shared.utils.cli.CommandLineException; -import org.apache.maven.shared.utils.cli.CommandLineUtils; import org.apache.maven.shared.utils.cli.Commandline; /** @@ -52,8 +51,6 @@ public class MavenCommandLineBuilder private File mavenExecutable; - private Properties systemEnvVars; - /** *

build.

* @@ -207,23 +204,7 @@ protected void setShellEnvironment( InvocationRequest request, Commandline cli ) { if ( request.isShellEnvironmentInherited() ) { - try - { - cli.addSystemEnvironment(); - cli.addEnvironment( "MAVEN_TERMINATE_CMD", "on" ); - // MSHARED-261: Ensure M2_HOME is not inherited, but gets a - // proper value - cli.addEnvironment( "M2_HOME", getMavenHome().getAbsolutePath() ); - } - catch ( RuntimeException e ) - { - throw e; - } - catch ( Exception e ) - { - throw new IllegalStateException( - "Unknown error retrieving shell environment variables. Reason: " + e.getMessage(), e ); - } + cli.addSystemEnvironment(); } if ( request.getJavaHome() != null ) @@ -585,19 +566,9 @@ void setupMavenHome( InvocationRequest request ) { mavenHome = request.getMavenHome(); } - - if ( mavenHome == null ) + else if ( System.getProperty( "maven.home" ) != null ) { - String mavenHomeProperty = System.getProperty( "maven.home" ); - if ( mavenHomeProperty == null && getSystemEnvVars().getProperty( "M2_HOME" ) != null ) - { - mavenHomeProperty = getSystemEnvVars().getProperty( "M2_HOME" ); - } - - if ( mavenHomeProperty != null ) - { - mavenHome = new File( mavenHomeProperty ); - } + mavenHome = new File( System.getProperty( "maven.home" ) ); } if ( mavenHome != null && !mavenHome.isDirectory() ) @@ -676,16 +647,6 @@ else if ( Os.isFamily( "windows" ) ) } } - private Properties getSystemEnvVars() - { - if ( this.systemEnvVars == null ) - { - // with 1.5 replace with System.getenv() - this.systemEnvVars = CommandLineUtils.getSystemEnvVars(); - } - return this.systemEnvVars; - } - /** *

Getter for the field localRepositoryDirectory.

* diff --git a/src/site/apt/usage.apt b/src/site/apt/usage.apt index 44d0cb3..30cc7a1 100644 --- a/src/site/apt/usage.apt +++ b/src/site/apt/usage.apt @@ -67,7 +67,7 @@ if ( result.getExitCode() != 0 ) This will retrieve the exit code from the invocation result, and throw an exception if it's not <<<0>>> (the traditional all-clear code). Note that we could capture the build output by adding an <<>> - instance to either the <<>> or the <<>>. + instance to the <<>>. * Caching the Invoker @@ -127,7 +127,7 @@ public void publishSite( File siteDirectory ) throws PublishException You can use the method <<>> to specify which Maven executable it should use. If you don't provide an explicit value for this setting, the <<>> will automatically try to detect - a Maven installation by evaluating the system property <<>> and the environment variable <<>>. + a Maven installation by evaluating the system property <<>>. <> If you use the invocation API in tests run by the {{{../../plugins/maven-surefire-plugin}Maven Surefire Plugin}}, you need to tell Surefire to pass the system property <<>> to the tests in order for the automatic Maven diff --git a/src/test/java/org/apache/maven/shared/invoker/DefaultInvokerTest.java b/src/test/java/org/apache/maven/shared/invoker/DefaultInvokerTest.java index a5aae00..70a4d6d 100644 --- a/src/test/java/org/apache/maven/shared/invoker/DefaultInvokerTest.java +++ b/src/test/java/org/apache/maven/shared/invoker/DefaultInvokerTest.java @@ -29,7 +29,6 @@ import java.util.Properties; import org.apache.maven.shared.utils.StringUtils; -import org.apache.maven.shared.utils.cli.CommandLineUtils; import org.junit.Test; import static org.junit.Assert.assertEquals; @@ -39,7 +38,7 @@ public class DefaultInvokerTest @Test public void testBuildShouldSucceed() - throws IOException, MavenInvocationException, URISyntaxException + throws MavenInvocationException, URISyntaxException { File basedir = getBasedirForBuild(); @@ -58,7 +57,7 @@ public void testBuildShouldSucceed() @Test public void testBuildShouldFail() - throws IOException, MavenInvocationException, URISyntaxException + throws MavenInvocationException, URISyntaxException { File basedir = getBasedirForBuild(); @@ -77,7 +76,7 @@ public void testBuildShouldFail() @Test public void testBuildShouldTimeout() - throws IOException, MavenInvocationException, URISyntaxException + throws MavenInvocationException, URISyntaxException { File basedir = getBasedirForBuild(); @@ -237,15 +236,10 @@ private File findMavenHome() { String mavenHome = System.getProperty( "maven.home" ); - if ( mavenHome == null ) - { - mavenHome = CommandLineUtils.getSystemEnvVars().getProperty( "M2_HOME" ); - } - if ( mavenHome == null ) { throw new IllegalStateException( "Cannot find Maven application " - + "directory. Either specify 'maven.home' system property, or M2_HOME environment variable." ); + + "directory. Specify 'maven.home' system property" ); } return new File( mavenHome ); diff --git a/src/test/java/org/apache/maven/shared/invoker/MavenCommandLineBuilderTest.java b/src/test/java/org/apache/maven/shared/invoker/MavenCommandLineBuilderTest.java index f7b2b0c..9e96652 100644 --- a/src/test/java/org/apache/maven/shared/invoker/MavenCommandLineBuilderTest.java +++ b/src/test/java/org/apache/maven/shared/invoker/MavenCommandLineBuilderTest.java @@ -45,6 +45,7 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; +import static org.junit.Assume.assumeThat; import static org.junit.Assume.assumeTrue; public class MavenCommandLineBuilderTest @@ -795,41 +796,6 @@ public void testBuildTypicalMavenInvocationEndToEnd() assertEquals( projectDir.getCanonicalPath(), commandline.getWorkingDirectory().getCanonicalPath() ); } - @Test - public void testShouldSetEnvVar_MAVEN_TERMINATE_CMD() - throws Exception - { - setupTempMavenHomeIfMissing( false ); - - InvocationRequest request = newRequest(); - - File projectDir = temporaryFolder.newFolder( "invoker-tests", "maven-terminate-cmd-options-set" ); - - request.setBaseDirectory( projectDir ); - - createDummyFile( projectDir, "pom.xml" ); - - List goals = new ArrayList<>(); - - goals.add( "clean" ); - request.setGoals( goals ); - - Commandline commandline = mclb.build( request ); - - String[] environmentVariables = commandline.getEnvironmentVariables(); - String envVarMavenTerminateCmd = null; - for ( String envVar : environmentVariables ) - { - if ( envVar.startsWith( "MAVEN_TERMINATE_CMD=" ) ) - { - envVarMavenTerminateCmd = envVar; - break; - } - } - assertEquals( "MAVEN_TERMINATE_CMD=on", envVarMavenTerminateCmd ); - - } - @Test public void testShouldInsertActivatedProfiles() throws Exception @@ -852,50 +818,12 @@ public void testShouldInsertActivatedProfiles() assertArgumentsPresentInOrder( commandline, "-P", profile1 + "," + profile2 ); } - @Test - public void testShouldSetEnvVar_M2_HOME() - throws Exception - { - Assume.assumeNotNull( System.getenv( "M2_HOME" ) ); - - setupTempMavenHomeIfMissing( true ); - - InvocationRequest request = newRequest(); - - File projectDir = temporaryFolder.newFolder( "invoker-tests/maven-terminate-cmd-options-set" ); - - request.setBaseDirectory( projectDir ); - - createDummyFile( projectDir, "pom.xml" ); - - List goals = new ArrayList<>(); - - goals.add( "clean" ); - request.setGoals( goals ); - - File mavenHome2 = new File( System.getProperty( "maven.home" ) ); - mclb.setMavenHome( mavenHome2 ); - - Commandline commandline = mclb.build( request ); - - String[] environmentVariables = commandline.getEnvironmentVariables(); - String m2Home = null; - for ( String envVar : environmentVariables ) - { - if ( envVar.startsWith( "M2_HOME=" ) ) - { - m2Home = envVar; - } - } - assertEquals( "M2_HOME=" + mavenHome2.getAbsolutePath(), m2Home ); - } - @Test public void testMvnExecutableFromInvoker() throws Exception { - assumeTrue( "Test only works when maven home can be assigned", - System.getProperty( "maven.home" ) != null || System.getenv( "M2_HOME" ) != null ); + assumeThat( "Test only works when maven.home is set", + System.getProperty( "maven.home" ), is(notNullValue())); File mavenExecutable = new File( "mvnDebug" ); @@ -911,8 +839,8 @@ public void testMvnExecutableFromInvoker() public void testMvnExecutableFormRequest() throws Exception { - assumeTrue( "Test only works when maven home can be assigned", - System.getProperty( "maven.home" ) != null || System.getenv( "M2_HOME" ) != null ); + assumeThat( "Test only works when maven.home is set", + System.getProperty( "maven.home" ), is(notNullValue())); File mavenExecutable = new File( "mvnDebug" ); @@ -927,8 +855,8 @@ public void testMvnExecutableFormRequest() public void testDefaultMavenCommand() throws Exception { - assumeTrue( "Test only works when maven home can be assigned", - System.getProperty( "maven.home" ) != null || System.getenv( "M2_HOME" ) != null ); + assumeThat( "Test only works when maven.home is set", + System.getProperty( "maven.home" ), is(notNullValue())); mclb.build( newRequest() );