Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
add code
  • Loading branch information
clayton committed May 13, 2017
1 parent 3a375fd commit 4c92353
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 0 deletions.
35 changes: 35 additions & 0 deletions bin/install.sh
@@ -0,0 +1,35 @@
#!/usr/bin/env bash

numArgs=$#

set -e -o pipefail

function die() {
MESG="${1:-Died}"
echo "${MESG}" >&2
exit 1
}

if [[ !$numArgs -gt 0 ]]; then
die "Please supply a version number e.g. 0.0.1"
fi

group="de.mpg.shh"
artifact="util-properties"
version=$1
shift

lein jar
lein localrepo install target/${artifact}-${version}.jar ${group}/${artifact} ${version}

# /Users/clayton/.m2/repository/de/mpg/shh/util-properties/0.0.1/util-properties-0.0.1.jar
# create sha1sums for the jar and pom
group_path=$(echo "${group}" | tr "." "/")
jar_path="${HOME}/.m2/repository/${group_path}/${artifact}/${version}/${artifact}-${version}.jar"
jar_sum_path="${jar_path}.sha1"

pom_path="${HOME}/.m2/repository/${group_path}/${artifact}/${version}/${artifact}-${version}.pom"
pom_sum_path="${pom_path}.sha1"

shasum ${jar_path} | cut -d ' ' -f 1 > ${jar_sum_path}
shasum ${pom_path} | cut -d ' ' -f 1 > ${pom_sum_path}
11 changes: 11 additions & 0 deletions project.clj
@@ -0,0 +1,11 @@
(defproject de.mpg.shh/util-properties "0.0.1"
:description "Read properties files from the classpath"
:url "http://www.shh.mpg.de/"
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:dependencies [[org.clojure/clojure "1.8.0"]
[org.clojure/tools.logging "0.3.1"]
[org.apache.logging.log4j/log4j-api "2.5"]
[org.apache.logging.log4j/log4j-core "2.5"]
[org.apache.logging.log4j/log4j-1.2-api "2.5"]]
:source-paths ["src/main/clojure"])
27 changes: 27 additions & 0 deletions src/main/clojure/de/mpg/shh/util_properties/properties.clj
@@ -0,0 +1,27 @@
(ns de.mpg.shh.util-properties.properties
(:require [clojure.java.io :as io]
[clojure.string :as str]))

(defn properties->map
"Convert the properties list to a map, transforming the value
whenever a transformer is defined for that key."
([properties]
(properties->map properties {}))
([properties transformer-for]
(letfn [(keyfor [s] (mapv keyword (str/split (key s) #"\.")))]
(reduce (fn [accum entry]
(let [k (keyfor entry)]
(if-let [f (transformer-for k)]
(assoc-in accum k (f (val entry)))
(assoc-in accum k (val entry)))))
{} properties))))

(defn load-properties
"Load named properties file from the classpath, return a map with
values optionally transformed by `transform-map`."
([resource-name]
(load-properties resource-name {}))
([resource-name transform-map]
(when-let [resource (io/resource resource-name)]
(let [properties (doto (java.util.Properties.) (.load (io/input-stream resource)))]
(properties->map properties transform-map)))))

0 comments on commit 4c92353

Please sign in to comment.