You are viewing a plain text version of this content. The canonical link for it is here.
Posted to surefire-commits@maven.apache.org by fg...@apache.org on 2006/09/02 23:24:06 UTC

svn commit: r439656 - /maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/SurefireBooter.java

Author: fgiust
Date: Sat Sep  2 14:24:06 2006
New Revision: 439656

URL: http://svn.apache.org/viewvc?rev=439656&view=rev
Log:
PR: SUREFIRE-53 context classloader not always reset to original values
Submitted by: Milos Kleint
Reviewed by: Fabrizio Giustina

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?rev=439656&r1=439655&r2=439656&view=diff
==============================================================================
--- 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 Sat Sep  2 14:24:06 2006
@@ -197,6 +197,7 @@
         // TODO: replace with plexus
 
         //noinspection CatchGenericClass,OverlyBroadCatchBlock
+        ClassLoader oldContextClassLoader = Thread.currentThread().getContextClassLoader();
         try
         {
             // TODO: assertions = true shouldn't be required for this CL if we had proper separation (see TestNG)
@@ -212,15 +213,12 @@
             Method run = surefireClass.getMethod( "run", new Class[]{List.class, Object[].class, String.class,
                 ClassLoader.class, ClassLoader.class, Properties.class} );
 
-            ClassLoader oldContextClassLoader = Thread.currentThread().getContextClassLoader();
 
             Thread.currentThread().setContextClassLoader( testsClassLoader );
 
             Boolean result = (Boolean) run.invoke( surefire, new Object[]{reports, testSuites.get( 0 ), testSet,
                 surefireClassLoader, testsClassLoader, results} );
 
-            Thread.currentThread().setContextClassLoader( oldContextClassLoader );
-
             return result.booleanValue();
         }
         catch ( InvocationTargetException e )
@@ -231,6 +229,10 @@
         {
             throw new SurefireExecutionException( "Unable to instantiate and execute Surefire", e );
         }
+        finally 
+        {
+            Thread.currentThread().setContextClassLoader( oldContextClassLoader );
+        }
     }
 
     private boolean runSuitesInProcess()
@@ -239,6 +241,8 @@
         // TODO: replace with plexus
 
         //noinspection CatchGenericClass,OverlyBroadCatchBlock
+        ClassLoader oldContextClassLoader = Thread.currentThread().getContextClassLoader();
+        
         try
         {
             // The test classloader must be constructed first to avoid issues with commons-logging until we properly
@@ -255,15 +259,12 @@
             Method run = surefireClass.getMethod( "run", new Class[]{List.class, List.class, ClassLoader.class,
                 ClassLoader.class} );
 
-            ClassLoader oldContextClassLoader = Thread.currentThread().getContextClassLoader();
 
             Thread.currentThread().setContextClassLoader( testsClassLoader );
 
             Boolean result = (Boolean) run.invoke( surefire, new Object[]{reports, testSuites, surefireClassLoader,
                 testsClassLoader} );
 
-            Thread.currentThread().setContextClassLoader( oldContextClassLoader );
-
             return result.booleanValue();
         }
         catch ( InvocationTargetException e )
@@ -273,6 +274,10 @@
         catch ( Exception e )
         {
             throw new SurefireExecutionException( "Unable to instantiate and execute Surefire", e );
+        }
+        finally 
+        {
+            Thread.currentThread().setContextClassLoader( oldContextClassLoader );
         }
     }