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/12 01:11:13 UTC

[maven-surefire] 04/04: extension abstraction for StatelessXmlReporter

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

commit f17801acc08eac9b9662b20b2ab02867cd31c8b3
Author: tibordigana <ti...@apache.org>
AuthorDate: Fri Apr 12 03:06:55 2019 +0200

    extension abstraction for StatelessXmlReporter
---
 .../plugin/surefire/AbstractSurefireMojo.java      | 10 ++--
 .../plugin/surefire/extensions/DefaultShader.java  | 53 --------------------
 .../DefaultStatelessReportMojoConfiguration.java   | 58 ++++++++++++++++++++++
 .../extensions/DefaultStatelessReporter.java       |  9 ++--
 .../maven/plugin/surefire/extensions/Shader.java   | 30 -----------
 pom.xml                                            |  2 +-
 .../extensions/StatelessReportEventListener.java   |  4 +-
 ....java => StatelessReportMojoConfiguration.java} | 52 +++++++++----------
 .../surefire/extensions/StatelessReporter.java     | 44 ++++------------
 9 files changed, 104 insertions(+), 158 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 a3cec45..6fc4c87 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
@@ -25,7 +25,7 @@ import org.apache.maven.artifact.DefaultArtifact;
 import org.apache.maven.artifact.handler.ArtifactHandler;
 import org.apache.maven.artifact.repository.ArtifactRepository;
 import org.apache.maven.model.Dependency;
-import org.apache.maven.plugin.surefire.extensions.Shader;
+import org.apache.maven.plugin.surefire.extensions.DefaultStatelessReporter;
 import org.apache.maven.plugins.annotations.Component;
 import org.apache.maven.project.ProjectBuildingRequest;
 import org.apache.maven.repository.RepositorySystem;
@@ -70,7 +70,6 @@ import org.apache.maven.surefire.booter.StartupConfiguration;
 import org.apache.maven.surefire.booter.SurefireBooterForkException;
 import org.apache.maven.surefire.booter.SurefireExecutionException;
 import org.apache.maven.surefire.cli.CommandLineOption;
-import org.apache.maven.surefire.extensions.StatelessReporter;
 import org.apache.maven.surefire.providerapi.SurefireProvider;
 import org.apache.maven.surefire.report.ReporterConfiguration;
 import org.apache.maven.surefire.suite.RunResult;
@@ -158,11 +157,8 @@ public abstract class AbstractSurefireMojo
 
     private final ProviderDetector providerDetector = new ProviderDetector();
 
-    // @Component( hint = "default", role = StatelessReporter.class )
-    private StatelessReporter statelessReporter;
-
-    @Component( hint = "default", role = Shader.class )
-    private Shader shader;
+    @Parameter
+    private DefaultStatelessReporter statelessReporter;
 
     /**
      * Information about this plugin, mainly used to lookup this plugin's configuration from the currently executing
diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/extensions/DefaultShader.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/extensions/DefaultShader.java
deleted file mode 100644
index 8230ad4..0000000
--- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/extensions/DefaultShader.java
+++ /dev/null
@@ -1,53 +0,0 @@
-package org.apache.maven.plugin.surefire.extensions;
-
-/*
- * 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.codehaus.plexus.component.annotations.Component;
-// import org.codehaus.plexus.component.annotations.Configuration;
-import org.codehaus.plexus.logging.AbstractLogEnabled;
-
-/**
- * @author Jason van Zyl
- */
-// @Component( role = Shader.class, hint = "default" )
-public class DefaultShader
-        extends AbstractLogEnabled
-        implements Shader
-{
-
-    // @Configuration( "false" )
-    private boolean disableXmlReport;
-
-    public boolean isDisableXmlReport()
-    {
-        return disableXmlReport;
-    }
-
-    public void setDisableXmlReport( boolean disableXmlReport )
-    {
-        this.disableXmlReport = disableXmlReport;
-    }
-
-    @Override
-    public void shade()
-    {
-
-    }
-}
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
new file mode 100644
index 0000000..b223deb
--- /dev/null
+++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/extensions/DefaultStatelessReportMojoConfiguration.java
@@ -0,0 +1,58 @@
+package org.apache.maven.plugin.surefire.extensions;
+
+/*
+ * 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.plugin.surefire.report.WrappedReportEntry;
+import org.apache.maven.surefire.extensions.StatelessReportMojoConfiguration;
+
+import java.io.File;
+import java.util.Deque;
+import java.util.Map;
+
+/**
+ * Why Deprecated: The field {@code testClassMethodRunHistory} makes
+ * {@link org.apache.maven.plugin.surefire.report.StatelessXmlReporter} stateful and overloads reporter by permanently
+ * overriding XML using re-run feature. To fix this issue, the providers should use more events for re-run feature and
+ * events bounding provider's execution. After provider's execution is finished, this reporter should be announced with
+ * {@link StatelessReporterEvent event} only once per test class. All test report entries should be cached in
+ * {@link org.apache.maven.plugin.surefire.report.TestSetRunListener} keeping it already stateful.
+ */
+@Deprecated
+public class DefaultStatelessReportMojoConfiguration
+        extends StatelessReportMojoConfiguration
+{
+    private final Map<String, Deque<WrappedReportEntry>> testClassMethodRunHistory;
+
+    public DefaultStatelessReportMojoConfiguration( File reportsDirectory,
+                                                    String reportNameSuffix,
+                                                    boolean trimStackTrace,
+                                                    int rerunFailingTestsCount,
+                                                    String xsdSchemaLocation,
+                                                    Map<String, Deque<WrappedReportEntry>> testClassMethodRunHistory )
+    {
+        super( reportsDirectory, reportNameSuffix, trimStackTrace, rerunFailingTestsCount, xsdSchemaLocation );
+        this.testClassMethodRunHistory = testClassMethodRunHistory;
+    }
+
+    public Map<String, Deque<WrappedReportEntry>> getTestClassMethodRunHistory()
+    {
+        return testClassMethodRunHistory;
+    }
+}
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 3838272..744edc4 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
@@ -21,17 +21,18 @@ package org.apache.maven.plugin.surefire.extensions;
 
 import org.apache.maven.surefire.extensions.StatelessReportEventListener;
 import org.apache.maven.surefire.extensions.StatelessReporter;
-// import org.codehaus.plexus.component.annotations.Component;
 
 /**
  * author <a href="mailto:tibordigana@apache.org">Tibor Digana (tibor17)</a>
  * @since 3.0.0-M4
  */
-// @Component( role = StatelessReporter.class, hint = "default" )
-public class DefaultStatelessReporter extends StatelessReporter<StatelessReporterEvent>
+public class DefaultStatelessReporter
+        extends StatelessReporter<StatelessReporterEvent, DefaultStatelessReportMojoConfiguration>
 {
+
     @Override
-    public StatelessReportEventListener<StatelessReporterEvent> createStatelessReportEventListener()
+    public StatelessReportEventListener<StatelessReporterEvent> createStatelessReportEventListener(
+            DefaultStatelessReportMojoConfiguration configuration )
     {
         return null;
     }
diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/extensions/Shader.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/extensions/Shader.java
deleted file mode 100644
index fce55f0..0000000
--- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/extensions/Shader.java
+++ /dev/null
@@ -1,30 +0,0 @@
-package org.apache.maven.plugin.surefire.extensions;
-
-/*
- * 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.
- */
-
-/**
- * Interface that defines the process of shading.
- */
-public interface Shader
-{
-    String ROLE = Shader.class.getName();
-
-    void shade();
-}
diff --git a/pom.xml b/pom.xml
index 0d380ef..25536f7 100644
--- a/pom.xml
+++ b/pom.xml
@@ -50,6 +50,7 @@
   <modules>
     <module>surefire-logger-api</module>
     <module>surefire-api</module>
+    <module>surefire-extensions-api</module>
     <module>surefire-booter</module>
     <module>surefire-grouper</module>
     <module>surefire-providers</module>
@@ -60,7 +61,6 @@
     <module>maven-failsafe-plugin</module>
     <module>maven-surefire-report-plugin</module>
     <module>surefire-its</module>
-    <module>surefire-extensions-api</module>
   </modules>
 
   <scm>
diff --git a/surefire-extensions-api/src/main/java/org/apache/maven/surefire/extensions/StatelessReportEventListener.java b/surefire-extensions-api/src/main/java/org/apache/maven/surefire/extensions/StatelessReportEventListener.java
index f5610a4..8ea318f 100644
--- a/surefire-extensions-api/src/main/java/org/apache/maven/surefire/extensions/StatelessReportEventListener.java
+++ b/surefire-extensions-api/src/main/java/org/apache/maven/surefire/extensions/StatelessReportEventListener.java
@@ -29,7 +29,7 @@ import java.util.EventObject;
  *
  * author <a href="mailto:tibordigana@apache.org">Tibor Digana (tibor17)</a>
  * @since 3.0.0-M4
- * @param <T> Generic type of event type
+ * @param <T> Generic type of event type (see org.apache.maven.plugin.surefire.extensions.StatelessReporterEvent)
  */
 public interface StatelessReportEventListener<T extends EventObject>
         extends EventListener
@@ -40,7 +40,7 @@ public interface StatelessReportEventListener<T extends EventObject>
      * The {@code event} (of type <em>org.apache.maven.plugin.surefire.extensions.StatelessReporterEvent</em>)
      * wraps <em>WrappedReportEntry</em> and <em>TestSetStats</em> from the module <em>maven-surefire-common</em>.
      * <br>
-     * The {@link EventObject#getSource()} may access <em>TestSetRunListener</em> object or returns <tt>null</tt>.
+     * The {@link EventObject#getSource()} may access <em>TestSetRunListener</em> object.
      *
      * @param event event wrapper (type can be changed between major or minor versions)
      */
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/StatelessReportMojoConfiguration.java
similarity index 54%
copy from surefire-extensions-api/src/main/java/org/apache/maven/surefire/extensions/StatelessReporter.java
copy to surefire-extensions-api/src/main/java/org/apache/maven/surefire/extensions/StatelessReportMojoConfiguration.java
index 908d1a6..c9691a5 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/StatelessReportMojoConfiguration.java
@@ -19,41 +19,32 @@ package org.apache.maven.surefire.extensions;
  * under the License.
  */
 
-// import org.codehaus.plexus.component.annotations.Configuration;
-
 import java.io.File;
-import java.util.EventObject;
 
 /**
- * @author <a href="mailto:tibordigana@apache.org">Tibor Digana (tibor17)</a>
- * @since 3.0.0-M4
- * @param <T> Generic type of event type
+ * Configuration passed to the constructor of default reporter
+ * <em>org.apache.maven.plugin.surefire.report.StatelessXmlReporter</em>.
  */
-public abstract class StatelessReporter<T extends EventObject>
+public class StatelessReportMojoConfiguration
 {
-    public static final String ROLE = StatelessReporter.class.getName();
+    private final File reportsDirectory;
 
-    // @Configuration( "false" )
-    private boolean disableXmlReport;
+    private final String reportNameSuffix;
 
-    private File reportsDirectory;
-    private boolean trimStackTrace;
+    private final boolean trimStackTrace;
 
-    /**
-     * Creates reporter.
-     *
-     * @return reporter object
-     */
-    public abstract StatelessReportEventListener<T> createStatelessReportEventListener();
+    private final int rerunFailingTestsCount;
 
-    public boolean isDisableXmlReport()
-    {
-        return disableXmlReport;
-    }
+    private final String xsdSchemaLocation;
 
-    public void setDisableXmlReport( boolean disableXmlReport )
+    public StatelessReportMojoConfiguration( File reportsDirectory, String reportNameSuffix, boolean trimStackTrace,
+                                             int rerunFailingTestsCount, String xsdSchemaLocation )
     {
-        this.disableXmlReport = disableXmlReport;
+        this.reportsDirectory = reportsDirectory;
+        this.reportNameSuffix = reportNameSuffix;
+        this.trimStackTrace = trimStackTrace;
+        this.rerunFailingTestsCount = rerunFailingTestsCount;
+        this.xsdSchemaLocation = xsdSchemaLocation;
     }
 
     public File getReportsDirectory()
@@ -61,9 +52,9 @@ public abstract class StatelessReporter<T extends EventObject>
         return reportsDirectory;
     }
 
-    public void setReportsDirectory( File reportsDirectory )
+    public String getReportNameSuffix()
     {
-        this.reportsDirectory = reportsDirectory;
+        return reportNameSuffix;
     }
 
     public boolean isTrimStackTrace()
@@ -71,8 +62,13 @@ public abstract class StatelessReporter<T extends EventObject>
         return trimStackTrace;
     }
 
-    public void setTrimStackTrace( boolean trimStackTrace )
+    public int getRerunFailingTestsCount()
     {
-        this.trimStackTrace = trimStackTrace;
+        return rerunFailingTestsCount;
+    }
+
+    public String getXsdSchemaLocation()
+    {
+        return xsdSchemaLocation;
     }
 }
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 908d1a6..ab87bcc 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
@@ -19,33 +19,18 @@ package org.apache.maven.surefire.extensions;
  * under the License.
  */
 
-// import org.codehaus.plexus.component.annotations.Configuration;
-
-import java.io.File;
 import java.util.EventObject;
 
 /**
  * @author <a href="mailto:tibordigana@apache.org">Tibor Digana (tibor17)</a>
  * @since 3.0.0-M4
  * @param <T> Generic type of event type
+ * @param <C> mojo config
  */
-public abstract class StatelessReporter<T extends EventObject>
+public abstract class StatelessReporter<T extends EventObject, C extends StatelessReportMojoConfiguration>
 {
-    public static final String ROLE = StatelessReporter.class.getName();
-
-    // @Configuration( "false" )
     private boolean disableXmlReport;
 
-    private File reportsDirectory;
-    private boolean trimStackTrace;
-
-    /**
-     * Creates reporter.
-     *
-     * @return reporter object
-     */
-    public abstract StatelessReportEventListener<T> createStatelessReportEventListener();
-
     public boolean isDisableXmlReport()
     {
         return disableXmlReport;
@@ -56,23 +41,16 @@ public abstract class StatelessReporter<T extends EventObject>
         this.disableXmlReport = disableXmlReport;
     }
 
-    public File getReportsDirectory()
-    {
-        return reportsDirectory;
-    }
-
-    public void setReportsDirectory( File reportsDirectory )
-    {
-        this.reportsDirectory = reportsDirectory;
-    }
-
-    public boolean isTrimStackTrace()
-    {
-        return trimStackTrace;
-    }
+    /**
+     * Creates reporter.
+     *
+     * @return reporter object
+     */
+    public abstract StatelessReportEventListener<T> createStatelessReportEventListener( C configuration );
 
-    public void setTrimStackTrace( boolean trimStackTrace )
+    @Override
+    public String toString()
     {
-        this.trimStackTrace = trimStackTrace;
+        return "StatelessReporter{" + "disableXmlReport=" + disableXmlReport + '}';
     }
 }