Skip to content
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

Remove "exact-version" argument from mvn-repo-info #155

Merged
merged 1 commit into from
Nov 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions src/cljnix/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,17 @@
(map (fn [[lib {:keys [mvn/version paths]}]]
(when-not (= 1 (count paths))
(throw+ "Maven deps can have only 1 path" {:lib lib :paths paths}))
(let [local-path (first paths)]
(assoc (utils/mvn-repo-info local-path {:exact-version version :mvn-repos mvn-repos})
:lib lib
:version version
:local-path local-path))))
(let [local-path (-> paths first (utils/fixed-snapshot-path version))
result (assoc (utils/mvn-repo-info local-path {:mvn-repos mvn-repos})
:lib lib
:version version
:local-path local-path)]
result)))
; Add POM
(mapcat (juxt identity
(fn [{:keys [local-path version]}]
(let [pom-path (utils/artifact->pom local-path)]
(assoc (utils/mvn-repo-info pom-path {:exact-version version :mvn-repos mvn-repos})
(let [pom-path (-> local-path utils/artifact->pom (utils/fixed-snapshot-path version))]
(assoc (utils/mvn-repo-info pom-path {:mvn-repos mvn-repos})
:version version
:local-path pom-path)))))

Expand Down
49 changes: 36 additions & 13 deletions src/cljnix/utils.clj
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,20 @@
;; foo-SNAPSHOT.jar
(defn- snapshot-info
[path]
(let [[artifact-id snapshot-version]
(let [[group-id artifact-id snapshot-version]
(-> (str (fs/strip-ext path) ".pom")
(pom)
((juxt
(memfn ^Model getGroupId)
(memfn ^Model getArtifactId)
(memfn ^Model getVersion))))]
{:artifact-id artifact-id
:group-id group-id
:snapshot-version snapshot-version
:version (subs
(fs/file-name (fs/strip-ext path))
(inc (count artifact-id)))}))

(defn- latest-snapshot
[path]
(->> (fs/glob (fs/parent path) "*.pom")
Expand All @@ -76,7 +79,7 @@
(last)))

(defn- resolve-snapshot
[path exact-version]
[path]
(if-not (snapshot? path)
{:resolved-path (str path)}
(let [ext (fs/extension path)
Expand All @@ -86,13 +89,32 @@
path
(str (fs/path (fs/parent path) (str artifact-id
"-"
(if (version/snapshot? exact-version)
(if (version/snapshot? version)
(latest-snapshot path)
exact-version)
version)
"."
ext))))
:snapshot (str artifact-id "-" snapshot-version "." ext)})))

; deps/create-basis returns '~/.../foo-1.0-SNAPSHOT.jar' as path,
; even if the maven version is fixed: 'foo-1.0-20220502.201054-5'
(defn fixed-snapshot-path
"Helper to convert a maven artifact snapshot to the fixed version.
e.g.: ~/.../foo-1.0-SNAPSHOT.jar -> ~/.../foo-1.0-20220502.201054-5.jar
Path must be a SNAPSHOT, and version a fixed version, if not, does nothing"
[path fixed-version]
(if-not (and
(snapshot? path)
(not (string/includes? fixed-version "SNAPSHOT")))
path
;; fixed-version is 1.0-20220502.201054-5
;; path is ~/.../my-lib-1.0-SNAPSHOT.jar
(let [{:keys [version]} (snapshot-info path)]
(fs/path
(fs/parent path)
(string/replace (fs/file-name path) version fixed-version)))))


(defn- get-mvn-repo-name
[path mvn-repos]
(try
Expand Down Expand Up @@ -135,10 +157,10 @@
"Given a path for a jar in the maven local repo, e.g:
$REPO/babashka/fs/0.1.4/fs-0.1.4.jar
return the maven repository url and the dependecy url"
[path & {:keys [cache-dir exact-version mvn-repos]
[path & {:keys [cache-dir mvn-repos]
:or {cache-dir @mvn/cached-local-repo
mvn-repos mvn/standard-repos}}]
(let [{:keys [resolved-path snapshot]} (resolve-snapshot path exact-version)
(let [{:keys [resolved-path snapshot]} (resolve-snapshot path)
mvn-path (str (fs/relativize cache-dir resolved-path))
repo-name (or
(get-mvn-repo-name resolved-path mvn-repos)
Expand Down Expand Up @@ -379,6 +401,10 @@

(comment

(fixed-snapshot-path
(fs/expand-home "~/.m2/repository/clj-kondo/clj-kondo/2022.04.26-SNAPSHOT/clj-kondo-2022.04.26-SNAPSHOT.jar")
"2022.04.26-20220502.201054-5")

(get-maven-repos
(deps/create-basis {:user nil
:project (str (fs/expand-home "~/projects/clj-demo-project/deps.edn"))}))
Expand All @@ -394,14 +420,11 @@
(get-parent-poms (fs/expand-home "~/.m2/repository/io/grpc/grpc-bom/1.55.1/pom.xml"))


(=
(mvn-repo-info
(fs/expand-home "~/.m2/repository/clj-kondo/clj-kondo/2022.04.26-SNAPSHOT/clj-kondo-2022.04.26-SNAPSHOT.jar")
{:exact-version "2022.04.26-SNAPSHOT"})
(mvn-repo-info
(fs/expand-home "~/.m2/repository/clj-kondo/clj-kondo/2022.04.26-SNAPSHOT/clj-kondo-2022.04.26-SNAPSHOT.jar"))

(mvn-repo-info
(fs/expand-home "~/.m2/repository/clj-kondo/clj-kondo/2022.04.26-SNAPSHOT/clj-kondo-2022.04.26-20220502.201054-5.jar")
{:exact-version "2022.04.26-20220502.201054-5"}))
(mvn-repo-info
(fs/expand-home "~/.m2/repository/clj-kondo/clj-kondo/2022.04.26-SNAPSHOT/clj-kondo-2022.04.26-20220502.201054-5.jar"))


(get-deps-files (fs/canonicalize ".") {:bb? true :deps-exclude ["templates/default/deps.edn"]})
Expand Down
16 changes: 15 additions & 1 deletion test/cljnix/utils_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,21 @@
:mvn-repo "https://repo.clojars.org/"
:url "https://repo.clojars.org/babashka/fs/0.1.5/fs-0.1.5.jar"}
(utils/mvn-repo-info
(fs/path @mvn/cached-local-repo "babashka/fs/0.1.5/fs-0.1.5.jar")))))
(fs/path @mvn/cached-local-repo "babashka/fs/0.1.5/fs-0.1.5.jar"))))

(is (= {:mvn-path "clj-kondo/clj-kondo/2022.04.26-SNAPSHOT/clj-kondo-2022.04.26-20220502.201054-5.jar"
:mvn-repo "https://repo.clojars.org/"
:url "https://repo.clojars.org/clj-kondo/clj-kondo/2022.04.26-SNAPSHOT/clj-kondo-2022.04.26-20220502.201054-5.jar"
:snapshot "clj-kondo-2022.04.26-SNAPSHOT.jar"}
(utils/mvn-repo-info
(fs/path @mvn/cached-local-repo "clj-kondo/clj-kondo/2022.04.26-SNAPSHOT/clj-kondo-2022.04.26-20220502.201054-5.jar"))))

(is (= {:mvn-repo "https://repo.clojars.org/",
:mvn-path "clj-kondo/clj-kondo/2022.04.26-SNAPSHOT/clj-kondo-2022.04.26-20220526.212013-27.jar",
:url "https://repo.clojars.org/clj-kondo/clj-kondo/2022.04.26-SNAPSHOT/clj-kondo-2022.04.26-20220526.212013-27.jar",
:snapshot "clj-kondo-2022.04.26-SNAPSHOT.jar"}
(utils/mvn-repo-info
(fs/path @mvn/cached-local-repo "clj-kondo/clj-kondo/2022.04.26-SNAPSHOT/clj-kondo-2022.04.26-SNAPSHOT.jar")))))

(deftest get-parent-test
(is (= (str (fs/path @mvn/cached-local-repo "org/clojure/pom.contrib/1.1.0/pom.contrib-1.1.0.pom"))
Expand Down