You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by vs...@apache.org on 2006/11/09 14:34:15 UTC

svn commit: r472891 - in /maven/components/trunk/maven-cli/src: main/java/org/apache/maven/cli/MavenCli.java test/java/org/apache/maven/cli/MavenCliTest.java

Author: vsiveton
Date: Thu Nov  9 05:34:14 2006
New Revision: 472891

URL: http://svn.apache.org/viewvc?view=rev&rev=472891
Log:
o Merged from 2.0.x branch revision r472890, MNG-2413

Added:
    maven/components/trunk/maven-cli/src/test/java/org/apache/maven/cli/MavenCliTest.java   (with props)
Modified:
    maven/components/trunk/maven-cli/src/main/java/org/apache/maven/cli/MavenCli.java

Modified: maven/components/trunk/maven-cli/src/main/java/org/apache/maven/cli/MavenCli.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-cli/src/main/java/org/apache/maven/cli/MavenCli.java?view=diff&rev=472891&r1=472890&r2=472891
==============================================================================
--- maven/components/trunk/maven-cli/src/main/java/org/apache/maven/cli/MavenCli.java (original)
+++ maven/components/trunk/maven-cli/src/main/java/org/apache/maven/cli/MavenCli.java Thu Nov  9 05:34:14 2006
@@ -1,7 +1,7 @@
 package org.apache.maven.cli;
 
 /*
- * Copyright 2001-2005 The Apache Software Foundation.
+ * Copyright 2001-2006 The Apache Software Foundation.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -46,7 +46,7 @@
     public static void main( String[] args )
     {
         ClassWorld classWorld = new ClassWorld( "plexus.core", Thread.currentThread().getContextClassLoader() );
-        
+
         int result = main( args, classWorld );
         System.exit(result);
     }
@@ -75,11 +75,17 @@
         }
 
         // TODO: maybe classworlds could handle this requirement...
-        if ( System.getProperty( "java.class.version", "44.0" ).compareTo( "48.0" ) < 0 )
+        if ( "1.4".compareTo( System.getProperty( "java.specification.version" ) ) > 0 )
         {
-            System.err.println( "Sorry, but JDK 1.4 or above is required to execute Maven" );
-            System.err.println(
-                "You appear to be using Java version: " + System.getProperty( "java.version", "<unknown>" ) );
+            System.err.println( "Sorry, but JDK 1.4 or above is required to execute Maven. You appear to be using "
+                + "Java:" );
+            System.err.println( "java version \"" + System.getProperty( "java.version", "<unknown java version>" )
+                + "\"" );
+            System.err.println( System.getProperty( "java.runtime.name", "<unknown runtime name>" ) + " (build "
+                + System.getProperty( "java.runtime.version", "<unknown runtime version>" ) + ")" );
+            System.err.println( System.getProperty( "java.vm.name", "<unknown vm name>" ) + " (build "
+                + System.getProperty( "java.vm.version", "<unknown vm version>" ) + ", "
+                + System.getProperty( "java.vm.info", "<unknown vm info>" ) + ")" );
 
             return 1;
         }
@@ -345,7 +351,7 @@
             }
 
             Properties executionProperties = getExecutionProperties( commandLine );
-            
+
             File userSettingsPath = mavenEmbedder.getUserSettingsPath( commandLine.getOptionValue( CLIManager.ALTERNATE_USER_SETTINGS ) );
 
             File globalSettingsFile = mavenEmbedder.getGlobalSettingsPath();

Added: maven/components/trunk/maven-cli/src/test/java/org/apache/maven/cli/MavenCliTest.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-cli/src/test/java/org/apache/maven/cli/MavenCliTest.java?view=auto&rev=472891
==============================================================================
--- maven/components/trunk/maven-cli/src/test/java/org/apache/maven/cli/MavenCliTest.java (added)
+++ maven/components/trunk/maven-cli/src/test/java/org/apache/maven/cli/MavenCliTest.java Thu Nov  9 05:34:14 2006
@@ -0,0 +1,79 @@
+package org.apache.maven.cli;
+
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.io.OutputStream;
+import java.io.PrintStream;
+
+import org.codehaus.classworlds.ClassWorld;
+import org.codehaus.plexus.util.StringOutputStream;
+
+import junit.framework.TestCase;
+
+/**
+ * Test method for 'org.apache.maven.cli.MavenCli.main(String[], ClassWorld)'
+ *
+ * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
+ * @version $Id$
+ */
+public class MavenCliTest
+    extends TestCase
+{
+    /**
+     * Test that JDK 1.4 or above is required to execute MavenCli
+     *
+     * @throws Exception
+     */
+    public void testMain()
+        throws Exception
+    {
+        ClassWorld classWorld = new ClassWorld();
+
+        PrintStream oldErr = System.err;
+        PrintStream oldOut = System.out;
+
+        OutputStream errOS = new StringOutputStream();
+        PrintStream err = new PrintStream( errOS );
+        System.setErr( err );
+        OutputStream outOS = new StringOutputStream();
+        PrintStream out = new PrintStream( outOS );
+        System.setOut( out );
+
+        try
+        {
+            System.setProperty( "java.specification.version", "1.0" );
+            assertEquals( 1, MavenCli.main( new String[] { "-h" }, classWorld ) );
+            System.setProperty( "java.specification.version", "1.1" );
+            assertEquals( 1, MavenCli.main( new String[] { "-h" }, classWorld ) );
+            System.setProperty( "java.specification.version", "1.2" );
+            assertEquals( 1, MavenCli.main( new String[] { "-h" }, classWorld ) );
+            System.setProperty( "java.specification.version", "1.3" );
+            assertEquals( 1, MavenCli.main( new String[] { "-h" }, classWorld ) );
+            System.setProperty( "java.specification.version", "1.4" );
+            assertEquals( 0, MavenCli.main( new String[] { "-h" }, classWorld ) );
+            System.setProperty( "java.specification.version", "1.5" );
+            assertEquals( 0, MavenCli.main( new String[] { "-h" }, classWorld ) );
+            System.setProperty( "java.specification.version", "1.6" );
+            assertEquals( 0, MavenCli.main( new String[] { "-h" }, classWorld ) );
+        }
+        finally
+        {
+            System.setErr( oldErr );
+            System.setErr( oldOut );
+        }
+    }
+}

Propchange: maven/components/trunk/maven-cli/src/test/java/org/apache/maven/cli/MavenCliTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/components/trunk/maven-cli/src/test/java/org/apache/maven/cli/MavenCliTest.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"