Author: kenney
Date: Thu Sep 7 07:24:14 2006
New Revision: 441092
URL: http://svn.apache.org/viewvc?view=rev&rev=441092
Log:
PR: SUREFIRE-54
Reverted the revert of my previous fix, and fixed classloading for
TestNG.
The surefireClassloader is now a child of the testsClassloader, meaning
that the tests also contain the testing framework, and surefire has access
to that.
In the case of TestNG, the annotations used to be in the two classloaders,
making them incompatible. Now they're only in the testsClassloader
and the surefireClassloader can safely instantiate and run TestNG tests.
Also childDelegation is deprecated now - it is no longer needed since
the testsClassloaders have no parent. Code is still here, just in case.
Modified:
maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/SurefireBooter.java
Modified:
maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/SurefireBooter.java
URL:
http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/SurefireBooter.java?view=diff&rev=441092&r1=441091&r2=441092
==============================================================================
---
maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/SurefireBooter.java
(original)
+++
maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/SurefireBooter.java
Thu Sep 7 07:24:14 2006
@@ -80,6 +80,7 @@
private static Method assertionStatusMethod;
+ /** @deprecated because the IsolatedClassLoader is really isolated - no
parent. */
private boolean childDelegation = true;
private File reportsDirectory;
@@ -183,6 +184,10 @@
{
result = runSuitesForkPerTestSet();
}
+ else
+ {
+ throw new SurefireExecutionException( "Unknown forkmode: " +
forkConfiguration.getForkMode(), null );
+ }
return result;
}
@@ -200,11 +205,11 @@
ClassLoader oldContextClassLoader =
Thread.currentThread().getContextClassLoader();
try
{
+ ClassLoader testsClassLoader = createClassLoader( classPathUrls,
null, childDelegation, true );
+
// TODO: assertions = true shouldn't be required for this CL if we
had proper separation (see TestNG)
ClassLoader surefireClassLoader =
- createClassLoader( surefireClassPathUrls,
getClass().getClassLoader(), true );
-
- ClassLoader testsClassLoader = getTestClassLoader( childDelegation
);
+ createClassLoader( surefireClassPathUrls, testsClassLoader,
true );
Class surefireClass = surefireClassLoader.loadClass(
Surefire.class.getName() );
@@ -213,7 +218,6 @@
Method run = surefireClass.getMethod( "run", new
Class[]{List.class, Object[].class, String.class,
ClassLoader.class, ClassLoader.class, Properties.class} );
-
Thread.currentThread().setContextClassLoader( testsClassLoader );
Boolean result = (Boolean) run.invoke( surefire, new
Object[]{reports, testSuites.get( 0 ), testSet,
@@ -247,10 +251,10 @@
{
// The test classloader must be constructed first to avoid issues
with commons-logging until we properly
// separate the TestNG classloader
- ClassLoader testsClassLoader = getTestClassLoader( childDelegation
);
+ ClassLoader testsClassLoader = createClassLoader( classPathUrls,
null, childDelegation, true );
ClassLoader surefireClassLoader =
- createClassLoader( surefireClassPathUrls,
getClass().getClassLoader(), true );
+ createClassLoader( surefireClassPathUrls, testsClassLoader,
true );
Class surefireClass = surefireClassLoader.loadClass(
Surefire.class.getName() );
@@ -294,9 +298,9 @@
ClassLoader surefireClassLoader;
try
{
- testsClassLoader = getTestClassLoader( false );
+ testsClassLoader = createClassLoader( classPathUrls, null, false,
true );
// TODO: assertions = true shouldn't be required if we had proper
separation (see TestNG)
- surefireClassLoader = createClassLoader( surefireClassPathUrls,
false, true );
+ surefireClassLoader = createClassLoader( surefireClassPathUrls,
testsClassLoader, false, true );
}
catch ( MalformedURLException e )
{
@@ -554,33 +558,10 @@
return returnCode == 0;
}
- /**
- * This method actually calls <code>createClassLoader( classPathUrls,
ClassLoader.getSystemClassLoader(),
- * childDelegation, true );</code> and it's here to handle the use of a
parent classloader consistently.
- */
- private ClassLoader getTestClassLoader( boolean childDelegation )
- throws MalformedURLException
- {
- // warning, parent should probably be set to null, but at this moment
this totally breaks TestNG
- // Comment from Kenney:
- // If this is not done, the System classloader is added, in this case
an AppClassloader containing everything in
- // the root classpath. For instance, in maven, everything in core/ is
available.This can cause clashes with the
- // plexus-utils used in maven itself.
- return createClassLoader( classPathUrls,
ClassLoader.getSystemClassLoader(), childDelegation, true );
- }
-
private static ClassLoader createClassLoader( List classPathUrls,
ClassLoader parent, boolean assertionsEnabled )
throws MalformedURLException
{
return createClassLoader( classPathUrls, parent, false,
assertionsEnabled );
- }
-
- private static ClassLoader createClassLoader( List classPathUrls, boolean
childDelegation,
- boolean assertionsEnabled )
- throws MalformedURLException
- {
- return createClassLoader( classPathUrls,
ClassLoader.getSystemClassLoader(), childDelegation,
- assertionsEnabled );
}
private static ClassLoader createClassLoader( List classPathUrls,
ClassLoader parent, boolean childDelegation,