[junitlauncher] - Introduce the ability to let listener/result formatter implementations decide whether to use legacy or new style display names for test identifiers
diff --git a/WHATSNEW b/WHATSNEW
index 15ab134..c25a17b 100644
--- a/WHATSNEW
+++ b/WHATSNEW
@@ -12,6 +12,16 @@
  * javaversion condition now has a new "atmost" attribute. See the javaversion
    manual for more details
 
+ * The "listener" nested element of the "junitlauncher" task now has a new
+   "useLegacyReportingName" attribute which can be used to control the test
+   identifiers names that get reported by the listener. See the junitlauncher
+   manual for more details.
+   Note that this change also introduces a new "setUseLegacyReportingName" method
+   on the org.apache.tools.ant.taskdefs.optional.junitlauncher.TestResultFormatter
+   interface. This will break backward compatibility with any of your custom
+   result formatters which implemented this interface and such implementations
+   are now expected to implement this new method.
+
 Changes from Ant 1.10.8 TO Ant 1.10.9
 =====================================
 
diff --git a/manual/Tasks/junitlauncher.html b/manual/Tasks/junitlauncher.html
index ec14e03..4a96e71 100644
--- a/manual/Tasks/junitlauncher.html
+++ b/manual/Tasks/junitlauncher.html
@@ -402,6 +402,14 @@
             is <strong>not</strong> set</a>.</td>
         <td>No</td>
     </tr>
+    <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.
+            <p><em>Since Ant 1.10.10</em></p>
+        </td>
+        <td>No</td>
+    </tr>
 </table>
 
 <h4>test</h4>
diff --git a/src/etc/testcases/taskdefs/optional/junitlauncher.xml b/src/etc/testcases/taskdefs/optional/junitlauncher.xml
index f86ddc8..87b00ad 100644
--- a/src/etc/testcases/taskdefs/optional/junitlauncher.xml
+++ b/src/etc/testcases/taskdefs/optional/junitlauncher.xml
@@ -161,7 +161,7 @@
                     <sysproperty key="junitlauncher.test.sysprop.one" value="forked"/>
                 </fork>
 
-                <listener type="legacy-xml" sendSysErr="true" sendSysOut="true"/>
+                <listener type="legacy-xml" sendSysErr="true" sendSysOut="true" useLegacyReportingName="false"/>
             </test>
         </junitlauncher>
     </target>
@@ -368,6 +368,7 @@
                 </fork>
             </testclasses>
             <listener type="legacy-plain" sendSysOut="true" />
+            <listener type="legacy-brief" sendSysOut="true" useLegacyReportingName="true"/>
         </junitlauncher>
     </target>
 </project>
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 a5ce996..3b56016 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
@@ -226,6 +226,7 @@
         testRequest.closeUponCompletion(resultFormatter);
         // set the execution context
         resultFormatter.setContext(this.testExecutionContext);
+        resultFormatter.setUseLegacyReportingName(formatterDefinition.isUseLegacyReportingName());
         // set the destination output stream for writing out the formatted result
         final java.nio.file.Path resultOutputFile = getListenerOutputFile(testRequest, formatterDefinition);
         try {
diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/junitlauncher/LegacyPlainResultFormatter.java b/src/main/org/apache/tools/ant/taskdefs/optional/junitlauncher/LegacyPlainResultFormatter.java
index 997e86e..7583d78 100644
--- a/src/main/org/apache/tools/ant/taskdefs/optional/junitlauncher/LegacyPlainResultFormatter.java
+++ b/src/main/org/apache/tools/ant/taskdefs/optional/junitlauncher/LegacyPlainResultFormatter.java
@@ -47,6 +47,7 @@
     private final Map<TestIdentifier, Stats> testIds = new ConcurrentHashMap<>();
     private TestPlan testPlan;
     private BufferedWriter writer;
+    private boolean useLegacyReportingName = true;
 
     @Override
     public void testPlanExecutionStarted(final TestPlan testPlan) {
@@ -111,7 +112,7 @@
         if (testIdentifier.isTest()) {
             final StringBuilder sb = new StringBuilder();
             sb.append("Test: ");
-            sb.append(testIdentifier.getLegacyReportingName());
+            sb.append(this.useLegacyReportingName ? testIdentifier.getLegacyReportingName() : testIdentifier.getDisplayName());
             sb.append(" took ");
             stats.appendElapsed(sb);
             sb.append(" SKIPPED");
@@ -175,7 +176,7 @@
         if (testIdentifier.isTest() && shouldReportExecutionFinished(testIdentifier, testExecutionResult)) {
             final StringBuilder sb = new StringBuilder();
             sb.append("Test: ");
-            sb.append(testIdentifier.getLegacyReportingName());
+            sb.append(this.useLegacyReportingName ? testIdentifier.getLegacyReportingName() : testIdentifier.getDisplayName());
             if (stats != null) {
                 sb.append(" took ");
                 stats.appendElapsed(sb);
@@ -230,6 +231,11 @@
         this.writer = new BufferedWriter(new OutputStreamWriter(this.outputStream, StandardCharsets.UTF_8));
     }
 
+    @Override
+    public void setUseLegacyReportingName(final boolean useLegacyReportingName) {
+        this.useLegacyReportingName = useLegacyReportingName;
+    }
+
     protected boolean shouldReportExecutionFinished(final TestIdentifier testIdentifier, final TestExecutionResult testExecutionResult) {
         return true;
     }
diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/junitlauncher/LegacyXmlResultFormatter.java b/src/main/org/apache/tools/ant/taskdefs/optional/junitlauncher/LegacyXmlResultFormatter.java
index dad1cc8..c0d4bee 100644
--- a/src/main/org/apache/tools/ant/taskdefs/optional/junitlauncher/LegacyXmlResultFormatter.java
+++ b/src/main/org/apache/tools/ant/taskdefs/optional/junitlauncher/LegacyXmlResultFormatter.java
@@ -63,6 +63,7 @@
     private final AtomicLong numTestsFailed = new AtomicLong(0);
     private final AtomicLong numTestsSkipped = new AtomicLong(0);
     private final AtomicLong numTestsAborted = new AtomicLong(0);
+    private boolean useLegacyReportingName = true;
 
 
     @Override
@@ -141,6 +142,11 @@
         this.outputStream = os;
     }
 
+    @Override
+    public void setUseLegacyReportingName(final boolean useLegacyReportingName) {
+        this.useLegacyReportingName = useLegacyReportingName;
+    }
+
     private final class Stats {
         @SuppressWarnings("unused")
         private final TestIdentifier testIdentifier;
@@ -252,7 +258,8 @@
                 final String classname = (parentClassSource.get()).getClassName();
                 writer.writeStartElement(ELEM_TESTCASE);
                 writer.writeAttribute(ATTR_CLASSNAME, classname);
-                writer.writeAttribute(ATTR_NAME, testId.getLegacyReportingName());
+                writer.writeAttribute(ATTR_NAME, useLegacyReportingName ? testId.getLegacyReportingName()
+                        : testId.getDisplayName());
                 final Stats stats = entry.getValue();
                 writer.writeAttribute(ATTR_TIME, String.valueOf((stats.endedAt - stats.startedAt) / ONE_SECOND));
                 // skipped element if the test was skipped
diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/junitlauncher/TestResultFormatter.java b/src/main/org/apache/tools/ant/taskdefs/optional/junitlauncher/TestResultFormatter.java
index f59641b..4de168a 100644
--- a/src/main/org/apache/tools/ant/taskdefs/optional/junitlauncher/TestResultFormatter.java
+++ b/src/main/org/apache/tools/ant/taskdefs/optional/junitlauncher/TestResultFormatter.java
@@ -51,6 +51,17 @@
     void setContext(TestExecutionContext context);
 
     /**
+     * This method will be invoked by the {@code junitlauncher} to let the result formatter implementation
+     * know whether or not to use JUnit 4 style, legacy reporting names for test identifiers that get
+     * displayed in the test reports. Result formatter implementations are allowed to default to a specific
+     * reporting style for test identifiers, if this method isn't invoked.
+     * @param useLegacyReportingName {@code true} if legacy reporting name is to be used, {@code false}
+     *                               otherwise.
+     * @since Ant 1.10.10
+     */
+    void setUseLegacyReportingName(boolean useLegacyReportingName);
+
+    /**
      * This method will be invoked by the <code>junitlauncher</code>, <strong>regularly/multiple times</strong>,
      * as and when any content is generated on the standard output stream during the test execution.
      * This method will be only be called if the <code>sendSysOut</code> attribute of the <code>listener</code>,
diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/junitlauncher/confined/Constants.java b/src/main/org/apache/tools/ant/taskdefs/optional/junitlauncher/confined/Constants.java
index ddd5902..7117907 100644
--- a/src/main/org/apache/tools/ant/taskdefs/optional/junitlauncher/confined/Constants.java
+++ b/src/main/org/apache/tools/ant/taskdefs/optional/junitlauncher/confined/Constants.java
@@ -48,6 +48,7 @@
     public static final String LD_XML_ATTR_SEND_SYS_ERR = "sendSysErr";
     public static final String LD_XML_ATTR_SEND_SYS_OUT = "sendSysOut";
     public static final String LD_XML_ATTR_LISTENER_RESULT_FILE = "resultFile";
+    public static final String LD_XML_ATTR_LISTENER_USE_LEGACY_REPORTING_NAME = "useLegacyReportingName";
 
 
     private Constants() {
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 c600e60..ce9fdee 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
@@ -28,6 +28,7 @@
 
 import static org.apache.tools.ant.taskdefs.optional.junitlauncher.confined.Constants.LD_XML_ATTR_CLASS_NAME;
 import static org.apache.tools.ant.taskdefs.optional.junitlauncher.confined.Constants.LD_XML_ATTR_LISTENER_RESULT_FILE;
+import static org.apache.tools.ant.taskdefs.optional.junitlauncher.confined.Constants.LD_XML_ATTR_LISTENER_USE_LEGACY_REPORTING_NAME;
 import static org.apache.tools.ant.taskdefs.optional.junitlauncher.confined.Constants.LD_XML_ATTR_OUTPUT_DIRECTORY;
 import static org.apache.tools.ant.taskdefs.optional.junitlauncher.confined.Constants.LD_XML_ATTR_SEND_SYS_ERR;
 import static org.apache.tools.ant.taskdefs.optional.junitlauncher.confined.Constants.LD_XML_ATTR_SEND_SYS_OUT;
@@ -51,6 +52,7 @@
     private boolean sendSysOut;
     private boolean sendSysErr;
     private String outputDir;
+    private boolean useLegacyReportingName = true;
 
     public ListenerDefinition() {
 
@@ -135,6 +137,26 @@
         return this.outputDir;
     }
 
+    /**
+     *
+     * @return Returns {@code true} if legacy reporting name (JUnit 4 style) is to be used.
+     *         Else returns {@code false}.
+     * @since Ant 1.10.10
+     */
+    public boolean isUseLegacyReportingName() {
+        return useLegacyReportingName;
+    }
+
+    /**
+     * Set the test identifier reporting style
+     * @param useLegacyReportingName {@code true} if legacy reporting name (JUnit 4 style) is to
+     *                               be used. Else {@code false}.
+     * @since Ant 1.10.10
+     */
+    public void setUseLegacyReportingName(final boolean useLegacyReportingName) {
+        this.useLegacyReportingName = useLegacyReportingName;
+    }
+
     public boolean shouldUse(final Project project) {
         final PropertyHelper propertyHelper = PropertyHelper.getPropertyHelper(project);
         return propertyHelper.testIfCondition(this.ifProperty) && propertyHelper.testUnlessCondition(this.unlessProperty);
@@ -157,6 +179,7 @@
         writer.writeAttribute(LD_XML_ATTR_CLASS_NAME, this.className);
         writer.writeAttribute(LD_XML_ATTR_SEND_SYS_ERR, Boolean.toString(this.sendSysErr));
         writer.writeAttribute(LD_XML_ATTR_SEND_SYS_OUT, Boolean.toString(this.sendSysOut));
+        writer.writeAttribute(LD_XML_ATTR_LISTENER_USE_LEGACY_REPORTING_NAME, Boolean.toString(this.useLegacyReportingName));
         if (this.outputDir != null) {
             writer.writeAttribute(LD_XML_ATTR_OUTPUT_DIRECTORY, this.outputDir);
         }
@@ -187,6 +210,11 @@
         if (resultFile != null) {
             listenerDef.setResultFile(resultFile);
         }
+        final String useLegacyReportingName = reader.getAttributeValue(null,
+                LD_XML_ATTR_LISTENER_USE_LEGACY_REPORTING_NAME);
+        if (useLegacyReportingName != null) {
+            listenerDef.setUseLegacyReportingName(Boolean.parseBoolean(useLegacyReportingName));
+        }
         reader.nextTag();
         reader.require(XMLStreamConstants.END_ELEMENT, null, LD_XML_ELM_LISTENER);
         return listenerDef;
diff --git a/src/tests/junit/org/example/junitlauncher/Tracker.java b/src/tests/junit/org/example/junitlauncher/Tracker.java
index ba31ec8..ec5f30a 100644
--- a/src/tests/junit/org/example/junitlauncher/Tracker.java
+++ b/src/tests/junit/org/example/junitlauncher/Tracker.java
@@ -74,6 +74,11 @@
     }
 
     @Override
+    public void setUseLegacyReportingName(final boolean useLegacyReportingName) {
+        // do nothing
+    }
+
+    @Override
     public void close() throws IOException {
         this.writer.flush();
         if (this.appendModeFile != null) {