maven-surefire-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jvan...@apache.org
Subject svn commit: r356178 - in /maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire: ForkedSurefireRunner.java SurefireBooter.java
Date Mon, 12 Dec 2005 06:30:48 GMT
Author: jvanzyl
Date: Sun Dec 11 22:30:46 2005
New Revision: 356178

URL: http://svn.apache.org/viewcvs?rev=356178&view=rev
Log:
o bit messy but checking in so that john can give it a whirl

Modified:
    maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/ForkedSurefireRunner.java
    maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/SurefireBooter.java

Modified: maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/ForkedSurefireRunner.java
URL: http://svn.apache.org/viewcvs/maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/ForkedSurefireRunner.java?rev=356178&r1=356177&r2=356178&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/ForkedSurefireRunner.java
(original)
+++ maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/ForkedSurefireRunner.java
Sun Dec 11 22:30:46 2005
@@ -17,26 +17,35 @@
  */
 
 import java.io.File;
+import java.io.FileInputStream;
 import java.lang.reflect.Method;
 import java.util.ArrayList;
 import java.util.Arrays;
-import java.util.LinkedHashMap;
+import java.util.Iterator;
 import java.util.List;
-import java.util.Map;
+import java.util.Properties;
 
 /**
  * This class is executed when SurefireBooter forks surefire JUnit processes
  *
- * @author <a href="mailto:andyglick@acm.org">Andy Glick</a>
+ * @author Jason van Zyl
  * @version $Id$
  */
 public class ForkedSurefireRunner
 {
-    public static String FORK_ONCE = "once";
+    public static final String FORK_ONCE = "once";
 
-    public static String FORK_PERTEST = "pertest";
+    public static final String FORK_PERTEST = "pertest";
 
-    public static String FORK_NONE = "none";
+    public static final String FORK_NONE = "none";
+
+    public static final String SUREFIRE_PROPERTIES = "surefire.properties";
+
+    public static final String SYSTEM_PROPERTIES = "surefire-system.properties";
+
+    public static final String CLASSLOADER_PROPERTIES = "surefire-classloader.properties";
+
+    static String basedir;
 
     static int TESTS_SUCCEEDED = 0;
 
@@ -46,34 +55,71 @@
 
     static int OTHER_EXCEPTION = 200;
 
-    private static Class thisClass = ForkedSurefireRunner.class;
-
     private ForkedSurefireRunner()
     {
         super();
     }
 
-    /**
-     * Constructs a Map from a set of strings of the form <key>=<value>
-     *
-     * @param args an array of strings composed of name/value pairs
-     * @return Map keyed by the names with the respective values
-     */
-    private static Map getArgMap( String[] args )
+    private static Properties getSurefireProperties()
+        throws Exception
     {
-        Map argMap = new LinkedHashMap();
+        File f = new File( basedir, SUREFIRE_PROPERTIES );
+
+        f.deleteOnExit();
 
-        for ( int i = 0; i < args.length; i++ )
+        Properties p = new Properties();
+
+        p.load( new FileInputStream( f ) );
+
+        return p;
+    }
+
+    private static void  setSystemProperties()
+        throws Exception
+    {
+        File f = new File( basedir, SYSTEM_PROPERTIES );
+
+        f.deleteOnExit();
+
+        if ( !f.exists() )
         {
-            String[] mapArgs = args[i].split( "=" );
+            return;
+        }
 
-            argMap.put( mapArgs[0], mapArgs[1] );
 
-            System.out.println( "mapArgs[0] = " + mapArgs[0] );
-            System.out.println( "mapArgs[1] = " + mapArgs[1] );
+        Properties p = new Properties();
+
+        p.load( new FileInputStream( f ) );
+
+        for ( Iterator i = p.keySet().iterator(); i.hasNext(); )
+        {
+            String key = (String) i.next();
+
+            System.setProperty( key, p.getProperty( key ) );
+        }
+    }
+
+    private static ClassLoader createClassLoader()
+        throws Exception
+    {
+        File f = new File( basedir, CLASSLOADER_PROPERTIES );
+
+        f.deleteOnExit();
+
+        Properties p = new Properties();
+
+        p.load( new FileInputStream( f ) );
+
+        IsolatedClassLoader classLoader = new IsolatedClassLoader( ClassLoader.getSystemClassLoader()
);
+
+        for ( Iterator i = p.values().iterator(); i.hasNext(); )
+        {
+            String entry = (String) i.next();
+
+            classLoader.addURL( new File( entry ).toURL() );
         }
 
-        return argMap;
+        return classLoader;
     }
 
     /**
@@ -87,23 +133,25 @@
     public static void main( String[] args )
         throws Exception
     {
-        Map argMap = getArgMap( args );
+        ClassLoader classLoader = createClassLoader();
 
-        ClassLoader surefireClassLoader = thisClass.getClassLoader();
+        setSystemProperties();
 
-        String batteryExecutorName = (String) argMap.get( "batteryExecutorName" );
+        Properties p = getSurefireProperties();
 
-        Class batteryExecutorClass = surefireClassLoader.loadClass( batteryExecutorName );
+        String batteryExecutorName = p.getProperty( "batteryExecutorName" );
+
+        Class batteryExecutorClass = classLoader.loadClass( batteryExecutorName );
 
         Object batteryExecutor = batteryExecutorClass.newInstance();
 
-        String reports = (String) argMap.get( "reportClassNames" );
+        String reports = p.getProperty( "reportClassNames" );
 
         String[] reportClasses = reports.split( "," );
 
         List reportList = Arrays.asList( reportClasses );
 
-        String batteryConfig = (String) argMap.get( "batteryConfig" );
+        String batteryConfig = p.getProperty( "batteryConfig" );
 
         String[] batteryParts = batteryConfig.split( "\\|" );
 
@@ -111,7 +159,7 @@
 
         Object[] batteryParms;
 
-        String forkMode = (String) argMap.get( "forkMode" );
+        String forkMode = p.getProperty( "forkMode" );
 
         if ( forkMode.equals( FORK_ONCE ) )
         {
@@ -166,7 +214,7 @@
 
         batteryHolders.add( new Object[]{batteryClassName, batteryParms} );
 
-        String reportsDirectory = (String) argMap.get( "reportsDirectory" );
+        String reportsDirectory = p.getProperty( "reportsDirectory" );
 
         Method run = batteryExecutorClass.getMethod( "run", new Class[]{List.class, List.class,
String.class} );
 
@@ -190,6 +238,8 @@
         }
         catch ( Exception e )
         {
+            e.printStackTrace();
+
             returnCode = OTHER_EXCEPTION;
         }
 

Modified: maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/SurefireBooter.java
URL: http://svn.apache.org/viewcvs/maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/SurefireBooter.java?rev=356178&r1=356177&r2=356178&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/SurefireBooter.java
(original)
+++ maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/SurefireBooter.java
Sun Dec 11 22:30:46 2005
@@ -25,17 +25,15 @@
 
 import java.io.BufferedReader;
 import java.io.File;
+import java.io.FileOutputStream;
 import java.io.StringReader;
 import java.io.StringWriter;
 import java.io.Writer;
 import java.lang.reflect.Method;
-import java.lang.reflect.Array;
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Properties;
-import java.util.Enumeration;
-import java.util.Arrays;
 
 /**
  * @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
@@ -147,8 +145,6 @@
     {
         boolean result = false;
 
-        System.out.println( ">>>>>>>>> forkMode = " + forkMode
);
-
         if ( forkMode.equals( ForkedSurefireRunner.FORK_NONE ) )
         {
             result = runTestsInProcess();
@@ -212,7 +208,9 @@
     private boolean runTestsForkOnce()
         throws Exception
     {
-        return fork( getForkOnceArgs() );
+        getForkOnceArgs();
+
+        return fork();
     }
 
     private boolean runTestsForkEach()
@@ -226,7 +224,9 @@
         {
             String testClass = (String) i.next();
 
-            boolean result = fork( getForkPerTestArgs( testClass ) );
+            getForkPerTestArgs( testClass );
+
+            boolean result = fork();
 
             if ( !result )
             {
@@ -237,7 +237,7 @@
         return noFailures;
     }
 
-    private boolean fork( String[] args )
+    private boolean fork()
         throws Exception
     {
         File workingDirectory = new File( "." );
@@ -250,7 +250,13 @@
 
         cli.setExecutable( jvm );
 
-        cli.addArguments( args );
+        cli.createArgument().setValue( "-classpath" );
+
+        cli.createArgument().setValue( surefireBooterJar );
+
+        cli.createArgument().setValue( RUNNER );
+
+        cli.createArgument().setValue( basedir );
 
         System.out.println( Commandline.toString( cli.getCommandline() ) );
 
@@ -328,67 +334,78 @@
         return testClasses;
     }
 
-    private String[] getForkOnceArgs()
+    private void getForkOnceArgs()
         throws Exception
     {
-        return getForkArgs( getStringArrayFromBatteries()[0] );
+        getForkArgs( getStringArrayFromBatteries()[0] );
     }
 
-    private String[] getForkPerTestArgs( String testClass )
+    private void getForkPerTestArgs( String testClass )
         throws Exception
     {
-        return getForkArgs( SINGLE_TEST_BATTERY + "|" + testClass );
+        getForkArgs( SINGLE_TEST_BATTERY + "|" + testClass );
     }
 
-    private String[] getForkArgs( String batteryConfig )
+    private String surefireBooterJar;
+
+    private void getForkArgs( String batteryConfig )
         throws Exception
     {
         String reportClassNames = getListOfStringsAsString( reports, "," );
 
-        String classpathEntries = makeClasspath( classpathUrls );
+        Properties p = new Properties();
 
-        List args = new ArrayList();
+        for ( int i = 0; i < classpathUrls.size(); i++ )
+        {
+            String entry = (String) classpathUrls.get( i );
+
+            // Exclude the surefire booter
+            if ( entry.indexOf( "surefire-booter" ) > 0 )
+            {
+                surefireBooterJar = entry;
+            }
+            else
+            {
+                p.setProperty( Integer.toString( i ), entry );
+            }
+
+        }
 
-        args.add( "-classpath" );
+        FileOutputStream fos = new FileOutputStream( new File( basedir, ForkedSurefireRunner.CLASSLOADER_PROPERTIES
) );
 
-        args.add( classpathEntries );
+        p.store( fos, "classpath entries" );
 
-        // ----------------------------------------------------------------------
-        // Add some system propeties
-        // ----------------------------------------------------------------------
+        fos.close();
 
         if ( systemProperties != null )
         {
-            Enumeration propertyKeys = systemProperties.propertyNames();
+            File f = new File( basedir, ForkedSurefireRunner.SYSTEM_PROPERTIES );
 
-            while ( propertyKeys.hasMoreElements() )
-            {
-                String key = (String) propertyKeys.nextElement();
+            fos = new FileOutputStream( f );
 
-                args.add( "-D" + key + "=" + systemProperties.getProperty( key ) );
-            }
+            systemProperties.store( fos, "system properties" );
+
+            fos.close();
         }
 
-        args.add( RUNNER );
+        p = new Properties();
 
-        args.add( "reportClassNames=" + reportClassNames );
+        p.setProperty( "reportClassNames",  reportClassNames );
 
-        args.add( "reportsDirectory=" + reportsDirectory );
+        p.setProperty( "reportsDirectory",  reportsDirectory );
 
-        args.add( "batteryExecutorName=" + BATTERY_EXECUTOR );
+        p.setProperty( "batteryExecutorName",  BATTERY_EXECUTOR );
 
-        args.add( "forkMode=" + forkMode );
+        p.setProperty( "forkMode",  forkMode );
 
-        args.add( "batteryConfig=" + batteryConfig );
+        p.setProperty( "batteryConfig", batteryConfig );
 
-        String[] s = new String[args.size()];
+        fos = new FileOutputStream( new File( basedir, ForkedSurefireRunner.SUREFIRE_PROPERTIES
) );
 
-        for ( int i = 0; i < s.length; i++ )
-        {
-            s[i] = (String) args.get( i );
-        }
+        p.store( fos, "surefire properties" );
+
+        fos.close();
 
-        return s;
     }
 
     public void reset()
@@ -398,22 +415,6 @@
         reports.clear();
 
         classpathUrls.clear();
-    }
-
-    private String makeClasspath( List list )
-    {
-        StringBuffer files = new StringBuffer();
-
-        for ( Iterator i = list.iterator(); i.hasNext(); )
-        {
-            String classpathElement = (String) i.next();
-
-            files.append( classpathElement );
-
-            files.append( PS );
-        }
-
-        return files.toString();
     }
 
     private String quotedPathArgument( String value )



Mime
View raw message