Skip to content

Commit

Permalink
junitlauncher - Support useFile attribute for listeners
Browse files Browse the repository at this point in the history
  • Loading branch information
azotcsit committed Nov 16, 2021
1 parent c8bc470 commit 372bc1a
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
11 changes: 10 additions & 1 deletion manual/Tasks/junitlauncher.html
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ <h4 id="nested-classpath">classpath</h4>
&lt;/classpath&gt;
&lt;testclasses outputdir="${output.dir}"&gt;
&lt;fileset dir="${build.classes.dir}"/&gt;
&lt;listener type="legacy-brief" sendSysOut="true"/&gt;
&lt;listener type="legacy-brief" sendSysOut="true" useFile="false"/&gt;
&lt;listener type="legacy-xml" sendSysErr="true" sendSysOut="true"/&gt;

&lt;/testclasses&gt;
Expand Down Expand Up @@ -380,6 +380,15 @@ <h5>Test result formatter</h5>
</td>
<td>No</td>
</tr>
<tr>
<td>useFile</td>
<td>If set to <q>true</q> then the listener's output will be saved to a file. Otherwise, the output will be sent
to <code>stdout</code> and <code>outputDir</code>, <code>resultFile</code>, <code>extension</code>
attributes will be ignored.
<p><em>Since Ant 1.10.13</em></p>
</td>
<td>No; defaults to <q>true</q></td>
</tr>
<tr>
<td>sendSysOut</td>
<td>If set to <q>true</q> then the listener will be passed the <code>stdout</code> content
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,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;
Expand Down Expand Up @@ -123,6 +124,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;
}
Expand Down

0 comments on commit 372bc1a

Please sign in to comment.