Browse files

make cd-client and dependencies optional at run-time

* --no-clojuredocs command line flag
* if flag is present, do not require cd-client and
  intern clojuredocs function in initialization
* if flag is present, omit cd-client depencies in classpath
  construction
  • Loading branch information...
1 parent b8abae7 commit cfec6667159e9e0babfa1c45aaa880f9ce553ef2 @casphas casphas committed with trptcolin Feb 4, 2012
Showing with 61 additions and 23 deletions.
  1. +34 −1 bin/reply.sh
  2. +24 −21 src/clj/reply/initialization.clj
  3. +3 −1 src/clj/reply/main.clj
View
35 bin/reply.sh
@@ -25,10 +25,43 @@ if [ -z "$USER_CP" ]; then
USER_CP=""
fi
+SKIP_CD=false
+if [[ $@ =~ "--no-clojuredocs" ]]
+then
+ SKIP_CD=true
+fi
+
+CD_DEPS=( cd-client
+ clj-http
+ httpclient
+ httpcore
+ commons-logging
+ commons-codec
+ commons-io
+ cheshire
+ jackson-core-asl
+ jackson-smile
+)
+
+function is_cd_dep() {
+ local dep=`basename $1`
+ for d in ${CD_DEPS[@]}
+ do
+ if expr ${dep} : ${d} > /dev/null
+ then
+ return 0
+ fi
+ done
+ return 1
+}
+
CP="$BASEDIR"/../src/clj/:\
"$BASEDIR"/../classes/
for j in "$BASEDIR"/../lib/*.jar; do
- CP=$CP:$j
+ if ! ($SKIP_CD && is_cd_dep $j)
+ then
+ CP=$CP:$j
+ fi
done
java -cp "$CP":"$USER_CP" reply.ReplyMain "$@"
View
45 src/clj/reply/initialization.clj
@@ -30,24 +30,26 @@
(with-meta sym (meta value-var))
@value-var))
-(defn default-init-code []
- '(do
- (println "Welcome to REPL-y!")
- (println "Clojure" (clojure-version))
- (use '[clojure.repl :only (source apropos dir pst doc find-doc)])
- (use '[clojure.java.javadoc :only (javadoc)])
- (use '[clojure.pprint :only (pp pprint)])
- (require '[cd-client.core])
- (def exit reply.main/exit)
- (def quit reply.main/exit)
- (def help reply.initialization/help)
+(defn default-init-code [no-clojuredocs?]
+ (list 'do
+ '(println "Welcome to REPL-y!")
+ '(println "Clojure" (clojure-version))
+ '(use '[clojure.repl :only (source apropos dir pst doc find-doc)])
+ '(use '[clojure.java.javadoc :only (javadoc)])
+ '(use '[clojure.pprint :only (pp pprint)])
+ (when-not no-clojuredocs?
+ '(require '[cd-client.core]))
+ '(def exit reply.main/exit)
+ '(def quit reply.main/exit)
+ '(def help reply.initialization/help)
- (help)
- (reply.initialization/intern-with-meta 'user 'clojuredocs #'cd-client.core/pr-examples)
- (binding [*err* (java.io.StringWriter.)]
- (reply.initialization/intern-with-meta 'user 'defn #'reply.initialization/repl-defn))
- (reply.initialization/intern-with-meta 'user 'sourcery #'reply.initialization/sourcery)
- nil))
+ '(help)
+ (when-not no-clojuredocs?
+ '(reply.initialization/intern-with-meta 'user 'clojuredocs #'cd-client.core/pr-examples))
+ '(binding [*err* (java.io.StringWriter.)]
+ (reply.initialization/intern-with-meta 'user 'defn #'reply.initialization/repl-defn))
+ '(reply.initialization/intern-with-meta 'user 'sourcery #'reply.initialization/sourcery)
+ nil))
(defn eval-in-user-ns [code]
(let [original-ns (symbol (str *ns*))]
@@ -57,9 +59,10 @@
(defn construct-init-code
[{:keys [skip-default-init
- custom-init] :as options}]
+ custom-init
+ no-clojuredocs] :as options}]
`(do
- ~(when-not skip-default-init (default-init-code))
- ~(when custom-init custom-init)
- nil))
+ ~(when-not skip-default-init (default-init-code no-clojuredocs))
+ ~(when custom-init custom-init)
+ nil))
View
4 src/clj/reply/main.clj
@@ -63,6 +63,7 @@
"--skip-default-init" (recur (cons arg more)
(assoc arg-map :skip-default-init true))
+ "--no-clojuredocs" (recur (cons arg more) (assoc arg-map :no-clojuredocs true))
arg-map)))
(defn launch-nrepl [options]
@@ -118,6 +119,7 @@ See -main for descriptions."
--nrepl: Launch nREPL (clojure.tools.nrepl) in interactive mode
--attach: Attach to an existing nrepl session on this port, when used with --nrepl
--port: Start a new nrepl session on this port, when used with --nrepl
- --color: Use color; currently only available with --nrepl"
+ --color: Use color; currently only available with --nrepl
+ --no-clojuredocs Do not include clojuredocs client dependencies"
[& args]
(launch (parse-args args)))

0 comments on commit cfec666

Please sign in to comment.