-
Notifications
You must be signed in to change notification settings - Fork 33
Support overriding pom.xml version via :exec-args and cli #21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,11 @@ | |
| [clojure.java.io :as io] | ||
| [clojure.data.xml :as xml])) | ||
|
|
||
|
|
||
| (aether/register-wagon-factory! "s3p" #(org.springframework.build.aws.maven.PrivateS3Wagon.)) | ||
| (aether/register-wagon-factory! "s3" #(org.springframework.build.aws.maven.SimpleStorageServiceWagon.)) | ||
|
|
||
|
|
||
| (def default-repo-settings {"clojars" {:url (or (System/getenv "CLOJARS_URL") "https://clojars.org/repo") | ||
| :username (System/getenv "CLOJARS_USERNAME") | ||
| :password (System/getenv "CLOJARS_PASSWORD")}}) | ||
|
|
@@ -75,9 +80,9 @@ | |
| (defn- artifact [{:keys [group-id artifact-id version]}] | ||
| (str group-id "/" artifact-id "-" version)) | ||
|
|
||
| (defmulti deploy :installer) | ||
| (defmulti deploy* :installer) | ||
|
|
||
| (defmethod deploy :clojars [{:keys [artifact-map coordinates repository] | ||
| (defmethod deploy* :remote [{:keys [artifact-map coordinates repository] | ||
| :or {repository default-repo-settings} :as opts}] | ||
| (println "Deploying" (artifact coordinates) "to clojars as" | ||
| (-> repository vals first :username)) | ||
|
|
@@ -88,22 +93,81 @@ | |
| :coordinates (mvn-coordinates coordinates)) | ||
| (println "done.")) | ||
|
|
||
| (defmethod deploy :local [{:keys [artifact-map coordinates]}] | ||
| (defmethod deploy* :local [{:keys [artifact-map coordinates]}] | ||
| (println "Installing" (artifact coordinates) "to your local `.m2`") | ||
| (aether/install :artifact-map artifact-map | ||
| :transfer-listener :stdout | ||
| :coordinates (mvn-coordinates coordinates)) | ||
| (println "done.")) | ||
|
|
||
| (defn -main [deploy-or-install artifact & [sign-releases]] | ||
| (let [pom (slurp "pom.xml") | ||
| coordinates (coordinates-from-pom pom) | ||
| versioned-pom (spit (versioned-pom-filename coordinates) pom)] | ||
|
|
||
| (defn- tag-val-replacer [tag->val] | ||
| (fn [{:keys [tag content attrs] :as el}] | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| (let [replacement-val (tag->val tag ::default)] | ||
| (if (= ::default replacement-val) | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a great use-case for (cond-> el
(not= ::default replacement-val) (assoc :content replacement-val))It's almost like this is an (update el :content (fn [c] (if (= ::default replacement-val) c replacement-val)))
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indeed it is. Will revise both of those. Thanks for caring. |
||
| el | ||
| (assoc el :content replacement-val))))) | ||
|
|
||
| (defn update-pom [{:keys [pom-file | ||
| mvn/version | ||
| mvn/group-id | ||
| mvn/artifact-id] :as opts}] | ||
| (-> (or pom-file "pom.xml") | ||
| io/reader | ||
| xml/parse | ||
| (update :content | ||
| #(map (tag-val-replacer {version-tag [version] | ||
| group-id-tag [group-id] | ||
| artifact-id-tag [artifact-id]}) %)) | ||
| xml/emit-str)) | ||
|
|
||
| (defn deploy | ||
| "The main entry point into deps-deploy via tools.deps :exec-fn which | ||
| supports an opts map that can be supplied via :exec-args. | ||
| Required keys are: | ||
| :artifact A string specifying the file path relative to the current | ||
| working directory to the artifact to be deployed. This will | ||
| normally be your library packaged as a jar. | ||
| :installer Set to either :local or :remote depending on whether you | ||
| want to install into your local .m2 cache or to a remote | ||
| :repository. | ||
| :pom-file defaults to \"pom.xml\" | ||
| :sign-releases? A boolean that specifies whether releases should be | ||
| signed | ||
| " | ||
| [{:keys [sign-releases? artifact] :as opts}] | ||
| (let [updated-pom (update-pom opts) | ||
| coordinates (coordinates-from-pom updated-pom) | ||
| updated-pom-file-name (versioned-pom-filename coordinates)] | ||
| (spit updated-pom-file-name updated-pom) | ||
| (try | ||
| (deploy {:installer (cond (= "deploy" deploy-or-install) :clojars | ||
| (= "install" deploy-or-install) :local) | ||
| :artifact-map (all-artifacts sign-releases coordinates artifact) | ||
| :coordinates coordinates}) | ||
| (deploy* | ||
| (assoc opts | ||
| :artifact-map (all-artifacts sign-releases? coordinates artifact) | ||
| :coordinates coordinates)) | ||
| (finally | ||
| (.delete (java.io.File. (versioned-pom-filename coordinates))))))) | ||
| (.delete (java.io.File. updated-pom-file-name)))))) | ||
|
|
||
| ;; command line mode | ||
| (defn -main [deploy-or-install artifact & [sign-releases]] | ||
| (deploy {:installer (cond (= "deploy" deploy-or-install) :remote | ||
| (= "install" deploy-or-install) :local) | ||
| :sign-releases? (= "true" sign-releases) | ||
| :artifact artifact})) | ||
|
|
||
| (comment | ||
|
|
||
| (deploy {:installer :remote | ||
| :artifact "deps-deploy.jar" | ||
| :pom-file "pom.xml" | ||
| :mvn/version "999" | ||
| :repository {"clojars" {:url "https://clojars.org/repo" | ||
| :username "clojars-username" | ||
| :password "CLOJARS-token"}}}) | ||
|
|
||
| ) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tend to prefer creating fns which take the required amount of args, and then rather bind the args using
partial(to which I'm, ehrm, partial) or with an anon-fn#(replace-tag {version-tag [version] group-id-tag [group-id] ...} %)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 Cool. I'm quite partial to doing things that way too ;-) it was even my first instinct, which I held back on because I figured it'd be bikeshedded the other way. Happy to change.