Source

Lein-LB / src / leiningen / lb.clj

Full commit
(ns leiningen.lb
  (:require [clojure.contrib.duck-streams :as ds]))

(def *version* "0.1-SNAPSHOT (uses Liquibase 2.0-RC6)")

;; DSL

(defn help
  []
  (println
    (str "
Lein-LB - Lein Liquibase plugin " *version* "

For help on Liquibase commands:

    $ lein lb help

Lein-LB commands (they all begin with a colon):
    :help               prints this help screen
    :sample-properties  prints sample properties to put in liquibase.properties
"
      )))


(defn sample-props
  []
  (let [filename "/liquibase.properties"
        istream  (.getResourceAsStream String filename)
        owriter  (java.io.StringWriter.)]
    ;; InputStream resourceAsStream = getClass().getResourceAsStream("/mypackage/mysubpackage/myfile.txt");
    (ds/copy istream owriter)
    (println (.toString owriter))))


(defn execute-liquibase-cmd
  "Execute Liquibase as if using command-line arguments (String array)"
  [argv]
  (liquibase.integration.commandline.Main/main argv))


;; ----- Leiningen plugin command -----

(defn lb
  [& args]
  (let [argc (count args)
        argv (into-array String args)
        cmd  (first args)]
    ;; check for lein-lb commands
    (cond
      (empty? args)                (help)
      (= cmd ":help")              (help)
      (= cmd ":sample-properties") (sample-props)
      :else                        (execute-liquibase-cmd argv))))