Skip to content

Commit c8bc470

Browse files
azotcsitjaikiran
authored andcommitted
junitlauncher - Support extension attribute for listeners
This closes #168 pull request at github.com/apache/ant
1 parent 5db51ce commit c8bc470

File tree

6 files changed

+37
-10
lines changed

6 files changed

+37
-10
lines changed

CONTRIBUTORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Adam Sotona
88
Adrian Nistor
99
Adrien Grand
1010
Aleksandr Ishutin
11+
Aleksei Zotov
1112
Alex
1213
Alex Rosen
1314
Alexander Grund

WHATSNEW

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ Other changes:
88
repackaged Jakarta Mail package rather than javax Mail.
99
Github Pull Request #161
1010

11+
* The "listener" element in the junitlauncher task now supports
12+
an "extension" attribute to control the filename extension
13+
of the generated output file from the listener.
14+
Github Pull Request #168
15+
1116
Changes from Ant 1.10.11 TO Ant 1.10.12
1217
=======================================
1318

contributors.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@
6262
<first>Aleksandr</first>
6363
<last>Ishutin</last>
6464
</name>
65+
<name>
66+
<first>Aleksei</first>
67+
<last>Zotov</last>
68+
</name>
6569
<name>
6670
<first>Alex</first>
6771
<last></last>

manual/Tasks/junitlauncher.html

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ <h5>Test result formatter</h5>
354354
If no value is specified for this attribute and the listener implements
355355
the <code>org.apache.tools.ant.taskdefs.optional.junitlauncher.TestResultFormatter</code>
356356
then the file name will be defaulted to and will be of the
357-
form <code>TEST-<i>testname</i>.<i>formatter-specific-extension</i></code>
357+
form <code>TEST-<i>testname</i>.<i>extension</i></code>
358358
(ex: <samp>TEST-org.myapp.SomeTest.xml</samp> for the <q>legacy-xml</q> type
359359
formatter)
360360
</p>
@@ -366,6 +366,13 @@ <h5>Test result formatter</h5>
366366
</td>
367367
<td>No</td>
368368
</tr>
369+
<tr>
370+
<td>extension</td>
371+
<td>Extension to append to the output filename.
372+
<p><em>Since Ant 1.10.13</em></p>
373+
</td>
374+
<td>No; defaults to <q>xml</q> for the <q>legacy-xml</q> formatter and to <q>txt</q> for the rest</td>
375+
</tr>
369376
<tr>
370377
<td>outputDir</td>
371378
<td>Directory into which to create the output of the listener.
@@ -406,10 +413,10 @@ <h5>Test result formatter</h5>
406413
<tr>
407414
<td>useLegacyReportingName</td>
408415
<td>Set to true, if the test identifiers reported by this listener should use legacy (JUnit4
409-
style) names. Else set to false. Defaults to true.
416+
style) names. Else set to false.
410417
<p><em>Since Ant 1.10.10</em></p>
411418
</td>
412-
<td>No</td>
419+
<td>No; defaults to <q>true</q></td>
413420
</tr>
414421
</table>
415422

src/main/org/apache/tools/ant/taskdefs/optional/junitlauncher/LauncherSupport.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -282,13 +282,7 @@ private Path getListenerOutputFile(final TestRequest testRequest, final Listener
282282
final StringBuilder sb = new StringBuilder("TEST-");
283283
sb.append(testRequest.getName() == null ? "unknown" : testRequest.getName());
284284
sb.append(".");
285-
final String suffix;
286-
if ("org.apache.tools.ant.taskdefs.optional.junitlauncher.LegacyXmlResultFormatter".equals(listener.getClassName())) {
287-
suffix = "xml";
288-
} else {
289-
suffix = "txt";
290-
}
291-
sb.append(suffix);
285+
sb.append(listener.getExtension());
292286
filename = sb.toString();
293287
}
294288
if (listener.getOutputDir() != null) {

src/main/org/apache/tools/ant/taskdefs/optional/junitlauncher/confined/ListenerDefinition.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ public class ListenerDefinition {
4949
private String unlessProperty;
5050
private String className;
5151
private String resultFile;
52+
private String extension = "txt";
5253
private boolean sendSysOut;
5354
private boolean sendSysErr;
5455
private String outputDir;
@@ -94,6 +95,7 @@ public void setType(final ListenerType type) {
9495
}
9596
case LEGACY_XML: {
9697
this.setClassName("org.apache.tools.ant.taskdefs.optional.junitlauncher.LegacyXmlResultFormatter");
98+
this.setExtension("xml");
9799
break;
98100
}
99101
}
@@ -107,6 +109,20 @@ public String getResultFile() {
107109
return this.resultFile;
108110
}
109111

112+
/**
113+
* Sets the output file extension for this listener.
114+
*
115+
* @param extension file extension to use
116+
* @since Ant 1.10.13
117+
*/
118+
public void setExtension(String extension) {
119+
this.extension = extension;
120+
}
121+
122+
public String getExtension() {
123+
return extension;
124+
}
125+
110126
public void setSendSysOut(final boolean sendSysOut) {
111127
this.sendSysOut = sendSysOut;
112128
}

0 commit comments

Comments
 (0)