Beispiel #1
0
 private void addProperty(File xmlFile, String cssClass, String cruiseProperty) {
   try {
     String xpath = "//div/p/span[@class='" + cssClass + "']";
     String output = XpathUtils.evaluate(factory, xmlFile, xpath);
     output = output.startsWith(".") ? "0" + output : output;
     Property property = new Property(cruiseProperty, output);
     publisher.setProperty(property);
   } catch (Exception e) {
     publisher.consumeLine("Could not publish property " + e.getMessage());
   }
 }
Beispiel #2
0
  private boolean isValidXml(File file) {
    try {
      boolean isTestFile = nodeExists(file, "//test-results") || nodeExists(file, "//testsuite");

      if (!isTestFile) {
        publisher.consumeLine(
            MessageFormat.format(
                "Ignoring file {0} - it is not a recognised test file.", file.getName()));
      }

      return isTestFile;
    } catch (Exception e) {
      publisher.consumeLine(
          MessageFormat.format(
              "The file {0} could not be parsed. It seems to be invalid.", file.getName()));
      return false;
    }
  }
Beispiel #3
0
  public Properties generate(File[] allTestFiles, String uploadDestPath) {
    FileOutputStream transformedHtml = null;
    File mergedResults =
        new File(folderToUpload.getAbsolutePath() + FileUtil.fileseparator() + TEST_RESULTS_FILE);
    File mergedResource = null;
    FileInputStream mergedFileStream = null;
    try {
      mergedResource = mergeAllTestResultToSingleFile(allTestFiles);
      transformedHtml = new FileOutputStream(mergedResults);

      try {
        mergedFileStream = new FileInputStream(mergedResource);
        InputStream xslt = getClass().getResourceAsStream("unittests.xsl");
        Source xmlSource = new StreamSource(mergedFileStream);
        Source xsltSource = new StreamSource(xslt);
        TransformerFactory transFact = TransformerFactory.newInstance();
        Transformer trans = transFact.newTransformer(xsltSource);
        StreamResult result = new StreamResult(transformedHtml);
        trans.transform(xmlSource, result);
      } catch (Exception e) {
        publisher.reportErrorMessage(
            "Unable to publish test properties. Error was " + e.getMessage(), e);
      } finally {
        IOUtils.closeQuietly(mergedFileStream);
      }

      extractProperties(mergedResults);

      publisher.upload(mergedResults, uploadDestPath);

      return null;
    } catch (Exception e) {
      publisher.reportErrorMessage(
          "Unable to publish test properties. Error was " + e.getMessage(), e);
    } finally {
      IOUtils.closeQuietly(mergedFileStream);
      IOUtils.closeQuietly(transformedHtml);
      if (mergedResource != null) {
        mergedResource.delete();
      }
    }
    return new Properties();
  }
Beispiel #4
0
 public void publish(GoPublisher publisher, final File rootPath) {
   WildcardScanner scanner = getArtifactSrc(rootPath);
   File[] files = scanner.getFiles();
   if (files.length == 0) {
     String message =
         "The rule [" + getSrc() + "] cannot match any resource under [" + rootPath + "]";
     publisher.consumeLineWithPrefix(message);
     throw new RuntimeException(message);
   }
   for (File file : files) {
     publishWithProperties(publisher, file, rootPath);
   }
 }
Beispiel #5
0
 protected void publishWithProperties(GoPublisher goPublisher, File fileToUpload, File rootPath) {
   goPublisher.upload(fileToUpload, destURL(rootPath, fileToUpload));
 }