01: // Copyright (C) 2003,2004,2005 by Object Mentor, Inc. All rights reserved.
02: // Released under the terms of the GNU General Public License version 2 or later.
03: package fitnesse;
04:
05: import fit.Parse;
06: import fit.Fixture;
07: import java.io.*;
08:
09: public class FitFilter {
10:
11: public String input;
12: public Parse tables;
13: public Fixture fixture = new Fixture();
14: public PrintWriter output;
15:
16: public static void main(String argv[]) {
17: new FitFilter().run(argv);
18: }
19:
20: public void run(String argv[]) {
21: args(argv);
22: process();
23: exit();
24: }
25:
26: public void process() {
27: try {
28: tables = new Parse(input);
29: fixture.doTables(tables);
30: } catch (Exception e) {
31: exception(e);
32: }
33: tables.print(output);
34: }
35:
36: public void args(String[] argv) {
37: if (argv.length != 0) {
38: System.err.println("usage: java fitnesse.FitFilter");
39: System.exit(-1);
40: }
41: try {
42: input = read();
43: output = new PrintWriter(System.out);
44: } catch (IOException e) {
45: System.err.println(e.getMessage());
46: System.exit(-1);
47: }
48: }
49:
50: protected String read() throws IOException {
51: StringBuffer buffer = new StringBuffer();
52: BufferedReader br = new BufferedReader(new InputStreamReader(
53: System.in));
54: String line;
55: while ((line = br.readLine()) != null)
56: buffer.append(line).append("\n");
57: return buffer.toString();
58: }
59:
60: protected void exception(Exception e) {
61: tables = new Parse("body",
62: "Unable to parse input. Input ignored.", null, null);
63: fixture.exception(tables, e);
64: }
65:
66: protected void exit() {
67: output.close();
68: System.exit(fixture.counts.wrong + fixture.counts.exceptions);
69: }
70:
71: }
|