Skip to content

Commit

Permalink
Fixed servlet compilation step
Browse files Browse the repository at this point in the history
  • Loading branch information
weavejester committed Dec 12, 2010
1 parent a897d9f commit 90fe405
Showing 1 changed file with 28 additions and 16 deletions.
44 changes: 28 additions & 16 deletions src/leiningen/ring/war.clj
Expand Up @@ -47,21 +47,29 @@
[:servlet-name "war-servlet"]
[:url-pattern "/*"]]])))

(defn compile-ns [project forms]

(defn source-file [project namespace]
(io/file (:compile-path project)
(-> (str namespace)
(.replace "-" "_")
(.replace "." java.io.File/separator)
(str ".clj"))))

(defn compile-form [project namespace form]
(let [out-file (source-file project namespace)]
(.mkdirs (.getParentFile out-file))
(with-open [out (io/writer out-file)]
(binding [*out* out] (prn form))))
(compile/eval-in-project project
`(binding [*compile-files* true]
(load-string (pr-str '~forms)))))
`(clojure.core/compile '~namespace)))

(defn compile-servlet [project]
(let [handler-sym (get-in project [:ring :handler])]
(compile-ns project
(let [handler-sym (get-in project [:ring :handler])
handler-ns (symbol (namespace handler-sym))]
(compile-form project 'deploy.servlet
`(do (ns deploy.servlet
(:require
~(symbol (namespace handler-sym))
ring.util.servlet)
(:gen-class
:name "deploy.servlet"
:extends javax.servlet.http.HttpServlet))
(:require ring.util.servlet ~handler-ns)
(:gen-class :extends javax.servlet.http.HttpServlet))
(ring.util.servlet/defservice ~handler-sym)))))

(defn create-war [project file-path]
Expand All @@ -76,18 +84,22 @@
(defn str-entry [war war-path content]
(write-entry war war-path (to-byte-stream content)))

(defn- in-war-path [war-path root file]
(defn in-war-path [war-path root file]
(str war-path "/"
(-> (.toURI (io/file root))
(.relativize (.toURI file))
(.getPath))))

(defn file-entry [war project war-path file]
(when (and (.exists file)
(.isFile file)
(not (skip-file? project war-path file)))
(write-entry war war-path file)))

(defn dir-entry [war project war-root dir-path]
(doseq [file (file-seq (io/file dir-path))]
(if (and (.exists file) (.isFile file))
(let [war-path (in-war-path war-root dir-path file)]
(if-not (skip-file? project war-path file)
(write-entry war war-path file))))))
(let [war-path (in-war-path war-root dir-path file)]
(file-entry war project war-path file))))

(defn write-war [project war-path]
(with-open [war-stream (create-war project war-path)]
Expand Down

0 comments on commit 90fe405

Please sign in to comment.