maven-surefire-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From krosenv...@apache.org
Subject svn commit: r1040708 [2/2] - 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/ maven-surefire-common/src/test/java/org/apac...
Date Tue, 30 Nov 2010 19:10:59 GMT
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=1040708&r1=1040707&r2=1040708&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:10:57 2010
@@ -1,4 +1,5 @@
 package org.apache.maven.surefire.junitcore;
+
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
@@ -18,13 +19,13 @@ package org.apache.maven.surefire.junitc
  * under the License.
  */
 
-import org.apache.maven.surefire.providerapi.FileScanningProvider;
-import org.apache.maven.surefire.providerapi.ProviderPropertiesAware;
 import org.apache.maven.surefire.providerapi.SurefireProvider;
 import org.apache.maven.surefire.report.ReporterException;
+import org.apache.maven.surefire.report.ReporterManagerFactory;
 import org.apache.maven.surefire.report.RunStatistics;
 import org.apache.maven.surefire.suite.RunResult;
 import org.apache.maven.surefire.testset.TestSetFailedException;
+import org.apache.maven.surefire.util.DirectoryScanner;
 
 import java.util.Iterator;
 import java.util.Properties;
@@ -34,11 +35,22 @@ import java.util.Properties;
  */
 @SuppressWarnings( { "UnusedDeclaration" } )
 public class JUnitCoreProvider
-    extends FileScanningProvider
-    implements SurefireProvider, ProviderPropertiesAware
+    implements SurefireProvider
 {
-    private Properties providerProperties;
+    private final Properties providerProperties;
+    private final ReporterManagerFactory reporterManagerFactory;
+    private final ClassLoader testClassLoader;
+    private final DirectoryScanner directoryScanner;
+
 
+    public JUnitCoreProvider( Properties providerProperties, ReporterManagerFactory reporterManagerFactory,
+                              ClassLoader testClassLoader, DirectoryScanner directoryScanner
)
+    {
+        this.providerProperties = providerProperties;
+        this.reporterManagerFactory = reporterManagerFactory;
+        this.testClassLoader = testClassLoader;
+        this.directoryScanner = directoryScanner;
+    }
 
     @SuppressWarnings( { "UnnecessaryUnboxing" } )
     public RunResult invoke( Object forkTestSet )
@@ -47,54 +59,32 @@ public class JUnitCoreProvider
         // Todo; Not there quite yet
         JUnitCoreDirectoryTestSuite jUnitCoreDirectoryTestSuite = getSuite();
 
-        RunStatistics runStatistics = getReporterManagerFactory().getGlobalRunStatistics();
-
-        jUnitCoreDirectoryTestSuite.locateTestSets( getTestsClassLoader() );
-        int totalTests = 0;
-
-        int testCount = jUnitCoreDirectoryTestSuite.getNumTests();
-        if ( testCount > 0 )
-        {
-            totalTests += testCount;
-        }
-
-        if ( totalTests == 0 && getFailifNoTests().booleanValue() )
-        {
-            getReporterManagerFactory().createReporterManager().writeMessage( "There are
no tests to run." );
-            return RunResult.No_Tests;
-        }
+        RunStatistics runStatistics = reporterManagerFactory.getGlobalRunStatistics();
 
+        jUnitCoreDirectoryTestSuite.locateTestSets( testClassLoader );
         // getLog().info( "Concurrency config is " + getProperties().toString() );
 
         if ( forkTestSet != null )
         {
-            jUnitCoreDirectoryTestSuite.execute( (String) forkTestSet, getReporterManagerFactory(),
-                                                 getTestsClassLoader() );
+            jUnitCoreDirectoryTestSuite.execute( (String) forkTestSet, reporterManagerFactory,
+                                                 testClassLoader );
         }
         else
         {
-            jUnitCoreDirectoryTestSuite.execute( getReporterManagerFactory(), getTestsClassLoader()
);
+            jUnitCoreDirectoryTestSuite.execute( reporterManagerFactory, testClassLoader
);
         }
-
-        jUnitCoreDirectoryTestSuite.execute( getReporterManagerFactory(), getTestsClassLoader()
);
-
-        return runStatistics.getRunResult();
+        reporterManagerFactory.close();
+        return reporterManagerFactory.getGlobalRunStatistics().getRunResult();
     }
 
     private JUnitCoreDirectoryTestSuite getSuite()
     {
-        return new JUnitCoreDirectoryTestSuite( getDirectoryScanner(), new JUnitCoreParameters(
providerProperties ),
-                                                getReporterManagerFactory() );
+        return new JUnitCoreDirectoryTestSuite( directoryScanner, new JUnitCoreParameters(
providerProperties ),
+                                                reporterManagerFactory );
     }
 
     public Iterator getSuites()
     {
-        return getSuite().locateTestSetsImpl( getTestsClassLoader() ).entrySet().iterator();
-    }
-
-
-    public void setProviderProperties( Properties providerProperties )
-    {
-        this.providerProperties = providerProperties;
+        return getSuite().locateTestSetsImpl( testClassLoader ).entrySet().iterator();
     }
 }

Copied: maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/JUnitCoreProviderFactory.java
(from r1040706, maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/ReporterConfiguration.java)
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/JUnitCoreProviderFactory.java?p2=maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/JUnitCoreProviderFactory.java&p1=maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/ReporterConfiguration.java&r1=1040706&r2=1040708&rev=1040708&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/ReporterConfiguration.java
(original)
+++ maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/JUnitCoreProviderFactory.java
Tue Nov 30 19:10:57 2010
@@ -1,4 +1,4 @@
-package org.apache.maven.surefire.report;
+package org.apache.maven.surefire.junitcore;
 
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
@@ -19,34 +19,32 @@ package org.apache.maven.surefire.report
  * under the License.
  */
 
-import java.io.File;
+
+import org.apache.maven.surefire.providerapi.BaseProviderFactory;
+import org.apache.maven.surefire.providerapi.ProviderPropertiesAware;
+import org.apache.maven.surefire.providerapi.SurefireProvider;
+import org.junit.runner.JUnitCore;
+
+import java.util.Properties;
 
 /**
  * @author Kristian Rosenvold
  */
-public class ReporterConfiguration
+@SuppressWarnings( { "UnusedDeclaration" } )
+public class JUnitCoreProviderFactory
+    extends BaseProviderFactory
+    implements ProviderPropertiesAware
 {
-    final File reportsDirectory;
+    Properties providerProperties;
 
-    /**
-     * A non-null Boolean value
-     */
-    final Boolean trimStackTrace;
-
-    public ReporterConfiguration( File reportsDirectory, Boolean trimStackTrace )
+    public void setProviderProperties( Properties providerProperties )
     {
-        this.reportsDirectory = reportsDirectory;
-        this.trimStackTrace = trimStackTrace;
+        this.providerProperties = providerProperties;
     }
 
-    public File getReportsDirectory()
+    public SurefireProvider createProvider()
     {
-        return reportsDirectory;
+        return new JUnitCoreProvider( providerProperties, getReporterManagerFactory(), getTestClassLoader(),
+                                      getDirectoryScanner() );
     }
-
-    public Boolean isTrimStackTrace()
-    {
-        return trimStackTrace;
-    }
-
 }

Modified: maven/surefire/trunk/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/ConcurrentReportingRunListenerTest.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/ConcurrentReportingRunListenerTest.java?rev=1040708&r1=1040707&r2=1040708&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/ConcurrentReportingRunListenerTest.java
(original)
+++ maven/surefire/trunk/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/ConcurrentReportingRunListenerTest.java
Tue Nov 30 19:10:57 2010
@@ -33,7 +33,6 @@ import org.junit.runner.Computer;
 import org.junit.runner.JUnitCore;
 
 import java.io.ByteArrayOutputStream;
-import java.io.File;
 import java.io.PrintStream;
 import java.util.ArrayList;
 import java.util.List;
@@ -401,10 +400,16 @@ public class ConcurrentReportingRunListe
         Object[] reporter = new Object[]{MockReporter.class.getCanonicalName(), new Object[]
{} };
         final List<Object> objects = new ArrayList();
         objects.add( reporter );
-        ReporterConfiguration reporterConfiguration = new ReporterConfiguration( new File(
"." ), Boolean.TRUE);
+        ReporterConfiguration reporterConfiguration = getTestReporterConfiguration();
         return new ReporterManagerFactory(objects, this.getClass().getClassLoader());
     }
 
+    public static ReporterConfiguration getTestReporterConfiguration()
+    {
+        return new ReporterConfiguration( new ArrayList(), null, Boolean.TRUE );
+    }
+
+
     private void assertReporter( RunStatistics result, int success, int ignored, int failure,
String message )
     {
         assertEquals( message,  success, result.getCompletedCount() );

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=1040708&r1=1040707&r2=1040708&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:10:57 2010
@@ -27,7 +27,6 @@ import org.junit.runner.JUnitCore;
 import org.junit.runner.Result;
 import org.junit.runner.notification.Failure;
 
-import java.io.File;
 import java.util.ArrayList;
 import java.util.List;
 
@@ -121,7 +120,7 @@ public class MavenSurefireJUnit47RunnerT
       List reportDefinitions = new ArrayList();
       reportDefinitions.add(reportDefinition);
 
-      ReporterConfiguration reporterConfiguration = new ReporterConfiguration( new File(
"." ), Boolean.TRUE );
+      ReporterConfiguration reporterConfiguration = ConcurrentReportingRunListenerTest.getTestReporterConfiguration();
 
       ReporterManagerFactory reporterManagerFactory = new ReporterManagerFactory(reportDefinitions,
this.getClass().getClassLoader());
 

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=1040708&r1=1040707&r2=1040708&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:10:57 2010
@@ -18,20 +18,19 @@ package org.apache.maven.surefire.testng
  * under the License.
  */
 
-import org.apache.maven.surefire.providerapi.FileScanningProvider;
-import org.apache.maven.surefire.providerapi.ProviderPropertiesAware;
-import org.apache.maven.surefire.providerapi.ReporterConfigurationAware;
 import org.apache.maven.surefire.providerapi.SurefireProvider;
-import org.apache.maven.surefire.providerapi.TestArtifactInfoAware;
 import org.apache.maven.surefire.report.ReporterConfiguration;
 import org.apache.maven.surefire.report.ReporterException;
+import org.apache.maven.surefire.report.ReporterManagerFactory;
 import org.apache.maven.surefire.suite.RunResult;
 import org.apache.maven.surefire.suite.SurefireTestSuite;
+import org.apache.maven.surefire.testset.DirectoryScannerParameters;
 import org.apache.maven.surefire.testset.TestArtifactInfo;
 import org.apache.maven.surefire.testset.TestRequest;
 import org.apache.maven.surefire.testset.TestSetFailedException;
-import org.apache.maven.surefire.util.DefaultDirectoryScanner;
+import org.apache.maven.surefire.util.DirectoryScanner;
 
+import java.io.File;
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.Properties;
@@ -41,31 +40,49 @@ import java.util.Properties;
  * @noinspection UnusedDeclaration
  */
 public class TestNGProvider
-    extends FileScanningProvider
-    implements SurefireProvider, ProviderPropertiesAware, TestArtifactInfoAware, ReporterConfigurationAware
+    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 File basedir;
+
+    public TestNGProvider( Properties providerProperties, TestArtifactInfo testArtifactInfo,
+                           ReporterConfiguration reporterConfiguration, ReporterManagerFactory
reporterManagerFactory,
+                           ClassLoader testClassLoader, DirectoryScannerParameters directoryScannerParameters,
+                           DirectoryScanner directoryScanner, TestRequest testRequest, File
basedir )
+    {
+        this.providerProperties = providerProperties;
+        this.testArtifactInfo = testArtifactInfo;
+        this.reporterConfiguration = reporterConfiguration;
+        this.reporterManagerFactory = reporterManagerFactory;
+        this.testClassLoader = testClassLoader;
+        this.directoryScannerParameters = directoryScannerParameters;
+        this.testRequest = testRequest;
+        this.basedir = basedir;
+    }
 
     public RunResult invoke( Object forkTestSet )
         throws TestSetFailedException, ReporterException
     {
         SurefireTestSuite suite = getActiveSuite();
-        suite.locateTestSets( getTestsClassLoader() );
-        if ( forkTestSet != null && getTestSuiteDefinition() == null)
+        suite.locateTestSets( testClassLoader );
+        if ( forkTestSet != null && testRequest == null)
         {
-            suite.execute( (String) forkTestSet, getReporterManagerFactory(),
-                           getTestsClassLoader() );
+            suite.execute( (String) forkTestSet, reporterManagerFactory,
+                           testClassLoader );
         }
         else
         {
-            suite.execute( getReporterManagerFactory(), getTestsClassLoader() );
+            suite.execute( reporterManagerFactory, testClassLoader );
         }
-        return RunResult.totalCountOnly( suite.getNumTests() );
+        reporterManagerFactory.close();
+        return reporterManagerFactory.getGlobalRunStatistics().getRunResult();
     }
 
     boolean isTestNGXmlTestSuite( TestRequest testSuiteDefinition )
@@ -75,26 +92,21 @@ public class TestNGProvider
 
     }
 
-    private DefaultDirectoryScanner getDefaultDirectoryScanner()
-    {
-        return (DefaultDirectoryScanner) getDirectoryScanner();  // A hack to get hold of
parameters
-    }
 
     private TestNGDirectoryTestSuite getDirectorySuite()
     {
-        final DefaultDirectoryScanner defaultDirectoryScanner = getDefaultDirectoryScanner();
-        return new TestNGDirectoryTestSuite( defaultDirectoryScanner.getBasedir(),
-                                             new ArrayList( defaultDirectoryScanner.getIncludes()
),
-                                             new ArrayList( defaultDirectoryScanner.getExcludes()
),
-                                             getTestSuiteDefinition().getTestSourceDirectory().toString(),
+        return new TestNGDirectoryTestSuite( basedir,
+                                             new ArrayList( directoryScannerParameters.getIncludes()
),
+                                             new ArrayList( directoryScannerParameters.getExcludes()
),
+                                             testRequest.getTestSourceDirectory().toString(),
                                              testArtifactInfo.getVersion(), testArtifactInfo.getClassifier(),
                                              providerProperties, reporterConfiguration.getReportsDirectory()
);
     }
 
     private TestNGXmlTestSuite getXmlSuite()
     {
-        return new TestNGXmlTestSuite( getTestSuiteDefinition().getSuiteXmlFiles(),
-                                       getTestSuiteDefinition().getTestSourceDirectory().toString(),
+        return new TestNGXmlTestSuite( testRequest.getSuiteXmlFiles(),
+                                       testRequest.getTestSourceDirectory().toString(),
                                        testArtifactInfo.getVersion(), testArtifactInfo.getClassifier(),
                                        providerProperties, reporterConfiguration.getReportsDirectory()
);
     }
@@ -102,7 +114,7 @@ public class TestNGProvider
 
     public SurefireTestSuite getActiveSuite()
     {
-        return isTestNGXmlTestSuite( getTestSuiteDefinition() )
+        return isTestNGXmlTestSuite( testRequest)
             ? (SurefireTestSuite) getXmlSuite()
             : getDirectorySuite();
     }
@@ -111,27 +123,11 @@ public class TestNGProvider
     {
         try
         {
-            return getActiveSuite().locateTestSets( getTestsClassLoader() ).keySet().iterator();
+            return getActiveSuite().locateTestSets( testClassLoader ).keySet().iterator();
         }
         catch ( TestSetFailedException e )
         {
             throw new RuntimeException( e );
         }
     }
-
-
-    public void setProviderProperties( Properties providerProperties )
-    {
-        this.providerProperties = providerProperties;
-    }
-
-    public void setTestArtifactInfo( TestArtifactInfo testArtifactInfo )
-    {
-        this.testArtifactInfo = testArtifactInfo;
-    }
-
-    public void setReporterConfiguration( ReporterConfiguration reporterConfiguration )
-    {
-        this.reporterConfiguration = reporterConfiguration;
-    }
 }

Added: maven/surefire/trunk/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGProviderFactory.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGProviderFactory.java?rev=1040708&view=auto
==============================================================================
--- maven/surefire/trunk/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGProviderFactory.java
(added)
+++ maven/surefire/trunk/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGProviderFactory.java
Tue Nov 30 19:10:57 2010
@@ -0,0 +1,63 @@
+package org.apache.maven.surefire.testng;
+
+/*
+ * 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.providerapi.BaseProviderFactory;
+import org.apache.maven.surefire.providerapi.ProviderPropertiesAware;
+import org.apache.maven.surefire.providerapi.SurefireProvider;
+import org.apache.maven.surefire.providerapi.TestArtifactInfoAware;
+import org.apache.maven.surefire.testset.DirectoryScannerParameters;
+import org.apache.maven.surefire.testset.TestArtifactInfo;
+
+import java.io.File;
+import java.util.Properties;
+
+/**
+ * @author Kristian Rosenvold
+ * @noinspection UnusedDeclaration
+ */
+public class TestNGProviderFactory
+    extends BaseProviderFactory
+    implements ProviderPropertiesAware, TestArtifactInfoAware
+{
+    Properties providerProperties;
+
+    TestArtifactInfo testArtifactInfo;
+
+    public void setProviderProperties( Properties providerProperties )
+    {
+        this.providerProperties = providerProperties;
+    }
+
+    public void setTestArtifactInfo( TestArtifactInfo testArtifactInfo )
+    {
+        this.testArtifactInfo = testArtifactInfo;
+    }
+
+    public SurefireProvider createProvider()
+    {
+        final DirectoryScannerParameters directoryScannerParameters = getDirectoryScannerParameters();
+        File testClassesDirectory =
+            directoryScannerParameters != null ? directoryScannerParameters.getTestClassesDirectory()
: null;
+        return new TestNGProvider( providerProperties, testArtifactInfo, getReporterConfiguration(),
+                                   getReporterManagerFactory(), getTestClassLoader(), getDirectoryScannerParameters(),
+                                   getDirectoryScanner(), getTestRequest(), testClassesDirectory
);
+    }
+}

Propchange: maven/surefire/trunk/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGProviderFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message