PageRenderTime 65ms CodeModel.GetById 59ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/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 */
16package com.google.test.metric.report;
17
18import java.io.FileReader;
19import java.io.FileWriter;
20
21import org.kohsuke.args4j.CmdLineException;
22import org.kohsuke.args4j.CmdLineParser;
23import org.kohsuke.args4j.Option;
24import org.w3c.dom.Document;
25
26import freemarker.template.Configuration;
27
28public class ReportDiffer {
29
30  @Option(name="-oldFile", usage="name of the old XML report", required=true)
31  private String oldFile;
32
33  @Option(name="-newFile", usage="name of the new XML report", required=true)
34  private String newFile;
35
36  @Option(name="-htmlReportFile", usage="name of the HTML result file", required=true)
37  private String htmlReportFile;
38
39  @Option(name="-oldLinkUrl", usage="a URL, to be used as a link on 'old' numbers (optional)\n" +
40      "  may link to anything, ie. source code, the annotated testability report\n" +
41      "  for example: http://myhost.com/oldReport/{path}.html", required=false)
42  private String oldLinkUrl;
43
44  @Option(name="-newLinkUrl", usage="a URL, to be used as a link on 'new' numbers (optional)\n" +
45      "  may link to anything, ie. source code, the annotated testability report\n" +
46      "  for example: http://myhost.com/newReport/{path}.html", required=false)
47  private String newLinkUrl;
48
49
50  public static void main(String[] args) throws Exception {
51    ReportDiffer differ = new ReportDiffer();
52    differ.parseArgs(args);
53    differ.doDiff(new DiffReportFactory());
54  }
55
56  private void doDiff(DiffReportFactory diffReportFactory) throws Exception {
57    XMLReportLoader reportLoader = new XMLReportLoader();
58    Document oldReport = reportLoader.loadXML(new FileReader(oldFile));
59    Document newReport = reportLoader.loadXML(new FileReader(newFile));
60    FileWriter out = new FileWriter(htmlReportFile);
61    Diff diff = new XMLReportDiffer().diff(oldReport, newReport);
62    DiffReport report = diffReportFactory.buildReport(diff);
63    if (oldLinkUrl != null && !oldLinkUrl.equals("")) {
64      report.setOldSourceUrl(oldLinkUrl);
65    }
66    if (newLinkUrl != null && !newLinkUrl.equals("")) {
67      report.setOldSourceUrl(newLinkUrl);
68    }
69    report.writeHtml(out);
70  }
71
72  private void parseArgs(String[] args) throws CmdLineException {
73    CmdLineParser parser = new CmdLineParser(this);
74    try {
75      parser.parseArgument(args);
76    } catch (CmdLineException e) {
77      System.err.println(e.getMessage() + "\n");
78      parser.setUsageWidth(120);
79      parser.printUsage(System.err);
80      throw new CmdLineException("Exiting...");
81    }
82  }
83
84  private static class DiffReportFactory {
85    public DiffReport buildReport(Diff diff) {
86      return new DiffReport(diff, new Configuration());
87    }
88  }
89}