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

Support :old-group-id #10

Merged
merged 1 commit into from
Jul 12, 2022
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
26 changes: 26 additions & 0 deletions src/lioss/pom.clj
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,29 @@
[:name "Clojars repository"]
[:url "https://clojars.org/repo"]]]]))

(defn old-group-id-pom [opts]
(let [proj-name (:name opts)
version (:version opts)
old-group-id (:old-group-id opts)
group-id (:group-id opts)]
[:project {:xmlns "http://maven.apache.org/POM/4.0.0"
:xmlns:xsi "http://www.w3.org/2001/XMLSchema-instance"
:xsi:schemalocation "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"}
[:modelVersion "4.0.0"]
[:groupId old-group-id]
[:artifactId proj-name]
[:version version]
[:dependencies
[:dependency
[:groupId group-id]
[:artifactId proj-name]
[:version version]]]
[:distributionManagement
[:repository
[:id "clojars"]
[:name "Clojars repository"]
[:url "https://clojars.org/repo"]]]]))

(defn spit-pom [h]
(util/spit-cwd "pom.xml" (hiccup->xml h)))

Expand All @@ -174,3 +197,6 @@
(defn spit-relocation-poms [opts]
(spit-pom (relocation-pom opts))
(util/do-modules opts (comp spit-pom relocation-pom)))

(defn spit-old-group-id-pom [opts]
(spit-pom (old-group-id-pom opts)))
9 changes: 9 additions & 0 deletions src/lioss/release.clj
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,15 @@
(pom/spit-poms opts)
(util/do-modules opts (fn [_] (mvn "deploy")))
(mvn "deploy")

;; if :old-group-id is defined, create a new pom (in temp dir)
;; with :old-group-id (name, version same) and points to the
;; package under actual :group-id as a single dependency
(when (:old-group-id opts)
(util/with-temp-cwd
(pom/spit-old-group-id-pom opts)
(mvn "deploy")))

(prepend-changelog-placeholders)
(git/git! "add" "pom.xml")
(util/do-modules opts (fn [_] (git/git! "add" "pom.xml")))
Expand Down
23 changes: 23 additions & 0 deletions src/lioss/util.clj
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
(ns lioss.util
(:require [clojure.java.io :as io])
(:import [java.io File]))

(defn delete-recursively
"Delete a directory recursively.

Also deletes if given just a file."
[^java.io.File file]
(when (.isDirectory file)
(run! delete-recursively (.listFiles file)))
(io/delete-file file))

(def ^:dynamic *cwd* (System/getProperty "user.dir"))

(defmacro with-cwd [cwd & body]
Expand All @@ -13,6 +23,19 @@
(finally
(System/setProperty "user.dir" prev#))))))

(defmacro with-temp-cwd
"Same as with-cwd except that it creates a temp dir
in *cwd* and evals the body inside it.

It cleans up the temp dir afterwards also removing
any temp files created within it."
[& body]
`(let [cwd# ".temp"
dir# (File. *cwd* cwd#)]
(.mkdirs dir#)
(with-cwd cwd# ~@body)
(delete-recursively dir#)))

(defn slurp-cwd [f]
(slurp (File. *cwd* f)))

Expand Down