summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRich Hickey <richhickey@gmail.com>2008-08-06 15:23:18 +0000
committerRich Hickey <richhickey@gmail.com>2008-08-06 15:23:18 +0000
commit5c97b610426556b6d032084f1dc601e85000f829 (patch)
treeba56103a1dab718116c7b0b3a49975d17e3d6c43 /src
parentfca8d50f0191456b3aa4e20824dae29e70a0b12d (diff)
made loadResourceScript throw if resource not found, added maybeLoadLoadResourceScript, failIfNotFound flag, based on patch from cemerick.
Added overload of RT.var that takes an initial value.
Diffstat (limited to 'src')
-rw-r--r--src/clj/clojure/genclass.clj3
-rw-r--r--src/jvm/clojure/lang/RT.java34
2 files changed, 29 insertions, 8 deletions
diff --git a/src/clj/clojure/genclass.clj b/src/clj/clojure/genclass.clj
index 8443788d..1649c22c 100644
--- a/src/clj/clojure/genclass.clj
+++ b/src/clj/clojure/genclass.clj
@@ -282,7 +282,8 @@
(. gen push ctype)
(. gen push (str (. name replace \. \/) ".clj"))
- (. gen (invokeStatic rt-type (. Method (getMethod "void loadResourceScript(Class,String)"))))
+ (. gen push 0)
+ (. gen (invokeStatic rt-type (. Method (getMethod "void loadResourceScript(Class,String,boolean)"))))
(. gen (returnValue))
(. gen (endMethod)))
diff --git a/src/jvm/clojure/lang/RT.java b/src/jvm/clojure/lang/RT.java
index e36baaf8..18a9521e 100644
--- a/src/jvm/clojure/lang/RT.java
+++ b/src/jvm/clojure/lang/RT.java
@@ -324,11 +324,27 @@ static public Var var(String ns, String name){
return Var.intern(Namespace.findOrCreate(Symbol.intern(null, ns)), Symbol.intern(null, name));
}
+static public Var var(String ns, String name, Object init){
+ return Var.intern(Namespace.findOrCreate(Symbol.intern(null, ns)), Symbol.intern(null, name), init);
+}
+
public static void loadResourceScript(String name) throws Exception{
- loadResourceScript(RT.class, name);
+ loadResourceScript(name, true);
+}
+
+public static void maybeLoadResourceScript(String name) throws Exception{
+ loadResourceScript(name, false);
+}
+
+public static void loadResourceScript(String name, boolean failIfNotFound) throws Exception{
+ loadResourceScript(RT.class, name, failIfNotFound);
}
public static void loadResourceScript(Class c, String name) throws Exception{
+ loadResourceScript(c, name, true);
+}
+
+public static void loadResourceScript(Class c, String name, boolean failIfNotFound) throws Exception{
int slash = name.lastIndexOf('/');
String file = slash >= 0 ? name.substring(slash + 1) : name;
InputStream ins = c.getResourceAsStream("/" + name);
@@ -337,6 +353,10 @@ public static void loadResourceScript(Class c, String name) throws Exception{
Compiler.load(new InputStreamReader(ins), name, file);
ins.close();
}
+ else if(failIfNotFound)
+ {
+ throw new FileNotFoundException("Could not locate Clojure resource on classpath: " + name);
+ }
}
static public void init() throws Exception{
@@ -345,11 +365,11 @@ static public void init() throws Exception{
static void doInit() throws Exception{
loadResourceScript(RT.class, "clojure/boot.clj");
- loadResourceScript(RT.class, "clojure/proxy.clj");
- loadResourceScript(RT.class, "clojure/genclass.clj");
- loadResourceScript(RT.class, "clojure/zip/zip.clj");
- loadResourceScript(RT.class, "clojure/xml/xml.clj");
- loadResourceScript(RT.class, "clojure/set/set.clj");
+ loadResourceScript(RT.class, "clojure/proxy.clj", false);
+ loadResourceScript(RT.class, "clojure/genclass.clj", false);
+ loadResourceScript(RT.class, "clojure/zip/zip.clj", false);
+ loadResourceScript(RT.class, "clojure/xml/xml.clj", false);
+ loadResourceScript(RT.class, "clojure/set/set.clj", false);
Var.pushThreadBindings(
RT.map(CURRENT_NS, CURRENT_NS.get(),
@@ -363,7 +383,7 @@ static void doInit() throws Exception{
Var refer = var("clojure", "refer");
in_ns.invoke(USER);
refer.invoke(CLOJURE);
- loadResourceScript(RT.class, "user.clj");
+ maybeLoadResourceScript("user.clj");
}
finally
{