You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ant.apache.org by ja...@apache.org on 2021/11/16 12:38:37 UTC

[ant] branch master updated: junitlauncher - Support extension attribute for listeners This closes #168 pull request at github.com/apache/ant

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

jaikiran pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ant.git


The following commit(s) were added to refs/heads/master by this push:
     new c8bc470  junitlauncher - Support extension attribute for listeners This closes #168 pull request at github.com/apache/ant
c8bc470 is described below

commit c8bc470774001278b809f69898bc43e98933ff15
Author: Aleksei Zotov <az...@gmail.com>
AuthorDate: Mon Nov 15 18:20:17 2021 +0400

    junitlauncher - Support extension attribute for listeners
    This closes #168 pull request at github.com/apache/ant
---
 CONTRIBUTORS                                             |  1 +
 WHATSNEW                                                 |  5 +++++
 contributors.xml                                         |  4 ++++
 manual/Tasks/junitlauncher.html                          | 13 ++++++++++---
 .../taskdefs/optional/junitlauncher/LauncherSupport.java |  8 +-------
 .../junitlauncher/confined/ListenerDefinition.java       | 16 ++++++++++++++++
 6 files changed, 37 insertions(+), 10 deletions(-)

diff --git a/CONTRIBUTORS b/CONTRIBUTORS
index d0e684e..5cbe061 100644
--- a/CONTRIBUTORS
+++ b/CONTRIBUTORS
@@ -8,6 +8,7 @@ Adam Sotona
 Adrian Nistor
 Adrien Grand
 Aleksandr Ishutin
+Aleksei Zotov
 Alex
 Alex Rosen
 Alexander Grund
diff --git a/WHATSNEW b/WHATSNEW
index 293f486..49c7815 100644
--- a/WHATSNEW
+++ b/WHATSNEW
@@ -8,6 +8,11 @@ Other changes:
   repackaged Jakarta Mail package rather than javax Mail.
   Github Pull Request #161
 
+* The "listener" element in the junitlauncher task now supports
+  an "extension" attribute to control the filename extension
+  of the generated output file from the listener.
+  Github Pull Request #168
+
 Changes from Ant 1.10.11 TO Ant 1.10.12
 =======================================
 
diff --git a/contributors.xml b/contributors.xml
index 74329cf..574f45e 100644
--- a/contributors.xml
+++ b/contributors.xml
@@ -63,6 +63,10 @@
     <last>Ishutin</last>
   </name>
   <name>
+    <first>Aleksei</first>
+    <last>Zotov</last>
+  </name>
+  <name>
     <first>Alex</first>
     <last></last>
   </name>
diff --git a/manual/Tasks/junitlauncher.html b/manual/Tasks/junitlauncher.html
index f8899bb..0f20648 100644
--- a/manual/Tasks/junitlauncher.html
+++ b/manual/Tasks/junitlauncher.html
@@ -354,7 +354,7 @@
                 If no value is specified for this attribute and the listener implements
                 the <code>org.apache.tools.ant.taskdefs.optional.junitlauncher.TestResultFormatter</code>
                 then the file name will be defaulted to and will be of the
-                form <code>TEST-<i>testname</i>.<i>formatter-specific-extension</i></code>
+                form <code>TEST-<i>testname</i>.<i>extension</i></code>
                 (ex: <samp>TEST-org.myapp.SomeTest.xml</samp> for the <q>legacy-xml</q> type
                 formatter)
             </p>
@@ -367,6 +367,13 @@
         <td>No</td>
     </tr>
     <tr>
+        <td>extension</td>
+        <td>Extension to append to the output filename.
+            <p><em>Since Ant 1.10.13</em></p>
+        </td>
+        <td>No; defaults to <q>xml</q> for the <q>legacy-xml</q> formatter and to <q>txt</q> for the rest</td>
+    </tr>
+    <tr>
         <td>outputDir</td>
         <td>Directory into which to create the output of the listener.
             <p><em>Since Ant 1.10.6</em></p>
@@ -406,10 +413,10 @@
     <tr>
         <td>useLegacyReportingName</td>
         <td>Set to true, if the test identifiers reported by this listener should use legacy (JUnit4
-            style) names. Else set to false. Defaults to true.
+            style) names. Else set to false.
             <p><em>Since Ant 1.10.10</em></p>
         </td>
-        <td>No</td>
+        <td>No; defaults to <q>true</q></td>
     </tr>
 </table>
 
diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/junitlauncher/LauncherSupport.java b/src/main/org/apache/tools/ant/taskdefs/optional/junitlauncher/LauncherSupport.java
index 7bd65e3..00b76df 100644
--- a/src/main/org/apache/tools/ant/taskdefs/optional/junitlauncher/LauncherSupport.java
+++ b/src/main/org/apache/tools/ant/taskdefs/optional/junitlauncher/LauncherSupport.java
@@ -282,13 +282,7 @@ public class LauncherSupport {
             final StringBuilder sb = new StringBuilder("TEST-");
             sb.append(testRequest.getName() == null ? "unknown" : testRequest.getName());
             sb.append(".");
-            final String suffix;
-            if ("org.apache.tools.ant.taskdefs.optional.junitlauncher.LegacyXmlResultFormatter".equals(listener.getClassName())) {
-                suffix = "xml";
-            } else {
-                suffix = "txt";
-            }
-            sb.append(suffix);
+            sb.append(listener.getExtension());
             filename = sb.toString();
         }
         if (listener.getOutputDir() != null) {
diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/junitlauncher/confined/ListenerDefinition.java b/src/main/org/apache/tools/ant/taskdefs/optional/junitlauncher/confined/ListenerDefinition.java
index ce9fdee..52479a9 100644
--- a/src/main/org/apache/tools/ant/taskdefs/optional/junitlauncher/confined/ListenerDefinition.java
+++ b/src/main/org/apache/tools/ant/taskdefs/optional/junitlauncher/confined/ListenerDefinition.java
@@ -49,6 +49,7 @@ public class ListenerDefinition {
     private String unlessProperty;
     private String className;
     private String resultFile;
+    private String extension = "txt";
     private boolean sendSysOut;
     private boolean sendSysErr;
     private String outputDir;
@@ -94,6 +95,7 @@ public class ListenerDefinition {
             }
             case LEGACY_XML: {
                 this.setClassName("org.apache.tools.ant.taskdefs.optional.junitlauncher.LegacyXmlResultFormatter");
+                this.setExtension("xml");
                 break;
             }
         }
@@ -107,6 +109,20 @@ public class ListenerDefinition {
         return this.resultFile;
     }
 
+    /**
+     * Sets the output file extension for this listener.
+     *
+     * @param extension file extension to use
+     * @since Ant 1.10.13
+     */
+    public void setExtension(String extension) {
+        this.extension = extension;
+    }
+
+    public String getExtension() {
+        return extension;
+    }
+
     public void setSendSysOut(final boolean sendSysOut) {
         this.sendSysOut = sendSysOut;
     }