diff --git a/manual/Tasks/junitlauncher.html b/manual/Tasks/junitlauncher.html index 0f20648e41..c7d3414378 100644 --- a/manual/Tasks/junitlauncher.html +++ b/manual/Tasks/junitlauncher.html @@ -240,7 +240,7 @@
truethen the listener's output will be saved to a file. Otherwise, the output will be sent + to
stdout
and outputDir
, resultFile
, extension
+ attributes will be ignored.
+ Since Ant 1.10.13
+true
truethen the listener will be passed the
stdout
content
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 00b76df8a2..87b289f345 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
@@ -256,10 +256,14 @@ private void setupResultFormatter(final TestRequest testRequest, final ListenerD
// set the destination output stream for writing out the formatted result
final java.nio.file.Path resultOutputFile = getListenerOutputFile(testRequest, formatterDefinition);
try {
- final OutputStream resultOutputStream = Files.newOutputStream(resultOutputFile);
- // enroll the output stream to be closed when the execution of the TestRequest completes
- testRequest.closeUponCompletion(resultOutputStream);
- resultFormatter.setDestination(new KeepAliveOutputStream(resultOutputStream));
+ if (formatterDefinition.shouldUseFile()) {
+ final OutputStream resultOutputStream = Files.newOutputStream(resultOutputFile);
+ // enroll the output stream to be closed when the execution of the TestRequest completes
+ testRequest.closeUponCompletion(resultOutputStream);
+ resultFormatter.setDestination(new KeepAliveOutputStream(resultOutputStream));
+ } else {
+ resultFormatter.setDestination(new KeepAliveOutputStream(System.out));
+ }
} catch (IOException e) {
throw new BuildException(e);
}
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 215d3f8431..75967d7db1 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
@@ -49,6 +49,7 @@ public final class Constants {
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_EXTENSION = "extension";
+ public static final String LD_XML_ATTR_LISTENER_USE_FILE = "useFile";
public static final String LD_XML_ATTR_LISTENER_USE_LEGACY_REPORTING_NAME = "useLegacyReportingName";
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 e661fd3c43..0b583e09a1 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
@@ -29,6 +29,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_EXTENSION;
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_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;
@@ -51,6 +52,7 @@ public class ListenerDefinition {
private String className;
private String resultFile;
private String extension = "txt";
+ private boolean useFile = true;
private boolean sendSysOut;
private boolean sendSysErr;
private String outputDir;
@@ -124,6 +126,19 @@ public String getExtension() {
return extension;
}
+ /**
+ * Sets whether the formatter should log to a file.
+ * @param useFile if true use a file, if false send to standard out.
+ * @since Ant 1.10.13
+ */
+ public void setUseFile(boolean useFile) {
+ this.useFile = useFile;
+ }
+
+ public boolean shouldUseFile() {
+ return useFile;
+ }
+
public void setSendSysOut(final boolean sendSysOut) {
this.sendSysOut = sendSysOut;
}
@@ -206,6 +221,7 @@ void toForkedRepresentation(final XMLStreamWriter writer) throws XMLStreamExcept
if (this.extension != null) {
writer.writeAttribute(LD_XML_ATTR_LISTENER_EXTENSION, this.extension);
}
+ writer.writeAttribute(LD_XML_ATTR_LISTENER_USE_FILE, Boolean.toString(this.useFile));
writer.writeEndElement();
}
@@ -234,6 +250,10 @@ public static ListenerDefinition fromForkedRepresentation(final XMLStreamReader
if (extension != null) {
listenerDef.setExtension(extension);
}
+ final String useFile = reader.getAttributeValue(null, LD_XML_ATTR_LISTENER_USE_FILE);
+ if (useFile != null) {
+ listenerDef.setUseFile(Boolean.parseBoolean(useFile));
+ }
final String useLegacyReportingName = reader.getAttributeValue(null,
LD_XML_ATTR_LISTENER_USE_LEGACY_REPORTING_NAME);
if (useLegacyReportingName != null) {