You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by kr...@apache.org on 2012/08/18 00:10:32 UTC

svn commit: r1374456 - in /maven/surefire/trunk: maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/ maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ maven-surefire-common/src/test/java/org/apache/mav...

Author: krosenvold
Date: Fri Aug 17 22:10:31 2012
New Revision: 1374456

URL: http://svn.apache.org/viewvc?rev=1374456&view=rev
Log:
[SUREFIRE-906] Sometimes get NullPointerException in forked process

Solution identified by Christopher Mosher

Modified:
    maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java
    maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/BooterSerializer.java
    maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ForkStarter.java
    maven/surefire/trunk/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/BooterDeserializerProviderConfigurationTest.java
    maven/surefire/trunk/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/BooterDeserializerStartupConfigurationTest.java
    maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ClasspathConfiguration.java

Modified: maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java?rev=1374456&r1=1374455&r2=1374456&view=diff
==============================================================================
--- maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java (original)
+++ maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java Fri Aug 17 22:10:31 2012
@@ -742,7 +742,7 @@ public abstract class AbstractSurefireMo
                     ForkStarter forkStarter =
                         createForkStarter( provider, forkConfiguration, classLoaderConfiguration, runOrderParameters,
                                            effectiveProperties );
-                    result = forkStarter.run( scanResult, getEffectiveForkMode() );
+                    result = forkStarter.run( effectiveProperties, scanResult, getEffectiveForkMode() );
                 }
                 finally
                 {
@@ -1224,8 +1224,7 @@ public abstract class AbstractSurefireMo
         StartupReportConfiguration startupReportConfiguration = getStartupReportConfiguration( configChecksum );
         ProviderConfiguration providerConfiguration = createProviderConfiguration( runOrderParameters );
         return new ForkStarter( providerConfiguration, startupConfiguration, forkConfiguration,
-                                getForkedProcessTimeoutInSeconds(), startupReportConfiguration,
-                                effectiveSystemProperties );
+                                getForkedProcessTimeoutInSeconds(), startupReportConfiguration );
     }
 
     protected InPluginVMSurefireStarter createInprocessStarter( ProviderInfo provider,

Modified: maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/BooterSerializer.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/BooterSerializer.java?rev=1374456&r1=1374455&r2=1374456&view=diff
==============================================================================
--- maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/BooterSerializer.java (original)
+++ maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/BooterSerializer.java Fri Aug 17 22:10:31 2012
@@ -55,20 +55,24 @@ class BooterSerializer
 {
     private final ForkConfiguration forkConfiguration;
 
-    private final PropertiesWrapper properties;
-
-    public BooterSerializer( ForkConfiguration forkConfiguration, Properties properties )
+    public BooterSerializer( ForkConfiguration forkConfiguration )
     {
         this.forkConfiguration = forkConfiguration;
-        this.properties = new PropertiesWrapper( properties );
     }
 
 
-    public File serialize(ProviderConfiguration booterConfiguration, StartupConfiguration providerConfiguration,
+    /*
+    DOes not modify sourceProperties
+     */
+    public File serialize(Properties sourceProperties, ProviderConfiguration booterConfiguration, StartupConfiguration providerConfiguration,
                           Object testSet)
         throws IOException
     {
-        providerConfiguration.getClasspathConfiguration().setForkProperties( properties );
+
+        PropertiesWrapper properties = new PropertiesWrapper(new Properties(  ) );
+        properties.getProperties().putAll( sourceProperties );
+
+        providerConfiguration.getClasspathConfiguration().addForkProperties( properties );
 
         TestArtifactInfo testNg = booterConfiguration.getTestArtifact();
         if ( testNg != null )

Modified: maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ForkStarter.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ForkStarter.java?rev=1374456&r1=1374455&r2=1374456&view=diff
==============================================================================
--- maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ForkStarter.java (original)
+++ maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ForkStarter.java Fri Aug 17 22:10:31 2012
@@ -82,8 +82,6 @@ public class ForkStarter
 
     private final StartupReportConfiguration startupReportConfiguration;
 
-    private final SurefireProperties effectiveSystemProperties;
-
     private final DefaultReporterFactory fileReporterFactory;
 
     private static volatile int systemPropertiesFileCounter = 0;
@@ -91,19 +89,17 @@ public class ForkStarter
 
     public ForkStarter( ProviderConfiguration providerConfiguration, StartupConfiguration startupConfiguration,
                         ForkConfiguration forkConfiguration, int forkedProcessTimeoutInSeconds,
-                        StartupReportConfiguration startupReportConfiguration,
-                        SurefireProperties effectiveSystemProperties )
+                        StartupReportConfiguration startupReportConfiguration )
     {
         this.forkConfiguration = forkConfiguration;
         this.providerConfiguration = providerConfiguration;
         this.forkedProcessTimeoutInSeconds = forkedProcessTimeoutInSeconds;
         this.startupConfiguration = startupConfiguration;
         this.startupReportConfiguration = startupReportConfiguration;
-        this.effectiveSystemProperties = effectiveSystemProperties;
         fileReporterFactory = new DefaultReporterFactory( startupReportConfiguration );
     }
 
-    public RunResult run( DefaultScanResult scanResult, String requestedForkMode )
+    public RunResult run( SurefireProperties effectiveSystemProperties, DefaultScanResult scanResult, String requestedForkMode )
         throws SurefireBooterForkException, SurefireExecutionException
     {
         final RunResult result;
@@ -115,15 +111,16 @@ public class ForkStarter
             {
                 final ForkClient forkClient =
                     new ForkClient( fileReporterFactory, startupReportConfiguration.getTestVmSystemProperties() );
-                result = fork( null, providerProperties, forkClient, fileReporterFactory.getGlobalRunStatistics() );
+                result = fork( null, providerProperties, forkClient, fileReporterFactory.getGlobalRunStatistics(),
+                               effectiveSystemProperties );
             }
             else if ( ForkConfiguration.FORK_ALWAYS.equals( requestedForkMode ) )
             {
-                result = runSuitesForkPerTestSet( providerProperties, 1 );
+                result = runSuitesForkPerTestSet( providerProperties, effectiveSystemProperties, 1 );
             }
             else if ( ForkConfiguration.FORK_PERTHREAD.equals( requestedForkMode ) )
             {
-                result = runSuitesForkPerTestSet( providerProperties, forkConfiguration.getForkCount() );
+                result = runSuitesForkPerTestSet( providerProperties, effectiveSystemProperties, forkConfiguration.getForkCount() );
             }
             else
             {
@@ -137,7 +134,8 @@ public class ForkStarter
         return result;
     }
 
-    private RunResult runSuitesForkPerTestSet( final Properties properties, int forkCount )
+    private RunResult runSuitesForkPerTestSet( final Properties properties,
+                                               final SurefireProperties effectiveSystemProperties, int forkCount )
         throws SurefireBooterForkException
     {
 
@@ -160,8 +158,9 @@ public class ForkStarter
                     public RunResult call()
                         throws Exception
                     {
-                        return fork( testSet, (Properties) properties.clone(), forkClient,
-                                     fileReporterFactory.getGlobalRunStatistics() );
+                        return fork( testSet, properties, forkClient,
+                                     fileReporterFactory.getGlobalRunStatistics(),
+                                     effectiveSystemProperties );
                     }
                 };
                 results.add( executorService.submit( pf ) );
@@ -217,17 +216,17 @@ public class ForkStarter
     }
 
 
-    private RunResult fork( Object testSet, Properties properties, ForkClient forkClient,
-                            RunStatistics globalRunStatistics )
+    private RunResult fork( Object testSet, Properties providerProperties, ForkClient forkClient,
+                            RunStatistics globalRunStatistics, SurefireProperties effectiveSystemProperties )
         throws SurefireBooterForkException
     {
         File surefireProperties;
         File systPropsFile = null;
         try
         {
-            BooterSerializer booterSerializer = new BooterSerializer( forkConfiguration, properties );
+            BooterSerializer booterSerializer = new BooterSerializer( forkConfiguration );
 
-            surefireProperties = booterSerializer.serialize( providerConfiguration, startupConfiguration, testSet );
+            surefireProperties = booterSerializer.serialize( providerProperties, providerConfiguration, startupConfiguration, testSet );
 
             if ( effectiveSystemProperties != null )
             {

Modified: maven/surefire/trunk/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/BooterDeserializerProviderConfigurationTest.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/BooterDeserializerProviderConfigurationTest.java?rev=1374456&r1=1374455&r2=1374456&view=diff
==============================================================================
--- maven/surefire/trunk/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/BooterDeserializerProviderConfigurationTest.java (original)
+++ maven/surefire/trunk/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/BooterDeserializerProviderConfigurationTest.java Fri Aug 17 22:10:31 2012
@@ -172,11 +172,9 @@ public class BooterDeserializerProviderC
     {
         final ForkConfiguration forkConfiguration = ForkConfigurationTest.getForkConfiguration( null, null );
         Properties props = new Properties();
-        BooterSerializer booterSerializer = new BooterSerializer( forkConfiguration, props );
+        BooterSerializer booterSerializer = new BooterSerializer( forkConfiguration );
         String aTest = "aTest";
-        booterSerializer.serialize( booterConfiguration, testProviderConfiguration, aTest);
-        final File propsTest =
-            SystemPropertyManager.writePropertiesFile( props, forkConfiguration.getTempDirectory(), "propsTest", true );
+        final File propsTest = booterSerializer.serialize( props, booterConfiguration, testProviderConfiguration, aTest);
         BooterDeserializer booterDeserializer = new BooterDeserializer( new FileInputStream( propsTest ) );
         return booterDeserializer.deserialize();
     }

Modified: maven/surefire/trunk/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/BooterDeserializerStartupConfigurationTest.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/BooterDeserializerStartupConfigurationTest.java?rev=1374456&r1=1374455&r2=1374456&view=diff
==============================================================================
--- maven/surefire/trunk/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/BooterDeserializerStartupConfigurationTest.java (original)
+++ maven/surefire/trunk/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/BooterDeserializerStartupConfigurationTest.java Fri Aug 17 22:10:31 2012
@@ -79,7 +79,7 @@ public class BooterDeserializerStartupCo
     private Properties getPropertiesForClasspathConfiguration( ClasspathConfiguration configuration )
     {
         Properties properties = new Properties();
-        configuration.setForkProperties( new PropertiesWrapper( properties ) );
+        configuration.addForkProperties( new PropertiesWrapper( properties ) );
         return properties;
     }
 
@@ -128,11 +128,9 @@ public class BooterDeserializerStartupCo
     {
         final ForkConfiguration forkConfiguration = ForkConfigurationTest.getForkConfiguration( null, null );
         Properties props = new Properties();
-        BooterSerializer booterSerializer = new BooterSerializer( forkConfiguration, props );
+        BooterSerializer booterSerializer = new BooterSerializer( forkConfiguration );
         String aTest = "aTest";
-        booterSerializer.serialize( getProviderConfiguration(), startupConfiguration, aTest);
-        final File propsTest =
-            SystemPropertyManager.writePropertiesFile( props, forkConfiguration.getTempDirectory(), "propsTest", true );
+        final File propsTest  = booterSerializer.serialize( props, getProviderConfiguration(), startupConfiguration, aTest);
         BooterDeserializer booterDeserializer = new BooterDeserializer( new FileInputStream( propsTest ) );
         return booterDeserializer.getProviderConfiguration();
     }

Modified: maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ClasspathConfiguration.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ClasspathConfiguration.java?rev=1374456&r1=1374455&r2=1374456&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ClasspathConfiguration.java (original)
+++ maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ClasspathConfiguration.java Fri Aug 17 22:10:31 2012
@@ -77,7 +77,7 @@ public class ClasspathConfiguration
         this.surefireClasspathUrls = surefireClassPathUrls;
     }
 
-    public void setForkProperties( PropertiesWrapper properties )
+    public void addForkProperties( PropertiesWrapper properties )
     {
         properties.setClasspath( CLASSPATH, classpathUrls );
         properties.setClasspath( SUREFIRE_CLASSPATH, surefireClasspathUrls );