From 8f50fa7572dfcdb6853df69cdefd4c0e65147229 Mon Sep 17 00:00:00 2001 From: Phil Hagelberg Date: Sun, 29 Aug 2010 13:40:50 -0700 Subject: [PATCH] Allow the socket-repl host/port to be customized in project.clj. --- sample.project.clj | 3 +++ src/leiningen/repl.clj | 15 +++++++++++---- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/sample.project.clj b/sample.project.clj index a7e0dfc7..fe6652cf 100644 --- a/sample.project.clj +++ b/sample.project.clj @@ -62,6 +62,9 @@ :main org.example.sample ;; This will get loaded automatically when you launch a repl. :repl-init-script "src/main/clojure/init.clj" + ;; Customize the socket the repl task listens on. + :repl-port 4001 + :repl-host "0.0.0.0" ;; Emit warnings on all reflection calls. :warn-on-reflection true ;; Set this in order to only use the :repositories you list below. diff --git a/src/leiningen/repl.clj b/src/leiningen/repl.clj index c9601ce3..bba6a6e1 100644 --- a/src/leiningen/repl.clj +++ b/src/leiningen/repl.clj @@ -77,14 +77,21 @@ (catch java.net.ConnectException _ :retry)) (recur port))) +(defn repl-socket-on [{:keys [repl-port repl-host]}] + [(Integer. (or repl-port + (System/getenv "LEIN_REPL_PORT") + (dec (+ 1024 (rand-int 64512))))) + (or repl-host + (System/getenv "LEIN_REPL_HOST") + "localhost")]) + (defn repl "Start a repl session. A socket-repl will also be launched in the -background; use the LEIN_REPL_PORT environment variable to set the port." +background on a socket based on the :repl-port key in project.clj or +chosen randomly." ([] (repl {})) ([project] - (let [host (or (System/getenv "LEIN_REPL_HOST") "localhost") - port (Integer. (or (System/getenv "LEIN_REPL_PORT") - (dec (+ 1024 (rand-int 64512))))) + (let [[host port] (repl-socket-on project) server-form (repl-server project host port)] (future (try (if (empty? project) (clojure.main/with-bindings