01: /* *****************************************************************************
02: * CompilationManager.java
03: * ****************************************************************************/
04:
05: /* J_LZ_COPYRIGHT_BEGIN *******************************************************
06: * Copyright 2001-2004 Laszlo Systems, Inc. All Rights Reserved. *
07: * Use is subject to license terms. *
08: * J_LZ_COPYRIGHT_END *********************************************************/
09:
10: package org.openlaszlo.cm;
11:
12: import org.openlaszlo.compiler.CompilationError;
13: import org.apache.log4j.*;
14: import java.io.*;
15: import java.util.Properties;
16:
17: public class Main {
18: /**
19: * Compile each file base.ext in args. If compilation is
20: * successful, create an object file base.swf. Otherwise, create
21: * an error report file base.html.
22: *
23: * Usage: <code>main [-src dir] [-cache dir] [-D...] file...</code>
24: *
25: * This method is used to test the class from the command line.
26: *
27: * @param args a <code>String</code> value
28: * @exception IOException if an error occurs
29: */
30: public static void main(String args[]) throws IOException {
31: // Configure logging
32: Logger logger = Logger.getRootLogger();
33: logger.setLevel(Level.ERROR);
34: BasicConfigurator.configure();
35: File srcDir = new File(".");
36: File cacheDir = new File(".");
37: Properties props = new Properties();
38:
39: for (int i = 0; i < args.length; i++) {
40: String arg = args[i].intern();
41: if (arg == "-src") {
42: srcDir = new File(args[++i]);
43: continue;
44: }
45: if (arg == "-cache") {
46: cacheDir = new File(args[++i]);
47: continue;
48: }
49: if (arg.startsWith("-D")) {
50: String key = arg.substring(2);
51: String value = "true";
52: int offset = key.indexOf('=');
53: if (offset >= 0) {
54: value = key.substring(offset + 1).intern();
55: key = key.substring(0, offset);
56: }
57: props.setProperty(key, value);
58: continue;
59: }
60: if (arg.startsWith("-")) {
61: System.err.println("usage error");
62: return;
63: }
64: String fileName = arg;
65: try {
66: CompilationManager cm;
67:
68: cm = new CompilationManager(srcDir, cacheDir, props);
69: cm.getItem(fileName, null);
70: } catch (CompilationError e) {
71: // Since this method is used to test the compilation
72: // manager, and we're currently interested in testing
73: // HTML errors, use this instead of getMessage.
74: // Later, we might want to add a --html flag that
75: // controls this.
76: System.err.print(e.toHTML());
77: }
78: }
79: }
80: }
|