You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by ol...@apache.org on 2007/11/21 23:11:00 UTC
svn commit: r597230 - in /maven/shared/trunk/maven-invoker/src:
main/java/org/apache/maven/shared/invoker/MavenCommandLineBuilder.java
test/java/org/apache/maven/shared/invoker/MavenCommandLineBuilderTest.java
Author: olamy
Date: Wed Nov 21 14:10:59 2007
New Revision: 597230
URL: http://svn.apache.org/viewvc?rev=597230&view=rev
Log:
[MNG-3298] checkRequiredState not throw Exception if M2_HOME exists
replace the use of System.getenv which throw an Error in jdk1.4
Modified:
maven/shared/trunk/maven-invoker/src/main/java/org/apache/maven/shared/invoker/MavenCommandLineBuilder.java
maven/shared/trunk/maven-invoker/src/test/java/org/apache/maven/shared/invoker/MavenCommandLineBuilderTest.java
Modified: maven/shared/trunk/maven-invoker/src/main/java/org/apache/maven/shared/invoker/MavenCommandLineBuilder.java
URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-invoker/src/main/java/org/apache/maven/shared/invoker/MavenCommandLineBuilder.java?rev=597230&r1=597229&r2=597230&view=diff
==============================================================================
--- maven/shared/trunk/maven-invoker/src/main/java/org/apache/maven/shared/invoker/MavenCommandLineBuilder.java (original)
+++ maven/shared/trunk/maven-invoker/src/main/java/org/apache/maven/shared/invoker/MavenCommandLineBuilder.java Wed Nov 21 14:10:59 2007
@@ -28,8 +28,12 @@
import org.codehaus.plexus.util.Os;
import org.codehaus.plexus.util.StringUtils;
+import org.codehaus.plexus.util.cli.CommandLineUtils;
import org.codehaus.plexus.util.cli.Commandline;
+/**
+ * @version $Id$
+ */
public class MavenCommandLineBuilder
{
private static final InvokerLogger DEFAULT_LOGGER = new SystemOutLogger();
@@ -43,14 +47,29 @@
private File mavenHome;
private File mvnCommand;
+
+ private Properties systemEnvVars;
public Commandline build( InvocationRequest request )
throws CommandLineConfigurationException
{
- checkRequiredState();
-
- File mvn = findMavenExecutable();
-
+ try
+ {
+ checkRequiredState();
+ }
+ catch ( IOException e )
+ {
+ throw new CommandLineConfigurationException( e.getMessage(), e );
+ }
+ File mvn = null;
+ try
+ {
+ mvn = findMavenExecutable();
+ }
+ catch ( IOException e )
+ {
+ throw new CommandLineConfigurationException( e.getMessage(), e );
+ }
Commandline cli = new Commandline();
cli.setExecutable( mvn.getAbsolutePath() );
@@ -84,6 +103,7 @@
}
protected void checkRequiredState()
+ throws IOException
{
if ( logger == null )
{
@@ -91,10 +111,15 @@
}
if ( ( mavenHome == null ) && ( System.getProperty( "maven.home" ) == null ) )
+ // can be restored with 1.5
+ //&& ( System.getenv( "M2_HOME" ) != null ) )
{
- throw new IllegalStateException( "Maven application directory was not "
- + "specified, and ${maven.home} is not provided in the system "
- + "properties. Please specify at least on of these." );
+ if ( !getSystemEnvVars().containsKey( "M2_HOME" ) )
+ {
+ throw new IllegalStateException( "Maven application directory was not "
+ + "specified, and ${maven.home} is not provided in the system "
+ + "properties. Please specify at least on of these." );
+ }
}
}
@@ -387,7 +412,7 @@
}
protected File findMavenExecutable()
- throws CommandLineConfigurationException
+ throws CommandLineConfigurationException, IOException
{
if ( mavenHome == null )
{
@@ -412,9 +437,9 @@
}
}
- if ( ( mavenHome == null ) && ( System.getenv( "M2_HOME" ) != null ) )
+ if ( ( mavenHome == null ) && ( getSystemEnvVars().getProperty( "M2_HOME" ) != null ) )
{
- mavenHome = new File( System.getenv( "M2_HOME" ) );
+ mavenHome = new File( getSystemEnvVars().getProperty( "M2_HOME" ) );
}
}
@@ -467,6 +492,17 @@
{
return path;
}
+ }
+
+ private Properties getSystemEnvVars()
+ throws IOException
+ {
+ if ( this.systemEnvVars == null )
+ {
+ // with 1.5 replace with System.getenv()
+ this.systemEnvVars = CommandLineUtils.getSystemEnvVars();
+ }
+ return this.systemEnvVars;
}
public File getLocalRepositoryDirectory()
Modified: maven/shared/trunk/maven-invoker/src/test/java/org/apache/maven/shared/invoker/MavenCommandLineBuilderTest.java
URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-invoker/src/test/java/org/apache/maven/shared/invoker/MavenCommandLineBuilderTest.java?rev=597230&r1=597229&r2=597230&view=diff
==============================================================================
--- maven/shared/trunk/maven-invoker/src/test/java/org/apache/maven/shared/invoker/MavenCommandLineBuilderTest.java (original)
+++ maven/shared/trunk/maven-invoker/src/test/java/org/apache/maven/shared/invoker/MavenCommandLineBuilderTest.java Wed Nov 21 14:10:59 2007
@@ -313,6 +313,10 @@
catch ( IllegalStateException e )
{
}
+ catch ( IOException e )
+ {
+ fail( e.getMessage() );
+ }
}
public void testShouldFindDummyMavenExecutable()
@@ -1045,12 +1049,13 @@
extends MavenCommandLineBuilder
{
public void checkRequiredState()
+ throws IOException
{
super.checkRequiredState();
}
public File findMavenExecutable()
- throws CommandLineConfigurationException
+ throws CommandLineConfigurationException, IOException
{
return super.findMavenExecutable();
}