improve testsuite-name attribute in XML report
git-svn-id: https://svn.apache.org/repos/asf/ant/antlibs/antunit/trunk@433516 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
8f66282084
commit
94670dc30a
|
|
@ -137,17 +137,7 @@ public abstract class BaseAntUnitListener extends ProjectComponent
|
|||
if (logTo.getValue().equals(SendLogTo.FILE)
|
||||
|| logTo.getValue().equals(SendLogTo.BOTH)) {
|
||||
|
||||
buildFile = FileUtils.getFileUtils()
|
||||
.removeLeadingPath(getProject().getBaseDir(),
|
||||
new File(buildFile));
|
||||
if (buildFile.length() > 0
|
||||
&& buildFile.charAt(0) == File.separatorChar) {
|
||||
buildFile = buildFile.substring(1);
|
||||
}
|
||||
|
||||
String fileName = "TEST-" +
|
||||
buildFile.replace(File.separatorChar, '.').replace(':', '.')
|
||||
+ "." + extension;
|
||||
String fileName = "TEST-" + normalize(buildFile) + "." + extension;
|
||||
File file = toDir == null
|
||||
? getProject().resolveFile(fileName)
|
||||
: new File(toDir, fileName);
|
||||
|
|
@ -163,6 +153,24 @@ public abstract class BaseAntUnitListener extends ProjectComponent
|
|||
return new TeeOutputStream(l, f);
|
||||
}
|
||||
|
||||
/**
|
||||
* Turns the build file name into something that vaguely looks
|
||||
* like a Java classname. Close enough to be suitable for
|
||||
* junitreport.
|
||||
*/
|
||||
protected final String normalize(String buildFile) {
|
||||
buildFile = FileUtils.getFileUtils()
|
||||
.removeLeadingPath(getProject().getBaseDir(),
|
||||
new File(buildFile));
|
||||
if (buildFile.length() > 0
|
||||
&& buildFile.charAt(0) == File.separatorChar) {
|
||||
buildFile = buildFile.substring(1);
|
||||
}
|
||||
|
||||
return buildFile.replace('.', '_').replace(':', '_')
|
||||
.replace(File.separatorChar, '.');
|
||||
}
|
||||
|
||||
public static class SendLogTo extends EnumeratedAttribute {
|
||||
public static final String ANT_LOG = "ant";
|
||||
public static final String FILE = "file";
|
||||
|
|
|
|||
|
|
@ -63,10 +63,14 @@ public class XMLAntUnitListener extends BaseAntUnitListener {
|
|||
wri = new OutputStreamWriter(getOut(buildFile), "UTF8");
|
||||
doc = DOMUtils.newDocument();
|
||||
root = doc.createElement(XMLConstants.TESTSUITE);
|
||||
String n = testProject.getName();
|
||||
root.setAttribute(XMLConstants.ATTR_NAME,
|
||||
n == null ? "unknown" : n);
|
||||
root.setAttribute("buildFile", buildFile);
|
||||
// if we want to (ab)use <junitreport> name needs to
|
||||
// follow the structure expected by that task:
|
||||
// package.class. package will be the directory holding
|
||||
// the build file (file separators replaced by dots) and
|
||||
// class the build file name with the last dot replaced
|
||||
// by an underscore
|
||||
root.setAttribute(XMLConstants.ATTR_NAME, normalize(buildFile));
|
||||
root.setAttribute(XMLConstants.BUILD_FILE, buildFile);
|
||||
|
||||
//add the timestamp
|
||||
String timestamp = DateUtils.format(new Date(),
|
||||
|
|
|
|||
|
|
@ -101,4 +101,9 @@ public interface XMLConstants {
|
|||
* name of host running the tests
|
||||
*/
|
||||
String HOSTNAME = "hostname";
|
||||
|
||||
/**
|
||||
* name of the build file.
|
||||
*/
|
||||
String BUILD_FILE = "buildFile";
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue