Skip to content

Commit

Permalink
Fix uploading of snapshots with classifiers [#511]
Browse files Browse the repository at this point in the history
The previous fix wasn't enough, since it used the version from the pom
to split filenames when determining the classifier, and the version in
the filename doesn't match the version from the pom for snapshots, since
the former will be a timestamp-based version.
  • Loading branch information
tobias committed Mar 9, 2016
1 parent 8a57869 commit d410689
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 16 deletions.
17 changes: 11 additions & 6 deletions src/clojars/routes/repo.clj
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@
(filter pom?)
first))

(defn re-find-after [re after v]
(re-find re (subs v (+ (.indexOf v after) (count after)))))

;; borrowed from
;; https://github.com/technomancy/leiningen/tree/2.5.3/src/leiningen/deploy.clj#L137
;; and modified
Expand All @@ -89,10 +92,8 @@
(last (.split name "\\.")))))

(defn- classifier [version f]
(let [name (.getName f)]
(when-let [[_ classifier] (re-find #"^-(.*?).jar"
(subs name (+ (.indexOf name version) (count version))))]
classifier)))
(when-let [[_ classifier] (re-find-after #"^-(.*?)\.jar" version (.getName f))]
classifier))

(defn- match-file-name [re f]
(re-find re (.getName f)))
Expand Down Expand Up @@ -220,13 +221,17 @@
(throw-invalid (str "invalid pom file: " (.getMessage e))
{:file pom-file}
e)))
{:keys [group name version] :as posted-metadata} (read-string (slurp (io/file dir "metadata.edn")))]
{:keys [group name version] :as posted-metadata} (read-string (slurp (io/file dir "metadata.edn")))
[_ version-from-pom-name] (re-find-after #"^-(.*)\.pom$" name (.getName pom-file))]
(validate-deploy dir pom posted-metadata)
(db/check-and-add-group db account group)
(aether/deploy
:coordinates [(symbol group name) version]
:artifact-map (reduce #(assoc %1
[:classifier (classifier version %2)
;; use the version from the pom
;; name so we have the timestamped
;; snapshot version
[:classifier (classifier version-from-pom-name %2)
:extension (extension %2)]
%2)
{} (find-artifacts dir))
Expand Down
37 changes: 27 additions & 10 deletions test/clojars/test/integration/uploads.clj
Original file line number Diff line number Diff line change
Expand Up @@ -171,20 +171,37 @@
(deftest user-can-deploy-with-classifiers
(-> (session (help/app-from-system))
(register-as "dantheman" "[email protected]" "password"))
(let [pom (io/file (io/resource "test-0.0.1/test.pom"))]
(aether/deploy
:coordinates '[fake/test "0.0.1"]
:artifact-map {[:extension "jar"] (io/file (io/resource "test.jar"))
[:classifier "test" :extension "jar"] (io/file (io/resource "test.jar"))
[:extension "pom"] pom}
:repository {"test" {:url (str "http://localhost:" help/test-port "/repo")
:username "dantheman"
:password "password"}}
:local-repo help/local-repo))
(aether/deploy
:coordinates '[fake/test "0.0.1"]
:artifact-map {[:extension "jar"] (io/file (io/resource "test.jar"))
[:classifier "test" :extension "jar"] (io/file (io/resource "test.jar"))
[:extension "pom"] (io/file (io/resource "test-0.0.1/test.pom"))}
:repository {"test" {:url (str "http://localhost:" help/test-port "/repo")
:username "dantheman"
:password "password"}}
:local-repo help/local-repo)
(are [ext] (.exists (io/file (:repo help/test-config) "fake" "test" "0.0.1"
(format "test-0.0.1%s" ext)))
".pom" ".jar" "-test.jar"))

(deftest user-can-deploy-snapshot-with-classifiers
(-> (session (help/app-from-system))
(register-as "dantheman" "[email protected]" "password"))
(aether/deploy
:coordinates '[fake/test "0.0.3-SNAPSHOT"]
:artifact-map {[:extension "jar"] (io/file (io/resource "test.jar"))
[:classifier "test" :extension "jar"] (io/file (io/resource "test.jar"))
[:extension "pom"] (io/file (io/resource "test-0.0.3-SNAPSHOT/test.pom"))}
:repository {"test" {:url (str "http://localhost:" help/test-port "/repo")
:username "dantheman"
:password "password"}}
:local-repo help/local-repo)
;; we can't look for files directly since the version will be timestamped
(is (= 3 (->> (file-seq (io/file (:repo help/test-config) "fake" "test" "0.0.3-SNAPSHOT"))
(filter (memfn isFile))
(filter #(re-find #"(pom|jar|-test\.jar)$" (.getName %)))
count))))

(deftest user-can-deploy-with-signatures
(-> (session (help/app-from-system))
(register-as "dantheman" "[email protected]" "password"))
Expand Down

0 comments on commit d410689

Please sign in to comment.