From 3ac7034ceb6807e36a3d231b5a22277c8419ddc2 Mon Sep 17 00:00:00 2001 From: Stephen Starkey Date: Wed, 9 Dec 2015 15:32:38 -0600 Subject: [PATCH 1/4] Plugin can now optionally write the SHA to the project manifest. --- .gitignore | 3 ++- README.md | 8 ++++++++ project.clj | 2 +- src/lein_sha_version/plugin.clj | 20 +++++++++++++++----- 4 files changed, 26 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index 2c811ef..82ba019 100644 --- a/.gitignore +++ b/.gitignore @@ -7,4 +7,5 @@ pom.xml *.class .lein-deps-sum .lein-failures -.lein-plugins \ No newline at end of file +.lein-plugins +.idea \ No newline at end of file diff --git a/README.md b/README.md index 25350a5..2968555 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,14 @@ To control the length of the generated SHA, you can set the `:length` key under :sha {:length 8} ``` +To add the generated SHA to your artifacts' `MANIFEST.MF`, you can set the +`:manifest-header` to your project or profile. The SHA will be written to that +header in your jar and/or uberjar. + +```clj +:sha {:manifest-header "Implementation-Version"} +``` + ## License Copyright © 2012 Hugo Duncan diff --git a/project.clj b/project.clj index 32b5f44..d948b24 100644 --- a/project.clj +++ b/project.clj @@ -1,4 +1,4 @@ -(defproject lein-sha-version "0.1.2-SNAPSHOT" +(defproject com.centriqhome.leiningen/lein-sha-version "0.2.0-SNAPSHOT" :description "A Leiningen plugin to set the project version based on the git SHA." :url "https://github.com/pallet/lein-sha-version" :license {:name "Eclipse Public License" diff --git a/src/lein_sha_version/plugin.clj b/src/lein_sha_version/plugin.clj index 51052e4..01f27ea 100644 --- a/src/lein_sha_version/plugin.clj +++ b/src/lein_sha_version/plugin.clj @@ -1,10 +1,10 @@ (ns lein-sha-version.plugin (:use - [clojure.java.io :only [file]] - [leiningen.core.main :only [debug]]) + [clojure.java.io :only [file]] + [leiningen.core.main :only [debug]]) (:import - org.eclipse.jgit.storage.file.FileRepositoryBuilder - [org.eclipse.jgit.lib ObjectId Repository])) + org.eclipse.jgit.storage.file.FileRepositoryBuilder + [org.eclipse.jgit.lib ObjectId Repository])) (defn git-sha [{:keys [root version sha]}] (debug "Finding SHA for" root) @@ -19,6 +19,16 @@ (.name abbr)) version))) +(defn update-manifest [git-sha {manifest :manifest + {:keys [manifest-header]} :sha}] + (if manifest-header + (merge {manifest-header git-sha} manifest) + manifest)) + (defn middleware [project] - (assoc project :version (git-sha project))) + (let [sha (git-sha project) + manifest (update-manifest sha project)] + (-> project + (assoc :version sha) + (assoc :manifest manifest)))) From e16477d9662b22ec27258266b766bd565f7851b6 Mon Sep 17 00:00:00 2001 From: Stephen Starkey Date: Wed, 9 Dec 2015 15:46:45 -0600 Subject: [PATCH 2/4] Put project name back. --- project.clj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/project.clj b/project.clj index d948b24..8223ba4 100644 --- a/project.clj +++ b/project.clj @@ -1,4 +1,4 @@ -(defproject com.centriqhome.leiningen/lein-sha-version "0.2.0-SNAPSHOT" +(defproject lein-sha-version "0.2.0-SNAPSHOT" :description "A Leiningen plugin to set the project version based on the git SHA." :url "https://github.com/pallet/lein-sha-version" :license {:name "Eclipse Public License" From b116122a20ad1261709334882e3e9a96f1a64554 Mon Sep 17 00:00:00 2001 From: Stephen Starkey Date: Wed, 9 Dec 2015 16:35:36 -0600 Subject: [PATCH 3/4] Added some error handling. --- src/lein_sha_version/plugin.clj | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/src/lein_sha_version/plugin.clj b/src/lein_sha_version/plugin.clj index 01f27ea..6ce3997 100644 --- a/src/lein_sha_version/plugin.clj +++ b/src/lein_sha_version/plugin.clj @@ -1,22 +1,26 @@ (ns lein-sha-version.plugin (:use [clojure.java.io :only [file]] - [leiningen.core.main :only [debug]]) + [leiningen.core.main :only [warn debug]]) (:import org.eclipse.jgit.storage.file.FileRepositoryBuilder [org.eclipse.jgit.lib ObjectId Repository])) (defn git-sha [{:keys [root version sha]}] (debug "Finding SHA for" root) - (let [^Repository repository (.. (FileRepositoryBuilder.) - (readEnvironment) - (findGitDir (file root)) - (build)) - ^ObjectId head (.resolve repository "HEAD")] - (if head - (let [abbr (.abbreviate head (:length sha 7))] - (debug "Found SHA" (.name head) "using" (.name abbr)) - (.name abbr)) + (try + (let [^Repository repository (.. (FileRepositoryBuilder.) + (readEnvironment) + (findGitDir (file root)) + (build)) + ^ObjectId head (.resolve repository "HEAD")] + (if head + (let [abbr (.abbreviate head (:length sha 7))] + (debug "Found SHA" (.name head) "using" (.name abbr)) + (.name abbr)) + version)) + (catch Throwable e + (warn (format "Unable to get SHA: %s" (.getMessage e))) version))) (defn update-manifest [git-sha {manifest :manifest @@ -27,8 +31,8 @@ (defn middleware [project] - (let [sha (git-sha project) - manifest (update-manifest sha project)] + (let [version (git-sha project) + manifest (update-manifest version project)] (-> project - (assoc :version sha) + (assoc :version version) (assoc :manifest manifest)))) From f1ee38e9ab314917d6d8f86fff8e03dbfa5ceb17 Mon Sep 17 00:00:00 2001 From: sstarkey Date: Sun, 28 Jun 2020 13:36:06 -0500 Subject: [PATCH 4/4] Complete the fork --- README.md | 4 ++-- project.clj | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 2968555..b55ae05 100644 --- a/README.md +++ b/README.md @@ -6,12 +6,12 @@ current branch. ## Usage To be able to access the plugin from any project, put -`[lein-sha-version "0.1.1"]` into the `:plugins` vector of your `:sha`, or other +`[coreagile/lein-sha-version "0.1.2"]` into the `:plugins` vector of your `:sha`, or other non-standard, profile. Invoke `lein` with `lein with-profile sha` to use the sha version number for the project, e.g. `lein with-profile sha deploy clojars` to deploy the sha based version to clojars. -Put `[lein-sha-version "0.1.1"]` into the `:plugins` vector of your `:dev` +Put `[coreagile/lein-sha-version "0.1.2"]` into the `:plugins` vector of your `:dev` profile in `project.clj` if you always want to use a sha version with a specific project. diff --git a/project.clj b/project.clj index 8223ba4..77515be 100644 --- a/project.clj +++ b/project.clj @@ -1,4 +1,4 @@ -(defproject lein-sha-version "0.2.0-SNAPSHOT" +(defproject coreagile/lein-sha-version "0.1.2" :description "A Leiningen plugin to set the project version based on the git SHA." :url "https://github.com/pallet/lein-sha-version" :license {:name "Eclipse Public License"