Mercurial > lasercutter
comparison src/clojure/lang/Compile.java @ 10:ef7dbbd6452c
added clojure source goodness
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Sat, 21 Aug 2010 06:25:44 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
9:35cf337adfcf | 10:ef7dbbd6452c |
---|---|
1 /** | |
2 * Copyright (c) Rich Hickey. All rights reserved. | |
3 * The use and distribution terms for this software are covered by the | |
4 * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) | |
5 * which can be found in the file epl-v10.html at the root of this distribution. | |
6 * By using this software in any fashion, you are agreeing to be bound by | |
7 * the terms of this license. | |
8 * You must not remove this notice, or any other, from this software. | |
9 **/ | |
10 | |
11 | |
12 package clojure.lang; | |
13 | |
14 import java.io.OutputStreamWriter; | |
15 import java.io.PrintWriter; | |
16 import java.io.IOException; | |
17 | |
18 // Compiles libs and generates class files stored within the directory | |
19 // named by the Java System property "clojure.compile.path". Arguments are | |
20 // strings naming the libs to be compiled. The libs and compile-path must | |
21 // all be within CLASSPATH. | |
22 | |
23 public class Compile{ | |
24 | |
25 private static final String PATH_PROP = "clojure.compile.path"; | |
26 private static final String REFLECTION_WARNING_PROP = "clojure.compile.warn-on-reflection"; | |
27 private static final Var compile_path = RT.var("clojure.core", "*compile-path*"); | |
28 private static final Var compile = RT.var("clojure.core", "compile"); | |
29 private static final Var warn_on_reflection = RT.var("clojure.core", "*warn-on-reflection*"); | |
30 | |
31 public static void main(String[] args) throws Exception{ | |
32 | |
33 OutputStreamWriter out = (OutputStreamWriter) RT.OUT.deref(); | |
34 PrintWriter err = RT.errPrintWriter(); | |
35 String path = System.getProperty(PATH_PROP); | |
36 int count = args.length; | |
37 | |
38 if(path == null) | |
39 { | |
40 err.println("ERROR: Must set system property " + PATH_PROP + | |
41 "\nto the location for compiled .class files." + | |
42 "\nThis directory must also be on your CLASSPATH."); | |
43 System.exit(1); | |
44 } | |
45 | |
46 boolean warnOnReflection = System.getProperty(REFLECTION_WARNING_PROP, "false").equals("true"); | |
47 | |
48 try | |
49 { | |
50 Var.pushThreadBindings(RT.map(compile_path, path, warn_on_reflection, warnOnReflection)); | |
51 | |
52 for(String lib : args) | |
53 { | |
54 out.write("Compiling " + lib + " to " + path + "\n"); | |
55 out.flush(); | |
56 compile.invoke(Symbol.intern(lib)); | |
57 } | |
58 } | |
59 finally | |
60 { | |
61 Var.popThreadBindings(); | |
62 try | |
63 { | |
64 out.flush(); | |
65 out.close(); | |
66 } | |
67 catch(IOException e) | |
68 { | |
69 e.printStackTrace(err); | |
70 } | |
71 } | |
72 } | |
73 } |