Skip to content

Commit

Permalink
Merge pull request #27 from technomancy/plural-paths
Browse files Browse the repository at this point in the history
Plural paths
  • Loading branch information
weavejester committed Mar 9, 2012
2 parents 1077cb4 + 8b6f9d4 commit dec4080
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 36 deletions.
47 changes: 26 additions & 21 deletions src/leiningen/ring/uberwar.clj
Expand Up @@ -7,41 +7,46 @@
(or (:uberjar-name project)
(str (:name project) "-" (:version project) "-standalone.war")))

(defn get-classpath [project]
(if-let [get-cp (resolve 'leiningen.core.classpath/get-classpath)]
(get-cp project)
(->> (:library-path project) io/file .listFiles (map str))))

(defn jar-dependencies [project]
(->> (:library-path project)
(io/file)
(.listFiles)
(filter #(.endsWith (str %) ".jar"))
;; Servlet container will have it's own servlet-api implementation
(remove #(.startsWith (.getName %) "servlet-api-"))))
(for [file (get-classpath project)
:when (and (.endsWith file ".jar")
;; Servlet container will have it's own servlet-api impl
(not (.startsWith file "servlet-api-")))]
(io/file file)))

(defn jar-entries [war project]
(doseq [jar-file (jar-dependencies project)]
(let [dir-path (:library-path project)
(let [dir-path (.getParent jar-file)
war-path (war/in-war-path "WEB-INF/lib/" dir-path jar-file)]
(war/file-entry war project war-path jar-file))))

(defn write-uberwar [project war-path]
(with-open [war-stream (war/create-war project war-path)]
(doto war-stream
(war/str-entry "WEB-INF/web.xml" (war/make-web-xml project))
(war/dir-entry project "WEB-INF/classes/" (:compile-path project))
(war/dir-entry project "WEB-INF/classes/" (:source-path project))
(war/dir-entry project "WEB-INF/classes/" (:resources-path project))
(war/dir-entry project "" (war/war-resources-path project))
(jar-entries project))))
(war/dir-entry project "WEB-INF/classes/" (:compile-path project)))
(doseq [path (concat [(:source-path project)] (:source-paths project)
[(:resources-path project)] (:resource-paths project))
:when path]
(war/dir-entry war-stream project "WEB-INF/classes/" path))
(war/dir-entry war-stream project "" (war/war-resources-path project))
(jar-entries war-stream project)))

(defn uberwar
"Create a $PROJECT-$VERSION.war with dependencies."
([project]
(uberwar project (default-uberwar-name project)))
([project war-name]
(binding [compile/*silently* true]
(when (zero? (compile/compile project))
(let [war-path (war/war-file-path project war-name)]
(war/compile-servlet project)
(if (war/has-listener? project)
(war/compile-listener project))
(write-uberwar project war-path)
(println "Created" war-path)
war-path)))))
(when (zero? (compile/compile project))
(let [war-path (war/war-file-path project war-name)]
(war/compile-servlet project)
(if (war/has-listener? project)
(war/compile-listener project))
(write-uberwar project war-path)
(println "Created" war-path)
war-path))))
32 changes: 17 additions & 15 deletions src/leiningen/ring/war.clj
Expand Up @@ -15,7 +15,7 @@
(str (:name project) "-" (:version project) ".war")))

(defn war-file-path [project war-name]
(let [target-dir (:target-dir project)]
(let [target-dir (or (:target-dir project) (:target-path project))]
(.mkdirs (io/file target-dir))
(str target-dir "/" war-name)))

Expand Down Expand Up @@ -175,7 +175,7 @@

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

Expand All @@ -197,22 +197,24 @@
(with-open [war-stream (create-war project war-path)]
(doto war-stream
(str-entry "WEB-INF/web.xml" (make-web-xml project))
(dir-entry project "WEB-INF/classes/" (:compile-path project))
(dir-entry project "WEB-INF/classes/" (:source-path project))
(dir-entry project "WEB-INF/classes/" (:resources-path project))
(dir-entry project "" (war-resources-path project)))))
(dir-entry project "WEB-INF/classes/" (:compile-path project)))
(doseq [path (concat [(:source-path project)] (:source-paths project)
[(:resources-path project)] (:resource-paths project))
:when path]
(dir-entry war-stream project "WEB-INF/classes/" path))
(dir-entry war-stream project "" (war-resources-path project))
war-stream))

(defn war
"Create a $PROJECT-$VERSION.war file."
([project]
(war project (default-war-name project)))
([project war-name]
(binding [compile/*silently* true]
(when (zero? (compile/compile project))
(let [war-path (war-file-path project war-name)]
(compile-servlet project)
(if (has-listener? project)
(compile-listener project))
(write-war project war-path)
(println "Created" war-path)
war-path)))))
(when (zero? (compile/compile project))
(let [war-path (war-file-path project war-name)]
(compile-servlet project)
(if (has-listener? project)
(compile-listener project))
(write-war project war-path)
(println "Created" war-path)
war-path))))

0 comments on commit dec4080

Please sign in to comment.