|
1 | 1 | (ns immutant.deploy-tools.war |
2 | 2 | (:require [clojure.string :as str] |
| 3 | + [clojure.set :as set] |
3 | 4 | [clojure.java.io :as io] |
4 | 5 | [version-clj.core :as version]) |
5 | 6 | (:import [java.io BufferedOutputStream FileOutputStream] |
| 7 | + [java.nio.file Files FileSystems StandardOpenOption] |
6 | 8 | java.util.Properties |
7 | 9 | java.util.zip.ZipOutputStream |
8 | 10 | [java.util.jar JarEntry JarOutputStream])) |
|
71 | 73 | (update-in [:classpath] (partial str/join ":")) |
72 | 74 | (update-in [:classpath-jars] (partial map io/file)))) |
73 | 75 |
|
74 | | -(defn build-descriptor [{:keys [root classpath] :as options}] |
| 76 | +(defn build-descriptor [{:keys [dev? init-fn root classpath] :as options}] |
75 | 77 | (cond-> {:language "clojure" |
| 78 | + :raw-init-fn init-fn |
| 79 | + :dev? dev? |
76 | 80 | :init (build-init options)} |
77 | 81 | (:dev? options) (merge |
78 | 82 | {:root root |
|
85 | 89 | (defn map->properties [m] |
86 | 90 | (reduce (fn [p [k v]] |
87 | 91 | (doto p |
88 | | - (.setProperty (name k) v))) |
| 92 | + (.setProperty (name k) (str v)))) |
89 | 93 | (Properties.) |
90 | 94 | m)) |
91 | 95 |
|
| 96 | +(defn properties->partial-options-map [p] |
| 97 | + (-> (->> p |
| 98 | + (map (fn [[k v]] [(keyword k) v])) |
| 99 | + (map (fn [[k v]] [k (case k |
| 100 | + :dev? (= "true" v) |
| 101 | + :raw-init-fn (read-string v) |
| 102 | + v)])) |
| 103 | + (into {})) |
| 104 | + (select-keys [:root :classpath :dev? :raw-init-fn]) |
| 105 | + (set/rename-keys {:raw-init-fn :init-fn}))) |
| 106 | + |
| 107 | +(defn replace-file [zip path bytes] |
| 108 | + (with-open [fs (FileSystems/newFileSystem (.toPath zip) nil)] |
| 109 | + (Files/write (.getPath fs path (make-array String 0)) |
| 110 | + bytes (into-array [StandardOpenOption/CREATE]))) |
| 111 | + zip) |
| 112 | + |
92 | 113 | (defn build-war |
93 | 114 | "Creates a war file with the given entry specs. |
94 | 115 |
|
|
0 commit comments