Skip to content

Commit

Permalink
Adjust compile task to make use of regex fns
Browse files Browse the repository at this point in the history
Also update documentation.
  • Loading branch information
Josh-Tilles authored and technomancy committed Mar 19, 2013
1 parent ededa95 commit 437e63d
Show file tree
Hide file tree
Showing 10 changed files with 95 additions and 6 deletions.
47 changes: 42 additions & 5 deletions src/leiningen/compile.clj
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,48 @@
(blacklisted-class? project f))]
(.delete f))))

(require 'clojure.test)
(refer 'clojure.test :only '[with-test testing is])
(with-test
(defn- probably-cli-regex? [thing]
(.startsWith thing "#\""))
(testing "that we correctly identify a string that the user intends to be a regex"
(is (probably-cli-regex? "#\"^jwz is displeased$\"")))
(testing "that we don't think _everything_ is a regex"
(is (not (probably-cli-regex? "^jwz is displeased$")))))

(with-test
(defn regex? [v]
(instance? java.util.regex.Pattern v))
(is (regex? #"blah"))
(is (not (regex? "blah")))
(is (regex? (re-pattern "blah"))))

;; @TODO are we consistent about "regex" vs "regexp"?
;; I felt compelled to include the :pre/:post-conditions as a
;; result of using `read-string`
(defn compilation-specs [cli-args]
{:pre [(every? string? cli-args)]
:post [(or (= % :all)
(every? (some-fn symbol? regex?)
%))]}
(cond (empty? cli-args) nil

(= cli-args [":all"]) :all

:else
(let [{namespaces false
regexps true} (group-by probably-cli-regex? cli-args)]
(concat
(map symbol namespaces)
(map read-string regexps)))))

(defn compile
"Compile Clojure source into .class files.
Uses the namespaces specified under :aot in project.clj or those given
as command-line arguments. Use :all argument to compile everything.
as command-line arguments. Use :all argument to compile everything. Pass
#\"regular expressions\" to compile any matching namespaces.
This should automatically happen when required if it's configured correctly; it
shouldn't need to be manually invoked. See the javac task as well.
Expand All @@ -125,7 +162,7 @@ Code that should run on startup belongs in a -main defn."
(main/abort "Compilation failed:" (.getMessage e)))
(finally (clean-non-project-classes project))))
(main/debug "All namespaces already AOT compiled.")))
([project & namespaces]
(compile (assoc project :aot (if (= namespaces [":all"])
:all
(map symbol namespaces))))))
([project & args]
(compile
(assoc-in project [:aot]
(compilation-specs args)))))
12 changes: 11 additions & 1 deletion test/leiningen/test/compile.clj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
[leiningen.compile]
[leiningen.test.helper :only [sample-project delete-file-recursively
sample-failing-project
tricky-name-project]])
tricky-name-project
more-gen-classes-project]])
(:require [leiningen.core.eval :as eval]
[leiningen.core.main :as main]))

Expand All @@ -28,6 +29,15 @@
(is (.exists (file "test_projects" "sample" "target"
"classes" "nom" "nom" "nom.class"))))

(deftest test-compile-regex
(compile more-gen-classes-project "#\"\\.ba.$\"")
(is (.exists (file "test_projects" "more-gen-classes" "target"
"classes" "more_gen_classes" "bar.class")))
(is (.exists (file "test_projects" "more-gen-classes" "target"
"classes" "more_gen_classes" "baz.class")))
(is (not (.exists (file "test_projects" "more-gen-classes" "target"
"classes" "more_gen_classes" "foo.class")))))

(def eip-check (atom false))

(deftest test-plugin
Expand Down
2 changes: 2 additions & 0 deletions test/leiningen/test/helper.clj
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@

(def overlapped-sourcepaths-project (read-test-project "overlapped-sourcepaths"))

(def more-gen-classes-project (read-test-project "more-gen-classes"))

(defn abort-msg
"Catches main/abort thrown by calling f on its args and returns its error
message."
Expand Down
12 changes: 12 additions & 0 deletions test_projects/more-gen-classes/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/target
/lib
/classes
/checkouts
pom.xml
pom.xml.asc
*.jar
*.class
.lein-deps-sum
.lein-failures
.lein-plugins
.lein-repl-history
13 changes: 13 additions & 0 deletions test_projects/more-gen-classes/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# more-gen-classes

A Clojure library designed to ... well, that part is up to you.

## Usage

FIXME

## License

Copyright © 2013 FIXME

Distributed under the Eclipse Public License, the same as Clojure.
3 changes: 3 additions & 0 deletions test_projects/more-gen-classes/doc/intro.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Introduction to more-gen-classes

TODO: write [great documentation](http://jacobian.org/writing/great-documentation/what-to-write/)
6 changes: 6 additions & 0 deletions test_projects/more-gen-classes/project.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
(defproject more-gen-classes "0.1.0-SNAPSHOT"
:description "FIXME: write description"
:url "http://example.com/FIXME"
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:dependencies [[org.clojure/clojure "1.5.1"]])
2 changes: 2 additions & 0 deletions test_projects/more-gen-classes/src/more_gen_classes/bar.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
(ns more-gen-classes.bar
(:gen-class))
2 changes: 2 additions & 0 deletions test_projects/more-gen-classes/src/more_gen_classes/baz.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
(ns more-gen-classes.baz
(:gen-class))
2 changes: 2 additions & 0 deletions test_projects/more-gen-classes/src/more_gen_classes/foo.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
(ns more-gen-classes.foo
(:gen-class))

0 comments on commit 437e63d

Please sign in to comment.