Skip to content

Commit

Permalink
Merge branch 'release/0.8.0-beta.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
hugoduncan committed Mar 16, 2013
2 parents 8f7b11e + 0cee233 commit de238b6
Show file tree
Hide file tree
Showing 11 changed files with 171 additions and 150 deletions.
19 changes: 16 additions & 3 deletions .gitignore
Original file line number Original file line Diff line number Diff line change
@@ -1,3 +1,16 @@
doc /target
target /lib
logs /classes
/checkouts
/logs
/doc
doc-src/VERSIONS.md
doc-src/INTRO.md
pom.xml
pom.xml.asc
*.jar
*.class
.lein-deps-sum
.lein-failures
.lein-plugins
.lein-repl-history
18 changes: 8 additions & 10 deletions README.md
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -10,33 +10,31 @@ See [tests](https://github.com/pallet/stevedore/tree/develop/test/pallet/stevedo
## Installation ## Installation


stevedore is distributed as a jar, and is available in the stevedore is distributed as a jar, and is available in the
[sonatype repository](http://oss.sonatype.org/content/repositories/releases/org/cloudhoist). [clojars repository](http://clojars.org/com.palletops/stevedore).


Installation is with maven or your favourite maven repository aware build tool. Installation is with lein or your favourite maven repository aware build tool.


### lein/cake project.clj ### lein project.clj


```clj ```clj
:dependencies [[org.cloudhoist/stevedore "0.8.0-beta.1"]] :dependencies [[com.palletops/stevedore "0.8.0-beta.2"]]
:repositories {"sonatype"
"http://oss.sonatype.org/content/repositories/releases"}
``` ```


### maven pom.xml ### maven pom.xml


```xml ```xml
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>org.cloudhoist</groupId> <groupId>com.palletops</groupId>
<artifactId>stevedore</artifactId> <artifactId>stevedore</artifactId>
<version>0.8.0-beta.1</version> <version>0.8.0-beta.2</version>
</dependency> </dependency>
<dependencies> <dependencies>


<repositories> <repositories>
<repository> <repository>
<id>sonatype</id> <id>clojars</id>
<url>http://oss.sonatype.org/content/repositories/releases</url> <url>http://clojars.org/repo</url>
</repository> </repository>
</repositories> </repositories>
``` ```
Expand Down
8 changes: 8 additions & 0 deletions ReleaseNotes.md
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@


The latest stable release is 0.7.3. The latest stable release is 0.7.3.


## 0.8.0-beta.2

- Allow mulitple arguments to quote

- Remove reflection warnings

- Fix unquote splicing

## 0.8.0-beta.1 ## 0.8.0-beta.1


- Change groupID to com.palletops - Change groupID to com.palletops
Expand Down
2 changes: 1 addition & 1 deletion profiles.clj
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
{:plugins [[lein-set-version "0.2.1"]] {:plugins [[lein-set-version "0.2.1"]]
:set-version :set-version
{:updates [{:path "README.md" :no-snapshot true}]}} {:updates [{:path "README.md" :no-snapshot true}]}}
:clojure-1.5.0 {:dependencies [[org.clojure/clojure "1.5.0-RC15"]]}} :clojure-1.5.0 {:dependencies [[org.clojure/clojure "1.5.1"]]}}
4 changes: 2 additions & 2 deletions project.clj
Original file line number Original file line Diff line number Diff line change
@@ -1,4 +1,4 @@
(defproject com.palletops/stevedore "0.8.0-beta.1" (defproject com.palletops/stevedore "0.8.0-beta.2"
:description "Embeds shell script in clojure" :description "Embeds shell script in clojure"
:url "http://palletops.com" :url "http://palletops.com"
:license {:name "Eclipse Public License" :license {:name "Eclipse Public License"
Expand All @@ -7,6 +7,6 @@


:dependencies [[org.clojure/clojure "1.4.0"] :dependencies [[org.clojure/clojure "1.4.0"]
[org.clojure/tools.logging "0.2.0"] [org.clojure/tools.logging "0.2.0"]
[org.cloudhoist/pallet-common "0.3.1"]] [com.palletops/pallet-common "0.4.0"]]
:profiles :profiles
{:dev {:dependencies [[ch.qos.logback/logback-classic "1.0.9"]]}}) {:dev {:dependencies [[ch.qos.logback/logback-classic "1.0.9"]]}})
2 changes: 1 addition & 1 deletion src/pallet/script.clj
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
- A function specialiser matches if it returns true when passed - A function specialiser matches if it returns true when passed
`*script-context*`" `*script-context*`"
[specialiser] [specialiser]
{:pre [*script-context* (seq *script-context*)]} {:pre [(bound? #'*script-context*) *script-context* (seq *script-context*)]}
(cond (cond
(keyword? specialiser) (some #(= specialiser %) *script-context*) (keyword? specialiser) (some #(= specialiser %) *script-context*)
(set? specialiser) (some #(specialiser %) *script-context*) (set? specialiser) (some #(specialiser %) *script-context*)
Expand Down
90 changes: 40 additions & 50 deletions src/pallet/stevedore.clj
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@
;; ;;
;; 4. A string results from the form. ;; 4. A string results from the form.


(defmulti emit (defmulti ^String emit
"Emit a shell expression as a string. Dispatched on the :type of the "Emit a shell expression as a string. Dispatched on the :type of the
expression." expression."
(fn [ expr ] [*script-language* (type expr)])) (fn [ expr ] [*script-language* (type expr)]))
Expand Down Expand Up @@ -255,27 +255,24 @@
;; These are a set of splicing utility functions. ;; These are a set of splicing utility functions.


(def (def
^{:doc "The empty splice"} ^{:doc "A sequence to splice"}
empty-splice splice-seq
::empty-splice) ::splice)


(defn- splice-list (defn splice-list
"Emit a collection as a space separated list. "Mark a collection for splicing"
(splice-list [a b c]) => \"a b c\""
[coll] [coll]
(if (seq coll) (list ::splice coll))
(string/join " " coll)
;; to maintain unquote splicing semantics, this term has to disappear
;; from the result
empty-splice))


(defn filter-empty-splice (defn splice-args
[args] [args]
(filter #(not= empty-splice %) args)) (mapcat

#(if (and (coll? %) (= ::splice (first %)))
(second %)
[%])
args))


;; Unquote/splicing handling utility functions. ;; Unquote/splicing handling utility functions.

(defn- unquote? (defn- unquote?
"Tests whether the form is (clj ...) or (unquote ...) or ~expr." "Tests whether the form is (clj ...) or (unquote ...) or ~expr."
[form] [form]
Expand All @@ -292,14 +289,8 @@
(defn- handle-unquote [form] (defn- handle-unquote [form]
(second form)) (second form))


(declare emit)
(defn splice [form]
(if (seq form)
(string/join " " (map emit form))
empty-splice))

(defn- handle-unquote-splicing [form] (defn- handle-unquote-splicing [form]
(form-meta (list `splice (second form)) form)) (list `splice-list (second form)))


(def resolve-script-fns true) (def resolve-script-fns true)


Expand All @@ -311,18 +302,18 @@
functions. Applies inner to each element of form, building up a functions. Applies inner to each element of form, building up a
data structure of the same type, then applies outer to the result. data structure of the same type, then applies outer to the result.
Recognizes all Clojure data structures. Consumes seqs as with doall." Recognizes all Clojure data structures. Consumes seqs as with doall."

{:added "1.1"}
[inner outer form] [inner outer form]
(tracef "walk %s %s" form (meta form)) (tracef "walk %s %s %s" form (meta form) (class form))
(cond (cond
(list? form) (outer (with-meta (or (list? form) (instance? clojure.lang.Cons form))
(if (and resolve-script-fns (outer (with-meta
(symbol? (first form)) (if (and resolve-script-fns
(not (unresolved (first form)))) (symbol? (first form))
(list* (first form) (map inner (rest form))) (not (unresolved (symbol (name (first form))))))
(list* (map inner form))) (list* (first form) (map inner (rest form)))
(meta form))) (list* (map inner form)))
(meta form)))

(instance? clojure.lang.IMapEntry form) (outer (vec (map inner form))) (instance? clojure.lang.IMapEntry form) (outer (vec (map inner form)))
(seq? form) (outer (with-meta (doall (map inner form)) (meta form))) (seq? form) (outer (with-meta (doall (map inner form)) (meta form)))
(coll? form) (outer (with-meta (coll? form) (outer (with-meta
Expand All @@ -333,7 +324,7 @@
(declare inner-walk outer-walk) (declare inner-walk outer-walk)


(defn- inner-walk [form] (defn- inner-walk [form]
(tracef "inner-walk %s %s" form (meta form)) (tracef "inner-walk %s %s" form (meta form) (class form))
(cond (cond
(unquote? form) (handle-unquote form) (unquote? form) (handle-unquote form)
(unquote-splicing? form) (handle-unquote-splicing form) (unquote-splicing? form) (handle-unquote-splicing form)
Expand All @@ -343,12 +334,12 @@
:else (walk inner-walk outer-walk form))) :else (walk inner-walk outer-walk form)))


(defn- outer-walk [form] (defn- outer-walk [form]
(tracef "outer-walk %s %s" form (meta form)) (tracef "outer-walk %s %s %s" form (meta form) (class form))
(cond (cond
(symbol? form) (form-meta (list 'quote form) form) (symbol? form) (form-meta (list 'quote form) form)
(seq? form) (seq? form)
(do (do
(tracef "outer-walk %s %s" form (meta form)) (tracef "outer-walk 2 %s %s %s" form (meta form) (class form))
(form-meta (list* `list form) form)) (form-meta (list* `list form) form))
:else form)) :else form))


Expand Down Expand Up @@ -378,7 +369,7 @@


(defn statement (defn statement
"Emit an expression as a valid shell statement, with separator." "Emit an expression as a valid shell statement, with separator."
[form script] [form ^String script]
;; check the substring count, as it can be negative if there is a syntax issue ;; check the substring count, as it can be negative if there is a syntax issue
;; in a stevedore expression, and generates a cryptic error message otherwise ;; in a stevedore expression, and generates a cryptic error message otherwise
(let [n (- (count script) (count statement-separator)) (let [n (- (count script) (count statement-separator))
Expand All @@ -390,28 +381,27 @@
statement-separator) statement-separator)
script))) script)))


(declare ^String emit)

(defn emit-do [exprs] (defn emit-do [exprs]
(let [exprs (filter-empty-splice exprs)] (->> exprs
(->> exprs (map emit)
(map emit) (map statement exprs)
(map statement exprs) string/join))
string/join)))


(defn emit-script (defn emit-script
[forms] [forms]
(tracef "emit-script %s" forms) (tracef "emit-script %s" forms)
(tracef "emit-script metas %s" (vec (map meta forms))) (tracef "emit-script metas %s" (vec (map meta forms)))
(let [code (if (> (count forms) 1) (let [code (if (> (count forms) 1)
(emit-do (filter-empty-splice forms)) (emit-do forms)
(let [form (first forms) (let [form (first forms)
m (meta form)] m (meta form)]
(if (= form empty-splice) (let [s (emit form)]
"" (str
(let [s (emit form)] (when (and m *src-line-comments* (not (string/blank? s)))
(str (script-location-comment m))
(when (and m *src-line-comments* (not (string/blank? s))) s))))]
(script-location-comment m))
s)))))]
code)) code))


;;; Script argument helpers ;;; Script argument helpers
Expand Down
9 changes: 3 additions & 6 deletions src/pallet/stevedore/bash.clj
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
(:use (:use
[pallet.stevedore.common] [pallet.stevedore.common]
[pallet.stevedore [pallet.stevedore
:only [emit emit-do empty-splice special-forms with-source-line-comments]] :only [emit emit-do special-forms splice-seq with-source-line-comments]]
[pallet.common.string :only [quoted substring underscore]])) [pallet.common.string :only [quoted substring underscore]]))


(derive ::bash :pallet.stevedore.common/common-impl) (derive ::bash :pallet.stevedore.common/common-impl)
Expand Down Expand Up @@ -214,8 +214,8 @@
(defmethod emit-special [::bash 'str] [type [str & args]] (defmethod emit-special [::bash 'str] [type [str & args]]
(apply clojure.core/str (map emit args))) (apply clojure.core/str (map emit args)))


(defmethod emit-special [::bash 'quoted] [type [quoted arg]] (defmethod emit-special [::bash 'quoted] [type [quoted & args]]
(common-string/quoted (emit arg))) (common-string/quoted (string/join " " (map emit args))))


(defmethod emit-special [::bash 'println] [type [println & args]] (defmethod emit-special [::bash 'println] [type [println & args]]
(str "echo " (string/join " " (map emit args)))) (str "echo " (string/join " " (map emit args))))
Expand Down Expand Up @@ -262,9 +262,6 @@
;;(defmethod emit [::bash java.lang.Object] [expr] ;;(defmethod emit [::bash java.lang.Object] [expr]
;; (str expr)) ;; (str expr))


(defmethod emit [::bash empty-splice] [expr]
"")

(defmethod emit [::bash clojure.lang.IPersistentVector] [expr] (defmethod emit [::bash clojure.lang.IPersistentVector] [expr]
(str (if *delimited-sequence* "(" "") (str (if *delimited-sequence* "(" "")
(string/join " " (map emit expr)) (string/join " " (map emit expr))
Expand Down
Loading

0 comments on commit de238b6

Please sign in to comment.