Skip to content

Commit

Permalink
Merge branch 'single-file-install-deploy' of https://github.com/xeqi/…
Browse files Browse the repository at this point in the history
…pomegranate

Conflicts:
	src/main/clojure/cemerick/pomegranate/aether.clj
  • Loading branch information
cemerick committed Jun 19, 2012
2 parents a462e6f + b9fa96a commit f41578a
Show file tree
Hide file tree
Showing 2 changed files with 205 additions and 26 deletions.
126 changes: 100 additions & 26 deletions src/main/clojure/cemerick/pomegranate/aether.clj
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,82 @@
[:scope scope])
(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 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.
:repository - {name url} | {name settings}
settings:
:url - URL of the repository
:snapshots - use snapshots versions? (default true)
:releases - use release versions? (default true)
:username - username to log in with
:password - password to log in with
:passphrase - passphrase to log in wth
:private-key-file - private key file to log in with
:update - :daily (default) | :always | :never
:checksum - :fail | :ignore | :warn (default)
:local-repo - path to the local repository (defaults to ~/.m2/repository)
:transfer-listener - same as provided to resolve-dependencies
:proxy - proxy configuration, can be nil, the host scheme and type must match
:host - proxy hostname
:type - http (default) | http | https
:port - proxy port
:non-proxy-hosts - The list of hosts to exclude from proxying, may be null
:username - username to log in with, may be null
:password - password to log in with, may be null
: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]}]
(let [system (repository-system)
session (repository-session system local-repo false transfer-listener nil)]
(.deploy system session
(doto (DeployRequest.)
(.setArtifacts (mapcat create-artifacts 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 ..)?]
: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]}]
(let [system (repository-system)
session (repository-session system local-repo false transfer-listener nil)]
(.install system session
(doto (InstallRequest.)
(.setArtifacts (mapcat create-artifacts artifacts))))))

(defn deploy
"Deploy the jar-file kwarg using the pom-file kwarg and coordinates
"Deploy the jar-file kwarg using the pom-file kwarg and coordinates
kwarg to the repository kwarg.
:coordinates - [group/name \"version\"]
Expand All @@ -291,26 +365,25 @@ kwarg to the repository kwarg.
:proxy - proxy configuration, can be nil, the host scheme and type must match
:host - proxy hostname
:type - http (default) | http | https
:type - http (default) | http | https
:port - proxy port
:non-proxy-hosts - The list of hosts to exclude from proxying, may be null
:username - username to log in with, may be null
:password - password to log in with, may be null
:passphrase - passphrase to log in wth, may be null
:private-key-file - private key file to log in with, may be null"

[& {:keys [coordinates jar-file pom-file repository local-repo
transfer-listener proxy mirrors]}]
(let [system (repository-system)
session (repository-session system local-repo false transfer-listener nil)
jar-artifact (-> (DefaultArtifact. (coordinate-string coordinates))
(.setFile jar-file))
pom-artifact (-> (SubArtifact. jar-artifact "" "pom")
(.setFile pom-file))]
(.deploy system session (doto (DeployRequest.)
(.addArtifact jar-artifact)
(.addArtifact pom-artifact)
(.setRepository (first (map #(make-repository % proxy) repository)))))))
[& {: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})}))))

(defn install
"Install the jar-file kwarg using the pom-file kwarg and coordinates kwarg.
Expand All @@ -321,17 +394,18 @@ kwarg to the repository kwarg.
:local-repo - path to the local repository (defaults to ~/.m2/repository)
:transfer-listener - same as provided to resolve-dependencies
:mirrors - same as provided to resolve-dependencies"
[& {:keys [coordinates jar-file pom-file local-repo transfer-listener mirrors]}]
(let [system (repository-system)
session (repository-session system local-repo false transfer-listener mirrors)
jar-artifact (-> (DefaultArtifact. (coordinate-string coordinates))
(.setFile jar-file))
inst-request (doto (InstallRequest.) (.addArtifact jar-artifact))]
(.install system session (if pom-file
(doto inst-request
(.addArtifact (-> (SubArtifact. jar-artifact "" "pom")
(.setFile pom-file))))
inst-request))))
[& {: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})}))))

(defn- dependency-graph
([node]
Expand Down
105 changes: 105 additions & 0 deletions src/test/clojure/cemerick/pomegranate/aether_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
(def tmp-dir (io/file (System/getProperty "java.io.tmpdir") "pomegranate-test-tmp"))
(def tmp-remote-repo-dir (.getAbsolutePath (io/file tmp-dir "remote-repo")))
(def tmp-local-repo-dir (io/file tmp-dir "local-repo"))
(def tmp-local-repo2-dir (io/file tmp-dir "local-repo2"))

(def test-remote-repo {"central" "http://repo1.maven.org/maven2/"})

Expand Down Expand Up @@ -113,13 +114,117 @@
:local-repo tmp-local-repo-dir)
(is (= 6 (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")
: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"))))))

(deftest install-jar
(aether/install :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")
:local-repo tmp-local-repo-dir)
(is (= 3 (count (.list (io/file tmp-local-repo-dir "group" "artifact" "1.0.0"))))))

(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}}}
:repository tmp-remote-repo
:local-repo tmp-local-repo-dir)
(is (= #{"demo-1.0.0.pom.md5"
"demo-1.0.0.pom.sha1"
"demo-1.0.0.pom"
"demo-1.0.0.pom.asc.md5"
"demo-1.0.0.pom.asc.sha1"
"demo-1.0.0.pom.asc"
"demo-1.0.0.jar.md5"
"demo-1.0.0.jar.sha1"
"demo-1.0.0.jar"
"demo-1.0.0.jar.asc.md5"
"demo-1.0.0.jar.asc.sha1"
"demo-1.0.0.jar.asc"}
(set (.list (io/file tmp-remote-repo-dir "demo" "demo" "1.0.0")))))
(is (= '{[demo "1.0.0"] nil}
(aether/resolve-dependencies :repositories tmp-remote-repo
:coordinates
'[[demo "1.0.0"]]
:local-repo tmp-local-repo2-dir)))
(is (= '{[demo "1.0.0" :extension "pom"] nil}
(aether/resolve-dependencies :repositories tmp-remote-repo
:coordinates
'[[demo "1.0.0" :extension "pom"]]
:local-repo tmp-local-repo2-dir)))
(is (= '{[demo "1.0.0" :extension "jar.asc"] nil}
(aether/resolve-dependencies :repositories tmp-remote-repo
:coordinates
'[[demo "1.0.0" :extension "jar.asc"]]
:local-repo tmp-local-repo2-dir)))
(is (= '{[demo "1.0.0" :extension "pom.asc"] nil}
(aether/resolve-dependencies :repositories tmp-remote-repo
:coordinates
'[[demo "1.0.0" :extension "pom.asc"]]
:local-repo tmp-local-repo2-dir))))

(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}}}
:local-repo tmp-local-repo-dir)
(is (= #{"demo-1.0.0.jar"
"demo-1.0.0.pom"
"demo-1.0.0.jar.asc"
"demo-1.0.0.pom.asc"
"_maven.repositories"}
(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\""
(aether/deploy-artifacts
:artifacts {(with-meta '[demo "1.0.0"]
{:file nil})
{(with-meta '[group/demo "1.0.0" :extension "*.asc"]
{:file nil})
nil}}
:repository tmp-remote-repo
:local-repo tmp-local-repo-dir)))
(is (thrown-with-msg? IllegalArgumentException #"not have artifact id \"demo\""
(aether/deploy-artifacts
:artifacts {(with-meta '[demo "1.0.0"]
{:file nil})
{(with-meta '[demo/artifact "1.0.0" :extension "*.asc"]
{:file nil})
nil}}
:repository tmp-remote-repo
:local-repo tmp-local-repo-dir)))
(is (thrown-with-msg? IllegalArgumentException #"not have version \"1.0.0\""
(aether/deploy-artifacts
:artifacts {(with-meta '[demo "1.0.0"]
{:file nil})
{(with-meta '[demo "1.0.1" :extension "*.asc"]
{:file nil})
nil}}
:repository tmp-remote-repo
:local-repo tmp-local-repo-dir))))

(deftest within?-comparisons
(is (aether/within? '[demo "0.0.1"]
'[demo "0.0.1"]))
Expand Down

0 comments on commit f41578a

Please sign in to comment.