/testability-explorer/src/main/java/com/google/test/metric/report/ReportDiffer.java

http://testability-explorer.googlecode.com/ · Java · 89 lines · 60 code · 14 blank · 15 comment · 6 complexity · a04c6117d4384c1c5cb72646c7d8ddef MD5 · raw file

  1. /*
  2. * Copyright 2007 Google Inc.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.google.test.metric.report;
  17. import java.io.FileReader;
  18. import java.io.FileWriter;
  19. import org.kohsuke.args4j.CmdLineException;
  20. import org.kohsuke.args4j.CmdLineParser;
  21. import org.kohsuke.args4j.Option;
  22. import org.w3c.dom.Document;
  23. import freemarker.template.Configuration;
  24. public class ReportDiffer {
  25. @Option(name="-oldFile", usage="name of the old XML report", required=true)
  26. private String oldFile;
  27. @Option(name="-newFile", usage="name of the new XML report", required=true)
  28. private String newFile;
  29. @Option(name="-htmlReportFile", usage="name of the HTML result file", required=true)
  30. private String htmlReportFile;
  31. @Option(name="-oldLinkUrl", usage="a URL, to be used as a link on 'old' numbers (optional)\n" +
  32. " may link to anything, ie. source code, the annotated testability report\n" +
  33. " for example: http://myhost.com/oldReport/{path}.html", required=false)
  34. private String oldLinkUrl;
  35. @Option(name="-newLinkUrl", usage="a URL, to be used as a link on 'new' numbers (optional)\n" +
  36. " may link to anything, ie. source code, the annotated testability report\n" +
  37. " for example: http://myhost.com/newReport/{path}.html", required=false)
  38. private String newLinkUrl;
  39. public static void main(String[] args) throws Exception {
  40. ReportDiffer differ = new ReportDiffer();
  41. differ.parseArgs(args);
  42. differ.doDiff(new DiffReportFactory());
  43. }
  44. private void doDiff(DiffReportFactory diffReportFactory) throws Exception {
  45. XMLReportLoader reportLoader = new XMLReportLoader();
  46. Document oldReport = reportLoader.loadXML(new FileReader(oldFile));
  47. Document newReport = reportLoader.loadXML(new FileReader(newFile));
  48. FileWriter out = new FileWriter(htmlReportFile);
  49. Diff diff = new XMLReportDiffer().diff(oldReport, newReport);
  50. DiffReport report = diffReportFactory.buildReport(diff);
  51. if (oldLinkUrl != null && !oldLinkUrl.equals("")) {
  52. report.setOldSourceUrl(oldLinkUrl);
  53. }
  54. if (newLinkUrl != null && !newLinkUrl.equals("")) {
  55. report.setOldSourceUrl(newLinkUrl);
  56. }
  57. report.writeHtml(out);
  58. }
  59. private void parseArgs(String[] args) throws CmdLineException {
  60. CmdLineParser parser = new CmdLineParser(this);
  61. try {
  62. parser.parseArgument(args);
  63. } catch (CmdLineException e) {
  64. System.err.println(e.getMessage() + "\n");
  65. parser.setUsageWidth(120);
  66. parser.printUsage(System.err);
  67. throw new CmdLineException("Exiting...");
  68. }
  69. }
  70. private static class DiffReportFactory {
  71. public DiffReport buildReport(Diff diff) {
  72. return new DiffReport(diff, new Configuration());
  73. }
  74. }
  75. }