maven-surefire-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From krosenv...@apache.org
Subject svn commit: r1040737 - in /maven/surefire/trunk: surefire-api/src/main/java/org/apache/maven/surefire/report/ surefire-booter/src/main/java/org/apache/maven/surefire/booter/ surefire-providers/surefire-junit/src/main/java/org/apache/maven/surefire/juni...
Date Tue, 30 Nov 2010 19:53:09 GMT
Author: krosenvold
Date: Tue Nov 30 19:53:08 2010
New Revision: 1040737

URL: http://svn.apache.org/viewvc?rev=1040737&view=rev
Log:
o Restored warning when no tests, cleaned up unused code. Simplified

Modified:
    maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/ReporterManagerFactory.java
    maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/SurefireStarter.java
    maven/surefire/trunk/surefire-providers/surefire-junit/src/main/java/org/apache/maven/surefire/junit/JUnit3Provider.java
    maven/surefire/trunk/surefire-providers/surefire-junit4/src/main/java/org/apache/maven/surefire/junit4/JUnit4Provider.java
    maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/JUnitCoreProvider.java
    maven/surefire/trunk/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/MavenSurefireJUnit47RunnerTestCase.java
    maven/surefire/trunk/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGProvider.java

Modified: maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/ReporterManagerFactory.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/ReporterManagerFactory.java?rev=1040737&r1=1040736&r2=1040737&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/ReporterManagerFactory.java
(original)
+++ maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/ReporterManagerFactory.java
Tue Nov 30 19:53:08 2010
@@ -19,6 +19,7 @@ package org.apache.maven.surefire.report
  * under the License.
  */
 
+import org.apache.maven.surefire.suite.RunResult;
 import org.apache.maven.surefire.testset.TestSetFailedException;
 
 import java.lang.reflect.Constructor;
@@ -39,8 +40,11 @@ import java.util.List;
  * @author Jason van Zyl
  * @author Kristian Rosenvold (extracted factory)
  */
-/** NOTE: The ReporterManagerFactory2 should take over for this once we build surefire with
2.7,
- * just merge it into this class, this is just a hack to be able to build 2.7 with 2.5 */
+
+/**
+ * NOTE: The ReporterManagerFactory2 should take over for this once we build surefire with
2.7,
+ * just merge it into this class, this is just a hack to be able to build 2.7 with 2.5
+ */
 public class ReporterManagerFactory
 {
     protected final List reportDefinitions;
@@ -87,7 +91,7 @@ public class ReporterManagerFactory
         return reporterManager;
     }
 
-    public void close()
+    public RunResult close()
     {
         synchronized ( lock )
         {
@@ -95,6 +99,7 @@ public class ReporterManagerFactory
             {
                 first.runCompleted();
             }
+            return globalRunStatistics.getRunResult();
         }
     }
 
@@ -184,4 +189,13 @@ public class ReporterManagerFactory
         }
         return object;
     }
+
+    public void warnIfNoTests()
+        throws TestSetFailedException
+    {
+        if ( getGlobalRunStatistics().getRunResult().getCompletedCount() == 0 )
+        {
+            createReporterManager().writeMessage( "There are no tests to run." );
+        }
+    }
 }

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=1040737&r1=1040736&r2=1040737&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
Tue Nov 30 19:53:08 2010
@@ -29,7 +29,7 @@ import java.util.Properties;
 /**
  * Invokes surefire with the correct classloader setup.
  * <p/>
- * This part of the booter that is always guaranteed to be in the
+ * 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
@@ -52,21 +52,19 @@ public class SurefireStarter
         throws SurefireExecutionException
     {
 
-        // TODO: replace with plexus
         final ProviderConfiguration starterConfiguration = booterConfiguration.getSurefireStarterConfiguration();
         final ClasspathConfiguration classpathConfiguration = starterConfiguration.getClasspathConfiguration();
 
         ClassLoader testsClassLoader = classpathConfiguration.createTestClassLoaderConditionallySystem(
             starterConfiguration.useSystemClassLoader() );
 
-        // TODO: assertions = true shouldn't be required for this CL if we had proper separation
(see TestNG)
         ClassLoader surefireClassLoader = classpathConfiguration.createSurefireClassLoader(
testsClassLoader );
 
         RunResult runResult = invokeProvider( testSet, testsClassLoader, surefireClassLoader
);
 
         updateResultsProperties( runResult, results );
 
-        return processRunCount( runResult, surefireClassLoader );
+        return processRunCount( runResult );
     }
 
     private static final String RESULTS_ERRORS = "errors";
@@ -88,16 +86,12 @@ public class SurefireStarter
 
     private RunResult invokeProvider( Object testSet, ClassLoader testsClassLoader, ClassLoader
surefireClassLoader )
     {
-        ClassLoader oldContextClassLoader = Thread.currentThread().getContextClassLoader();
-        Thread.currentThread().setContextClassLoader( surefireClassLoader );
-
         ProviderFactory providerFactory = new ProviderFactory( booterConfiguration, surefireClassLoader
);
         final SurefireProvider provider = providerFactory.createProvider( testsClassLoader
);
 
         try
         {
-            final RunResult invoke = provider.invoke( testSet );
-            return invoke;
+            return provider.invoke( testSet );
         }
         catch ( TestSetFailedException e )
         {
@@ -107,10 +101,6 @@ public class SurefireStarter
         {
             throw new RuntimeException( e );
         }
-        finally
-        {
-            Thread.currentThread().setContextClassLoader( oldContextClassLoader );
-        }
     }
 
     public int runSuitesInProcess( Properties p )
@@ -118,8 +108,6 @@ public class SurefireStarter
     {
         // TODO: replace with plexus
 
-        ClassLoader oldContextClassLoader = Thread.currentThread().getContextClassLoader();
-
         // The test classloader must be constructed first to avoid issues with commons-logging
until we properly
         // separate the TestNG classloader
         ClassLoader testsClassLoader;
@@ -142,40 +130,20 @@ public class SurefireStarter
 
         ClassLoader surefireClassLoader = classpathConfiguration.createSurefireClassLoader(
testsClassLoader );
 
-        Thread.currentThread().setContextClassLoader( surefireClassLoader );
         final RunResult runResult = invokeProvider( null, testsClassLoader, surefireClassLoader
);
-        return processRunCount( runResult, surefireClassLoader );
+        return processRunCount( runResult );
     }
 
     /**
-     * Returns
+     * Returns the process return code based on the RunResult
      *
-     * @param runCount            The run result
-     * @param surefireClassLoader The sirefore classloader
+     * @param runCount The run result
      * @return The process result code
      * @throws SurefireExecutionException When an exception is found
      */
-    private int processRunCount( RunResult runCount, ClassLoader surefireClassLoader )
+    private int processRunCount( RunResult runCount )
         throws SurefireExecutionException
     {
-        if ( runCount.getCompletedCount() == 0 )
-        {
-            // TODO: Bugbug find out WTF this means. This blows up like crap when running
here ;)
-/*            ReporterManagerFactory reporterManagerFactory =
-                new ReporterManagerFactory2( surefireClassLoader, booterConfiguration.getReporterConfiguration()
);
-            try
-            {
-                reporterManagerFactory.createReporterManager().writeMessage( "There are no
tests to run." );
-            }
-            catch ( TestSetFailedException e )
-            {
-                throw new SurefireExecutionException( "While reporting error", e );
-            }
-            finally
-            {
-                reporterManagerFactory.close();
-            }*/
-        }
 
         if ( runCount.getCompletedCount() == 0 && booterConfiguration.isFailIfNoTests().booleanValue()
)
         {

Modified: maven/surefire/trunk/surefire-providers/surefire-junit/src/main/java/org/apache/maven/surefire/junit/JUnit3Provider.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-providers/surefire-junit/src/main/java/org/apache/maven/surefire/junit/JUnit3Provider.java?rev=1040737&r1=1040736&r2=1040737&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-providers/surefire-junit/src/main/java/org/apache/maven/surefire/junit/JUnit3Provider.java
(original)
+++ maven/surefire/trunk/surefire-providers/surefire-junit/src/main/java/org/apache/maven/surefire/junit/JUnit3Provider.java
Tue Nov 30 19:53:08 2010
@@ -1,4 +1,5 @@
 package org.apache.maven.surefire.junit;
+
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
@@ -35,7 +36,9 @@ public class JUnit3Provider
     implements SurefireProvider
 {
     private final ReporterManagerFactory reporterManagerFactory;
+
     private final ClassLoader testClassLoader;
+
     private final DirectoryScanner directoryScanner;
 
     public JUnit3Provider( ReporterManagerFactory reporterManagerFactory, ClassLoader testClassLoader,
@@ -50,7 +53,7 @@ public class JUnit3Provider
         throws TestSetFailedException, ReporterException
     {
         JUnitDirectoryTestSuite suite = getSuite();
-        suite.locateTestSets(testClassLoader);
+        suite.locateTestSets( testClassLoader );
         if ( forkTestSet != null )
         {
             suite.execute( (String) forkTestSet, reporterManagerFactory, testClassLoader
);
@@ -59,8 +62,10 @@ public class JUnit3Provider
         {
             suite.execute( reporterManagerFactory, testClassLoader );
         }
-        reporterManagerFactory.close();
-        return reporterManagerFactory.getGlobalRunStatistics().getRunResult();
+
+        reporterManagerFactory.warnIfNoTests();
+
+        return reporterManagerFactory.close();
     }
 
     private JUnitDirectoryTestSuite getSuite()

Modified: maven/surefire/trunk/surefire-providers/surefire-junit4/src/main/java/org/apache/maven/surefire/junit4/JUnit4Provider.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-providers/surefire-junit4/src/main/java/org/apache/maven/surefire/junit4/JUnit4Provider.java?rev=1040737&r1=1040736&r2=1040737&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-providers/surefire-junit4/src/main/java/org/apache/maven/surefire/junit4/JUnit4Provider.java
(original)
+++ maven/surefire/trunk/surefire-providers/surefire-junit4/src/main/java/org/apache/maven/surefire/junit4/JUnit4Provider.java
Tue Nov 30 19:53:08 2010
@@ -1,4 +1,5 @@
 package org.apache.maven.surefire.junit4;
+
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
@@ -36,11 +37,13 @@ public class JUnit4Provider
 {
 
     private final ReporterManagerFactory reporterManagerFactory;
+
     private final ClassLoader testClassLoader;
+
     private final DirectoryScanner directoryScanner;
 
     public JUnit4Provider( ReporterManagerFactory reporterManagerFactory, ClassLoader testClassLoader,
-                           DirectoryScanner directoryScanner)
+                           DirectoryScanner directoryScanner )
     {
         this.reporterManagerFactory = reporterManagerFactory;
         this.testClassLoader = testClassLoader;
@@ -61,8 +64,9 @@ public class JUnit4Provider
         {
             suite.execute( reporterManagerFactory, testClassLoader );
         }
-        reporterManagerFactory.close();
-        return reporterManagerFactory.getGlobalRunStatistics().getRunResult();
+        reporterManagerFactory.warnIfNoTests();
+
+        return reporterManagerFactory.close();
     }
 
     private JUnit4DirectoryTestSuite getSuite()

Modified: maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/JUnitCoreProvider.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/JUnitCoreProvider.java?rev=1040737&r1=1040736&r2=1040737&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/JUnitCoreProvider.java
(original)
+++ maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/JUnitCoreProvider.java
Tue Nov 30 19:53:08 2010
@@ -73,8 +73,9 @@ public class JUnitCoreProvider
         {
             jUnitCoreDirectoryTestSuite.execute( reporterManagerFactory, testClassLoader
);
         }
-        reporterManagerFactory.close();
-        return reporterManagerFactory.getGlobalRunStatistics().getRunResult();
+        reporterManagerFactory.warnIfNoTests();
+
+        return reporterManagerFactory.close();
     }
 
     private JUnitCoreDirectoryTestSuite getSuite()

Modified: maven/surefire/trunk/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/MavenSurefireJUnit47RunnerTestCase.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/MavenSurefireJUnit47RunnerTestCase.java?rev=1040737&r1=1040736&r2=1040737&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/MavenSurefireJUnit47RunnerTestCase.java
(original)
+++ maven/surefire/trunk/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/MavenSurefireJUnit47RunnerTestCase.java
Tue Nov 30 19:53:08 2010
@@ -133,7 +133,7 @@ public class MavenSurefireJUnit47RunnerT
 
       junitCore.addListener(concurrentReportingRunListener);
 
-      Result result = junitCore.run(computer, FailingTestClassTest.class);
+      Result result = junitCore.run(computer, FailingTestClassTestNot.class);
 
       junitCore.removeListener(concurrentReportingRunListener);
 
@@ -163,7 +163,7 @@ public class MavenSurefireJUnit47RunnerT
     * Simple TestCase to force a Exception in @BeforeClass.
     *
     */
-   public static class FailingTestClassTest
+   public static class FailingTestClassTestNot
    {
       @BeforeClass
       public static void failingBeforeClass() throws Exception

Modified: maven/surefire/trunk/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGProvider.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGProvider.java?rev=1040737&r1=1040736&r2=1040737&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGProvider.java
(original)
+++ maven/surefire/trunk/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGProvider.java
Tue Nov 30 19:53:08 2010
@@ -1,4 +1,5 @@
 package org.apache.maven.surefire.testng;
+
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
@@ -43,13 +44,19 @@ public class TestNGProvider
     implements SurefireProvider
 {
     private Properties providerProperties;
+
     private TestArtifactInfo testArtifactInfo;
+
     private ReporterConfiguration reporterConfiguration;
+
     private final ReporterManagerFactory reporterManagerFactory;
+
     private final ClassLoader testClassLoader;
+
     private final DirectoryScannerParameters directoryScannerParameters;
 
-    private final TestRequest  testRequest;
+    private final TestRequest testRequest;
+
     private final File basedir;
 
     public TestNGProvider( Properties providerProperties, TestArtifactInfo testArtifactInfo,
@@ -72,17 +79,16 @@ public class TestNGProvider
     {
         SurefireTestSuite suite = getActiveSuite();
         suite.locateTestSets( testClassLoader );
-        if ( forkTestSet != null && testRequest == null)
+        if ( forkTestSet != null && testRequest == null )
         {
-            suite.execute( (String) forkTestSet, reporterManagerFactory,
-                           testClassLoader );
+            suite.execute( (String) forkTestSet, reporterManagerFactory, testClassLoader
);
         }
         else
         {
             suite.execute( reporterManagerFactory, testClassLoader );
         }
-        reporterManagerFactory.close();
-        return reporterManagerFactory.getGlobalRunStatistics().getRunResult();
+        reporterManagerFactory.warnIfNoTests();
+        return reporterManagerFactory.close();
     }
 
     boolean isTestNGXmlTestSuite( TestRequest testSuiteDefinition )
@@ -95,8 +101,7 @@ public class TestNGProvider
 
     private TestNGDirectoryTestSuite getDirectorySuite()
     {
-        return new TestNGDirectoryTestSuite( basedir,
-                                             new ArrayList( directoryScannerParameters.getIncludes()
),
+        return new TestNGDirectoryTestSuite( basedir, new ArrayList( directoryScannerParameters.getIncludes()
),
                                              new ArrayList( directoryScannerParameters.getExcludes()
),
                                              testRequest.getTestSourceDirectory().toString(),
                                              testArtifactInfo.getVersion(), testArtifactInfo.getClassifier(),
@@ -105,8 +110,7 @@ public class TestNGProvider
 
     private TestNGXmlTestSuite getXmlSuite()
     {
-        return new TestNGXmlTestSuite( testRequest.getSuiteXmlFiles(),
-                                       testRequest.getTestSourceDirectory().toString(),
+        return new TestNGXmlTestSuite( testRequest.getSuiteXmlFiles(), testRequest.getTestSourceDirectory().toString(),
                                        testArtifactInfo.getVersion(), testArtifactInfo.getClassifier(),
                                        providerProperties, reporterConfiguration.getReportsDirectory()
);
     }
@@ -114,9 +118,7 @@ public class TestNGProvider
 
     public SurefireTestSuite getActiveSuite()
     {
-        return isTestNGXmlTestSuite( testRequest)
-            ? (SurefireTestSuite) getXmlSuite()
-            : getDirectorySuite();
+        return isTestNGXmlTestSuite( testRequest ) ? (SurefireTestSuite) getXmlSuite() :
getDirectorySuite();
     }
 
     public Iterator getSuites()



Mime
View raw message