01: // Modified or written by Object Mentor, Inc. for inclusion with FitNesse.
02: // Copyright (c) 2002 Cunningham & Cunningham, Inc.
03: // Released under the terms of the GNU General Public License version 2 or later.
04: package fit;
05:
06: // Copyright (c) 2002 Cunningham & Cunningham, Inc.
07: // Released under the terms of the GNU General Public License version 2 or later.
08:
09: import java.io.*;
10: import java.util.*;
11:
12: public class FileRunner {
13:
14: public String input;
15: public Parse tables;
16: public Fixture fixture = new Fixture();
17: public PrintWriter output;
18:
19: public static void main(String argv[]) {
20: new FileRunner().run(argv);
21: }
22:
23: public void run(String argv[]) {
24: args(argv);
25: process();
26: exit();
27: }
28:
29: public void process() {
30: try {
31: tables = new Parse(input);
32: fixture.doTables(tables);
33: } catch (Exception e) {
34: exception(e);
35: }
36: tables.print(output);
37: }
38:
39: public void args(String[] argv) {
40: if (argv.length != 2) {
41: System.err
42: .println("usage: java fit.FileRunner input-file output-file");
43: System.exit(-1);
44: }
45: File in = new File(argv[0]);
46: File out = new File(argv[1]);
47: fixture.summary.put("input file", in.getAbsolutePath());
48: fixture.summary
49: .put("input update", new Date(in.lastModified()));
50: fixture.summary.put("output file", out.getAbsolutePath());
51: try {
52: input = read(in);
53: output = new PrintWriter(new BufferedWriter(new FileWriter(
54: out)));
55: } catch (IOException e) {
56: System.err.println(e.getMessage());
57: System.exit(-1);
58: }
59: }
60:
61: protected String read(File input) throws IOException {
62: char chars[] = new char[(int) (input.length())];
63: FileReader in = new FileReader(input);
64: in.read(chars);
65: in.close();
66: return new String(chars);
67: }
68:
69: protected void exception(Exception e) {
70: tables = new Parse("body",
71: "Unable to parse input. Input ignored.", null, null);
72: fixture.exception(tables, e);
73: }
74:
75: protected void exit() {
76: output.close();
77: System.err.println(fixture.counts());
78: System.exit(fixture.counts.wrong + fixture.counts.exceptions);
79: }
80:
81: }
|