Add :uberjar-exclusions to project.clj.
This commit is contained in:
parent
d72f01b41a
commit
2bda774edc
5 changed files with 41 additions and 8 deletions
|
@ -91,6 +91,8 @@
|
|||
:omit-source true
|
||||
;; Files with names matching any of these patterns will be excluded from jars
|
||||
:jar-exclusions [#"(?:^|/).svn/"]
|
||||
;; Same thing, but for uberjars.
|
||||
:uberjar-exclusions [#"META-INF/DUMMY.SF"]
|
||||
;; Set arbitrary key/value pairs for the jar's manifest.
|
||||
:manifest {"Project-awesome-level" "super-great"}
|
||||
;; You can set JVM-level options here.
|
||||
|
|
|
@ -18,13 +18,20 @@
|
|||
first
|
||||
:content)))
|
||||
|
||||
(defn- skip? [entry skip-set]
|
||||
(reduce (fn [skip matcher]
|
||||
(or skip (if (string? matcher)
|
||||
(= matcher (.getName entry))
|
||||
(re-find matcher (.getName entry)))))
|
||||
false skip-set))
|
||||
|
||||
(defn- copy-entries
|
||||
"Copies the entries of ZipFile in to the ZipOutputStream out, skipping
|
||||
the entries which satisfy skip-pred. Returns the names of the
|
||||
entries copied."
|
||||
[in out & [skip-pred]]
|
||||
[in out skip-set]
|
||||
(for [file (enumeration-seq (.entries in))
|
||||
:when (not (skip-pred file))]
|
||||
:when (not (skip? file skip-set))]
|
||||
(do
|
||||
(.setCompressedSize file -1) ; some jars report size incorrectly
|
||||
(.putNextEntry out file)
|
||||
|
@ -38,14 +45,15 @@
|
|||
(defn include-dep [out [skip-set components] dep]
|
||||
(println "Including" (.getName dep))
|
||||
(with-open [zipfile (ZipFile. dep)]
|
||||
[(into skip-set (copy-entries zipfile out #(skip-set (.getName %))))
|
||||
[(into skip-set (copy-entries zipfile out skip-set))
|
||||
(concat components (read-components zipfile))]))
|
||||
|
||||
(defn write-components
|
||||
"Given a list of jarfiles, writes contents to a stream"
|
||||
[deps out]
|
||||
[project deps out]
|
||||
(let [[_ components] (reduce (partial include-dep out)
|
||||
[#{"META-INF/plexus/components.xml"} nil]
|
||||
[(into #{"META-INF/plexus/components.xml"}
|
||||
(:uberjar-exclusions project)) nil]
|
||||
deps)]
|
||||
(when-not (empty? components)
|
||||
(.putNextEntry out (ZipEntry. "META-INF/plexus/components.xml"))
|
||||
|
@ -72,7 +80,7 @@ the dependency jars. Suitable for standalone distribution."
|
|||
(let [deps (->> (.listFiles (file (:library-path project)))
|
||||
(filter #(.endsWith (.getName %) ".jar"))
|
||||
(cons (file (get-jar-filename project))))]
|
||||
(write-components deps out)))
|
||||
(write-components project deps out)))
|
||||
(println "Created" standalone-filename))
|
||||
(abort "Uberjar aborting because jar/compilation failed.")))
|
||||
([project] (uberjar project (get-default-uberjar-name project))))
|
||||
|
|
21
test/test_uberjar.clj
Normal file
21
test/test_uberjar.clj
Normal file
|
@ -0,0 +1,21 @@
|
|||
(ns test-uberjar
|
||||
(:use [leiningen.uberjar] :reload)
|
||||
(:use [clojure.test]
|
||||
[leiningen.jar :only [get-jar-filename get-default-uberjar-name jar]]
|
||||
[leiningen.core :only [read-project]])
|
||||
(:import [java.util.zip ZipFile]))
|
||||
|
||||
(def project (binding [*ns* (the-ns 'leiningen.core)]
|
||||
(read-project "test_projects/sample_no_aot/project.clj")))
|
||||
|
||||
(deftest test-uberjar
|
||||
(let [filename (get-jar-filename project (get-default-uberjar-name project))
|
||||
_ (with-out-str (uberjar project))
|
||||
entries (->> (ZipFile. filename)
|
||||
.entries
|
||||
enumeration-seq
|
||||
(map (memfn getName))
|
||||
set)]
|
||||
(is (entries "nom/nom/nom.clj"))
|
||||
(is (entries "robert/hooke.clj"))
|
||||
(is (not (some #(re-find #"dummy" %) entries)))))
|
|
@ -5,7 +5,9 @@
|
|||
|
||||
(defproject nomnomnom "0.5.0-SNAPSHOT"
|
||||
:dependencies [[clojure "1.2.0"]
|
||||
[robert/hooke "1.0.2"]]
|
||||
[robert/hooke "1.0.2"]
|
||||
[janino "2.5.15"]]
|
||||
:uberjar-exclusions [#"DUMMY"]
|
||||
:test-selectors {:default (fn [m] (not (:integration m)))
|
||||
:integration :integration
|
||||
:int2 :int2
|
||||
|
|
2
todo.org
2
todo.org
|
@ -51,7 +51,7 @@ See also http://github.com/technomancy/leiningen/issues
|
|||
the standard lucene index system that Maven repositories offer.
|
||||
This would also mean getting Clojars to produce those indices.
|
||||
* For 1.4
|
||||
** TODO :uberjar-exclusions?
|
||||
** DONE :uberjar-exclusions?
|
||||
** DONE :all test-selector built-in
|
||||
** DONE test selectors need to support things like constantly, complement
|
||||
** DONE detect missing level of nesting in project.clj's deps/dev-deps
|
||||
|
|
Loading…
Reference in a new issue