Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

adjust API of deploy-artifacts and install-artifacts to be metadata-free

  • Loading branch information...
commit 2dbfc6361908477625967ce73e55391757a1b72c 1 parent 96b159f
Chas Emerick authored
92 src/main/clojure/cemerick/pomegranate/aether.clj
View
@@ -269,33 +269,22 @@
(when (seq exclusions)
[:exclusions (vec (map exclusion-spec exclusions))])))))
-(defn- create-subartifacts
- [parent [[group-artifact version & {:keys [classifier extension]} :as coords]
- children]]
- (let [group (group group-artifact)
- artifact (name group-artifact)]
- (when (not= (.getGroupId parent)
- group)
- (throw (IllegalArgumentException. (str "Subartifact " coords " does not have group \"" (.getGroupId parent) "\""))))
- (when (not= (.getArtifactId parent)
- artifact)
- (throw (IllegalArgumentException. (str "Subartifact " coords " does not have artifact id \"" (.getArtifactId parent) "\""))))
- (when (not= (.getVersion parent)
- version)
- (throw (IllegalArgumentException. (str "Subartifact " coords " does not have version \"" (.getVersion parent) "\""))))
- (let [da (-> (SubArtifact. parent classifier extension)
- (.setFile (:file (meta coords))))]
- (conj (mapcat (partial create-subartifacts da) children) da))))
-
-(defn- create-artifacts [[coordinates children]]
- (let [da (-> (DefaultArtifact. (coordinate-string coordinates))
- (.setFile (:file (meta coordinates))))]
- (conj (mapcat (partial create-subartifacts da) children) da)))
+(defn- create-artifact
+ [files artifact]
+ (if-let [file (get files artifact)]
+ (-> (coordinate-string artifact)
+ DefaultArtifact.
+ (.setFile (io/file file)))
+ (throw (IllegalArgumentException. (str "No file provided for artifact " artifact)))))
(defn deploy-artifacts
"Deploy the artifacts kwarg to the repository kwarg.
- :artifacts - map from (with-meta coordinates {:file ..}) to list of subartifacts. subartifacts are the same, but must have a group/artifact and version the same as the parent.
+ :artifacts - a seq of artifact vectors, e.g. '[[group/artifact \"1.0.0\"]] or
+ '[[group/artifact \"1.0.0\"] [group/artifact \"1.0.0\" :extension \"pom\"]].
+ All artifacts should have the same version and group and artifact IDs.
+ :files - map from artifact vectors to file paths or java.io.File objects
+ where the file to be deployed for each artifact is to be found
:repository - {name url} | {name settings}
settings:
:url - URL of the repository
@@ -320,27 +309,36 @@
:passphrase - passphrase to log in wth, may be null
:private-key-file - private key file to log in with, may be null"
- [& {:keys [artifacts repository local-repo transfer-listener proxy]}]
+ [& {:keys [artifacts files repository local-repo transfer-listener proxy]}]
+ (when (or (empty? artifacts) (empty? files))
+ (throw (IllegalArgumentException. "Must provide valid :artifacts and :files to deploy-artifacts")))
+ (when (->> artifacts
+ (map (fn [[ga v]] [(if (namespace ga) ga (symbol (str ga) (str ga))) v]))
+ set
+ count
+ (< 1))
+ (throw (IllegalArgumentException.
+ (str "Provided artifacts have varying version, group, or artifact IDs: " artifacts))))
(let [system (repository-system)
session (repository-session system local-repo false transfer-listener nil)]
(.deploy system session
(doto (DeployRequest.)
- (.setArtifacts (mapcat create-artifacts artifacts))
+ (.setArtifacts (vec (map (partial create-artifact files) artifacts)))
(.setRepository (first (map #(make-repository % proxy) repository)))))))
(defn install-artifacts
"Deploy the file kwarg using the coordinates kwarg to the repository kwarg.
- :artifacts - map from (with-meta coordinates {:file ..}) to list of subartifacts. subartifacts are the same, but must have a group/artifact and version the same as the parent.:coordinates - [group/name \"version\" (:classifier ..)? (:extension ..)?]
+ :artifacts - same as with deploy-artifacts
+ :files - same as with deploy-artifacts
:local-repo - path to the local repository (defaults to ~/.m2/repository)
:transfer-listener - same as provided to resolve-dependencies"
-
- [& {:keys [artifacts local-repo transfer-listener]}]
+ [& {:keys [artifacts files local-repo transfer-listener]}]
(let [system (repository-system)
session (repository-session system local-repo false transfer-listener nil)]
(.install system session
(doto (InstallRequest.)
- (.setArtifacts (mapcat create-artifacts artifacts))))))
+ (.setArtifacts (vec (map (partial create-artifact files) artifacts)))))))
(defn deploy
"Deploy the jar-file kwarg using the pom-file kwarg and coordinates
@@ -375,16 +373,13 @@ kwarg to the repository kwarg.
:private-key-file - private key file to log in with, may be null"
[& {:keys [coordinates jar-file pom-file] :as opts}]
(apply deploy-artifacts
- (apply concat (assoc opts :artifacts
- {(with-meta coordinates
- {:file jar-file})
- (when pom-file
- {(with-meta
- ((fn [[name version & _]]
- [name version :extension "pom"])
- coordinates)
- {:file pom-file})
- nil})}))))
+ (apply concat (assoc opts
+ :artifacts (if pom-file
+ [coordinates (into coordinates [:extension "pom"])]
+ [coordinates])
+ :files (merge {coordinates jar-file}
+ (when pom-file
+ {(into coordinates [:extension "pom"]) pom-file}))))))
(defn install
"Install the jar-file kwarg using the pom-file kwarg and coordinates kwarg.
@@ -395,17 +390,14 @@ kwarg to the repository kwarg.
:local-repo - path to the local repository (defaults to ~/.m2/repository)
:transfer-listener - same as provided to resolve-dependencies"
[& {:keys [coordinates jar-file pom-file] :as opts}]
- (apply install-artifacts
- (apply concat (assoc opts :artifacts
- {(with-meta coordinates
- {:file jar-file})
- (when pom-file
- {(with-meta
- ((fn [[name version & _]]
- [name version :extension "pom"])
- coordinates)
- {:file pom-file})
- nil})}))))
+ (apply install-artifacts
+ (apply concat (assoc opts
+ :artifacts (if pom-file
+ [coordinates (into coordinates [:extension "pom"])]
+ [coordinates])
+ :files (merge {coordinates jar-file}
+ (when pom-file
+ {(into coordinates [:extension "pom"]) pom-file}))))))
(defn- dependency-graph
([node]
87 src/test/clojure/cemerick/pomegranate/aether_test.clj
View
@@ -139,17 +139,17 @@
(deftest deploy-jar
(aether/deploy :coordinates '[group/artifact "1.0.0"]
:jar-file (io/file "test-repo" "demo" "demo" "1.0.0" "demo-1.0.0.jar")
- :pom-file (io/file "test-repo" "demo" "demo" "1.0.0" "demo-1.0.0.pom")
:repository tmp-remote-repo
:local-repo tmp-local-repo-dir)
- (is (= 6 (count (.list (io/file tmp-remote-repo-dir "group" "artifact" "1.0.0"))))))
+ (is (= 3 (count (.list (io/file tmp-remote-repo-dir "group" "artifact" "1.0.0"))))))
(deftest deploy-jar-with-pom
(aether/deploy :coordinates '[group/artifact "1.0.0"]
:jar-file (io/file "test-repo" "demo" "demo" "1.0.0" "demo-1.0.0.jar")
+ :pom-file (io/file "test-repo" "demo" "demo" "1.0.0" "demo-1.0.0.pom")
:repository tmp-remote-repo
:local-repo tmp-local-repo-dir)
- (is (= 3 (count (.list (io/file tmp-remote-repo-dir "group" "artifact" "1.0.0"))))))
+ (is (= 6 (count (.list (io/file tmp-remote-repo-dir "group" "artifact" "1.0.0"))))))
(deftest install-jar
(aether/install :coordinates '[group/artifact "1.0.0"]
@@ -160,16 +160,15 @@
(deftest deploy-artifacts
(aether/deploy-artifacts
- :artifacts {(with-meta '[demo "1.0.0"]
- {:file (io/file "test-repo" "demo" "demo" "1.0.0" "demo-1.0.0.jar")})
- {(with-meta '[demo "1.0.0" :extension "*.asc"]
- {:file (io/file "test-repo" "demo" "demo" "1.0.0" "demo-1.0.0.jar")})
- nil
- (with-meta '[demo "1.0.0" :extension "pom"]
- {:file (io/file "test-repo" "demo" "demo" "1.0.0" "demo-1.0.0.jar")})
- {(with-meta '[demo "1.0.0" :extension "*.asc"]
- {:file (io/file "test-repo" "demo" "demo" "1.0.0" "demo-1.0.0.jar")})
- nil}}}
+ :artifacts '[[demo "1.0.0"]
+ [demo "1.0.0" :extension "jar.asc"]
+ [demo "1.0.0" :extension "pom"]
+ [demo "1.0.0" :extension "pom.asc"]]
+ ;; note: the .asc files in the test-repo are dummies, but it doesn't matter for this test
+ :files {'[demo "1.0.0"] (io/file "test-repo" "demo" "demo" "1.0.0" "demo-1.0.0.jar")
+ '[demo "1.0.0" :extension "jar.asc"] (io/file "test-repo" "demo" "demo" "1.0.0" "demo-1.0.0.jar.asc")
+ '[demo "1.0.0" :extension "pom"] (io/file "test-repo" "demo" "demo" "1.0.0" "demo-1.0.0.pom")
+ '[demo "1.0.0" :extension "pom.asc"] (io/file "test-repo" "demo" "demo" "1.0.0" "demo-1.0.0.pom.asc")}
:repository tmp-remote-repo
:local-repo tmp-local-repo-dir)
(is (= #{"demo-1.0.0.pom.md5"
@@ -208,16 +207,15 @@
(deftest install-artifacts
(aether/install-artifacts
- :artifacts {(with-meta '[demo "1.0.0"]
- {:file (io/file "test-repo" "demo" "demo" "1.0.0" "demo-1.0.0.jar")})
- {(with-meta '[demo "1.0.0" :extension "*.asc"]
- {:file (io/file "test-repo" "demo" "demo" "1.0.0" "demo-1.0.0.jar")})
- nil
- (with-meta '[demo "1.0.0" :extension "pom"]
- {:file (io/file "test-repo" "demo" "demo" "1.0.0" "demo-1.0.0.jar")})
- {(with-meta '[demo "1.0.0" :extension "*.asc"]
- {:file (io/file "test-repo" "demo" "demo" "1.0.0" "demo-1.0.0.jar")})
- nil}}}
+ :artifacts '[[demo "1.0.0"]
+ [demo "1.0.0" :extension "jar.asc"]
+ [demo "1.0.0" :extension "pom"]
+ [demo "1.0.0" :extension "pom.asc"]]
+ ;; note: the .asc files in the test-repo are dummies, but it doesn't matter for this test
+ :files {'[demo "1.0.0"] (io/file "test-repo" "demo" "demo" "1.0.0" "demo-1.0.0.jar")
+ '[demo "1.0.0" :extension "jar.asc"] (io/file "test-repo" "demo" "demo" "1.0.0" "demo-1.0.0.jar.asc")
+ '[demo "1.0.0" :extension "pom"] (io/file "test-repo" "demo" "demo" "1.0.0" "demo-1.0.0.pom")
+ '[demo "1.0.0" :extension "pom.asc"] (io/file "test-repo" "demo" "demo" "1.0.0" "demo-1.0.0.pom.asc")}
:local-repo tmp-local-repo-dir)
(is (= #{"demo-1.0.0.jar"
"demo-1.0.0.pom"
@@ -227,31 +225,38 @@
(set (.list (io/file tmp-local-repo-dir "demo" "demo" "1.0.0"))))))
(deftest deploy-exceptions
- (is (thrown-with-msg? IllegalArgumentException #"not have group \"demo\""
+ (is (thrown-with-msg? IllegalArgumentException #"Provided artifacts have varying"
+ (aether/deploy-artifacts
+ :artifacts '[[demo "1.0.0"]
+ [group/demo "1.0.0" :extension "jar.asc"]]
+ :files {'[demo "1.0.0"] (io/file "test-repo" "demo" "demo" "1.0.0" "demo-1.0.0.jar")
+ '[group/demo "1.0.0" :extension "jar.asc"]
+ (io/file "test-repo" "demo" "demo" "1.0.0" "demo-1.0.0.jar.asc")}
+ :repository tmp-remote-repo
+ :local-repo tmp-local-repo-dir)))
+ (is (thrown-with-msg? IllegalArgumentException #"Provided artifacts have varying version, group, or artifact IDs"
(aether/deploy-artifacts
- :artifacts {(with-meta '[demo "1.0.0"]
- {:file nil})
- {(with-meta '[group/demo "1.0.0" :extension "*.asc"]
- {:file nil})
- nil}}
+ :artifacts '[[demo "1.0.0"]
+ [demo/artifact "1.0.0" :extension "jar.asc"]]
+ :files {'[demo "1.0.0"] (io/file "test-repo" "demo" "demo" "1.0.0" "demo-1.0.0.jar")
+ '[demo/artifact "1.0.0" :extension "jar.asc"]
+ (io/file "test-repo" "demo" "demo" "1.0.0" "demo-1.0.0.jar.asc")}
:repository tmp-remote-repo
:local-repo tmp-local-repo-dir)))
- (is (thrown-with-msg? IllegalArgumentException #"not have artifact id \"demo\""
+ (is (thrown-with-msg? IllegalArgumentException #"Provided artifacts have varying version, group, or artifact IDs"
(aether/deploy-artifacts
- :artifacts {(with-meta '[demo "1.0.0"]
- {:file nil})
- {(with-meta '[demo/artifact "1.0.0" :extension "*.asc"]
- {:file nil})
- nil}}
+ :artifacts '[[demo "1.0.0"]
+ [demo "1.1.0" :extension "jar.asc"]]
+ :files {'[demo "1.0.0"] (io/file "test-repo" "demo" "demo" "1.0.0" "demo-1.0.0.jar")
+ '[demo "1.1.0" :extension "jar.asc"]
+ (io/file "test-repo" "demo" "demo" "1.0.0" "demo-1.0.0.jar.asc")}
:repository tmp-remote-repo
:local-repo tmp-local-repo-dir)))
- (is (thrown-with-msg? IllegalArgumentException #"not have version \"1.0.0\""
+ (is (thrown-with-msg? IllegalArgumentException #"Provided artifacts have varying version, group, or artifact IDs"
(aether/deploy-artifacts
- :artifacts {(with-meta '[demo "1.0.0"]
- {:file nil})
- {(with-meta '[demo "1.0.1" :extension "*.asc"]
- {:file nil})
- nil}}
+ :artifacts '[[demo "1.0.0"]
+ [demo "1.1.0" :extension "jar.asc"]]
+ :files {'[demo "1.0.0"] (io/file "test-repo" "demo" "demo" "1.0.0" "demo-1.0.0.jar")}
:repository tmp-remote-repo
:local-repo tmp-local-repo-dir))))
1  test-repo/demo/demo/1.0.0/demo-1.0.0.jar.asc
View
@@ -0,0 +1 @@
+This file here only to test deployment operations; the fact that this isn't a signature file shouldn't cause any issues.
1  test-repo/demo/demo/1.0.0/demo-1.0.0.pom.asc
View
@@ -0,0 +1 @@
+This file here only to test deployment operations; the fact that this isn't a signature file shouldn't cause any issues.
Please sign in to comment.
Something went wrong with that request. Please try again.