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 2011/11/20 23:22:25 UTC
svn commit: r1204285 - 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/
surefire-api/src/main/java/org/apache/maven/surefi...
Author: krosenvold
Date: Sun Nov 20 22:22:25 2011
New Revision: 1204285
URL: http://svn.apache.org/viewvc?rev=1204285&view=rev
Log:
o Refactored slightly to split InProcess/Forked creation. Also tried to move reporting further out of the fork.
This area of the code still needs a lot more work
Added:
maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/CommonReflector.java (with props)
maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/InPluginVMSurefireStarter.java (with props)
maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/StarterCommon.java
- copied, changed from r1203992, maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/SurefireStarter.java
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/ForkStarter.java
maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/booter/BaseProviderFactory.java
maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/booter/SurefireReflector.java
maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/util/ReflectionUtils.java
maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ProviderFactory.java
maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/SurefireStarter.java
maven/surefire/trunk/surefire-providers/surefire-junit4/src/test/java/org/apache/maven/surefire/junit4/JUnit4ProviderTest.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=1204285&r1=1204284&r2=1204285&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 Sun Nov 20 22:22:25 2011
@@ -33,7 +33,6 @@ import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
-
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
@@ -59,7 +58,6 @@ import org.apache.maven.surefire.booter.
import org.apache.maven.surefire.booter.StartupReportConfiguration;
import org.apache.maven.surefire.booter.SurefireBooterForkException;
import org.apache.maven.surefire.booter.SurefireExecutionException;
-import org.apache.maven.surefire.booter.SurefireStarter;
import org.apache.maven.surefire.report.ReporterConfiguration;
import org.apache.maven.surefire.suite.RunResult;
import org.apache.maven.surefire.testset.DirectoryScannerParameters;
@@ -190,7 +188,7 @@ public abstract class AbstractSurefireMo
final RunResult result;
if ( ForkConfiguration.FORK_NEVER.equals( forkConfiguration.getForkMode() ) )
{
- SurefireStarter surefireStarter =
+ InPluginVMSurefireStarter surefireStarter =
createInprocessStarter( provider, forkConfiguration, classLoaderConfiguration );
result = surefireStarter.runSuitesInProcess();
}
@@ -571,7 +569,7 @@ public abstract class AbstractSurefireMo
getForkedProcessTimeoutInSeconds(), startupReportConfiguration );
}
- protected SurefireStarter createInprocessStarter( ProviderInfo provider, ForkConfiguration forkConfiguration,
+ protected InPluginVMSurefireStarter createInprocessStarter( ProviderInfo provider, ForkConfiguration forkConfiguration,
ClassLoaderConfiguration classLoaderConfiguration )
throws MojoExecutionException, MojoFailureException
{
@@ -579,7 +577,7 @@ public abstract class AbstractSurefireMo
createStartupConfiguration( forkConfiguration, provider, classLoaderConfiguration );
StartupReportConfiguration startupReportConfiguration = getStartupReportConfiguration();
ProviderConfiguration providerConfiguration = createProviderConfiguration();
- return new SurefireStarter( startupConfiguration, providerConfiguration, startupReportConfiguration );
+ return new InPluginVMSurefireStarter( startupConfiguration, providerConfiguration, startupReportConfiguration );
}
Added: maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/CommonReflector.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/CommonReflector.java?rev=1204285&view=auto
==============================================================================
--- maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/CommonReflector.java (added)
+++ maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/CommonReflector.java Sun Nov 20 22:22:25 2011
@@ -0,0 +1,81 @@
+package org.apache.maven.plugin.surefire;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.File;
+import java.lang.reflect.Constructor;
+import org.apache.maven.plugin.surefire.report.FileReporterFactory;
+import org.apache.maven.surefire.booter.StartupReportConfiguration;
+import org.apache.maven.surefire.util.ReflectionUtils;
+import org.apache.maven.surefire.util.SurefireReflectionException;
+
+/**
+ * @author Kristian Rosenvold
+ */
+public class CommonReflector
+{
+ private final Class startupReportConfiguration;
+
+ private final ClassLoader surefireClassLoader;
+
+ public CommonReflector( ClassLoader surefireClassLoader )
+ {
+ this.surefireClassLoader = surefireClassLoader;
+
+ try
+ {
+ startupReportConfiguration = surefireClassLoader.loadClass( StartupReportConfiguration.class.getName() );
+ }
+ catch ( ClassNotFoundException e )
+ {
+ throw new SurefireReflectionException( e );
+ }
+ }
+
+ public Object createReportingReporterFactory( StartupReportConfiguration startupReportConfiguration )
+ {
+ Class[] args =
+ new Class[]{ this.startupReportConfiguration };
+ Object src = createStartupReportConfiguration( startupReportConfiguration );
+ Object[] params = new Object[]{ src };
+ return ReflectionUtils.instantiateObject( FileReporterFactory.class.getName(), args,
+ params, surefireClassLoader );
+ }
+
+
+ Object createStartupReportConfiguration( StartupReportConfiguration reporterConfiguration )
+ {
+ Constructor constructor = ReflectionUtils.getConstructor( this.startupReportConfiguration,
+ new Class[]{ boolean.class, boolean.class,
+ String.class, boolean.class, boolean.class,
+ File.class, boolean.class, String.class } );
+ //noinspection BooleanConstructorCall
+ final Object[] params =
+ { new Boolean( reporterConfiguration.isUseFile() ), new Boolean( reporterConfiguration.isPrintSummary() ),
+ reporterConfiguration.getReportFormat(),
+ new Boolean( reporterConfiguration.isRedirectTestOutputToFile() ),
+ new Boolean( reporterConfiguration.isDisableXmlReport() ),
+ reporterConfiguration.getReportsDirectory(),
+ new Boolean( reporterConfiguration.isTrimStackTrace()),
+ reporterConfiguration.getReportNameSuffix()};
+ return ReflectionUtils.newInstance( constructor, params );
+ }
+
+}
Propchange: maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/CommonReflector.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/InPluginVMSurefireStarter.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/InPluginVMSurefireStarter.java?rev=1204285&view=auto
==============================================================================
--- maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/InPluginVMSurefireStarter.java (added)
+++ maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/InPluginVMSurefireStarter.java Sun Nov 20 22:22:25 2011
@@ -0,0 +1,73 @@
+package org.apache.maven.plugin.surefire;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.maven.surefire.booter.ProviderConfiguration;
+import org.apache.maven.surefire.booter.StarterCommon;
+import org.apache.maven.surefire.booter.StartupConfiguration;
+import org.apache.maven.surefire.booter.StartupReportConfiguration;
+import org.apache.maven.surefire.booter.SurefireExecutionException;
+import org.apache.maven.surefire.suite.RunResult;
+
+/**
+ * Starts the provider in the same VM as the surefire plugin.
+ * <p/>
+ * This part of the booter is always guaranteed to be in the
+ * same vm as the tests will be run in.
+ *
+ * @author Jason van Zyl
+ * @author Brett Porter
+ * @author Emmanuel Venisse
+ * @author Dan Fabulich
+ * @author Kristian Rosenvold
+ * @version $Id$
+ */
+public class InPluginVMSurefireStarter
+{
+
+ private final StartupReportConfiguration startupReportConfiguration;
+
+ private final StarterCommon starterCommon;
+
+ public InPluginVMSurefireStarter( StartupConfiguration startupConfiguration,
+ ProviderConfiguration providerConfiguration,
+ StartupReportConfiguration startupReportConfiguration )
+ {
+ this.startupReportConfiguration = startupReportConfiguration;
+ this.starterCommon = new StarterCommon( startupConfiguration, providerConfiguration );
+ }
+
+ public RunResult runSuitesInProcess()
+ throws SurefireExecutionException
+ {
+ // The test classloader must be constructed first to avoid issues with commons-logging until we properly
+ // separate the TestNG classloader
+ ClassLoader testsClassLoader = starterCommon.createInProcessTestClassLoader();
+
+ ClassLoader surefireClassLoader = starterCommon.createSurefireClassloader( testsClassLoader );
+
+ CommonReflector surefireReflector = new CommonReflector( surefireClassLoader );
+
+ final Object factory = surefireReflector.createReportingReporterFactory( startupReportConfiguration );
+
+ return starterCommon.invokeProvider( null, testsClassLoader, surefireClassLoader, factory, false );
+ }
+
+}
Propchange: maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/InPluginVMSurefireStarter.java
------------------------------------------------------------------------------
svn:eol-style = native
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=1204285&r1=1204284&r2=1204285&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 Sun Nov 20 22:22:25 2011
@@ -23,6 +23,7 @@ import java.io.File;
import java.io.IOException;
import java.util.Iterator;
import java.util.Properties;
+import org.apache.maven.plugin.surefire.CommonReflector;
import org.apache.maven.plugin.surefire.booterclient.output.ForkClient;
import org.apache.maven.plugin.surefire.booterclient.output.ThreadedStreamConsumer;
import org.apache.maven.plugin.surefire.report.FileReporterFactory;
@@ -34,7 +35,6 @@ import org.apache.maven.surefire.booter.
import org.apache.maven.surefire.booter.StartupReportConfiguration;
import org.apache.maven.surefire.booter.SurefireBooterForkException;
import org.apache.maven.surefire.booter.SurefireExecutionException;
-import org.apache.maven.surefire.booter.SurefireReflector;
import org.apache.maven.surefire.booter.SystemPropertyManager;
import org.apache.maven.surefire.providerapi.SurefireProvider;
import org.apache.maven.surefire.report.ReporterFactory;
@@ -220,13 +220,13 @@ public class ForkStarter
ClassLoader testsClassLoader = classpathConfiguration.createTestClassLoader( false );
ClassLoader surefireClassLoader = classpathConfiguration.createSurefireClassLoader( testsClassLoader );
- SurefireReflector surefireReflector = new SurefireReflector( surefireClassLoader );
- Object reporterFactory = surefireReflector.createReportingReporterFactory( startupReportConfiguration );
+ CommonReflector commonReflector = new CommonReflector( surefireClassLoader );
+ Object reporterFactory = commonReflector.createReportingReporterFactory( startupReportConfiguration );
final ProviderFactory providerFactory =
new ProviderFactory( startupConfiguration, providerConfiguration, surefireClassLoader, testsClassLoader,
reporterFactory );
- SurefireProvider surefireProvider = providerFactory.createProvider();
+ SurefireProvider surefireProvider = providerFactory.createProvider(false);
return surefireProvider.getSuites();
}
catch ( SurefireExecutionException e )
@@ -235,4 +235,6 @@ public class ForkStarter
}
}
+
+
}
Modified: maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/booter/BaseProviderFactory.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/booter/BaseProviderFactory.java?rev=1204285&r1=1204284&r2=1204285&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/booter/BaseProviderFactory.java (original)
+++ maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/booter/BaseProviderFactory.java Sun Nov 20 22:22:25 2011
@@ -20,7 +20,6 @@ package org.apache.maven.surefire.booter
*/
import java.util.Properties;
-import org.apache.maven.plugin.surefire.report.FileReporterFactory;
import org.apache.maven.surefire.providerapi.ProviderParameters;
import org.apache.maven.surefire.report.ConsoleLogger;
import org.apache.maven.surefire.report.DefaultDirectConsoleReporter;
@@ -59,9 +58,12 @@ public class BaseProviderFactory
private final ReporterFactory reporterFactory;
- public BaseProviderFactory( ReporterFactory reporterFactory )
+ private final boolean insideFork;
+
+ public BaseProviderFactory( ReporterFactory reporterFactory, Boolean insideFork )
{
this.reporterFactory = reporterFactory;
+ this.insideFork = insideFork.booleanValue();
}
public DirectoryScanner getDirectoryScanner()
@@ -106,13 +108,12 @@ public class BaseProviderFactory
public ConsoleLogger getConsoleLogger()
{
- // Maybe a somewhat odd way to determine if we're forking
- if ( getReporterFactory() instanceof FileReporterFactory )
+ if ( insideFork )
{
- return new DefaultDirectConsoleReporter( reporterConfiguration.getOriginalSystemOut() );
+ return new ForkingRunListener( reporterConfiguration.getOriginalSystemOut(), ROOT_CHANNEl.intValue(),
+ reporterConfiguration.isTrimStackTrace().booleanValue() );
}
- return new ForkingRunListener( reporterConfiguration.getOriginalSystemOut(), ROOT_CHANNEl.intValue(),
- reporterConfiguration.isTrimStackTrace().booleanValue() );
+ return new DefaultDirectConsoleReporter( reporterConfiguration.getOriginalSystemOut() );
}
public void setTestRequest( TestRequest testRequest )
Modified: maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/booter/SurefireReflector.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/booter/SurefireReflector.java?rev=1204285&r1=1204284&r2=1204285&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/booter/SurefireReflector.java (original)
+++ maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/booter/SurefireReflector.java Sun Nov 20 22:22:25 2011
@@ -26,8 +26,6 @@ import java.lang.reflect.InvocationHandl
import java.lang.reflect.Method;
import java.util.List;
import java.util.Properties;
-
-import org.apache.maven.plugin.surefire.report.FileReporterFactory;
import org.apache.maven.surefire.providerapi.ProviderParameters;
import org.apache.maven.surefire.report.ReporterConfiguration;
import org.apache.maven.surefire.report.ReporterFactory;
@@ -36,7 +34,6 @@ import org.apache.maven.surefire.testset
import org.apache.maven.surefire.testset.TestArtifactInfo;
import org.apache.maven.surefire.testset.TestRequest;
import org.apache.maven.surefire.util.ReflectionUtils;
-import org.apache.maven.surefire.util.RunOrder;
import org.apache.maven.surefire.util.SurefireReflectionException;
/**
@@ -76,15 +73,12 @@ public class SurefireReflector
private final Class reporterFactory;
- private final Class startupReportConfiguration;
-
public SurefireReflector( ClassLoader surefireClassLoader )
{
this.surefireClassLoader = surefireClassLoader;
try
{
reporterConfiguration = surefireClassLoader.loadClass( ReporterConfiguration.class.getName() );
- startupReportConfiguration = surefireClassLoader.loadClass( StartupReportConfiguration.class.getName() );
testRequest = surefireClassLoader.loadClass( TestRequest.class.getName() );
testArtifactInfo = surefireClassLoader.loadClass( TestArtifactInfo.class.getName() );
testArtifactInfoAware = surefireClassLoader.loadClass( TestArtifactInfoAware.class.getName() );
@@ -199,24 +193,6 @@ public class SurefireReflector
reporterConfiguration.isTrimStackTrace()} );
}
- Object createStartupReportConfiguration( StartupReportConfiguration reporterConfiguration )
- {
- Constructor constructor = ReflectionUtils.getConstructor( this.startupReportConfiguration,
- new Class[]{ boolean.class, boolean.class,
- String.class, boolean.class, boolean.class,
- File.class, boolean.class, String.class } );
- //noinspection BooleanConstructorCall
- final Object[] params =
- { new Boolean( reporterConfiguration.isUseFile() ), new Boolean( reporterConfiguration.isPrintSummary() ),
- reporterConfiguration.getReportFormat(),
- new Boolean( reporterConfiguration.isRedirectTestOutputToFile() ),
- new Boolean( reporterConfiguration.isDisableXmlReport() ),
- reporterConfiguration.getReportsDirectory(),
- new Boolean( reporterConfiguration.isTrimStackTrace()),
- reporterConfiguration.getReportNameSuffix()};
- return ReflectionUtils.newInstance( constructor, params );
- }
-
public Object createForkingReporterFactory( Boolean trimStackTrace, PrintStream originalSystemOut )
{
Class[] args = new Class[]{ Boolean.class, PrintStream.class };
@@ -225,21 +201,12 @@ public class SurefireReflector
surefireClassLoader );
}
- public Object createReportingReporterFactory( StartupReportConfiguration startupReportConfiguration )
- {
- Class[] args =
- new Class[]{ this.startupReportConfiguration };
- Object src = createStartupReportConfiguration( startupReportConfiguration );
- Object[] params = new Object[]{ src };
- return ReflectionUtils.instantiateObject( FileReporterFactory.class.getName(), args, params,
- surefireClassLoader );
-
- }
-
- public Object createBooterConfiguration( ClassLoader surefireClassLoader, Object factoryInstance )
+ public Object createBooterConfiguration( ClassLoader surefireClassLoader, Object factoryInstance,
+ boolean insideFork )
{
- return ReflectionUtils.instantiateOneArg( surefireClassLoader, BaseProviderFactory.class.getName(),
- reporterFactory, factoryInstance );
+ return ReflectionUtils.instantiateTwoArgs( surefireClassLoader, BaseProviderFactory.class.getName(),
+ reporterFactory, factoryInstance, Boolean.class,
+ insideFork ? Boolean.TRUE : Boolean.FALSE );
}
public Object instantiateProvider( String providerClassName, Object booterParameters )
Modified: maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/util/ReflectionUtils.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/util/ReflectionUtils.java?rev=1204285&r1=1204284&r2=1204285&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/util/ReflectionUtils.java (original)
+++ maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/util/ReflectionUtils.java Sun Nov 20 22:22:25 2011
@@ -142,7 +142,31 @@ public class ReflectionUtils
throw new SurefireReflectionException( e );
}
}
+ public static Object instantiateTwoArgs( ClassLoader classLoader, String className, Class param1Class,
+ Object param1, Class param2Class, Object param2 )
+ {
+ try
+ {
+ Class aClass = loadClass( classLoader, className );
+ Constructor constructor = ReflectionUtils.getConstructor( aClass, new Class[]{ param1Class, param2Class } );
+ return constructor.newInstance( new Object[]{ param1, param2 } );
+ }
+ catch ( InvocationTargetException e )
+ {
+ throw new SurefireReflectionException( e );
+ }
+ catch ( InstantiationException e )
+ {
+ throw new SurefireReflectionException( e );
+ }
+ catch ( IllegalAccessException e )
+ {
+ throw new SurefireReflectionException( e );
+ }
+ }
+
+
public static void invokeSetter( Object o, String name, Class value1clazz, Object value )
{
Modified: maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ProviderFactory.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ProviderFactory.java?rev=1204285&r1=1204284&r2=1204285&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ProviderFactory.java (original)
+++ maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ProviderFactory.java Sun Nov 20 22:22:25 2011
@@ -63,14 +63,15 @@ public class ProviderFactory
this.reporterManagerFactory = reporterManagerFactory;
}
- public SurefireProvider createProvider()
+ public SurefireProvider createProvider(boolean isInsideFork)
{
ClassLoader context = java.lang.Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader( surefireClassLoader );
StartupConfiguration starterConfiguration = startupConfiguration;
- final Object o = surefireReflector.createBooterConfiguration( surefireClassLoader, reporterManagerFactory );
+ final Object o = surefireReflector.createBooterConfiguration( surefireClassLoader, reporterManagerFactory,
+ isInsideFork );
surefireReflector.setTestSuiteDefinitionAware( o, providerConfiguration.getTestSuiteDefinition() );
surefireReflector.setProviderPropertiesAware( o, providerConfiguration.getProviderProperties() );
surefireReflector.setReporterConfigurationAware( o, providerConfiguration.getReporterConfiguration() );
Copied: maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/StarterCommon.java (from r1203992, maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/SurefireStarter.java)
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/StarterCommon.java?p2=maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/StarterCommon.java&p1=maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/SurefireStarter.java&r1=1203992&r2=1204285&rev=1204285&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/SurefireStarter.java (original)
+++ maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/StarterCommon.java Sun Nov 20 22:22:25 2011
@@ -25,7 +25,6 @@ import org.apache.maven.surefire.report.
import org.apache.maven.surefire.suite.RunResult;
import org.apache.maven.surefire.testset.TestSetFailedException;
import org.apache.maven.surefire.util.NestedRuntimeException;
-import org.apache.maven.surefire.util.ReflectionUtils;
/**
* Invokes surefire with the correct classloader setup.
@@ -40,7 +39,7 @@ import org.apache.maven.surefire.util.Re
* @author Kristian Rosenvold
* @version $Id$
*/
-public class SurefireStarter
+public class StarterCommon
{
private final ProviderConfiguration providerConfiguration;
@@ -48,82 +47,13 @@ public class SurefireStarter
private final static String SUREFIRE_TEST_CLASSPATH = "surefire.test.class.path";
- private final StartupReportConfiguration startupReportConfiguration;
-
- public SurefireStarter( StartupConfiguration startupConfiguration, ProviderConfiguration providerConfiguration,
- StartupReportConfiguration startupReportConfiguration )
+ public StarterCommon( StartupConfiguration startupConfiguration, ProviderConfiguration providerConfiguration )
{
this.providerConfiguration = providerConfiguration;
this.startupConfiguration = startupConfiguration;
- this.startupReportConfiguration = startupReportConfiguration;
- }
-
- public RunResult runSuitesInProcessWhenForked( TypeEncodedValue testSet )
- throws SurefireExecutionException
- {
- writeSurefireTestClasspathProperty();
- final ClasspathConfiguration classpathConfiguration = startupConfiguration.getClasspathConfiguration();
-
- // todo: Find out....
- // Why is the classloader structure created differently when a testSet is specified ?
- // Smells like a legacy bug. Need to check issue tracker.
- ClassLoader testsClassLoader = classpathConfiguration.createTestClassLoaderConditionallySystem(
- startupConfiguration.useSystemClassLoader() );
-
- ClassLoader surefireClassLoader = classpathConfiguration.createSurefireClassLoader( testsClassLoader );
-
- SurefireReflector surefireReflector = new SurefireReflector( surefireClassLoader );
-
- final Object forkingReporterFactory = createForkingReporterFactory( surefireReflector );
-
- Object test = testSet.getDecodedValue();
-
- return invokeProvider( test, testsClassLoader, surefireClassLoader, forkingReporterFactory );
- }
-
- private Object createForkingReporterFactory( SurefireReflector surefireReflector )
- {
- final Boolean trimStackTrace = this.providerConfiguration.getReporterConfiguration().isTrimStackTrace();
- final PrintStream originalSystemOut =
- this.providerConfiguration.getReporterConfiguration().getOriginalSystemOut();
- return surefireReflector.createForkingReporterFactory( trimStackTrace, originalSystemOut );
- }
-
- // todo: Fix duplication in this method and runSuitesInProcess
- // This should be fixed "at a higher level", because this whole way
- // of organizing the code stinks.
-
- public RunResult runSuitesInProcessWhenForked()
- throws SurefireExecutionException
- {
- ClassLoader testsClassLoader = createInProcessTestClassLoader();
-
- ClassLoader surefireClassLoader = createSurefireClassloader( testsClassLoader );
-
- SurefireReflector surefireReflector = new SurefireReflector( surefireClassLoader );
-
- final Object factory = createForkingReporterFactory( surefireReflector );
-
- return invokeProvider( null, testsClassLoader, surefireClassLoader, factory );
- }
-
- public RunResult runSuitesInProcess()
- throws SurefireExecutionException
- {
- // The test classloader must be constructed first to avoid issues with commons-logging until we properly
- // separate the TestNG classloader
- ClassLoader testsClassLoader = createInProcessTestClassLoader();
-
- ClassLoader surefireClassLoader = createSurefireClassloader( testsClassLoader );
-
- SurefireReflector surefireReflector = new SurefireReflector( surefireClassLoader );
-
- final Object factory = surefireReflector.createReportingReporterFactory( startupReportConfiguration );
-
- return invokeProvider( null, testsClassLoader, surefireClassLoader, factory );
}
- private ClassLoader createSurefireClassloader( ClassLoader testsClassLoader )
+ public ClassLoader createSurefireClassloader( ClassLoader testsClassLoader )
throws SurefireExecutionException
{
final ClasspathConfiguration classpathConfiguration = startupConfiguration.getClasspathConfiguration();
@@ -131,7 +61,7 @@ public class SurefireStarter
return classpathConfiguration.createSurefireClassLoader( testsClassLoader );
}
- private ClassLoader createInProcessTestClassLoader()
+ public ClassLoader createInProcessTestClassLoader()
throws SurefireExecutionException
{
writeSurefireTestClasspathProperty();
@@ -151,14 +81,14 @@ public class SurefireStarter
}
}
- private void writeSurefireTestClasspathProperty()
+ public void writeSurefireTestClasspathProperty()
{
ClasspathConfiguration classpathConfiguration = startupConfiguration.getClasspathConfiguration();
classpathConfiguration.getTestClasspath().writeToSystemProperty( SUREFIRE_TEST_CLASSPATH );
}
- private RunResult invokeProvider( Object testSet, ClassLoader testsClassLoader, ClassLoader surefireClassLoader,
- Object factory )
+ public RunResult invokeProvider( Object testSet, ClassLoader testsClassLoader, ClassLoader surefireClassLoader,
+ Object factory, boolean insideFork )
{
final PrintStream orgSystemOut = System.out;
final PrintStream orgSystemErr = System.err;
@@ -168,7 +98,7 @@ public class SurefireStarter
ProviderFactory providerFactory =
new ProviderFactory( startupConfiguration, providerConfiguration, surefireClassLoader, testsClassLoader,
factory );
- final SurefireProvider provider = providerFactory.createProvider();
+ final SurefireProvider provider = providerFactory.createProvider( insideFork );
try
{
Modified: maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/SurefireStarter.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/SurefireStarter.java?rev=1204285&r1=1204284&r2=1204285&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/SurefireStarter.java (original)
+++ maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/SurefireStarter.java Sun Nov 20 22:22:25 2011
@@ -20,15 +20,10 @@ package org.apache.maven.surefire.booter
*/
import java.io.PrintStream;
-import org.apache.maven.surefire.providerapi.SurefireProvider;
-import org.apache.maven.surefire.report.ReporterException;
import org.apache.maven.surefire.suite.RunResult;
-import org.apache.maven.surefire.testset.TestSetFailedException;
-import org.apache.maven.surefire.util.NestedRuntimeException;
-import org.apache.maven.surefire.util.ReflectionUtils;
/**
- * Invokes surefire with the correct classloader setup.
+ * Invokes surefire with the correct classloader setup. This class covers all startups in forked VM's.
* <p/>
* This part of the booter is always guaranteed to be in the
* same vm as the tests will be run in.
@@ -46,22 +41,20 @@ public class SurefireStarter
private final StartupConfiguration startupConfiguration;
- private final static String SUREFIRE_TEST_CLASSPATH = "surefire.test.class.path";
-
- private final StartupReportConfiguration startupReportConfiguration;
+ private final StarterCommon starterCommon;
public SurefireStarter( StartupConfiguration startupConfiguration, ProviderConfiguration providerConfiguration,
StartupReportConfiguration startupReportConfiguration )
{
this.providerConfiguration = providerConfiguration;
this.startupConfiguration = startupConfiguration;
- this.startupReportConfiguration = startupReportConfiguration;
+ this.starterCommon = new StarterCommon( startupConfiguration, providerConfiguration );
}
public RunResult runSuitesInProcessWhenForked( TypeEncodedValue testSet )
throws SurefireExecutionException
{
- writeSurefireTestClasspathProperty();
+ starterCommon.writeSurefireTestClasspathProperty();
final ClasspathConfiguration classpathConfiguration = startupConfiguration.getClasspathConfiguration();
// todo: Find out....
@@ -78,7 +71,7 @@ public class SurefireStarter
Object test = testSet.getDecodedValue();
- return invokeProvider( test, testsClassLoader, surefireClassLoader, forkingReporterFactory );
+ return starterCommon.invokeProvider( test, testsClassLoader, surefireClassLoader, forkingReporterFactory, true );
}
private Object createForkingReporterFactory( SurefireReflector surefireReflector )
@@ -96,99 +89,15 @@ public class SurefireStarter
public RunResult runSuitesInProcessWhenForked()
throws SurefireExecutionException
{
- ClassLoader testsClassLoader = createInProcessTestClassLoader();
+ ClassLoader testsClassLoader = starterCommon.createInProcessTestClassLoader();
- ClassLoader surefireClassLoader = createSurefireClassloader( testsClassLoader );
+ ClassLoader surefireClassLoader = starterCommon.createSurefireClassloader( testsClassLoader );
SurefireReflector surefireReflector = new SurefireReflector( surefireClassLoader );
final Object factory = createForkingReporterFactory( surefireReflector );
- return invokeProvider( null, testsClassLoader, surefireClassLoader, factory );
+ return starterCommon.invokeProvider( null, testsClassLoader, surefireClassLoader, factory, true );
}
- public RunResult runSuitesInProcess()
- throws SurefireExecutionException
- {
- // The test classloader must be constructed first to avoid issues with commons-logging until we properly
- // separate the TestNG classloader
- ClassLoader testsClassLoader = createInProcessTestClassLoader();
-
- ClassLoader surefireClassLoader = createSurefireClassloader( testsClassLoader );
-
- SurefireReflector surefireReflector = new SurefireReflector( surefireClassLoader );
-
- final Object factory = surefireReflector.createReportingReporterFactory( startupReportConfiguration );
-
- return invokeProvider( null, testsClassLoader, surefireClassLoader, factory );
- }
-
- private ClassLoader createSurefireClassloader( ClassLoader testsClassLoader )
- throws SurefireExecutionException
- {
- final ClasspathConfiguration classpathConfiguration = startupConfiguration.getClasspathConfiguration();
-
- return classpathConfiguration.createSurefireClassLoader( testsClassLoader );
- }
-
- private ClassLoader createInProcessTestClassLoader()
- throws SurefireExecutionException
- {
- writeSurefireTestClasspathProperty();
- ClasspathConfiguration classpathConfiguration = startupConfiguration.getClasspathConfiguration();
- if ( startupConfiguration.isManifestOnlyJarRequestedAndUsable() )
- {
- ClassLoader testsClassLoader = getClass().getClassLoader(); // ClassLoader.getSystemClassLoader()
- // SUREFIRE-459, trick the app under test into thinking its classpath was conventional
- // (instead of a single manifest-only jar)
- System.setProperty( "surefire.real.class.path", System.getProperty( "java.class.path" ) );
- classpathConfiguration.getTestClasspath().writeToSystemProperty( "java.class.path" );
- return testsClassLoader;
- }
- else
- {
- return classpathConfiguration.createTestClassLoader();
- }
- }
-
- private void writeSurefireTestClasspathProperty()
- {
- ClasspathConfiguration classpathConfiguration = startupConfiguration.getClasspathConfiguration();
- classpathConfiguration.getTestClasspath().writeToSystemProperty( SUREFIRE_TEST_CLASSPATH );
- }
-
- private RunResult invokeProvider( Object testSet, ClassLoader testsClassLoader, ClassLoader surefireClassLoader,
- Object factory )
- {
- final PrintStream orgSystemOut = System.out;
- final PrintStream orgSystemErr = System.err;
- // Note that System.out/System.err are also read in the "ReporterConfiguration" instatiation
- // in createProvider below. These are the same values as here.
-
- ProviderFactory providerFactory =
- new ProviderFactory( startupConfiguration, providerConfiguration, surefireClassLoader, testsClassLoader,
- factory );
- final SurefireProvider provider = providerFactory.createProvider();
-
- try
- {
- return provider.invoke( testSet );
- }
- catch ( TestSetFailedException e )
- {
- throw new NestedRuntimeException( e );
- }
- catch ( ReporterException e )
- {
- throw new NestedRuntimeException( e );
- }
- finally
- {
- if ( System.getSecurityManager() == null )
- {
- System.setOut( orgSystemOut );
- System.setErr( orgSystemErr );
- }
- }
- }
}
Modified: maven/surefire/trunk/surefire-providers/surefire-junit4/src/test/java/org/apache/maven/surefire/junit4/JUnit4ProviderTest.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-providers/surefire-junit4/src/test/java/org/apache/maven/surefire/junit4/JUnit4ProviderTest.java?rev=1204285&r1=1204284&r2=1204285&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-providers/surefire-junit4/src/test/java/org/apache/maven/surefire/junit4/JUnit4ProviderTest.java (original)
+++ maven/surefire/trunk/surefire-providers/surefire-junit4/src/test/java/org/apache/maven/surefire/junit4/JUnit4ProviderTest.java Sun Nov 20 22:22:25 2011
@@ -32,7 +32,7 @@ public class JUnit4ProviderTest
extends TestCase
{
public void testCreateProvider(){
- BaseProviderFactory providerParameters = new BaseProviderFactory(null);
+ BaseProviderFactory providerParameters = new BaseProviderFactory(null, Boolean.TRUE);
providerParameters.setProviderProperties( new Properties() );
providerParameters.setClassLoaders( this.getClass().getClassLoader(), this.getClass().getClassLoader() );
providerParameters.setTestRequest( new TestRequest( null, null, null ) );