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/09 20:31:02 UTC

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

Author: krosenvold
Date: Thu Aug  9 18:31:02 2012
New Revision: 1371363

URL: http://svn.apache.org/viewvc?rev=1371363&view=rev
Log:
o Made forkConfiguration immutable, refactored away more mutable state

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/ForkConfiguration.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/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/ForkConfigurationTest.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=1371363&r1=1371362&r2=1371363&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 Thu Aug  9 18:31:02 2012
@@ -729,6 +729,12 @@ public abstract class AbstractSurefireMo
             else
             {
                 ForkConfiguration forkConfiguration = getForkConfiguration();
+                if ( getLog().isDebugEnabled() )
+                {
+                    showMap( getEnvironmentVariables(), "environment variable" );
+                }
+
+
                 Properties originalSystemProperties = (Properties) System.getProperties().clone();
                 try
                 {
@@ -1017,7 +1023,7 @@ public abstract class AbstractSurefireMo
             logClasspath( testClasspath, "test classpath" );
             logClasspath( providerClasspath, "provider classpath" );
             final ClasspathConfiguration classpathConfiguration =
-                new ClasspathConfiguration( testClasspath, providerClasspath, inprocClassPath, isEnableAssertions(),
+                new ClasspathConfiguration( testClasspath, providerClasspath, inprocClassPath, effectiveIsEnableAssertions(),
                                             isChildDelegation() );
 
             return new StartupConfiguration( providerName, classpathConfiguration, classLoaderConfiguration,
@@ -1238,45 +1244,19 @@ public abstract class AbstractSurefireMo
         final Classpath bootClasspathConfiguration =
             getArtifactClasspath( shadeFire != null ? shadeFire : surefireBooterArtifact );
 
-        ForkConfiguration fork = new ForkConfiguration( bootClasspathConfiguration, tmpDir );
-
-        setUseSystemClassLoader( isUseSystemClassLoader() );
-
-        fork.setDebugLine( getEffectiveDebugForkedProcess() );
-
-        fork.setJvmExecutable( getEffectiveJvm() );
-
-        fork.setWorkingDirectory( getWorkingDirectory() != null ? getWorkingDirectory() : getBasedir() );
-
-        fork.setArgLine( getArgLine() );
-
-        fork.setEnvironmentVariables( getEnvironmentVariables() );
+        ForkConfiguration fork =
+            new ForkConfiguration( bootClasspathConfiguration, tmpDir, getEffectiveDebugForkedProcess(),
+                                   getEffectiveJvm(),
+                                   getWorkingDirectory() != null ? getWorkingDirectory() : getBasedir(), getArgLine(),
+                                   getEnvironmentVariables(), getLog().isDebugEnabled(), getEffectiveForkCount() );
 
-        if ( getLog().isDebugEnabled() )
-        {
-            showMap( getEnvironmentVariables(), "environment variable" );
-
-            fork.setDebug( true );
-        }
+        return fork;
+    }
 
-        if ( getArgLine() != null )
-        {
-            List<String> args = Arrays.asList( getArgLine().split( " " ) );
-            if ( args.contains( "-da" ) || args.contains( "-disableassertions" ) )
-            {
-                setEnableAssertions( false );
-            }
-        }
 
-        if ( ForkConfiguration.FORK_PERTHREAD.equals( getEffectiveForkMode() ) )
-        {
-            fork.setThreadCount( getThreadCount() );
-        }
-        else
-        {
-            fork.setThreadCount( 1 );
-        }
-        return fork;
+    private int getEffectiveForkCount()
+    {
+        return ( ForkConfiguration.FORK_PERTHREAD.equals( getEffectiveForkMode() ) ) ? getThreadCount() : 1;
     }
 
     private String getEffectiveDebugForkedProcess()
@@ -1333,7 +1313,7 @@ public abstract class AbstractSurefireMo
     /**
      * Operates on raw plugin paramenters, not the "effective" values.
      *
-     * @return  The checksum
+     * @return The checksum
      */
     private String getConfigChecksum()
     {
@@ -2214,6 +2194,18 @@ public abstract class AbstractSurefireMo
         return enableAssertions;
     }
 
+    public boolean effectiveIsEnableAssertions(){
+        if ( getArgLine() != null )
+        {
+            List<String> args = Arrays.asList( getArgLine().split( " " ) );
+            if ( args.contains( "-da" ) || args.contains( "-disableassertions" ) )
+            {
+                return false;
+            }
+        }
+        return isEnableAssertions();
+    }
+
     @SuppressWarnings( "UnusedDeclaration" )
     public void setEnableAssertions( boolean enableAssertions )
     {

Modified: maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ForkConfiguration.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ForkConfiguration.java?rev=1371363&r1=1371362&r2=1371363&view=diff
==============================================================================
--- maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ForkConfiguration.java (original)
+++ maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ForkConfiguration.java Thu Aug  9 18:31:02 2012
@@ -54,28 +54,37 @@ public class ForkConfiguration
 
     public static final String FORK_PERTHREAD = "perthread";
 
-    private int threadCount;
+    private final int forkCount;
 
     private final Classpath bootClasspathConfiguration;
 
-    private String jvmExecutable;
+    private final String jvmExecutable;
 
-    private String argLine;
+    private final String argLine;
 
-    private Map<String, String> environmentVariables;
+    private final Map<String, String> environmentVariables;
 
-    private File workingDirectory;
+    private final File workingDirectory;
 
     private final File tempDirectory;
 
-    private boolean debug;
+    private final boolean debug;
 
-    private String debugLine;
+    private final String debugLine;
 
-    public ForkConfiguration(Classpath bootClasspathConfiguration, File tmpDir)
+    public ForkConfiguration( Classpath bootClasspathConfiguration, File tmpDir, String debugLine, String jvmExecutable,
+                              File workingDirectory, String argLine, Map<String, String> environmentVariables,
+                              boolean debugEnabled, int forkCount )
     {
         this.bootClasspathConfiguration = bootClasspathConfiguration;
         this.tempDirectory = tmpDir;
+        this.debugLine = debugLine;
+        this.jvmExecutable = jvmExecutable;
+        this.workingDirectory = workingDirectory;
+        this.argLine = argLine;
+        this.environmentVariables = environmentVariables;
+        this.debug = debugEnabled;
+        this.forkCount = forkCount;
     }
 
     public Classpath getBootClasspath()
@@ -104,31 +113,6 @@ public class ForkConfiguration
         }
     }
 
-    public void setJvmExecutable( String jvmExecutable )
-    {
-        this.jvmExecutable = jvmExecutable;
-    }
-
-    public void setArgLine( String argLine )
-    {
-        this.argLine = argLine;
-    }
-
-    public void setDebugLine( String debugLine )
-    {
-        this.debugLine = debugLine;
-    }
-
-    public void setEnvironmentVariables( Map<String, String> environmentVariables )
-    {
-        this.environmentVariables = new HashMap<String, String>( environmentVariables );
-    }
-
-    public void setWorkingDirectory( File workingDirectory )
-    {
-        this.workingDirectory = workingDirectory;
-    }
-
 
     /**
      * @param classPath              cla the classpath arguments
@@ -246,11 +230,6 @@ public class ForkConfiguration
         return file;
     }
 
-    public void setDebug( boolean debug )
-    {
-        this.debug = debug;
-    }
-
     public boolean isDebug()
     {
         return debug;
@@ -266,19 +245,13 @@ public class ForkConfiguration
         return debugLine;
     }
 
-
     public File getTempDirectory()
     {
         return tempDirectory;
     }
 
-    public int getThreadCount()
-    {
-        return threadCount;
-    }
-
-    public void setThreadCount( int threadCount )
+    public int getForkCount()
     {
-        this.threadCount = threadCount;
+        return forkCount;
     }
 }

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=1371363&r1=1371362&r2=1371363&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 Thu Aug  9 18:31:02 2012
@@ -123,7 +123,7 @@ public class ForkStarter
             }
             else if ( ForkConfiguration.FORK_PERTHREAD.equals( requestedForkMode ) )
             {
-                result = runSuitesForkPerTestSet( providerProperties, forkConfiguration.getThreadCount() );
+                result = runSuitesForkPerTestSet( providerProperties, forkConfiguration.getForkCount() );
             }
             else
             {

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=1371363&r1=1371362&r2=1371363&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 Thu Aug  9 18:31:02 2012
@@ -170,7 +170,7 @@ public class BooterDeserializerProviderC
                                                  StartupConfiguration testProviderConfiguration )
         throws IOException
     {
-        final ForkConfiguration forkConfiguration = ForkConfigurationTest.getForkConfiguration();
+        final ForkConfiguration forkConfiguration = ForkConfigurationTest.getForkConfiguration( null, null );
         Properties props = new Properties();
         BooterSerializer booterSerializer = new BooterSerializer( forkConfiguration, props );
         String aTest = "aTest";

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=1371363&r1=1371362&r2=1371363&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 Thu Aug  9 18:31:02 2012
@@ -126,7 +126,7 @@ public class BooterDeserializerStartupCo
     private StartupConfiguration saveAndReload( StartupConfiguration startupConfiguration )
         throws IOException
     {
-        final ForkConfiguration forkConfiguration = ForkConfigurationTest.getForkConfiguration();
+        final ForkConfiguration forkConfiguration = ForkConfigurationTest.getForkConfiguration( null, null );
         Properties props = new Properties();
         BooterSerializer booterSerializer = new BooterSerializer( forkConfiguration, props );
         String aTest = "aTest";

Modified: maven/surefire/trunk/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/ForkConfigurationTest.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/ForkConfigurationTest.java?rev=1371363&r1=1371362&r2=1371363&view=diff
==============================================================================
--- maven/surefire/trunk/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/ForkConfigurationTest.java (original)
+++ maven/surefire/trunk/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/ForkConfigurationTest.java Thu Aug  9 18:31:02 2012
@@ -36,15 +36,14 @@ public class ForkConfigurationTest
     public void testCreateCommandLine_UseSystemClassLoaderForkOnce_ShouldConstructManifestOnlyJar()
         throws IOException, SurefireBooterForkException
     {
-        ForkConfiguration config = getForkConfiguration();
+        ForkConfiguration config = getForkConfiguration(null, "java");
         File cpElement = getTempClasspathFile();
-        config.setJvmExecutable( "java" );
 
         Commandline cli =
             config.createCommandLine( Collections.singletonList( cpElement.getAbsolutePath() ), true, false );
 
         String line = StringUtils.join( cli.getCommandline(), " " );
-        assertTrue( line.indexOf( "-jar" ) > -1 );
+        assertTrue( line.contains( "-jar" ) );
     }
 
     public void testArglineWithNewline()
@@ -52,9 +51,7 @@ public class ForkConfigurationTest
     {
         // SUREFIRE-657
         File cpElement = getTempClasspathFile();
-        ForkConfiguration forkConfiguration = getForkConfiguration();
-
-        forkConfiguration.setArgLine( "abc\ndef" );
+        ForkConfiguration forkConfiguration = getForkConfiguration("abc\ndef", null );
 
         final Commandline commandLine =
             forkConfiguration.createCommandLine( Collections.singletonList( cpElement.getAbsolutePath() ), false,
@@ -70,12 +67,12 @@ public class ForkConfigurationTest
         return cpElement;
     }
 
-    public static ForkConfiguration getForkConfiguration()
+    public static ForkConfiguration getForkConfiguration( String argLine, String jvm )
         throws IOException
     {
         ForkConfiguration forkConfiguration =
-            new ForkConfiguration( new Classpath(), null );
-        forkConfiguration.setWorkingDirectory( new File( "." ).getCanonicalFile() );
+            new ForkConfiguration( new Classpath(), null, null, jvm, new File( "." ).getCanonicalFile() ,
+                                   argLine, null, false, 1 );
         return forkConfiguration;
     }