Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
ragnard committed Jun 13, 2015
1 parent 814d9b6 commit 71786cc
Showing 1 changed file with 25 additions and 28 deletions.
53 changes: 25 additions & 28 deletions boot/pod/src/boot/pod.clj
Original file line number Diff line number Diff line change
Expand Up @@ -342,47 +342,44 @@
[#".*" first-wins-merger]])

(defn merge-duplicate-jar-entry
[mergers curr-file new-path new-url & {:keys [merged-url]}]
[mergers curr-file new-path new-stream & {:keys [merged-url]}]
(let [merged-url (or merged-url curr-file)]
(when-let [merger (some (fn [[re v]] (when (re-find re new-path) v)) mergers)]
(util/dbug "Merging duplicate jar entry (%s)\n" new-path)
(let [out-file (File/createTempFile (.getName curr-file) nil
(.getParentFile curr-file))]
(with-open [curr-stream (io/input-stream curr-file)
new-stream (io/input-stream new-url)
out-stream (io/output-stream out-file)]
(merger curr-stream new-stream out-stream))
(Files/move (.toPath out-file) (.toPath merged-url)
(into-array [StandardCopyOption/REPLACE_EXISTING]))))))

(defn url-last-modified
[url]
(let [conn (.openConnection (URL. url))]
(try
(.getLastModified conn)
(finally
(when-let [is (.getInputStream conn)]
(.close is))))))

(defn unpack-jar
[jar dir & {:keys [include exclude mergers cache] :or {cache true}}]
(doseq [[path url] (jar-entries jar :cache cache)]
(let [out (io/file dir path)
keep? (partial file/keep-filters? include exclude)]
(when (keep? (io/file path))
(try
(util/dbug "Unpacking %s from %s (caching %s)...\n"
path (.getName (io/file jar)) (if cache "on" "off"))
(if (.exists out)
(let [pre (digest/md5 out)]
(merge-duplicate-jar-entry mergers out path url)
(when (not= pre (digest/md5 out))
(.setLastModified out (url-last-modified url))))
(do
(copy-url url out :cache false)
(.setLastModified out (url-last-modified url))))
(catch Exception err
(util/warn "Error while extracting %s: %s\n" url err)))))))
(with-open [jf (JarFile. jar)]
(doseq [entry (enumeration-seq (.entries jf))
:when (not (.isDirectory entry))]
(let [path (.getName entry)
out-file (io/file dir path)
keep? (partial file/keep-filters? include exclude)]
(when (keep? (io/file path))
(try
(util/dbug "Unpacking %s from %s (caching %s)...\n"
path (.getName jf) (if cache "on" "off"))
(if (.exists out-file)
(let [pre (digest/md5 out-file)]
(with-open [entry-stream (.getInputStream jf entry)]
(merge-duplicate-jar-entry mergers out-file path entry-stream))
(when (not= pre (digest/md5 out-file))
(.setLastModified out-file (.getTime entry))))
(do
(with-open [entry-stream (.getInputStream jf entry)
out (io/output-stream (doto (io/file out-file) io/make-parents))]
(io/copy entry-stream out))
(.setLastModified out-file (.getTime entry))))
(catch Exception err
(util/warn "Error while extracting %s:%s: %s\n" jar entry err)
(.printStackTrace err))))))))

(defn jars-dep-graph
[env]
Expand Down

0 comments on commit 71786cc

Please sign in to comment.