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 2018/08/21 11:09:58 UTC
ant git commit: [junitlauncher] allow listener element to define an
outputDir for better control over where the output is generated
Repository: ant
Updated Branches:
refs/heads/master d1c59063d -> 460303f6d
[junitlauncher] allow listener element to define an outputDir for better control over where the output is generated
Project: http://git-wip-us.apache.org/repos/asf/ant/repo
Commit: http://git-wip-us.apache.org/repos/asf/ant/commit/460303f6
Tree: http://git-wip-us.apache.org/repos/asf/ant/tree/460303f6
Diff: http://git-wip-us.apache.org/repos/asf/ant/diff/460303f6
Branch: refs/heads/master
Commit: 460303f6dd173a6dfaa73c1876d1c2a8976df4b8
Parents: d1c5906
Author: Jaikiran Pai <ja...@apache.org>
Authored: Tue Aug 21 16:38:24 2018 +0530
Committer: Jaikiran Pai <ja...@apache.org>
Committed: Tue Aug 21 16:38:55 2018 +0530
----------------------------------------------------------------------
manual/Tasks/junitlauncher.html | 12 ++++++++
.../optional/junitlauncher/LauncherSupport.java | 26 +++++++++++++-----
.../junitlauncher/ListenerDefinition.java | 29 ++++++++++++++++----
3 files changed, 54 insertions(+), 13 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ant/blob/460303f6/manual/Tasks/junitlauncher.html
----------------------------------------------------------------------
diff --git a/manual/Tasks/junitlauncher.html b/manual/Tasks/junitlauncher.html
index 8cf4a22..fb36259 100644
--- a/manual/Tasks/junitlauncher.html
+++ b/manual/Tasks/junitlauncher.html
@@ -324,6 +324,18 @@
(ex: <samp>TEST-org.myapp.SomeTest.xml</samp> for the <q>legacy-xml</q> type
formatter)
</p>
+ <p>
+ This file is considered relative to the <code>outputDir</code> configured on the listener.
+ If no <code>outputDir</code> is set on the listener, then the file is considered relative to the
+ <code>outputDir</code> of the test in context of which this listener is being run.
+ </p>
+ </td>
+ <td>No</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>
</td>
<td>No</td>
</tr>
http://git-wip-us.apache.org/repos/asf/ant/blob/460303f6/src/main/org/apache/tools/ant/taskdefs/optional/junitlauncher/LauncherSupport.java
----------------------------------------------------------------------
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 f020f66..1260a3b 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
@@ -19,6 +19,7 @@
package org.apache.tools.ant.taskdefs.optional.junitlauncher;
import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.MagicNames;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.util.FileUtils;
import org.apache.tools.ant.util.KeepAliveOutputStream;
@@ -199,13 +200,7 @@ class LauncherSupport {
// set the execution context
resultFormatter.setContext(this.launchDefinition.getTestExecutionContext());
// set the destination output stream for writing out the formatted result
- final TestDefinition test = testRequest.getOwner();
- final TestExecutionContext testExecutionContext = this.launchDefinition.getTestExecutionContext();
- final Path baseDir = testExecutionContext.getProject().isPresent()
- ? testExecutionContext.getProject().get().getBaseDir().toPath() : Paths.get(System.getProperty("user.dir"));
- final java.nio.file.Path outputDir = test.getOutputDir() != null ? Paths.get(test.getOutputDir()) : baseDir;
- final String filename = formatterDefinition.requireResultFile(test);
- final java.nio.file.Path resultOutputFile = Paths.get(outputDir.toString(), filename);
+ 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
@@ -223,6 +218,23 @@ class LauncherSupport {
}
}
+ private Path getListenerOutputFile(final TestRequest testRequest, final ListenerDefinition listener) {
+ final TestDefinition test = testRequest.getOwner();
+ final String filename = listener.requireResultFile(test);
+ if (listener.getOutputDir() != null) {
+ // use the output dir defined on the listener
+ return Paths.get(listener.getOutputDir(), filename);
+ }
+ // check on the enclosing test definition, in context of which this listener is being run
+ if (test.getOutputDir() != null) {
+ return Paths.get(test.getOutputDir(), filename);
+ }
+ // neither listener nor the test define a output dir, so use basedir of the project
+ final TestExecutionContext testExecutionContext = this.launchDefinition.getTestExecutionContext();
+ final String baseDir = testExecutionContext.getProperties().getProperty(MagicNames.PROJECT_BASEDIR);
+ return Paths.get(baseDir, filename);
+ }
+
private TestExecutionListener requireTestExecutionListener(final ListenerDefinition listener, final ClassLoader classLoader) {
final String className = listener.getClassName();
if (className == null || className.trim().isEmpty()) {
http://git-wip-us.apache.org/repos/asf/ant/blob/460303f6/src/main/org/apache/tools/ant/taskdefs/optional/junitlauncher/ListenerDefinition.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/junitlauncher/ListenerDefinition.java b/src/main/org/apache/tools/ant/taskdefs/optional/junitlauncher/ListenerDefinition.java
index c24e872..b2a3dba 100644
--- a/src/main/org/apache/tools/ant/taskdefs/optional/junitlauncher/ListenerDefinition.java
+++ b/src/main/org/apache/tools/ant/taskdefs/optional/junitlauncher/ListenerDefinition.java
@@ -49,8 +49,7 @@ public class ListenerDefinition {
private String resultFile;
private boolean sendSysOut;
private boolean sendSysErr;
-
- private String defaultResultFileSuffix = "txt";
+ private String outputDir;
public ListenerDefinition() {
@@ -84,17 +83,14 @@ public class ListenerDefinition {
switch (type.getValue()) {
case LEGACY_PLAIN: {
this.setClassName("org.apache.tools.ant.taskdefs.optional.junitlauncher.LegacyPlainResultFormatter");
- this.defaultResultFileSuffix = "txt";
break;
}
case LEGACY_BRIEF: {
this.setClassName("org.apache.tools.ant.taskdefs.optional.junitlauncher.LegacyBriefResultFormatter");
- this.defaultResultFileSuffix = "txt";
break;
}
case LEGACY_XML: {
this.setClassName("org.apache.tools.ant.taskdefs.optional.junitlauncher.LegacyXmlResultFormatter");
- this.defaultResultFileSuffix = "xml";
break;
}
}
@@ -114,7 +110,14 @@ public class ListenerDefinition {
} else {
sb.append("unknown");
}
- sb.append(".").append(this.defaultResultFileSuffix);
+ sb.append(".");
+ final String suffix;
+ if ("org.apache.tools.ant.taskdefs.optional.junitlauncher.LegacyXmlResultFormatter".equals(this.className)) {
+ suffix = "xml";
+ } else {
+ suffix = "txt";
+ }
+ sb.append(suffix);
return sb.toString();
}
@@ -134,6 +137,20 @@ public class ListenerDefinition {
return this.sendSysErr;
}
+ /**
+ * Sets the output directory for this listener
+ *
+ * @param dir Path to the output directory
+ * @since Ant 1.10.6
+ */
+ public void setOutputDir(final String dir) {
+ this.outputDir = dir;
+ }
+
+ String getOutputDir() {
+ return this.outputDir;
+ }
+
protected boolean shouldUse(final Project project) {
final PropertyHelper propertyHelper = PropertyHelper.getPropertyHelper(project);
return propertyHelper.testIfCondition(this.ifProperty) && propertyHelper.testUnlessCondition(this.unlessProperty);