Commit 8fdc7d29 authored by Amar Mehta's avatar Amar Mehta

write project pom.properties as lein does

parent de831ff9
......@@ -92,6 +92,19 @@
ByteArrayInputStream.
Manifest.))
(defn make-project-properties
[{:keys [app-group-id app-artifact-id app-version] :as task}]
(with-open [baos (java.io.ByteArrayOutputStream.)]
(let [properties (doto (java.util.Properties.)
(.setProperty "version" app-version)
(.setProperty "groupId" app-group-id)
(.setProperty "artifactId" app-artifact-id))]
(when-let [revision (utils/read-git-head)]
(.setProperty properties "revision" revision))
(.store properties baos "Cambada"))
(str baos)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Jar proper functions
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
......@@ -194,6 +207,12 @@
(first (filter #(instance? Element %) (first roots)))))
(defn- write-pom-properties [{:keys [app-group-id app-artifact-id] :as task} jar-os jar-paths]
(let [path (format "META-INF/maven/%s/%s/pom.properties" app-group-id app-artifact-id)
props (make-project-properties task)]
(copy-to-jar task jar-os jar-paths {:type :bytes :bytes props :path path})))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Main functions
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
......@@ -207,6 +226,7 @@
(let [jar-paths (reduce (partial copy-to-jar task jar-os)
#{}
filespecs)]
(write-pom-properties task jar-os jar-paths)
(if main
(let [main-path (str (-> (string/replace main "." "/")
(string/replace "-" "_"))
......
(ns cambada.utils
(:require [clojure.java.io :as io])
(:require [clojure.java.io :as io]
[clojure.java.shell :as sh])
(:import (java.io File)))
;; # OS detection
......@@ -121,3 +122,14 @@
(assoc m k (val-agg-fn (map val-fn v))))
{}
(group-by key-fn xs))))
(defn read-git-head
"Reads the value of HEAD and returns a commit SHA1, or nil if no commit
exist."
[]
(try
(let [git-ref (sh/sh "git" "rev-parse" "HEAD")]
(when (= (:exit git-ref) 0)
(.trim (:out git-ref))))
(catch java.io.IOException e)))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment