KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openlaszlo > cm > Main


1 /* *****************************************************************************
2  * CompilationManager.java
3 * ****************************************************************************/

4
5 /* J_LZ_COPYRIGHT_BEGIN *******************************************************
6 * Copyright 2001-2004 Laszlo Systems, Inc. All Rights Reserved. *
7 * Use is subject to license terms. *
8 * J_LZ_COPYRIGHT_END *********************************************************/

9
10 package org.openlaszlo.cm;
11 import org.openlaszlo.compiler.CompilationError;
12 import org.apache.log4j.*;
13 import java.io.*;
14 import java.util.Properties JavaDoc;
15
16 public class Main {
17     /**
18      * Compile each file base.ext in args. If compilation is
19      * successful, create an object file base.swf. Otherwise, create
20      * an error report file base.html.
21      *
22      * Usage: <code>main [-src dir] [-cache dir] [-D...] file...</code>
23      *
24      * This method is used to test the class from the command line.
25      *
26      * @param args a <code>String</code> value
27      * @exception IOException if an error occurs
28      */

29     public static void main(String JavaDoc args[])
30         throws IOException
31     {
32         // Configure logging
33
Logger logger = Logger.getRootLogger();
34         logger.setLevel(Level.ERROR);
35         BasicConfigurator.configure();
36         File srcDir = new File(".");
37         File cacheDir = new File(".");
38         Properties JavaDoc props = new Properties JavaDoc();
39         
40         for (int i = 0; i < args.length; i++) {
41             String JavaDoc arg = args[i].intern();
42             if (arg == "-src") {
43                 srcDir = new File(args[++i]);
44                 continue;
45             }
46             if (arg == "-cache") {
47                 cacheDir = new File(args[++i]);
48                 continue;
49             }
50             if (arg.startsWith("-D")) {
51                 String JavaDoc key = arg.substring(2);
52                 String JavaDoc value = "true";
53                 int offset = key.indexOf('=');
54                 if (offset >= 0) {
55                     value = key.substring(offset + 1).intern();
56                     key = key.substring(0, offset);
57                 }
58                 props.setProperty(key, value);
59                 continue;
60             }
61             if (arg.startsWith("-")) {
62                 System.err.println("usage error");
63                 return;
64             }
65             String JavaDoc fileName = arg;
66             try {
67                 CompilationManager cm;
68
69                 cm = new CompilationManager(srcDir, cacheDir, props);
70                 cm.getItem(fileName, null);
71             } catch (CompilationError e) {
72                 // Since this method is used to test the compilation
73
// manager, and we're currently interested in testing
74
// HTML errors, use this instead of getMessage.
75
// Later, we might want to add a --html flag that
76
// controls this.
77
System.err.print(e.toHTML());
78             }
79         }
80     }
81 }
82
Popular Tags