/** * Generate a report based on the document created by the merge. * @return the report */ public AggregateTransformer createReport() { AggregateTransformer transformer = new AggregateTransformer(this); transformers.add(transformer); return transformer; }
/** * Get the systemid of the appropriate stylesheet based on its * name and styledir. If no styledir is defined it will load * it as a java resource in the xsl child package, otherwise it * will get it from the given directory. * @return system ID of the stylesheet. * @throws IOException thrown if the requested stylesheet does * not exist. */ protected String getStylesheetSystemId() throws IOException { final String xslname = getXslName(); if (styleDir == null) { URL url = getClass().getResource("xsl/" + xslname); if (url == null) { throw new FileNotFoundException("Could not find jar resource " + xslname); } return url.toExternalForm(); } File file = new File(styleDir, xslname); if (!file.exists()) { throw new FileNotFoundException("Could not find file '" + file + "'"); } return JAXPUtils.getSystemId(file); }
/** * Set the xml file to be processed. This is a helper if you want * to set the file directly. Much more for testing purposes. * @param xmlfile xml file to be processed * @throws BuildException if the document cannot be parsed. */ protected void setXmlfile(File xmlfile) throws BuildException { try { DocumentBuilder builder = privateDBFactory.newDocumentBuilder(); try (InputStream in = Files.newInputStream(xmlfile.toPath())) { Document doc = builder.parse(in); setXmlDocument(doc); } } catch (Exception e) { throw new BuildException("Error while parsing document: " + xmlfile, e); } }
checkOptions(); Project project = task.getProject(); tempFileTask.bindToOwner(task); xsltTask.setXslResource(getStylesheet()); paramx.setName("output.dir"); paramx.setExpression(toDir.getAbsolutePath()); configureForRedirectExtension(); final long t0 = System.currentTimeMillis(); try {
/** * Aggregate all testsuites into a single document and write it to the * specified directory and file. * @throws BuildException thrown if there is a serious error while writing * the document. */ @Override public void execute() throws BuildException { Element rootElement = createDocument(); File destFile = getDestinationFile(); // write the document try { writeDOMTree(rootElement.getOwnerDocument(), destFile); } catch (IOException e) { throw new BuildException("Unable to write test aggregate to '" + destFile + "'", e); } // apply transformation for (AggregateTransformer transformer : transformers) { transformer.setXmlDocument(rootElement.getOwnerDocument()); transformer.transform(); } }
/** * If we end up using the JDK's own TraX factory on Java 9+, then * set the features and attributes necessary to allow redirect * extensions to be used. * @since Ant 1.9.8 */ protected void configureForRedirectExtension() { XSLTProcess.Factory factory = createFactory(); String factoryName = factory.getName(); if (factoryName == null) { try { factoryName = TransformerFactory.newInstance().getClass().getName(); } catch (TransformerFactoryConfigurationError exc) { throw new BuildException(exc); } } if (JDK_INTERNAL_FACTORY.equals(factoryName) && JavaEnvUtils.isAtLeastJavaVersion(JavaEnvUtils.JAVA_9)) { factory.addFeature(new XSLTProcess.Factory.Feature( "http://www.oracle.com/xml/jaxp/properties/enableExtensionFunctions", true)); } } }
/** * access the stylesheet to be used as a resource. * @return stylesheet as a resource */ protected Resource getStylesheet() { final String xslname = getXslName(); if (styleDir == null) { // If style dir is not specified we have to retrieve // the stylesheet from the classloader URL stylesheetURL = getClass().getClassLoader().getResource( "org/apache/tools/ant/taskdefs/optional/junit/xsl/" + xslname); return new URLResource(stylesheetURL); } // If we are here, then the style dir is here and we // should read the stylesheet from the filesystem return new FileResource(new File(styleDir, xslname)); }