Repository navigation
Expand file tree
/
Copy pathdeploy.clj
More file actions
97 lines (86 loc) · 4.13 KB
/
Copy pathdeploy.clj
File metadata and controls
97 lines (86 loc) · 4.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
(ns leiningen.deploy
"Build and deploy jar to remote repository."
(:require [cemerick.pomegranate.aether :as aether]
[leiningen.core.classpath :as classpath]
[leiningen.core.main :as main]
[leiningen.core.eval :as eval]
[clojure.java.io :as io]
[leiningen.pom :as pom]
[leiningen.jar :as jar]))
(defn- abort-message [message]
(cond (re-find #"Return code is 405" message)
(str message "\n" "Ensure you are deploying over SSL.")
(re-find #"Return code is 401" message)
(str message "\n" "See `lein help deploy` for an explanation of how to"
" specify credentials.")
:else message))
(defn add-auth-interactively [[id settings]]
(if (or (and (:username settings) (some settings [:password :passphrase
:private-key-file]))
(.startsWith (:url settings) "file://"))
[id settings]
(do
(println "No credentials found for" id)
(println "See `lein help deploying` for how to configure credentials.")
(print "Username: ") (flush)
(let [username (read-line)
password (.readPassword (System/console) "%s"
(into-array ["Password: "]))]
[id (assoc settings :username username :password password)]))))
(defn repo-for [project name]
(let [[settings] (for [[id settings] (concat (:deploy-repositories project)
(:repositories project)
[[name {:url name}]])
:when (= id name)] settings)]
(-> [name settings]
(classpath/add-repo-auth)
(add-auth-interactively))))
(defn sign [file]
(let [exit (binding [*out* (java.io.StringWriter.)]
(eval/sh "gpg" "--yes" "-ab" file))]
(when-not (zero? exit)
(main/abort "Could not sign" file))
(str file ".asc")))
(defn signatures-for [jar-file pom-file coords]
{(into coords [:extension "jar.asc"]) (sign jar-file)
(into coords [:extension "pom.asc"]) (sign pom-file)})
(defn files-for [project repo]
(let [coords [(symbol (:group project) (:name project)) (:version project)]
jar-file (jar/jar project)
pom-file (pom/pom project)]
(merge {(into coords [:extension "jar"]) jar-file
(into coords [:extension "pom"]) pom-file}
(if (and (:sign-releases (second repo) true)
(not (.endsWith (:version project) "-SNAPSHOT")))
(signatures-for jar-file pom-file coords)))))
(defn warn-missing-metadata [project]
(doseq [key [:description :license :url]]
(when (or (nil? (project key)) (re-find #"FIXME" (str (project key))))
(main/info "WARNING: please set" key "in project.clj."))))
(defn deploy
"Build jar and deploy to remote repository.
The target repository will be looked up in :repositories in project.clj:
:repositories [[\"snapshots\" \"https://internal.repo/snapshots\"]
[\"releases\" \"https://internal.repo/releases\"]
[\"alternate\" \"https://other.server/repo\"]]
If you don't provide a repository name to deploy to, either \"snapshots\" or
\"releases\" will be used depending on your project's current version. See
`lein help deploying` under \"Authentication\" for instructions on how to
configure your credentials so you are not prompted on each deploy."
([project repository-name]
(warn-missing-metadata project)
(let [repo (repo-for project repository-name)
files (files-for project repo)]
(try
(main/debug "Deploying" files "to" repo)
(aether/deploy-artifacts :artifacts (keys files)
:files files
:transfer-listener :stdout
:repository [repo])
(catch org.sonatype.aether.deployment.DeploymentException e
(when main/*debug* (.printStackTrace e))
(main/abort (abort-message (.getMessage e)))))))
([project]
(deploy project (if (pom/snapshot? project)
"snapshots"
"releases"))))