private static void diffAll(
      String htmlOutputDir, String previousChangelist, String currentChangelist) throws Exception {
    ResultFileSetLoader loader = new ResultFileSetLoader();
    Map currentTests = loader.loadResultFiles(".");

    FileTestImporter imp = new FileTestImporter();
    Map previousTests = imp.getTestsForChangelist(previousChangelist);

    ArrayList diffs = new ArrayList(currentTests.keySet().size());
    Object[] keys = currentTests.keySet().toArray();
    Arrays.sort(keys);

    for (int i = 0; i < keys.length; i++) {
      String testFile = (String) keys[i];

      XMLResult previous = (XMLResult) previousTests.get(testFile);
      if (null == previous) {
        System.out.println("Null Test file: " + testFile);
        previous = new EmptyXMLResult(testFile);
        previousTests.put(testFile, previous);
      }
      previous.setChangelist(previousChangelist);
      XMLResult current = (XMLResult) currentTests.get(testFile);
      current.setChangelist(currentChangelist);
      ResultDiff diff = new ResultDiff(previous, current);
      diffs.add(diff);
    }

    String databaseType = System.getProperty("database.key");
    ReportIndex index = new ReportIndex(previousChangelist, currentChangelist, databaseType);
    XMLOutputter out = new XMLOutputter("  ", true);
    final String ACS_HOME = System.getProperty("ACS_HOME");
    Transformer tran =
        TransformerFactory.newInstance()
            .newTransformer(new StreamSource(ACS_HOME + "/test/xsl/junit.xsl"));
    for (Iterator iterator = diffs.iterator(); iterator.hasNext(); ) {
      ResultDiff resultDiff = (ResultDiff) iterator.next();
      index.addResult(resultDiff);

      String htmlFile = resultDiff.getAttributeValue("name") + ".html";
      FileWriter file = new FileWriter(htmlOutputDir + "/" + htmlFile);
      JDOMResult html = new JDOMResult();
      tran.transform(new JDOMSource(new Document(resultDiff)), html);
      out.output(html.getDocument(), file);
    }

    JDOMResult indexHtml = new JDOMResult();
    tran =
        TransformerFactory.newInstance()
            .newTransformer(new StreamSource(ACS_HOME + "/test/xsl/index.xsl"));
    tran.transform(new JDOMSource(new Document(index)), indexHtml);
    FileWriter indexFile = new FileWriter(htmlOutputDir + "/index.html");
    out.output(indexHtml.getDocument(), indexFile);

    out.output(
        new Document(index), new FileOutputStream("report_index_" + currentChangelist + ".xml"));
  }
  protected <T> Document marshall(
      Class<T> marshalledObjectClass, String schemaPath, ServiceMessage message) {
    JDOMResult marshallResult = new JDOMResult();
    try {
      JAXBContext jaxbContext = JAXBContext.newInstance(marshalledObjectClass);
      Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
      // SchemaFactory sf = SchemaFactory.newInstance( XMLConstants.W3C_XML_SCHEMA_NS_URI );
      // Schema schema = sf.newSchema( new URL( SCHEMA_PATH ) );
      // jaxbMarshaller.setSchema( schema );
      jaxbMarshaller.marshal(messageAsObject, marshallResult);
    } catch (Exception e) {
      throw new RuntimeException(e);
    }

    return marshallResult.getDocument();
  }
Exemplo n.º 3
0
  protected List<Text> transform(Document doc, Document xsldoc) throws JDOMException {
    try {
      JDOMSource xslSource = new JDOMSource(xsldoc);

      Transformer transformer = TransformerFactory.newInstance().newTransformer(xslSource);

      JDOMSource in = new JDOMSource(doc);
      JDOMResult out = new JDOMResult();

      transformer.transform(in, out);

      return out.getResult();
    } catch (TransformerException e) {
      throw new JDOMException("XSLT Transformation failed", e);
    }
  }
Exemplo n.º 4
0
 /**
  * Transforms an xml tree into another using a stylesheet on disk and pass parameters.
  *
  * @param xml
  * @param styleSheetPath
  * @param params
  * @return
  * @throws Exception
  */
 public static Element transform(Element xml, String styleSheetPath, Map<String, String> params)
     throws Exception {
   JDOMResult resXml = new JDOMResult();
   transform(xml, styleSheetPath, resXml, params);
   return (Element) resXml.getDocument().getRootElement().detach();
 }