From 94670dc30af73dd061c3eb19e71d98ab7b879c99 Mon Sep 17 00:00:00 2001 From: Stefan Bodewig Date: Tue, 22 Aug 2006 04:55:07 +0000 Subject: [PATCH] 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 --- .../antunit/listener/BaseAntUnitListener.java | 30 ++++++++++++------- .../antunit/listener/XMLAntUnitListener.java | 12 +++++--- .../ant/antunit/listener/XMLConstants.java | 5 ++++ 3 files changed, 32 insertions(+), 15 deletions(-) diff --git a/src/main/org/apache/ant/antunit/listener/BaseAntUnitListener.java b/src/main/org/apache/ant/antunit/listener/BaseAntUnitListener.java index ca466a5..2756047 100644 --- a/src/main/org/apache/ant/antunit/listener/BaseAntUnitListener.java +++ b/src/main/org/apache/ant/antunit/listener/BaseAntUnitListener.java @@ -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"; diff --git a/src/main/org/apache/ant/antunit/listener/XMLAntUnitListener.java b/src/main/org/apache/ant/antunit/listener/XMLAntUnitListener.java index 45fb915..17270e1 100644 --- a/src/main/org/apache/ant/antunit/listener/XMLAntUnitListener.java +++ b/src/main/org/apache/ant/antunit/listener/XMLAntUnitListener.java @@ -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 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(), diff --git a/src/main/org/apache/ant/antunit/listener/XMLConstants.java b/src/main/org/apache/ant/antunit/listener/XMLConstants.java index c3b17c4..dda1a59 100644 --- a/src/main/org/apache/ant/antunit/listener/XMLConstants.java +++ b/src/main/org/apache/ant/antunit/listener/XMLConstants.java @@ -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"; }