bodewig 00/12/18 07:40:42
Modified: src/main/org/apache/tools/ant/taskdefs/optional/junit
BaseTest.java BatchTest.java JUnitTask.java
JUnitTest.java
Log:
Make the directory for the output of <junit> configurable.
Submitted by: Stephane Bailliez <[EMAIL PROTECTED]>
Revision Changes Path
1.2 +25 -2
jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/junit/BaseTest.java
Index: BaseTest.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/junit/BaseTest.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- BaseTest.java 2000/09/14 08:49:39 1.1
+++ BaseTest.java 2000/12/18 15:40:36 1.2
@@ -23,7 +23,7 @@
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
- * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
+ * 4. The names "The Jakarta Project", "Ant", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
@@ -54,12 +54,14 @@
package org.apache.tools.ant.taskdefs.optional.junit;
+import java.io.File;
import java.util.Vector;
/**
* Baseclass for BatchTest and JUnitTest.
*
- * @author <a href="mailto:[EMAIL PROTECTED]">Stefan Bodewig</a>
+ * @author <a href="mailto:[EMAIL PROTECTED]">Stefan Bodewig</a>
+ * @author <a href="mailto:[EMAIL PROTECTED]">Stephane Bailliez</a>
*/
public abstract class BaseTest {
protected boolean haltOnError = false;
@@ -68,6 +70,8 @@
protected String ifProperty = null;
protected String unlessProperty = null;
protected Vector formatters = new Vector();
+ /** destination directory */
+ protected File destDir = null;
public void setFork(boolean value) {
fork = value;
@@ -104,4 +108,23 @@
public void addFormatter(FormatterElement elem) {
formatters.addElement(elem);
}
+
+ /**
+ * Sets the destination directory.
+ */
+ public void setTodir(File destDir) {
+ this.destDir = destDir;
+ }
+
+ /**
+ * @return the destination directory as an absolute path if it exists
+ * otherwise return <tt>null</tt>
+ */
+ public String getTodir(){
+ if (destDir != null){
+ return destDir.getAbsolutePath();
+ }
+ return null;
+ }
+
}
1.4 +10 -3
jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/junit/BatchTest.java
Index: BatchTest.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/junit/BatchTest.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- BatchTest.java 2000/09/14 08:49:39 1.3
+++ BatchTest.java 2000/12/18 15:40:37 1.4
@@ -23,7 +23,7 @@
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
- * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
+ * 4. The names "The Jakarta Project", "Ant", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
@@ -61,12 +61,14 @@
import org.apache.tools.ant.types.Reference;
import java.util.*;
+import java.io.File;
/**
* Create JUnitTests from a list of files.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Jeff Martin</a>
- * @author <a href="mailto:[EMAIL PROTECTED]">Stefan Bodewig</a>
+ * @author <a href="mailto:[EMAIL PROTECTED]">Stefan Bodewig</a>
+ * @author <a href="mailto:[EMAIL PROTECTED]">Stephane Bailliez</a>
*/
public final class BatchTest extends BaseTest {
private Project project;
@@ -87,8 +89,9 @@
public class FileList implements Enumeration{
private String files[]=null;
+
private int i=0;
-
+
private FileList(){
Vector v = new Vector();
for (int j=0; j<filesets.size(); j++) {
@@ -108,10 +111,12 @@
files = new String[v.size()];
v.copyInto(files);
}
+
public final boolean hasMoreElements(){
if(i<files.length)return true;
return false;
}
+
public final Object nextElement() throws NoSuchElementException{
if(hasMoreElements()){
JUnitTest test = new JUnitTest(javaToClass(files[i]));
@@ -120,6 +125,7 @@
test.setFork(fork);
test.setIf(ifProperty);
test.setUnless(unlessProperty);
+ test.setTodir(destDir);
Enumeration list = formatters.elements();
while (list.hasMoreElements()) {
test.addFormatter((FormatterElement)list.nextElement());
@@ -129,6 +135,7 @@
}
throw new NoSuchElementException();
}
+
public final String javaToClass(String fileName){
return fileName.replace(java.io.File.separatorChar, '.');
}
1.14 +28 -20
jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java
Index: JUnitTask.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- JUnitTask.java 2000/11/25 02:38:49 1.13
+++ JUnitTask.java 2000/12/18 15:40:37 1.14
@@ -23,7 +23,7 @@
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
- * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
+ * 4. The names "The Jakarta Project", "Ant", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
@@ -84,6 +84,7 @@
*
* @author Thomas Haas
* @author <a href="mailto:[EMAIL PROTECTED]">Stefan Bodewig</a>
+ * @author <a href="mailto:[EMAIL PROTECTED]">Stephane Bailliez</a>
*/
public class JUnitTask extends Task {
@@ -204,8 +205,12 @@
continue;
}
+ if (test.getTodir() == null){
+ test.setTodir(project.resolveFile("."));
+ }
+
if (test.getOutfile() == null) {
- test.setOutfile(project.resolveFile("TEST-" +
test.getName()));
+ test.setOutfile( "TEST-" + test.getName() );
}
int exitValue = JUnitTestRunner.ERRORS;
@@ -246,22 +251,12 @@
for (int i=0; i<formatters.size(); i++) {
FormatterElement fe = (FormatterElement)
formatters.elementAt(i);
- if (fe.getUseFile()) {
- fe.setOutfile(project.resolveFile(test.getOutfile()
-
+fe.getExtension()));
- } else {
- fe.setOutput(new LogOutputStream(this,
Project.MSG_INFO));
- }
+ setOutput(fe, test);
runner.addFormatter(fe.createFormatter());
}
FormatterElement[] add = test.getFormatters();
for (int i=0; i<add.length; i++) {
- if (add[i].getUseFile()) {
-
add[i].setOutfile(project.resolveFile(test.getOutfile()
-
+add[i].getExtension()));
- } else {
- add[i].setOutput(new LogOutputStream(this,
Project.MSG_INFO));
- }
+ setOutput(add[i], test);
runner.addFormatter(add[i].createFormatter());
}
@@ -290,9 +285,10 @@
formatterArg.append(fe.getClassname());
if (fe.getUseFile()) {
formatterArg.append(",");
-
formatterArg.append(project.resolveFile(test.getOutfile()
-
+fe.getExtension())
- .getAbsolutePath());
+ File destFile = new File( test.getTodir(),
+ test.getOutfile() +
fe.getExtension() );
+ String filename = destFile.getAbsolutePath();
+ formatterArg.append( project.resolveFile(filename) );
}
cmd.createArgument().setValue(formatterArg.toString());
formatterArg.setLength(0);
@@ -304,9 +300,10 @@
formatterArg.append(add[i].getClassname());
if (add[i].getUseFile()) {
formatterArg.append(",");
-
formatterArg.append(project.resolveFile(test.getOutfile()
-
+add[i].getExtension())
- .getAbsolutePath());
+ File destFile = new File( test.getTodir(),
+ test.getOutfile() +
add[i].getExtension() );
+ String filename = destFile.getAbsolutePath();
+ formatterArg.append( project.resolveFile(filename) );
}
cmd.createArgument().setValue(formatterArg.toString());
formatterArg.setLength(0);
@@ -371,5 +368,16 @@
return batchEnum.nextElement();
}
};
+ }
+
+ protected void setOutput(FormatterElement fe, JUnitTest test) {
+ if (fe.getUseFile()) {
+ File destFile = new File( test.getTodir(),
+ test.getOutfile() + fe.getExtension()
);
+ String filename = destFile.getAbsolutePath();
+ fe.setOutfile( project.resolveFile(filename) );
+ } else {
+ fe.setOutput(new LogOutputStream(this, Project.MSG_INFO));
+ }
}
}
1.4 +14 -9
jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTest.java
Index: JUnitTest.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTest.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- JUnitTest.java 2000/09/14 08:49:39 1.3
+++ JUnitTest.java 2000/12/18 15:40:37 1.4
@@ -23,7 +23,7 @@
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
- * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
+ * 4. The names "The Jakarta Project", "Ant", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
@@ -63,12 +63,17 @@
/**
*
* @author Thomas Haas
- * @author <a href="mailto:[EMAIL PROTECTED]">Stefan Bodewig</a>
+ * @author <a href="mailto:[EMAIL PROTECTED]">Stefan Bodewig</a>,
+ * @author <a href="mailto:[EMAIL PROTECTED]">Stephane Bailliez</a>
*/
public class JUnitTest extends BaseTest {
+
+ /** the name of the test case */
private String name = null;
- private File outfile = null;
-
+
+ /** the name of the result file */
+ private String outfile = null;
+
private long runs, failures, errors;
private long runTime;
@@ -89,7 +94,7 @@
name = value;
}
- public void setOutfile(File value) {
+ public void setOutfile(String value) {
outfile = value;
}
@@ -97,11 +102,11 @@
return name;
}
+ /**
+ * @return the name of the output file.
+ */
public String getOutfile() {
- if (outfile != null) {
- return outfile.getAbsolutePath();
- }
- return null;
+ return outfile;
}
public void setCounts(long runs, long failures, long errors) {