vhardy 01/10/08 04:37:47 Modified: test-resources/org/apache/batik/test regard.xml test-resources/org/apache/batik/test/xml/resources Messages.properties test-sources/org/apache/batik/test/xml XMLTestReportProcessor.java XSLXMLReportConsumer.java Log: Modified regard output structure. Now, reports are generated in a test-reports subdirectory with the following naming convention: <year>.<month>.<date>-<hh>h<mm>m<ss>s All report resources for one test run are under that directory, which makes it easier to archive test results. Revision Changes Path 1.12 +4 -6 xml-batik/test-resources/org/apache/batik/test/regard.xml Index: regard.xml =================================================================== RCS file: /home/cvs/xml-batik/test-resources/org/apache/batik/test/regard.xml,v retrieving revision 1.11 retrieving revision 1.12 diff -u -r1.11 -r1.12 --- regard.xml 2001/10/05 13:12:22 1.11 +++ regard.xml 2001/10/08 11:37:46 1.12 @@ -11,7 +11,7 @@ <!-- regression testing. --> <!-- --> <!-- @author [EMAIL PROTECTED] --> -<!-- @version $Id: regard.xml,v 1.11 2001/10/05 13:12:22 vhardy Exp $ --> +<!-- @version $Id: regard.xml,v 1.12 2001/10/08 11:37:46 vhardy Exp $ --> <!-- ========================================================================= --> <testRun id="regard" name="Batik Standard Regression Test Run"> <testReportProcessor class="org.apache.batik.test.xml.XMLTestReportProcessor" > @@ -19,11 +19,9 @@ <!-- Stylesheet --> <arg class="java.lang.String" value="file:test-resources/org/apache/batik/test/svg/HTMLReport.xsl" /> <!-- Ouput Directory --> - <arg class="java.lang.String" value="test-reports/html" /> - <!-- Output file prefix --> - <arg class="java.lang.String" value="RegardResult" /> - <!-- Output file suffix --> - <arg class="java.lang.String" value=".html" /> + <arg class="java.lang.String" value="html" /> + <!-- Output file name --> + <arg class="java.lang.String" value="regardReport.html" /> </arg> </testReportProcessor> 1.6 +8 -11 xml-batik/test-resources/org/apache/batik/test/xml/resources/Messages.properties Index: Messages.properties =================================================================== RCS file: /home/cvs/xml-batik/test-resources/org/apache/batik/test/xml/resources/Messages.properties,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- Messages.properties 2001/10/04 08:25:38 1.5 +++ Messages.properties 2001/10/08 11:37:46 1.6 @@ -9,20 +9,17 @@ # # XMLTestReportProcessor configuration # -XMLTestReportProcessor.config.xml.test.report.prefix = \ -XTR - -XMLTestReportProcessor.config.xml.test.report.resource.prefix = \ -res_ +XMLTestReportProcessor.config.xml.test.report.default.directory = \ +test-reports -XMLTestReportProcessor.config.xml.test.report.suffix = \ -.xml +XMLTestReportProcessor.xml.report.directory = \ +xml -XMLTestReportProcessor.config.xml.test.report.default.directory = \ -test-reports/xml +XMLTestReportProcessor.xml.resources.directory = \ +resources -XMLTestReportProcessor.config.xml.test.report.resources.default.directory = \ -test-reports/xml/resources +XMLTestReportProcessor.config.xml.test.report.name = \ +report.xml # # Messages 1.10 +137 -42 xml-batik/test-sources/org/apache/batik/test/xml/XMLTestReportProcessor.java Index: XMLTestReportProcessor.java =================================================================== RCS file: /home/cvs/xml-batik/test-sources/org/apache/batik/test/xml/XMLTestReportProcessor.java,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- XMLTestReportProcessor.java 2001/10/04 08:25:37 1.9 +++ XMLTestReportProcessor.java 2001/10/08 11:37:47 1.10 @@ -23,6 +23,8 @@ import java.net.URL; +import java.util.Calendar; + import org.apache.batik.test.TestReport; import org.apache.batik.test.TestReportProcessor; import org.apache.batik.test.TestSuite; @@ -49,7 +51,7 @@ * report consumer of the XML file it created. * * @author <a href="mailto:[EMAIL PROTECTED]">Vincent Hardy</a> - * @version $Id: XMLTestReportProcessor.java,v 1.9 2001/10/04 08:25:37 vhardy Exp $ + * @version $Id: XMLTestReportProcessor.java,v 1.10 2001/10/08 11:37:47 vhardy Exp $ */ public class XMLTestReportProcessor implements TestReportProcessor, @@ -61,8 +63,12 @@ public static interface XMLReportConsumer { /** * Invoked when new report has been generated. + * @param xmlReport file containing the xml report + * @param reportDirectory base directory where any resource relative + * to the report processing should be stored. */ - public void onNewReport(File xmlReport) throws Exception ; + public void onNewReport(File xmlReport, + File reportDirectory) throws Exception ; } /** @@ -78,43 +84,52 @@ = "xml.XMLTestReportProcessor.error.report.resources.directory.unusable"; /** - * Prefix for the files created by this processor + * Default report directory */ - public static final String XML_TEST_REPORT_PREFIX - = Messages.formatMessage("XMLTestReportProcessor.config.xml.test.report.prefix", null); + public static final String XML_TEST_REPORT_DEFAULT_DIRECTORY + = Messages.formatMessage("XMLTestReportProcessor.config.xml.test.report.default.directory", null); /** - * Prefix for the resource files created by this processor. Resource files are - * copies of files found as Entries in TestReports. + * Directory where the XML report is created */ - public static final String XML_TEST_REPORT_RESOURCE_PREFIX - = Messages.formatMessage("XMLTestReportProcessor.config.xml.test.report.resource.prefix", null); + public static final String XML_REPORT_DIRECTORY + = Messages.formatMessage("XMLTestReportProcessor.xml.report.directory", null); /** - * Suffix for the files created by this processor + * Directory where resources (e.g., images) referenced by the + * XML report are copied. */ - public static final String XML_TEST_REPORT_SUFFIX - = Messages.formatMessage("XMLTestReportProcessor.config.xml.test.report.suffix", null); + public static final String XML_RESOURCES_DIRECTORY + = Messages.formatMessage("XMLTestReportProcessor.xml.resources.directory", null); /** - * Default report directory + * Test report name */ - public static final String XML_TEST_REPORT_DEFAULT_DIRECTORY - = Messages.formatMessage("XMLTestReportProcessor.config.xml.test.report.default.directory", null); + public static final String XML_TEST_REPORT_NAME + = Messages.formatMessage("XMLTestReportProcessor.config.xml.test.report.name", null); /** - * Default report resources directory - */ - public static final String XML_TEST_REPORT_RESOURCES_DEFAULT_DIRECTORY - = Messages.formatMessage("XMLTestReportProcessor.config.xml.test.report.resources.default.directory", null); - - /** * The XMLReportConsumer instance is notified whenever * this object generates a new report. */ protected XMLReportConsumer consumer; /** + * Directory into which this processor puts all files and resources. + */ + protected File reportDirectory; + + /** + * Directory into which XML files are created + */ + protected File xmlDirectory; + + /** + * Directory into whichr resources refered to by XML files are created + */ + protected File xmlResourcesDirectory; + + /** * Default constructor */ public XMLTestReportProcessor(){ @@ -136,13 +151,10 @@ throws TestException { /** - * First, try to create the directories for the - * report and report resources if they do not exist + * First, create the directories for the + * report and report resources */ - checkDirectory(getReportDirectory(), - ERROR_REPORT_DIRECTORY_UNUSABLE); - checkDirectory(getReportResourcesDirectory(), - ERROR_REPORT_RESOURCES_DIRECTORY_UNUSABLE); + initializeReportDirectories(); try { @@ -172,7 +184,7 @@ File xmlReport = serializeReport(root); if(consumer != null){ - consumer.onNewReport(xmlReport); + consumer.onNewReport(xmlReport, getReportDirectory()); } } catch(Exception e) { @@ -215,19 +227,68 @@ /** * By default, the report directory is given by a configuration - * variable. + * variable. Each test run will create a sub directory with + * the current date and time as the same. All the resources + * created by the report processor are then put into that + * "dated" directory. + */ + public void initializeReportDirectories() throws TestException { + // + // Base report directory + // + File baseReportDir = new File(XML_TEST_REPORT_DEFAULT_DIRECTORY); + checkDirectory(baseReportDir, ERROR_REPORT_DIRECTORY_UNUSABLE); + + // + // Create sub-directory name based on date and time + // + Calendar c = Calendar.getInstance(); + String dirName = "" + c.get(c.YEAR) + "." + + c.get(c.MONTH) + "." + + makeTwoDigits(c.get(c.DAY_OF_MONTH)) + "-" + + makeTwoDigits(c.get(c.HOUR_OF_DAY)) + "h" + + makeTwoDigits(c.get(c.MINUTE)) + "m" + + makeTwoDigits(c.get(c.SECOND)) + "s"; + + reportDirectory = new File(baseReportDir, dirName); + checkDirectory(reportDirectory, ERROR_REPORT_DIRECTORY_UNUSABLE); + + // + // Now, create a sub-directory for XML files and + // anotherone for resources + // + xmlDirectory = new File(reportDirectory, XML_REPORT_DIRECTORY); + checkDirectory(xmlDirectory, ERROR_REPORT_DIRECTORY_UNUSABLE); + + xmlResourcesDirectory = new File(xmlDirectory, XML_RESOURCES_DIRECTORY); + checkDirectory(xmlResourcesDirectory, ERROR_REPORT_DIRECTORY_UNUSABLE); + } + + /** + * Forces a two digit string */ - public File getReportDirectory() { - File file = new File(XML_TEST_REPORT_DEFAULT_DIRECTORY); - return file; + protected String makeTwoDigits(int i){ + if(i > 9){ + return "" + i; + } + else{ + return "0" + i; + } } /** + * Returns the report directory + */ + public File getReportDirectory(){ + return reportDirectory; + } + + /** * By default, the report resources directory is * given by a configuration variable. */ public File getReportResourcesDirectory() { - return new File(XML_TEST_REPORT_RESOURCES_DEFAULT_DIRECTORY); + return xmlResourcesDirectory; } /** @@ -338,9 +399,7 @@ // File tmpFile = (File)value; - File tmpFileCopy = File.createTempFile(XML_TEST_REPORT_RESOURCE_PREFIX, - tmpFile.getName(), - getReportResourcesDirectory()); + File tmpFileCopy = createResourceFileForName(tmpFile.getName()); copy(tmpFile, tmpFileCopy); @@ -380,6 +439,44 @@ } /** + * Untility method. Creates a file in the resources directory + * for the given name. If a file in that directory does not + * exist yet, then it is used. Otherwise, a file with the same + * name with a digit suffix is created. For example, if "myFile.png" + * is requested, then "myFile.png" is created or "myFile<n>.png" + * where <n> will be one or several digits. + */ + protected File createResourceFileForName(String fileName){ + File r = new File(xmlResourcesDirectory, fileName); + if(!r.exists()){ + return r; + } + else{ + return createResourceFileForName(fileName, 1); + } + } + + protected File createResourceFileForName(String fileName, + int instance){ + // First, create a 'versioned' file name + int n = fileName.lastIndexOf('.'); + String iFileName = fileName + instance; + if(n != -1){ + iFileName = fileName.substring(0, n) + instance + + fileName.substring(n, fileName.length()); + } + + File r = new File(xmlResourcesDirectory, iFileName); + if(!r.exists()){ + return r; + } + else{ + return createResourceFileForName(fileName, + instance + 1); + } + } + + /** * Utility method. Copies in to out */ protected void copy(File in, File out) throws IOException { @@ -403,12 +500,10 @@ // // First, create a new File // - File tmpFile = File.createTempFile(XML_TEST_REPORT_PREFIX, - XML_TEST_REPORT_SUFFIX, - getReportDirectory()); - - FileWriter fw = new FileWriter(tmpFile); + File reportFile = new File(xmlDirectory, + XML_TEST_REPORT_NAME); + FileWriter fw = new FileWriter(reportFile); serializeElement(reportElement, "", @@ -416,7 +511,7 @@ fw.close(); - return tmpFile; + return reportFile; } 1.4 +13 -22 xml-batik/test-sources/org/apache/batik/test/xml/XSLXMLReportConsumer.java Index: XSLXMLReportConsumer.java =================================================================== RCS file: /home/cvs/xml-batik/test-sources/org/apache/batik/test/xml/XSLXMLReportConsumer.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- XSLXMLReportConsumer.java 2001/05/14 22:43:20 1.3 +++ XSLXMLReportConsumer.java 2001/10/08 11:37:47 1.4 @@ -32,7 +32,7 @@ * XML file and stores the result in a configurable directory. * * @author <a href="mailto:[EMAIL PROTECTED]">Vincent Hardy</a> - * @version $Id: XSLXMLReportConsumer.java,v 1.3 2001/05/14 22:43:20 vhardy Exp $ + * @version $Id: XSLXMLReportConsumer.java,v 1.4 2001/10/08 11:37:47 vhardy Exp $ */ public class XSLXMLReportConsumer implements XMLTestReportProcessor.XMLReportConsumer { @@ -54,57 +54,48 @@ private String outputDirectory; /** - * Prefix for the output file names + * Output file name */ - private String outputPrefix; + private String outputFileName; /** - * Suffix for the output file names. - */ - private String outputSuffix; - - /** * Constructor * @param stylesheet URI for the stylesheet to apply to the XML report * @param outputDirectory directory where the result of the XSL transformation * should be written - * @param outputPrefix prefix for the output file name - * @param outputSuffic suffic for the output file name. + * @param outputFileName name of the output report. */ public XSLXMLReportConsumer(String stylesheet, String outputDirectory, - String outputPrefix, - String outputSuffix){ + String outputFileName){ this.stylesheet = stylesheet; this.outputDirectory = outputDirectory; - this.outputPrefix = outputPrefix; - this.outputSuffix = outputSuffix; + this.outputFileName = outputFileName; } /** * When a new report has been generated, this consumer * applies the same stylesheet to the input XML document */ - public void onNewReport(File xmlReport) + public void onNewReport(File xmlReport, + File reportDirectory) throws Exception{ TransformerFactory tFactory = TransformerFactory.newInstance(); Transformer transformer = tFactory.newTransformer(new StreamSource(stylesheet)); transformer.transform(new StreamSource(xmlReport.toURL().toString()), - new StreamResult(new FileOutputStream(createNewReportOutput().getAbsolutePath()))); + new StreamResult(new FileOutputStream(createNewReportOutput(reportDirectory).getAbsolutePath()))); } /** * Returns a new file in the outputDirectory, with - * the requested prefix/suffix + * the requested report name. */ - public File createNewReportOutput() throws Exception{ - File dir = new File(outputDirectory); + public File createNewReportOutput(File reportDirectory) throws Exception{ + File dir = new File(reportDirectory, outputDirectory); checkDirectory(dir); - return File.createTempFile(outputPrefix, - outputSuffix, - dir); + return new File(dir, outputFileName); } /**
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]