Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Switched to the lancet build tool.

  • Loading branch information...
commit 374af6297907c43351b2a00fbb4d23d5e3bb20cc 1 parent 732e09e
Matt Courtney authored
View
1  MANIFEST.MF
@@ -0,0 +1 @@
+Main-Class: conjure.Main
View
68 build.clj
@@ -0,0 +1,68 @@
+(ns build
+ (:use lancet))
+
+(def src "src")
+(def vendor "vendor")
+(def test-dir "test")
+(def conjure-src (str vendor "/conjure"))
+(def target "target")
+(def classes (str target "/classes"))
+(def test-app (str target "/test_app"))
+(def file-structure "file_structure")
+(def default (str file-structure "/default"))
+
+(define-ant-type ant-classpath org.apache.tools.ant.types.Path ant-project)
+(define-ant-type pathelement org.apache.tools.ant.types.Path ant-project)
+
+(deftarget compile-conjure "Compile Conjure sources."
+ (mkdir { :dir classes })
+ (javac { :srcdir src
+ :destdir classes
+ :debug "on" }))
+
+(deftarget jar-conjure "Creates the conjure.jar file."
+ (compile-conjure)
+ (jar { :jarfile (str target "/conjure.jar")
+ :manifest "MANIFEST.MF" }
+ (fileset { :dir classes })
+ (fileset { :dir file-structure })))
+
+(deftarget clean "Remove autogenerated files and directories."
+ (delete { :dir target }))
+
+(deftarget test-conjure "Run all of the tests for Conjure."
+ (jar-conjure)
+ (java { :jar (str target "/conjure.jar")
+ :fork "true"
+ :dir target
+ :args "test_app" })
+ (copy { :todir (str test-app "/test") }
+ (fileset { :dir test-dir }))
+ (echo { :message "\nRunning Tests...\n\n"})
+ (java { :classname "clojure.lang.Script"
+ :dir test-app
+ :fork "true"
+ :args "test/run_tests.clj"
+ :classpath
+ (ant-classpath {}
+ (pathelement { :path (str test-app "/vendor") })
+ (pathelement { :path (str test-app "/app") })
+ (pathelement { :path (str test-app "/config") })
+ (pathelement { :path (str test-app "/script") })
+ (pathelement { :path (str test-app "/db") })
+ (pathelement { :path (str test-app "/test") })
+ (fileset { :dir (str test-app "/lib")
+ :includes "**/*.jar" })) }))
+
+(deftarget all "Builds all of conjure."
+ (jar-conjure)
+ (test-conjure))
+
+(deftarget default "Executing default target."
+ (all))
+
+;(doall (map println (sort (seq (.. ant-project getTaskDefinitions keySet)))))
+
+(if (not-empty *command-line-args*)
+ (apply -main *command-line-args*)
+ (default))
View
68 build.xml
@@ -1,68 +0,0 @@
-<project name="conjure" default="all">
-
- <description>
- Build with "ant" and then generate a conjure
- project with java -jar conjure.jar *project name*
- </description>
-
- <property name="src" location="src"/>
- <property name="vendor" location="vendor"/>
- <property name="test" location="test"/>
- <property name="conjure_src" location="${vendor}/conjure"/>
- <property name="target" location="target"/>
- <property name="classes" location="${target}/classes"/>
- <property name="test_app" location="${target}/test_app"/>
-
- <property name="file_structure" location="file_structure"/>
- <property name="default" location="${filestructure}/default"/>
-
- <target name="compile-conjure"
- description="Compile Conjure sources.">
- <mkdir dir="${classes}" />
- <javac srcdir="${src}"
- destdir="${classes}"
- debug="on"
- />
- </target>
-
- <target name="jar" depends="compile-conjure">
- <jar destfile="${target}/conjure.jar">
- <fileset dir="${classes}"/>
- <fileset dir="${file_structure}"/>
- <manifest>
- <attribute name="Main-Class" value="conjure.Main"/>
- </manifest>
- </jar>
- </target>
-
- <target name="all" depends="jar, test"/>
-
- <target name="clean"
- description="Remove autogenerated files and directories.">
- <delete dir="${target}"/>
- </target>
-
- <target name="test" depends="jar" description="Run all of the tests for Conjure.">
- <java jar="${target}/conjure.jar" fork="true" dir="${target}">
- <arg value="test_app"/>
- </java>
- <copy todir="${target}/test_app/test">
- <fileset dir="${test}"/>
- </copy>
- <java classname="clojure.lang.Script" dir="${test_app}" fork="true">
- <arg value="test/run_tests.clj"/>
- <classpath>
- <pathelement path="${test_app}/vendor"/>
- <pathelement path="${test_app}/app"/>
- <pathelement path="${test_app}/config"/>
- <pathelement path="${test_app}/script"/>
- <pathelement path="${test_app}/db"/>
- <pathelement path="${test_app}/test"/>
- <fileset dir="${test_app}/lib">
- <include name="**/*.jar"/>
- </fileset>
- </classpath>
- </java>
- </target>
-
-</project>
View
BIN  file_structure/default/lib/ant-launcher.jar
Binary file not shown
View
BIN  file_structure/default/lib/ant.jar
Binary file not shown
View
14 lancet.bat
@@ -0,0 +1,14 @@
+@echo off
+
+set HOME_DIR=.
+set LIB_DIR=%HOME_DIR%/file_structure/default/lib
+
+set JARS_PATH=%LIB_DIR%/clojure-1.0.0.jar;%LIB_DIR%/clojure-contrib.jar;%LIB_DIR%/ant.jar;%LIB_DIR%/ant-launcher.jar
+
+set CLASS_PATH=.;%JARS_PATH%
+
+REM @echo on
+REM @echo %CLASS_PATH%
+REM @echo off
+
+java -cp %CLASS_PATH% clojure.lang.Script build.clj
View
156 lancet.clj
@@ -0,0 +1,156 @@
+(ns lancet
+ (:gen-class)
+ (:use [clojure.contrib.except :only (throw-if)]
+ clojure.contrib.shell-out
+ [clojure.contrib.str-utils :only (re-split)])
+ (:import (java.beans Introspector)
+ (java.util.concurrent CountDownLatch)
+ (org.apache.tools.ant.types Path)))
+
+(def
+ #^{:doc "Dummy ant project to keep Ant tasks happy"}
+ ant-project
+ (let [proj (org.apache.tools.ant.Project.)
+ logger (org.apache.tools.ant.NoBannerLogger.)]
+ (doto logger
+ (.setMessageOutputLevel org.apache.tools.ant.Project/MSG_INFO)
+ (.setOutputPrintStream System/out)
+ (.setErrorPrintStream System/err))
+ (doto proj
+ (.init)
+ (.addBuildListener logger))))
+
+(defmulti coerce (fn [dest-class src-inst] [dest-class (class src-inst)]))
+
+(defmethod coerce [java.io.File String] [_ str]
+ (java.io.File. str))
+(defmethod coerce [Boolean/TYPE String] [_ str]
+ (contains? #{"on" "yes" "true"} (.toLowerCase str)))
+(defmethod coerce [Path String] [_ str]
+ (new Path ant-project str))
+(defmethod coerce :default [dest-cls obj]
+ (cast dest-cls obj))
+
+(defn env [val]
+ (System/getenv (name val)))
+
+(defn- build-sh-args [args]
+ (concat (re-split #"\s+" (first args)) (rest args)))
+
+(defn system [& args]
+ (println (apply sh (build-sh-args args))))
+
+(defn property-descriptor [inst prop-name]
+ (first
+ (filter #(= prop-name (.getName %))
+ (.getPropertyDescriptors
+ (Introspector/getBeanInfo (class inst))))))
+
+(defn get-property-class [write-method]
+ (first (.getParameterTypes write-method)))
+
+(defn set-property! [inst prop value]
+ (let [pd (property-descriptor inst prop)]
+ (throw-if (nil? pd) (str "No such property " prop))
+ (let [write-method (.getWriteMethod pd)
+ dest-class (get-property-class write-method)]
+ (.invoke write-method inst (into-array [(coerce dest-class value)])))))
+
+(defn set-properties! [inst prop-map]
+ (doseq [[k v] prop-map] (set-property! inst (name k) v)))
+
+(defn add-subproperty [task property]
+ (try
+ (let [add-method (str "add" (.. property getClass getName))]
+ (. task (symbol add-method) property ))
+ (catch Exception ex
+ (try
+ (.add task property)
+ (catch Exception ex
+ (println "Could not find adder for" (. property getClass) "on task" (. task getClass)))))))
+
+(defn instantiate-task [project name props & filesets]
+ (let [task (.createTask project name)]
+ (throw-if (nil? task) (str "No task named " name))
+ (doto task
+ (.init)
+ (.setProject project)
+ (set-properties! props))
+ (doseq [fs filesets]
+ (add-subproperty task fs))
+ task))
+
+(defn runonce
+ "Create a function that will only run once. All other invocations
+ return the first calculated value. The function *can* have side effects,
+ and calls to runonce *can* be composed. Deadlock is possible
+ if you have circular dependencies.
+ Returns a [has-run-predicate, reset-fn, once-fn]"
+ [function]
+ (let [sentinel (Object.)
+ result (atom sentinel)
+ reset-fn (fn [] (reset! result sentinel))
+ has-run-fn (fn [] (not= @result sentinel))]
+ [has-run-fn
+ reset-fn
+ (fn [& args]
+ (locking sentinel
+ (if (= @result sentinel)
+ (reset! result (function))
+ @result)))]))
+
+(defmacro has-run? [f]
+ `((:has-run (meta (var ~f)))))
+
+(defmacro reset [f]
+ `((:reset-fn (meta (var ~f)))))
+
+(def targets (atom #{}))
+
+(defmacro deftarget [sym doc & forms]
+ (swap! targets #(conj % sym))
+ (let [has-run (gensym "hr-") reset-fn (gensym "rf-")]
+ `(let [[~has-run ~reset-fn once-fn#] (runonce (fn [] ~@forms))]
+ (def ~(with-meta sym {:doc doc :has-run has-run :reset-fn reset-fn})
+ once-fn#))))
+
+(defmacro define-ant-task [clj-name ant-name]
+ `(defn ~clj-name [& props#]
+ (let [task# (apply instantiate-task ant-project ~(name ant-name) props#)]
+ (.execute task#)
+ task#)))
+
+(defmacro define-ant-type [clj-name ant-name & constructor-args]
+ `(defn ~clj-name [props# & sub-types#]
+ (let [bean# (new ~ant-name ~@constructor-args)]
+ (set-properties! bean# props#)
+ (when (property-descriptor bean# "project")
+ (set-property! bean# "project" ant-project))
+ (doseq [sub-property# sub-types#]
+ (add-subproperty bean# sub-property#))
+ bean#)))
+
+(defn task-names [] (map symbol (seq (.. ant-project getTaskDefinitions keySet))))
+
+(defn safe-ant-name [n]
+ (if (ns-resolve 'clojure.core n) (symbol (str "ant-" n)) n))
+
+;(defmacro define-all-ant-tasks []
+; `(do ~@(map (fn [n] `(define-ant-task ~n ~n)) (task-names))))
+
+(defmacro define-all-ant-tasks []
+ `(do ~@(map (fn [n] `(define-ant-task ~(safe-ant-name n) ~n)) (task-names))))
+
+(define-all-ant-tasks)
+
+(define-ant-type files org.apache.tools.ant.types.resources.Files)
+(define-ant-type fileset org.apache.tools.ant.types.FileSet)
+
+(defn -main [& targs]
+ (load-file "build.clj")
+ (if targs
+ (doseq [targ (map symbol targs)]
+ (eval (list targ)))
+ (println "Available targets: " @targets)))
+
+
View
16 lancet.sh
@@ -0,0 +1,16 @@
+#!/bin/bash
+
+SCRIPT_DIR=`dirname $0`
+HOME_DIR=`(cd $SCRIPT_DIR; pwd)`
+
+LIB_DIR=$HOME_DIR/file_structure/default/lib
+JARS_PATH=`echo $LIB_DIR/*.jar | sed 's/ /:/g'`
+
+CLASSPATH=.:$JARS_PATH
+
+COMMAND="java -cp $CLASSPATH clojure.lang.Script build.clj
+
+echo $COMMAND
+echo
+
+$COMMAND
Please sign in to comment.
Something went wrong with that request. Please try again.