Skip to content

Commit 903ed7a

Browse files
committed
Add deploy task, cleanup some things
1 parent 1f133bc commit 903ed7a

File tree

6 files changed

+72
-30
lines changed

6 files changed

+72
-30
lines changed

boot/aether/src/boot/aether.clj

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -146,15 +146,26 @@
146146
with-out-str))
147147

148148
(defn install
149-
[jarfile]
150-
(let [pomprop (pod/pom-properties jarfile)
151-
gid (.getProperty pomprop "groupId")
152-
aid (.getProperty pomprop "artifactId")
153-
version (.getProperty pomprop "version")
149+
[env jarfile]
150+
(let [{:keys [project version]}
151+
(-> jarfile pod/pom-properties pod/pom-properties-map)
154152
pomfile (doto (File/createTempFile "pom" ".xml")
155-
.deleteOnExit (spit (pod/pom-xml jarfile)))
156-
project (symbol gid aid)]
153+
.deleteOnExit (spit (pod/pom-xml jarfile)))]
157154
(aether/install
158155
:coordinates [project version]
159156
:jar-file (io/file jarfile)
160-
:pom-file (io/file pomfile))))
157+
:pom-file (io/file pomfile)
158+
:local-repo (or (:local-repo env) @local-repo nil))))
159+
160+
(defn deploy
161+
[env repo jarfile]
162+
(let [{:keys [project version]}
163+
(-> jarfile pod/pom-properties pod/pom-properties-map)
164+
pomfile (doto (File/createTempFile "pom" ".xml")
165+
.deleteOnExit (spit (pod/pom-xml jarfile)))]
166+
(aether/deploy
167+
:coordinates [project version]
168+
:jar-file (io/file jarfile)
169+
:pom-file (io/file pomfile)
170+
:repository [repo]
171+
:local-repo (or (:local-repo env) @local-repo nil))))

boot/core/src/boot/task/built_in.clj

Lines changed: 45 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@
132132
ign? (git/make-gitignore-matcher (core/get-env :src-paths))]
133133
(fn [continue]
134134
(fn [event]
135+
(util/info "Starting file watcher (CTRL-C to quit)...\n")
135136
(loop [ret (util/guard [(.take q)])]
136137
(when ret
137138
(if-let [more (.poll q (or debounce 10) TimeUnit/MILLISECONDS)]
@@ -209,6 +210,7 @@
209210
xmlfile (io/file pomdir "pom.xml")
210211
propfile (io/file pomdir "pom.properties")]
211212
(when-not (and (.exists xmlfile) (.exists propfile))
213+
(util/info "Writing %s and %s...\n" (.getName xmlfile) (.getName propfile))
212214
(pod/call-worker
213215
`(boot.pom/spit-pom! ~(.getPath xmlfile) ~(.getPath propfile) ~opts)))))))
214216

@@ -225,6 +227,7 @@
225227

226228
(let [tgt (core/mktgtdir! ::add-dir-tgt)]
227229
(core/with-pre-wrap
230+
(util/info "Adding resource directories...\n")
228231
(binding [file/*filters* (mapv re-pattern filters)]
229232
(apply file/sync :time tgt dirs)))))
230233

@@ -241,6 +244,7 @@
241244
(let [tgt (core/mktgtdir! ::add-srcs-tgt)]
242245
(core/with-pre-wrap
243246
(when-let [dirs (seq (remove core/tmpfile? (core/get-env :src-paths)))]
247+
(util/info "Adding src files...\n")
244248
(binding [file/*filters* (mapv re-pattern filters)]
245249
(apply file/sync :time tgt dirs))))))
246250

@@ -270,6 +274,7 @@
270274
urls (-> (core/get-env)
271275
(update-in [:dependencies] (partial filter scope?))
272276
pod/jar-entries-in-dep-order)]
277+
(util/info "Adding uberjar entries...\n")
273278
(doseq [[relpath url-str] urls]
274279
(when (or (empty? filters) (keep? relpath))
275280
(let [segs (file/split-path relpath)
@@ -294,8 +299,10 @@
294299
(when-not (.exists xmlfile)
295300
(-> (and (symbol? serve) (namespace serve))
296301
(assert "no serve function specified"))
302+
(util/info "Adding servlet impl...\n")
297303
(pod/copy-dependency-jar-entries
298304
(core/get-env) tgt implp implv #"^tailrecursion/.*\.(class|clj)$")
305+
(util/info "Writing %s...\n" (.getName xmlfile))
299306
(pod/call-worker
300307
`(boot.web/spit-web! ~(.getPath xmlfile) ~serve ~create ~destroy))))))
301308

@@ -315,6 +322,7 @@
315322
(when-not (.exists jarfile)
316323
(let [index (->> (core/tgt-files)
317324
(map (juxt core/relative-path (memfn getPath))))]
325+
(util/info "Writing %s...\n" (.getName jarfile))
318326
(pod/call-worker
319327
`(boot.jar/spit-jar! ~(.getPath jarfile) ~index ~manifest ~main))
320328
(doseq [[_ f] index] (core/consume-file! (io/file f)))))))))
@@ -335,12 +343,18 @@
335343
r
336344
(.getPath (apply io/file "WEB-INF" "classes" r'))))
337345
index (->> (core/tgt-files) (map (juxt ->war (memfn getPath))))]
346+
(util/info "Writing %s...\n" (.getName warfile))
338347
(pod/call-worker
339348
`(boot.jar/spit-jar! ~(.getPath warfile) ~index {} nil))
340349
(doseq [[_ f] index] (core/consume-file! (io/file f)))))))))
341350

342351
(core/deftask install
343-
"Install project jar to local Maven repository."
352+
"Install project jar to local Maven repository.
353+
354+
The file option allows installation of arbitrary jar files. If no file option
355+
is given then any jar artifacts created during the build will be installed.
356+
357+
Note that installation requires the jar to contain a pom.xml file."
344358

345359
[f file PATH str "The jar file to install."]
346360

@@ -351,20 +365,39 @@
351365
(doseq [jarfile jarfiles]
352366
(util/info "Installing %s...\n" (.getName jarfile))
353367
(pod/call-worker
354-
`(boot.aether/install ~(.getPath jarfile)))))))
368+
`(boot.aether/install ~(core/get-env) ~(.getPath jarfile)))))))
369+
370+
(core/deftask deploy
371+
"Deploy project jar to a Maven repository.
372+
373+
Both the file and repo options are required. The jar file must contain a
374+
pom.xml entry."
375+
376+
[f file PATH str "The jar file to deploy."
377+
r repo ALIAS str "The alias of the deploy repository."]
378+
379+
(core/with-pre-wrap
380+
(let [f (io/file file)
381+
r (-> (->> (core/get-env :repositories) (into {})) (get repo))]
382+
(when-not (and r (.exists f))
383+
(throw (Exception. "missing jar file or repo alias option")))
384+
(util/info "Deploying %s...\n" (.getName f))
385+
(pod/call-worker
386+
`(boot.aether/deploy ~(core/get-env) ~[repo r] ~(.getPath f))))))
355387

356388
(core/deftask push
357-
"Push project jar to Clojars."
389+
"Push project jar to Clojars.
390+
391+
The file option is required, and the jar file must contain a pom.xml entry."
358392

359-
[f file PATH str "The jar file to push to Clojars."]
393+
[f file PATH str "The path to the jar file."]
360394

361395
(let [tmp (core/mktmpdir! ::push-tmp)]
362396
(core/with-pre-wrap
363-
(let [jarfiles (or (and file [(io/file file)])
364-
(->> (core/tgt-files) (core/by-ext [".jar"])))]
365-
(when-not (seq jarfiles) (throw (Exception. "can't find jar file")))
366-
(doseq [jarfile jarfiles]
367-
(if-let [xml (pod/pom-xml jarfile)]
368-
(let [pom (doto (io/file tmp "pom.xml") (spit xml))]
369-
((helpers/sh "scp" (.getPath jarfile) (.getPath pom) "[email protected]:")))
370-
(throw (Exception. "jar file has no pom.xml"))))))))
397+
(let [jarfile (io/file file)]
398+
(when-not (.exists jarfile) (throw (Exception. "can't find jar file")))
399+
(if-let [xml (pod/pom-xml jarfile)]
400+
(let [pom (doto (io/file tmp "pom.xml") (spit xml))]
401+
(util/info "Pushing %s to Clojars...\n" (.getName jarfile))
402+
((helpers/sh "scp" (.getPath jarfile) (.getPath pom) "[email protected]:")))
403+
(throw (Exception. "jar file does not contain a pom.xml entry")))))))

boot/pod/src/boot/jar.clj

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
(let [manifest (create-manifest main attr)
3737
jarfile (io/file jarpath)]
3838
(io/make-parents jarfile)
39-
(util/info "Writing %s...\n" (.getName jarfile))
4039
(with-open [s (JarOutputStream. (io/output-stream jarfile) manifest)]
4140
(doseq [[jarpath srcpath] files :let [f (io/file srcpath)]]
4241
(let [entry (doto (JarEntry. jarpath) (.setTime (.lastModified f)))]
@@ -46,4 +45,4 @@
4645
(if-not (and (instance? ZipException t)
4746
(.startsWith (.getMessage t) "duplicate entry:"))
4847
(throw t)
49-
(println (.getMessage t))))))))))
48+
(util/warn "%s\n" (.getMessage t))))))))))

boot/pod/src/boot/pod.clj

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,14 +104,16 @@
104104
(.getInputStream jarfile))))))
105105

106106
(defn pom-properties-map
107-
[pom-properties-path]
108-
(let [p (doto (Properties.) (.load (io/input-stream pom-properties-path)))
109-
gid (.getProperty p "groupId")
110-
aid (.getProperty p "artifactId")]
107+
[prop-or-jarpath]
108+
(let [prop (if (instance? Properties prop-or-jarpath)
109+
prop-or-jarpath
110+
(doto (Properties.) (.load (io/input-stream prop-or-jarpath))))
111+
gid (.getProperty prop "groupId")
112+
aid (.getProperty prop "artifactId")]
111113
{:group-id gid
112114
:artifact-id aid
113115
:project (symbol gid aid)
114-
:version (.getProperty p "version")}))
116+
:version (.getProperty prop "version")}))
115117

116118
(defn pom-xml
117119
[jarpath]

boot/worker/src/boot/pom.clj

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,6 @@
6767
(.setProperty "version" version))
6868
xmlfile (doto (io/file xmlpath) io/make-parents)
6969
propfile (doto (io/file proppath) io/make-parents)]
70-
(util/info "Writing %s...\n" (.getName xmlfile))
7170
(spit xmlfile (pr-str (pom-xml env)))
72-
(util/info "Writing %s...\n" (.getName propfile))
7371
(with-open [s (io/output-stream propfile)]
7472
(.store prop s (str gid "/" aid " " version " property file")))))

boot/worker/src/boot/web.clj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030

3131
(defn spit-web! [webxmlfile serve create destroy]
3232
(let [xmlfile (io/file webxmlfile)]
33-
(util/info "Writing web.xml...\n")
3433
(spit
3534
(doto xmlfile io/make-parents)
3635
(pr-str (web-xml "boot-webapp" "boot-webapp" serve create destroy)))))

0 commit comments

Comments
 (0)