dion 02/01/26 18:04:30 Modified: latka/src/java/org/apache/commons/latka Latka.java Log: Formatting Revision Changes Path 1.25 +200 -201 jakarta-commons/latka/src/java/org/apache/commons/latka/Latka.java Index: Latka.java =================================================================== RCS file: /home/cvs/jakarta-commons/latka/src/java/org/apache/commons/latka/Latka.java,v retrieving revision 1.24 retrieving revision 1.25 diff -u -r1.24 -r1.25 --- Latka.java 27 Jan 2002 01:43:30 -0000 1.24 +++ Latka.java 27 Jan 2002 02:04:30 -0000 1.25 @@ -110,95 +110,96 @@ */ public class Latka { - protected boolean _isValidating = true; + protected boolean _isValidating = true; - protected URL _reportStylesheetUrl = null; + protected URL _reportStylesheetUrl = null; - protected static Category _log = - Category.getInstance(Latka.class.getName()); + protected static Category _log = + Category.getInstance(Latka.class.getName()); - protected Properties _props = LatkaProperties.getProperties(); + protected Properties _props = LatkaProperties.getProperties(); - protected static String LATKA_USAGE = null; - static { - StringBuffer buf = new StringBuffer(); - buf.append("\n######################\n"); - buf.append("Latka usage:\n"); - buf.append(" java org.apache.commons.latka.Latka \"XML_suite_URL\" "); - buf.append("[\"propfile:file_name\"] [\"prop:prop_name=prop_value\"]\n\n"); - buf.append("The quotes around properties are REQUIRED.\n"); - buf.append("######################\n"); - LATKA_USAGE = buf.toString(); - } - - /** - * Execute a single Latka test suite. The Latka event listner - * will receive all the events generated during the test. - * The Latka packages contain an implmentation of LatkaEventInfo - * which can generate an XML report according to a standard - * DTD (see documentation). - * - * @param suite test suite to execute - * @param listener target for test events - * - * @see XMLReporter XML-based implementation of LatkaEventInfo - */ - public void runTests(Suite suite, LatkaEventInfo listener) throws LatkaException { + protected static String LATKA_USAGE = null; - InputSource source = null; + static { + StringBuffer buf = new StringBuffer(); + buf.append("\n######################\n"); + buf.append("Latka usage:\n"); + buf.append(" java org.apache.commons.latka.Latka \"XML_suite_URL\" "); + buf.append("[\"propfile:file_name\"] [\"prop:prop_name=prop_value\"]\n\n"); + buf.append("The quotes around properties are REQUIRED.\n"); + buf.append("######################\n"); + LATKA_USAGE = buf.toString(); + } + + /** + * Execute a single Latka test suite. The Latka event listner + * will receive all the events generated during the test. + * The Latka packages contain an implmentation of LatkaEventInfo + * which can generate an XML report according to a standard + * DTD (see documentation). + * + * @param suite test suite to execute + * @param listener target for test events + * + * @see XMLReporter XML-based implementation of LatkaEventInfo + */ + public void runTests(Suite suite, LatkaEventInfo listener) + throws LatkaException { + + InputSource source = null; + + try { + + XMLPreprocessor preprocessor = XMLPreprocessor.instance(); + + preprocessor.preprocessXml(suite); + + source = new InputSource(suite.getReader()); + if (suite.getURL() != null) { + source.setSystemId(suite.getURL().toString()); + } + + SAXParserFactory factory = SAXParserFactory.newInstance(); + factory.setNamespaceAware(true); + + // always force validation of the tests + factory.setValidating(_isValidating); - try { + SAXParser parser = factory.newSAXParser(); - XMLPreprocessor preprocessor = XMLPreprocessor.instance(); + XMLReader reader = parser.getXMLReader(); - preprocessor.preprocessXml(suite); - - source = new InputSource(suite.getReader()); - if (suite.getURL() != null) { - source.setSystemId(suite.getURL().toString()); - } - - SAXParserFactory factory = SAXParserFactory.newInstance(); - factory.setNamespaceAware(true); - - // always force validation of the tests - factory.setValidating(_isValidating); - - SAXParser parser = factory.newSAXParser(); - - XMLReader reader = parser.getXMLReader(); - - SuiteHandler handler = new SuiteHandler(reader,listener); - - reader.setContentHandler(handler); - reader.setErrorHandler(handler); - reader.setEntityResolver(new LatkaVariableEntityResolver()); - - reader.parse(source); - - } catch (ParserConfigurationException e) { - throw new LatkaException(e); - } catch (SAXException e) { - throw new LatkaException(e); - } catch (IOException e) { - throw new LatkaException(e); - } - - } - - /** - * Set whether or not Latka will validate the XML in - * each test. - * - * @param isValidating whether or not to validate XML - */ - public void setValidating(boolean isValidating) { - _isValidating = isValidating; - } - - public void setReportStylesheet(URL url) { - _reportStylesheetUrl = url; - } + SuiteHandler handler = new SuiteHandler(reader,listener); + + reader.setContentHandler(handler); + reader.setErrorHandler(handler); + reader.setEntityResolver(new LatkaVariableEntityResolver()); + + reader.parse(source); + + } catch (ParserConfigurationException e) { + throw new LatkaException(e); + } catch (SAXException e) { + throw new LatkaException(e); + } catch (IOException e) { + throw new LatkaException(e); + } + } + + /** + * Set whether or not Latka will validate the XML in + * each test. + * + * @param isValidating whether or not to validate XML + */ + public void setValidating(boolean isValidating) { + _isValidating = isValidating; + } + + public void setReportStylesheet(URL url) { + _reportStylesheetUrl = url; + } /** * Use this method to log XML generated by the @@ -225,132 +226,130 @@ fileWriter.close(); } - /** - * Transform the XML generated by the XMLReporter using - * the default stylesheet. - * - * @param xml XML generated by XMLReporter - * @return transformed report - * @throws LatkaException if the XML could not be transformed - */ - public String transformXML(String xml) - throws LatkaException { + /** + * Transform the XML generated by the XMLReporter using + * the default stylesheet. + * + * @param xml XML generated by XMLReporter + * @return transformed report + * @throws LatkaException if the XML could not be transformed + */ + public String transformXML(String xml) throws LatkaException { - try { - StringWriter output = new StringWriter(); + try { + StringWriter output = new StringWriter(); - Source xslSource = null; + Source xslSource = null; - if (_reportStylesheetUrl == null) { - ClassLoader loader = Thread.currentThread().getContextClassLoader(); + if (_reportStylesheetUrl == null) { + ClassLoader loader = Thread.currentThread().getContextClassLoader(); - xslSource = - new StreamSource(loader.getResourceAsStream("org.apache.commons.latka.report.xsl")); - } else { - xslSource = new StreamSource(_reportStylesheetUrl.toString()); - } + xslSource = new StreamSource( + loader.getResourceAsStream( + "org.apache.commons.latka.report.xsl") + ); + } else { + xslSource = new StreamSource(_reportStylesheetUrl.toString()); + } + + + Transformer transformer = + TransformerFactory.newInstance().newTransformer(xslSource); + StreamSource xmlSource = new StreamSource(new StringReader(xml)); + StreamResult result = new StreamResult(output); + transformer.transform(xmlSource,result); + return output.toString(); + } catch (TransformerException e) { + throw new LatkaException(e); + } + } - - Transformer transformer = - TransformerFactory.newInstance().newTransformer(xslSource); - StreamSource xmlSource = new StreamSource(new StringReader(xml)); - StreamResult result = new StreamResult(output); - transformer.transform(xmlSource,result); - return output.toString(); - } catch (TransformerException e) { - throw new LatkaException(e); - } - } - - /** - * Processes the command line arguments, executes a single test. - * and processes the resulting report. Command line usage is - * described in the LATKA_USAGE constant. - * - * @param args arguments passed into the main(String[]) method - * - * @throws LatkaException - * if any problems are encountered during the execution - * of the tests - */ - protected void runCommandLine(String args[]) throws LatkaException { - - if (args.length < 1) { - System.out.println(LATKA_USAGE); - } - - String urlString = args[0]; - - if (args.length > 1) { - - for (int i = 1; i < args.length; ++i) { - String arg = args[i]; - if (arg.startsWith("prop:")) { - String propName = arg.substring(5,arg.indexOf("=")); - String propValue = arg.substring(arg.indexOf("=")+1); - _props.setProperty(propName,propValue); - } else if (arg.startsWith("propfile:")) { - try { - _props.load(new FileInputStream(arg.substring(9))); - } catch (IOException e) { - System.out.println("Could not load user prop file, uri=" + arg.substring(9)); - } - } else { - throw new IllegalArgumentException(LATKA_USAGE); - } - } - - } - - String xml = null; - XMLReporter listener = new XMLReporter(); - - try { - - URL url = new URL(urlString); - Suite suite = new Suite(url); - - - runTests(suite,listener); - - xml = listener.getDocumentAsString(); - _logXML(xml); - } catch (IOException e) { - throw new LatkaException(e); - } - - System.out.println(transformXML(xml)); - - if (listener.didSuiteSucceed() == false) { - // throw an exception, so the process will - // return as a failure - throw new LatkaException("SUITE FAILED"); - } - } - - /** - * Execute a single test suite via the command line - * interface. See the Latka documentation for detailed - * usage instructions. The Java process will return - * a 0 if all tests succeed and a 1 if any fail - * or there is an unrecoverable error in the test - * execution. - * - * @param args arguments containing the test suite location - * and any properties or property file references - */ - public static void main (String args[]) { - - Latka latka = new Latka(); - try { - latka.runCommandLine(args); - } catch (LatkaException e) { - e.printStackTrace(); - LatkaException.printWrappedExceptions(e); - System.exit(1); + /** + * Processes the command line arguments, executes a single test. + * and processes the resulting report. Command line usage is + * described in the LATKA_USAGE constant. + * + * @param args arguments passed into the main(String[]) method + * + * @throws LatkaException + * if any problems are encountered during the execution + * of the tests + */ + protected void runCommandLine(String args[]) throws LatkaException { + + if (args.length < 1) { + System.out.println(LATKA_USAGE); + } + + String urlString = args[0]; + + if (args.length > 1) { + + for (int i = 1; i < args.length; ++i) { + String arg = args[i]; + if (arg.startsWith("prop:")) { + String propName = arg.substring(5,arg.indexOf("=")); + String propValue = arg.substring(arg.indexOf("=")+1); + _props.setProperty(propName,propValue); + } else if (arg.startsWith("propfile:")) { + try { + _props.load(new FileInputStream(arg.substring(9))); + } catch (IOException e) { + System.out.println("Could not load user prop file, uri=" + arg.substring(9)); + } + } else { + throw new IllegalArgumentException(LATKA_USAGE); + } + } // for + } // if + + String xml = null; + XMLReporter listener = new XMLReporter(); + + try { + + URL url = new URL(urlString); + Suite suite = new Suite(url); + + + runTests(suite,listener); + + xml = listener.getDocumentAsString(); + _logXML(xml); + } catch (IOException e) { + throw new LatkaException(e); + } + + System.out.println(transformXML(xml)); + + if (listener.didSuiteSucceed() == false) { + // throw an exception, so the process will + // return as a failure + throw new LatkaException("SUITE FAILED"); + } } - - } + /** + * Execute a single test suite via the command line + * interface. See the Latka documentation for detailed + * usage instructions. The Java process will return + * a 0 if all tests succeed and a 1 if any fail + * or there is an unrecoverable error in the test + * execution. + * + * @param args arguments containing the test suite location + * and any properties or property file references + */ + public static void main (String args[]) { + Latka latka = new Latka(); + try { + latka.runCommandLine(args); + } catch (LatkaException e) { + e.printStackTrace(); + LatkaException.printWrappedExceptions(e); + System.exit(1); + } + + } }
-- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>