Browse Source

Make the directory for the output of <junit> configurable.

Submitted by:	Stephane Bailliez <sbailliez@imediation.com>


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@268368 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 24 years ago
parent
commit
6960c203e4
4 changed files with 77 additions and 34 deletions
  1. +25
    -2
      src/main/org/apache/tools/ant/taskdefs/optional/junit/BaseTest.java
  2. +10
    -3
      src/main/org/apache/tools/ant/taskdefs/optional/junit/BatchTest.java
  3. +28
    -20
      src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java
  4. +14
    -9
      src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTest.java

+ 25
- 2
src/main/org/apache/tools/ant/taskdefs/optional/junit/BaseTest.java View File

@@ -23,7 +23,7 @@
* Alternately, this acknowlegement may appear in the software itself, * Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear. * 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 * Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written * from this software without prior written permission. For written
* permission, please contact apache@apache.org. * permission, please contact apache@apache.org.
@@ -54,12 +54,14 @@


package org.apache.tools.ant.taskdefs.optional.junit; package org.apache.tools.ant.taskdefs.optional.junit;


import java.io.File;
import java.util.Vector; import java.util.Vector;


/** /**
* Baseclass for BatchTest and JUnitTest. * Baseclass for BatchTest and JUnitTest.
* *
* @author <a href="mailto:stefan.bodewig@megabit.net">Stefan Bodewig</a>
* @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a>
* @author <a href="mailto:sbailliez@imediation.com">Stephane Bailliez</a>
*/ */
public abstract class BaseTest { public abstract class BaseTest {
protected boolean haltOnError = false; protected boolean haltOnError = false;
@@ -68,6 +70,8 @@ public abstract class BaseTest {
protected String ifProperty = null; protected String ifProperty = null;
protected String unlessProperty = null; protected String unlessProperty = null;
protected Vector formatters = new Vector(); protected Vector formatters = new Vector();
/** destination directory */
protected File destDir = null;


public void setFork(boolean value) { public void setFork(boolean value) {
fork = value; fork = value;
@@ -104,4 +108,23 @@ public abstract class BaseTest {
public void addFormatter(FormatterElement elem) { public void addFormatter(FormatterElement elem) {
formatters.addElement(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;
}

} }

+ 10
- 3
src/main/org/apache/tools/ant/taskdefs/optional/junit/BatchTest.java View File

@@ -23,7 +23,7 @@
* Alternately, this acknowlegement may appear in the software itself, * Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear. * 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 * Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written * from this software without prior written permission. For written
* permission, please contact apache@apache.org. * permission, please contact apache@apache.org.
@@ -61,12 +61,14 @@ import org.apache.tools.ant.types.FileSet;
import org.apache.tools.ant.types.Reference; import org.apache.tools.ant.types.Reference;


import java.util.*; import java.util.*;
import java.io.File;


/** /**
* Create JUnitTests from a list of files. * Create JUnitTests from a list of files.
* *
* @author <a href="mailto:jeff.martin@synamic.co.uk">Jeff Martin</a> * @author <a href="mailto:jeff.martin@synamic.co.uk">Jeff Martin</a>
* @author <a href="mailto:stefan.bodewig@megabit.net">Stefan Bodewig</a>
* @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a>
* @author <a href="mailto:sbailliez@imediation.com">Stephane Bailliez</a>
*/ */
public final class BatchTest extends BaseTest { public final class BatchTest extends BaseTest {
private Project project; private Project project;
@@ -87,8 +89,9 @@ public final class BatchTest extends BaseTest {


public class FileList implements Enumeration{ public class FileList implements Enumeration{
private String files[]=null; private String files[]=null;

private int i=0; private int i=0;
private FileList(){ private FileList(){
Vector v = new Vector(); Vector v = new Vector();
for (int j=0; j<filesets.size(); j++) { for (int j=0; j<filesets.size(); j++) {
@@ -108,10 +111,12 @@ public final class BatchTest extends BaseTest {
files = new String[v.size()]; files = new String[v.size()];
v.copyInto(files); v.copyInto(files);
} }

public final boolean hasMoreElements(){ public final boolean hasMoreElements(){
if(i<files.length)return true; if(i<files.length)return true;
return false; return false;
} }

public final Object nextElement() throws NoSuchElementException{ public final Object nextElement() throws NoSuchElementException{
if(hasMoreElements()){ if(hasMoreElements()){
JUnitTest test = new JUnitTest(javaToClass(files[i])); JUnitTest test = new JUnitTest(javaToClass(files[i]));
@@ -120,6 +125,7 @@ public final class BatchTest extends BaseTest {
test.setFork(fork); test.setFork(fork);
test.setIf(ifProperty); test.setIf(ifProperty);
test.setUnless(unlessProperty); test.setUnless(unlessProperty);
test.setTodir(destDir);
Enumeration list = formatters.elements(); Enumeration list = formatters.elements();
while (list.hasMoreElements()) { while (list.hasMoreElements()) {
test.addFormatter((FormatterElement)list.nextElement()); test.addFormatter((FormatterElement)list.nextElement());
@@ -129,6 +135,7 @@ public final class BatchTest extends BaseTest {
} }
throw new NoSuchElementException(); throw new NoSuchElementException();
} }

public final String javaToClass(String fileName){ public final String javaToClass(String fileName){
return fileName.replace(java.io.File.separatorChar, '.'); return fileName.replace(java.io.File.separatorChar, '.');
} }


+ 28
- 20
src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java View File

@@ -23,7 +23,7 @@
* Alternately, this acknowlegement may appear in the software itself, * Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear. * 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 * Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written * from this software without prior written permission. For written
* permission, please contact apache@apache.org. * permission, please contact apache@apache.org.
@@ -84,6 +84,7 @@ import java.util.Vector;
* *
* @author Thomas Haas * @author Thomas Haas
* @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a> * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a>
* @author <a href="mailto:sbailliez@imediation.com">Stephane Bailliez</a>
*/ */
public class JUnitTask extends Task { public class JUnitTask extends Task {


@@ -204,8 +205,12 @@ public class JUnitTask extends Task {
continue; continue;
} }


if (test.getTodir() == null){
test.setTodir(project.resolveFile("."));
}

if (test.getOutfile() == null) { if (test.getOutfile() == null) {
test.setOutfile(project.resolveFile("TEST-" + test.getName()));
test.setOutfile( "TEST-" + test.getName() );
} }


int exitValue = JUnitTestRunner.ERRORS; int exitValue = JUnitTestRunner.ERRORS;
@@ -246,22 +251,12 @@ public class JUnitTask extends Task {


for (int i=0; i<formatters.size(); i++) { for (int i=0; i<formatters.size(); i++) {
FormatterElement fe = (FormatterElement) formatters.elementAt(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()); runner.addFormatter(fe.createFormatter());
} }
FormatterElement[] add = test.getFormatters(); FormatterElement[] add = test.getFormatters();
for (int i=0; i<add.length; i++) { 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()); runner.addFormatter(add[i].createFormatter());
} }


@@ -290,9 +285,10 @@ public class JUnitTask extends Task {
formatterArg.append(fe.getClassname()); formatterArg.append(fe.getClassname());
if (fe.getUseFile()) { if (fe.getUseFile()) {
formatterArg.append(","); 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()); cmd.createArgument().setValue(formatterArg.toString());
formatterArg.setLength(0); formatterArg.setLength(0);
@@ -304,9 +300,10 @@ public class JUnitTask extends Task {
formatterArg.append(add[i].getClassname()); formatterArg.append(add[i].getClassname());
if (add[i].getUseFile()) { if (add[i].getUseFile()) {
formatterArg.append(","); 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()); cmd.createArgument().setValue(formatterArg.toString());
formatterArg.setLength(0); formatterArg.setLength(0);
@@ -372,4 +369,15 @@ public class JUnitTask extends Task {
} }
}; };
} }

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));
}
}
} }

+ 14
- 9
src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTest.java View File

@@ -23,7 +23,7 @@
* Alternately, this acknowlegement may appear in the software itself, * Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear. * 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 * Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written * from this software without prior written permission. For written
* permission, please contact apache@apache.org. * permission, please contact apache@apache.org.
@@ -63,12 +63,17 @@ import java.util.Vector;
/** /**
* *
* @author Thomas Haas * @author Thomas Haas
* @author <a href="mailto:stefan.bodewig@megabit.net">Stefan Bodewig</a>
* @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a>,
* @author <a href="mailto:sbailliez@imediation.com">Stephane Bailliez</a>
*/ */
public class JUnitTest extends BaseTest { public class JUnitTest extends BaseTest {
/** the name of the test case */
private String name = null; 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 runs, failures, errors;
private long runTime; private long runTime;


@@ -89,7 +94,7 @@ public class JUnitTest extends BaseTest {
name = value; name = value;
} }


public void setOutfile(File value) {
public void setOutfile(String value) {
outfile = value; outfile = value;
} }


@@ -97,11 +102,11 @@ public class JUnitTest extends BaseTest {
return name; return name;
} }


/**
* @return the name of the output file.
*/
public String getOutfile() { public String getOutfile() {
if (outfile != null) {
return outfile.getAbsolutePath();
}
return null;
return outfile;
} }


public void setCounts(long runs, long failures, long errors) { public void setCounts(long runs, long failures, long errors) {


Loading…
Cancel
Save