Permalink
Browse files

Merge pull request #2 from kurtharriger/master

rlwrap shell script w/ emacs and os x handling; provide access to the instrumentation instance
  • Loading branch information...
djpowell committed May 20, 2012
2 parents 74119cf + 6bdbc35 commit 9b2643641fd394af75c2934e45596f0af2f6fde0
@@ -150,7 +150,7 @@ public static void agentmain(String agentArgs, Instrumentation inst) {
if (!clojureLoaded) { // if clojure wasn't loaded before, print current status
TRC.fine("Clojure is " + (isClojureLoaded() ? "" : "not ") + "loaded");
}
- startRepl(port);
+ startRepl(port, inst);
} finally {
popClassLoader(old);
}
@@ -169,14 +169,16 @@ public static void agentmain(String agentArgs, Instrumentation inst) {
return urls;
}
- private static void startRepl(int port) {
+ private static void startRepl(int port, Instrumentation inst) {
// avoids making load-time references to Clojure classes from the system classloader
try {
ClassLoader cl = Thread.currentThread().getContextClassLoader();
Class<?> repl = Class.forName("net.djpowell.liverepl.server.Repl", true, cl);
- Method method = repl.getMethod("main", InetAddress.class, Integer.TYPE);
- method.invoke(null, Main.LOCALHOST, port);
- } catch (Exception e) {
+ Method method = repl.getMethod("main", InetAddress.class, Integer.TYPE, Instrumentation.class);
+ method.invoke(null, Main.LOCALHOST, port, inst);
+ } catch (RuntimeException e) {
+ throw e;
+ } catch (Exception e) {
throw new RuntimeException(e);
}
}
@@ -1,6 +1,7 @@
package net.djpowell.liverepl.server;
import java.net.InetAddress;
+import java.lang.instrument.Instrumentation;
import clojure.lang.Namespace;
import clojure.lang.PersistentArrayMap;
@@ -9,21 +10,19 @@
import clojure.lang.Var;
public class Repl {
-
private final static Symbol REPL_NS = Symbol.create("net.djpowell.liverepl.server.repl");
private final static Namespace NS = Namespace.findOrCreate(REPL_NS);
private final static Var REQUIRE = Var.intern(RT.CLOJURE_NS, Symbol.create("require"));
private final static Var REPL = Var.intern(NS, Symbol.create("repl"));
+
+ private final static Symbol AGENT_NS_NAME = Symbol.create("jvm.agent");
+ private final static Namespace AGENT_NS = Namespace.findOrCreate(AGENT_NS_NAME);
- public static void main(InetAddress host, int port) throws Exception {
- // not really needed in clojure 1.1, as context class loaders are the default
- Var.pushThreadBindings(new PersistentArrayMap(new Object[] {RT.USE_CONTEXT_CLASSLOADER, Boolean.TRUE}));
- try {
- REQUIRE.invoke(REPL_NS);
- REPL.invoke(port, 0, host);
- } finally {
- Var.popThreadBindings();
- }
- }
-
+ public static void main(InetAddress host, int port, Instrumentation inst)
+ throws Exception {
+ final Var instv = Var.intern(AGENT_NS, Symbol.create("instrumentation"));
+ instv.bindRoot(inst);
+ REQUIRE.invoke(REPL_NS);
+ REPL.invoke(port, 0, host);
+ }
}
View
33 liverepl.sh 100644 → 100755
@@ -3,13 +3,34 @@
[ -z "$JDK_HOME" ] && JDK_HOME=/usr/lib/jvm/default-java
LIVEREPL_HOME="$(cd -P -- "$(dirname -- "$0")" && pwd -P)"
-CLOJURE_JAR="$LIVEREPL_HOME/clojure.jar"
-if [ ! -f "$JDK_HOME/lib/tools.jar" ]; then
- echo 'Unable to find $JDK_HOME/lib/tools.jar'
- echo "Please set the JDK_HOME environment variable to the location of your JDK."
- exit 1
+MAIN=net.djpowell.liverepl.client.Main
+CLOJURE_JAR=$(find $LIVEREPL_HOME/build -name 'clojure-*[0-9].jar' | head -1)
+AGENT_JAR="$LIVEREPL_HOME/build/liverepl-agent.jar"
+SERVER_JAR="$LIVEREPL_HOME/build/liverepl-server.jar"
+
+
+if [ "Darwin" = "`uname -s`" ]; then
+ CLASSPATH="${CLASSPATH}${JAVA_HOME}/bundle/Classes/classes.jar"
+elif [ ! -f "$JDK_HOME/lib/tools.jar" ]; then
+ echo 'Unable to find $JDK_HOME/lib/tools.jar'
+ echo "Please set the JDK_HOME environment variable to the location of your JDK."
+ exit 1
+else
+ CLASSPATH="${CLASSPATH}${JDK_HOME}/lib/tools.jar"
+fi
+
+if [ "$TERM" != "dumb" ]; then
+ if which rlwrap >/dev/null ; then
+ echo "Found rlwrap"
+ breakchars="(){}[],^%$#@\"\";:''|\\"
+ WRAP="exec rlwrap --remember -c -b \"$breakchars\" "
+ fi
fi
-java -cp "$LIVEREPL_HOME/liverepl-agent.jar:$JDK_HOME/lib/tools.jar" net.djpowell.liverepl.client.Main "$CLOJURE_JAR" "$LIVEREPL_HOME/liverepl-agent.jar" "$LIVEREPL_HOME/liverepl-server.jar" "$@"
+CLASSPATH="$CLASSPATH:$AGENT_JAR"
+
+${WRAP}java -cp $CLASSPATH $MAIN "$CLOJURE_JAR" "$AGENT_JAR" "$SERVER_JAR" "$@"
+
+

0 comments on commit 9b26436

Please sign in to comment.