You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by ti...@apache.org on 2019/04/15 22:40:26 UTC

[maven-surefire] branch 1546-1222 updated: fixed JUnitPlatformIT, enabled disableXmlReport in the extension and used UTF-8 in encoding by default.

This is an automated email from the ASF dual-hosted git repository.

tibordigana pushed a commit to branch 1546-1222
in repository https://gitbox.apache.org/repos/asf/maven-surefire.git


The following commit(s) were added to refs/heads/1546-1222 by this push:
     new d89f1be  fixed JUnitPlatformIT, enabled disableXmlReport in the extension and used UTF-8 in encoding by default.
d89f1be is described below

commit d89f1bec1851ca7ce233cec5171e9dfcc715929a
Author: tibordigana <ti...@apache.org>
AuthorDate: Tue Apr 16 00:40:15 2019 +0200

    fixed JUnitPlatformIT, enabled disableXmlReport in the extension and used UTF-8 in encoding by default.
---
 .../maven/plugin/surefire/AbstractSurefireMojo.java   | 15 +++++++++++----
 .../apache/maven/plugin/surefire/CommonReflector.java |  4 ++--
 .../plugin/surefire/StartupReportConfiguration.java   | 10 ++++------
 .../DefaultStatelessReportMojoConfiguration.java      | 15 ---------------
 .../surefire/extensions/DefaultStatelessReporter.java | 19 +++++++++++++++++++
 .../booterclient/TestSetMockReporterFactory.java      |  2 +-
 .../surefire/report/DefaultReporterFactoryTest.java   |  2 +-
 .../apache/maven/plugin/surefire/SurefirePlugin.java  |  2 +-
 .../extensions/StatelessReportMojoConfiguration.java  | 15 ---------------
 .../maven/surefire/extensions/StatelessReporter.java  |  1 +
 .../resources/junit-platform-engine-jupiter/pom.xml   |  6 ++++++
 .../maven/surefire/junitcore/JUnitCoreTester.java     |  2 +-
 12 files changed, 47 insertions(+), 46 deletions(-)

diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java
index e2807b4..0ebcce8 100644
--- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java
+++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java
@@ -160,6 +160,9 @@ public abstract class AbstractSurefireMojo
 
     private final ProviderDetector providerDetector = new ProviderDetector();
 
+    /**
+     * Note: use the legacy system property <em>disableXmlReport</em> set to {@code true} to disable the report.
+     */
     @Parameter
     private StatelessReporter<StatelessReporterEvent, DefaultStatelessReportMojoConfiguration> statelessReporter;
 
@@ -677,10 +680,10 @@ public abstract class AbstractSurefireMojo
 
     /**
      * Flag to disable the generation of report files in xml format.
-     * Deprecated since 3.0.0-M4. Use this parameter within {@code statelessReporter}.
+     * Deprecated since 3.0.0-M4. Instead use <em>disable</em> within {@code statelessReporter} since of 3.0.0-M6.
      * @since 2.2
      */
-    @Deprecated
+    @Deprecated // todo make readonly to handle system property
     @Parameter( property = "disableXmlReport", defaultValue = "false" )
     private boolean disableXmlReport;
 
@@ -1944,10 +1947,14 @@ public abstract class AbstractSurefireMojo
     private StartupReportConfiguration getStartupReportConfiguration( String configChecksum, boolean isForkMode )
     {
         StatelessReporter<StatelessReporterEvent, DefaultStatelessReportMojoConfiguration> xmlReporter =
-                statelessReporter == null ? new DefaultStatelessReporter() : statelessReporter;
+                statelessReporter == null
+                        ? new DefaultStatelessReporter( /*todo call def. constr.*/ isDisableXmlReport(), "3.0" )
+                        : statelessReporter;
+
+        xmlReporter.setDisable( isDisableXmlReport() ); // todo change to Boolean in the version 3.0.0-M6
 
         return new StartupReportConfiguration( isUseFile(), isPrintSummary(), getReportFormat(),
-                                               isRedirectTestOutputToFile(), isDisableXmlReport(),
+                                               isRedirectTestOutputToFile(),
                                                getReportsDirectory(), isTrimStackTrace(), getReportNameSuffix(),
                                                getStatisticsFile( configChecksum ), requiresRunHistory(),
                                                getRerunFailingTestsCount(), getReportSchemaLocation(), getEncoding(),
diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/CommonReflector.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/CommonReflector.java
index 7abfbcb..39d128a 100644
--- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/CommonReflector.java
+++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/CommonReflector.java
@@ -72,14 +72,14 @@ public class CommonReflector
     private Object createStartupReportConfiguration( @Nonnull StartupReportConfiguration reporterConfiguration )
     {
         Constructor<?> constructor = getConstructor( startupReportConfiguration, boolean.class, boolean.class,
-                                                           String.class, boolean.class, boolean.class, File.class,
+                                                           String.class, boolean.class, File.class,
                                                            boolean.class, String.class, File.class, boolean.class,
                                                            int.class, String.class, String.class, boolean.class,
                                                            statelessReporter );
         //noinspection BooleanConstructorCall
         Object[] params = { reporterConfiguration.isUseFile(), reporterConfiguration.isPrintSummary(),
             reporterConfiguration.getReportFormat(), reporterConfiguration.isRedirectTestOutputToFile(),
-            reporterConfiguration.isDisableXmlReport(), reporterConfiguration.getReportsDirectory(),
+            reporterConfiguration.getReportsDirectory(),
             reporterConfiguration.isTrimStackTrace(), reporterConfiguration.getReportNameSuffix(),
             reporterConfiguration.getStatisticsFile(), reporterConfiguration.isRequiresRunHistory(),
             reporterConfiguration.getRerunFailingTestsCount(), reporterConfiguration.getXsdSchemaLocation(),
diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/StartupReportConfiguration.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/StartupReportConfiguration.java
index ac00cdd..2c4d302 100644
--- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/StartupReportConfiguration.java
+++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/StartupReportConfiguration.java
@@ -38,6 +38,7 @@ import java.util.Deque;
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
 
+import static java.nio.charset.StandardCharsets.UTF_8;
 import static org.apache.commons.lang3.StringUtils.trimToNull;
 import static org.apache.maven.plugin.surefire.SurefireHelper.replaceForkThreadsInPath;
 import static org.apache.maven.plugin.surefire.report.ConsoleReporter.BRIEF;
@@ -69,8 +70,6 @@ public final class StartupReportConfiguration
 
     private final boolean redirectTestOutputToFile;
 
-    private final boolean disableXmlReport;
-
     private final File reportsDirectory;
 
     private final boolean trimStackTrace;
@@ -91,7 +90,7 @@ public final class StartupReportConfiguration
 
     @SuppressWarnings( "checkstyle:parameternumber" )
     public StartupReportConfiguration( boolean useFile, boolean printSummary, String reportFormat,
-                   boolean redirectTestOutputToFile, boolean disableXmlReport,
+                   boolean redirectTestOutputToFile,
                    @Nonnull File reportsDirectory, boolean trimStackTrace, String reportNameSuffix,
                    File statisticsFile, boolean requiresRunHistory, int rerunFailingTestsCount,
                    String xsdSchemaLocation, String encoding, boolean isForkMode,
@@ -101,7 +100,6 @@ public final class StartupReportConfiguration
         this.printSummary = printSummary;
         this.reportFormat = reportFormat;
         this.redirectTestOutputToFile = redirectTestOutputToFile;
-        this.disableXmlReport = disableXmlReport;
         this.reportsDirectory = reportsDirectory;
         this.trimStackTrace = trimStackTrace;
         this.reportNameSuffix = reportNameSuffix;
@@ -112,7 +110,7 @@ public final class StartupReportConfiguration
         this.rerunFailingTestsCount = rerunFailingTestsCount;
         this.xsdSchemaLocation = xsdSchemaLocation;
         String charset = trimToNull( encoding );
-        this.encoding = charset == null ? Charset.defaultCharset() : Charset.forName( charset );
+        this.encoding = charset == null ? UTF_8 : Charset.forName( charset );
         this.isForkMode = isForkMode;
         this.xmlReporter = xmlReporter;
     }
@@ -144,7 +142,7 @@ public final class StartupReportConfiguration
 
     public boolean isDisableXmlReport()
     {
-        return disableXmlReport;
+        return xmlReporter.isDisable();
     }
 
     public File getReportsDirectory()
diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/extensions/DefaultStatelessReportMojoConfiguration.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/extensions/DefaultStatelessReportMojoConfiguration.java
index 53ad089..b223deb 100644
--- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/extensions/DefaultStatelessReportMojoConfiguration.java
+++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/extensions/DefaultStatelessReportMojoConfiguration.java
@@ -55,19 +55,4 @@ public class DefaultStatelessReportMojoConfiguration
     {
         return testClassMethodRunHistory;
     }
-
-    public Object clone( ClassLoader target )
-    {
-        try
-        {
-            Class<?> cls = target.loadClass( getClass().getName() );
-            return cls.getConstructor( File.class, String.class, boolean.class, int.class, String.class, Map.class )
-                    .newInstance( getReportsDirectory(), getReportNameSuffix(), isTrimStackTrace(),
-                            getRerunFailingTestsCount(), getXsdSchemaLocation(), getTestClassMethodRunHistory() );
-        }
-        catch ( ReflectiveOperationException e )
-        {
-            throw new IllegalStateException( e.getLocalizedMessage() );
-        }
-    }
 }
diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/extensions/DefaultStatelessReporter.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/extensions/DefaultStatelessReporter.java
index c981ba6..a292e66 100644
--- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/extensions/DefaultStatelessReporter.java
+++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/extensions/DefaultStatelessReporter.java
@@ -32,6 +32,25 @@ import org.apache.maven.surefire.extensions.StatelessReporter;
 public class DefaultStatelessReporter
         extends StatelessReporter<StatelessReporterEvent, DefaultStatelessReportMojoConfiguration>
 {
+    /**
+     * Activated in the injection point of MOJO.
+     */
+    public DefaultStatelessReporter()
+    {
+        this( false, "3.0" );
+    }
+
+    /**
+     * Activated if null injection point in MOJO.
+     * @param disable             {@code true} to disable performing the report
+     * @param version             (xsd 3.0) version of the schema
+     */
+    public DefaultStatelessReporter( boolean disable, String version )
+    {
+        setDisable( disable );
+        setVersion( version );
+    }
+
     @Override
     public StatelessReportEventListener<StatelessReporterEvent> createStatelessReportEventListener(
             DefaultStatelessReportMojoConfiguration configuration )
diff --git a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/TestSetMockReporterFactory.java b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/TestSetMockReporterFactory.java
index f1131ed..fe69aed 100644
--- a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/TestSetMockReporterFactory.java
+++ b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/TestSetMockReporterFactory.java
@@ -56,7 +56,7 @@ public class TestSetMockReporterFactory
     {
         File target = new File( "./target" );
         File statisticsFile = new File( target, "TESTHASH" );
-        return new StartupReportConfiguration( true, true, "PLAIN", false, false, target, false, null, statisticsFile,
+        return new StartupReportConfiguration( true, true, "PLAIN", false, target, false, null, statisticsFile,
                 false, 0, null, null, true, new DefaultStatelessReporter() );
     }
 }
diff --git a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/report/DefaultReporterFactoryTest.java b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/report/DefaultReporterFactoryTest.java
index da070e5..7a674a0 100644
--- a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/report/DefaultReporterFactoryTest.java
+++ b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/report/DefaultReporterFactoryTest.java
@@ -68,7 +68,7 @@ public class DefaultReporterFactoryTest
         MessageUtils.setColorEnabled( false );
         File reportsDirectory = new File("target");
         StartupReportConfiguration reportConfig =
-                new StartupReportConfiguration( true, true, "PLAIN", false, false, reportsDirectory, false, null,
+                new StartupReportConfiguration( true, true, "PLAIN", false, reportsDirectory, false, null,
                         new File( reportsDirectory, "TESTHASH" ), false, 1, null, null, false,
                         new DefaultStatelessReporter() );
 
diff --git a/maven-surefire-plugin/src/main/java/org/apache/maven/plugin/surefire/SurefirePlugin.java b/maven-surefire-plugin/src/main/java/org/apache/maven/plugin/surefire/SurefirePlugin.java
index 21fb2f6..e23f05e 100644
--- a/maven-surefire-plugin/src/main/java/org/apache/maven/plugin/surefire/SurefirePlugin.java
+++ b/maven-surefire-plugin/src/main/java/org/apache/maven/plugin/surefire/SurefirePlugin.java
@@ -237,7 +237,7 @@ public class SurefirePlugin
     /**
      * The character encoding scheme to be applied while generating test report
      * files (see target/surefire-reports/yourTestName.txt).
-     * The report output files (*-out.txt) are still encoded with JVM's encoding used in standard out/err pipes.
+     * The report output files (*-out.txt) are encoded in UTF-8 if not set otherwise.
      *
      * @since 3.0.0-M1
      */
diff --git a/surefire-extensions-api/src/main/java/org/apache/maven/surefire/extensions/StatelessReportMojoConfiguration.java b/surefire-extensions-api/src/main/java/org/apache/maven/surefire/extensions/StatelessReportMojoConfiguration.java
index d3c4712..7baebfd 100644
--- a/surefire-extensions-api/src/main/java/org/apache/maven/surefire/extensions/StatelessReportMojoConfiguration.java
+++ b/surefire-extensions-api/src/main/java/org/apache/maven/surefire/extensions/StatelessReportMojoConfiguration.java
@@ -72,19 +72,4 @@ public class StatelessReportMojoConfiguration
     {
         return xsdSchemaLocation;
     }
-
-    public Object clone( ClassLoader target )
-    {
-        try
-        {
-            Class<?> cls = target.loadClass( getClass().getName() );
-            return cls.getConstructor( File.class, String.class, boolean.class, int.class, String.class )
-                    .newInstance( getReportsDirectory(), getReportNameSuffix(), isTrimStackTrace(),
-                            getRerunFailingTestsCount(), getXsdSchemaLocation() );
-        }
-        catch ( ReflectiveOperationException e )
-        {
-            throw new IllegalStateException( e.getLocalizedMessage() );
-        }
-    }
 }
diff --git a/surefire-extensions-api/src/main/java/org/apache/maven/surefire/extensions/StatelessReporter.java b/surefire-extensions-api/src/main/java/org/apache/maven/surefire/extensions/StatelessReporter.java
index d3760b5..5c690c4 100644
--- a/surefire-extensions-api/src/main/java/org/apache/maven/surefire/extensions/StatelessReporter.java
+++ b/surefire-extensions-api/src/main/java/org/apache/maven/surefire/extensions/StatelessReporter.java
@@ -35,6 +35,7 @@ public abstract class StatelessReporter<E extends EventObject, C extends Statele
     /**
      * {@code false} by default
      */
+    //todo remove isDisableXmlReport() in AbstractSurefireMojo and use this param instead
     private boolean disable;
 
     /**
diff --git a/surefire-its/src/test/resources/junit-platform-engine-jupiter/pom.xml b/surefire-its/src/test/resources/junit-platform-engine-jupiter/pom.xml
index 15d76b5..e90cd36 100644
--- a/surefire-its/src/test/resources/junit-platform-engine-jupiter/pom.xml
+++ b/surefire-its/src/test/resources/junit-platform-engine-jupiter/pom.xml
@@ -71,6 +71,12 @@
                 <version>${surefire.version}</version>
                 <configuration>
                     <redirectTestOutputToFile>true</redirectTestOutputToFile>
+                    <statelessReporter implementation="org.apache.maven.plugin.surefire.extensions.JUnit5Xml30StatelessReporter">
+                        <usePhrasedFileName>false</usePhrasedFileName>
+                        <usePhrasedTestSuiteClassName>false</usePhrasedTestSuiteClassName>
+                        <usePhrasedTestCaseClassName>true</usePhrasedTestCaseClassName>
+                        <usePhrasedTestCaseMethodName>true</usePhrasedTestCaseMethodName>
+                    </statelessReporter>
                 </configuration>
             </plugin>
         </plugins>
diff --git a/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/JUnitCoreTester.java b/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/JUnitCoreTester.java
index 71ca02c..7c3e046 100644
--- a/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/JUnitCoreTester.java
+++ b/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/JUnitCoreTester.java
@@ -105,7 +105,7 @@ public class JUnitCoreTester
     {
         File target = new File( "./target" );
         File statisticsFile = new File( target, "TESTHASHxXML" );
-        return new StartupReportConfiguration( true, true, "PLAIN", false, true, target, false, null, statisticsFile,
+        return new StartupReportConfiguration( true, true, "PLAIN", false, target, false, null, statisticsFile,
                 false, 0, null, null, false, new DefaultStatelessReporter() );
     }
 }