From 93535c5a17df197ba8ee5470da49b2a22e096492 Mon Sep 17 00:00:00 2001 From: Alan Dipert Date: Mon, 23 Aug 2010 23:03:52 -0400 Subject: [PATCH] Added a build-failing project for flexing compilation-failing aware 'jar'; created test_projects and moved sample there too --- src/leiningen/compile.clj | 17 ++++++++----- src/leiningen/jar.clj | 12 ++++----- src/leiningen/uberjar.clj | 25 +++++++++++-------- test/test_deps.clj | 2 +- test/test_install.clj | 2 +- test/test_jar.clj | 13 +++++++++- test/test_pom.clj | 2 +- test_projects/README.txt | 4 +++ .../sample}/checkouts/sample2/.gitignore | 0 .../sample}/checkouts/sample2/README | 0 .../sample}/checkouts/sample2/project.clj | 0 .../checkouts/sample2/src/sample2/core.clj | 0 .../sample2/test/sample2/core_test.clj | 0 {sample => test_projects/sample}/project.clj | 0 .../sample}/src/nom/nom/nom.clj | 0 .../sample}/test/test_nom_nom_nom.clj | 0 test_projects/sample_failing/project.clj | 9 +++++++ .../sample_failing/src/nom/nom/nom.clj | 13 ++++++++++ 18 files changed, 73 insertions(+), 26 deletions(-) create mode 100644 test_projects/README.txt rename {sample => test_projects/sample}/checkouts/sample2/.gitignore (100%) rename {sample => test_projects/sample}/checkouts/sample2/README (100%) rename {sample => test_projects/sample}/checkouts/sample2/project.clj (100%) rename {sample => test_projects/sample}/checkouts/sample2/src/sample2/core.clj (100%) rename {sample => test_projects/sample}/checkouts/sample2/test/sample2/core_test.clj (100%) rename {sample => test_projects/sample}/project.clj (100%) rename {sample => test_projects/sample}/src/nom/nom/nom.clj (100%) rename {sample => test_projects/sample}/test/test_nom_nom_nom.clj (100%) create mode 100644 test_projects/sample_failing/project.clj create mode 100644 test_projects/sample_failing/src/nom/nom/nom.clj diff --git a/src/leiningen/compile.clj b/src/leiningen/compile.clj index 97f70eb9e..c2d0e21c3 100644 --- a/src/leiningen/compile.clj +++ b/src/leiningen/compile.clj @@ -154,12 +154,17 @@ those given as command-line arguments." (.mkdir (file (:compile-path project))) (if (seq (compilable-namespaces project)) (if-let [namespaces (seq (stale-namespaces project))] - (eval-in-project project - `(doseq [namespace# '~namespaces] - (when-not ~*silently* - (println "Compiling" namespace#)) - (clojure.core/compile namespace#)) - nil :skip-auto-compile) + (let [exit-status (eval-in-project project + `(doseq [namespace# '~namespaces] + (when-not ~*silently* + (println "Compiling" namespace#)) + (clojure.core/compile namespace#)) + nil :skip-auto-compile)] + (if (= 1 exit-status) + (do (binding [*out* *err*] + (println "Compilation failed.")) + false) + true)) (when-not *silently* (println "All namespaces already :aot compiled."))) (when-not *silently* diff --git a/src/leiningen/jar.clj b/src/leiningen/jar.clj index e055f3d14..37b812f93 100644 --- a/src/leiningen/jar.clj +++ b/src/leiningen/jar.clj @@ -154,10 +154,10 @@ well as the source .clj files. If project.clj contains a :main symbol, it will be used as the main-class for an executable jar." ([project jar-name] (binding [compile/*silently* true] - (compile/compile project)) - (let [jar-path (get-jar-filename project jar-name) - deps-fileset (deps project :skip-dev)] - (write-jar project jar-path (filespecs project deps-fileset)) - (println "Created" jar-path) - jar-path)) + (when (compile/compile project) + (let [jar-path (get-jar-filename project jar-name) + deps-fileset (deps project :skip-dev)] + (write-jar project jar-path (filespecs project deps-fileset)) + (println "Created" jar-path) + jar-path)))) ([project] (jar project (get-default-jar-name project)))) diff --git a/src/leiningen/uberjar.clj b/src/leiningen/uberjar.clj index 24f3d8bed..7f184ea35 100644 --- a/src/leiningen/uberjar.clj +++ b/src/leiningen/uberjar.clj @@ -60,14 +60,19 @@ the dependency jars. Suitable for standalone distribution." ([project uberjar-name] (doto project - clean deps jar) - (let [standalone-filename (get-jar-filename project uberjar-name)] - (with-open [out (-> standalone-filename - (FileOutputStream.) - (ZipOutputStream.))] - (let [deps (->> (.listFiles (file (:library-path project))) - (filter #(.endsWith (.getName %) ".jar")) - (cons (file (get-jar-filename project))))] - (write-components deps out))) - (println "Created" standalone-filename))) + clean deps) + (if (jar project) + (let [standalone-filename (get-jar-filename project uberjar-name)] + (with-open [out (-> standalone-filename + (FileOutputStream.) + (ZipOutputStream.))] + (let [deps (->> (.listFiles (file (:library-path project))) + (filter #(.endsWith (.getName %) ".jar")) + (cons (file (get-jar-filename project))))] + (write-components deps out))) + (println "Created" standalone-filename)) + (do + (binding [*out* *err*] + (println "Uberjar aborting because jar/compilation failed.")) + (System/exit 1)))) ([project] (uberjar project (get-default-uberjar-name project)))) diff --git a/test/test_deps.clj b/test/test_deps.clj index e93f147d3..843903d81 100644 --- a/test/test_deps.clj +++ b/test/test_deps.clj @@ -5,7 +5,7 @@ [clojure.contrib.set] [clojure.contrib.io :only [file delete-file-recursively]])) -(def test-project (read-project "sample/project.clj")) +(def test-project (read-project "test_projects/sample/project.clj")) (deftest test-deps (delete-file-recursively (file (:root test-project) "lib") true) diff --git a/test/test_install.clj b/test/test_install.clj index a929e3203..8cc565aa8 100644 --- a/test/test_install.clj +++ b/test/test_install.clj @@ -8,7 +8,7 @@ (def m2-dir (file (System/getProperty "user.home") ".m2" "repository" "nomnomnom" "nomnomnom" "0.5.0-SNAPSHOT")) -(defonce test-project (read-project "sample/project.clj")) +(defonce test-project (read-project "test_projects/sample/project.clj")) (deftest test-install (delete-file-recursively m2-dir true) diff --git a/test/test_jar.clj b/test/test_jar.clj index b38c9eac2..110c444f5 100644 --- a/test/test_jar.clj +++ b/test/test_jar.clj @@ -14,7 +14,7 @@ (select-keys manifest ["hello" "Main-Class"]))))) (def sample-project (binding [*ns* (the-ns 'leiningen.core)] - (read-project "sample/project.clj"))) + (read-project "test_projects/sample/project.clj"))) (deftest test-jar (let [jar-file (JarFile. (jar sample-project)) @@ -30,3 +30,14 @@ manifest (manifest-map (.getManifest jar-file))] (is (nil? (.getEntry jar-file "bin/nom"))) (is (nil? (manifest "Leiningen-shell-wrapper"))))) + +(def sample-failing-project + (binding [*ns* (the-ns 'leiningen.core)] + (read-project "test_projects/sample_failing/project.clj"))) + +(deftest test-jar-fails + (println "**********************************************") + (println "***** You're about to see a stack trace. *****") + (println "***** Stay cool, it's part of the test. *****") + (println "**********************************************") + (is (not (jar sample-failing-project)))) diff --git a/test/test_pom.clj b/test/test_pom.clj index 141d69e50..4508643e3 100644 --- a/test/test_pom.clj +++ b/test/test_pom.clj @@ -5,7 +5,7 @@ (:use [clojure.test] [clojure.contrib.io :only [file delete-file]])) -(def test-project (read-project "sample/project.clj")) +(def test-project (read-project "test_projects/sample/project.clj")) (deftest test-pom (let [pom-file (file (:root test-project) "pom.xml")] diff --git a/test_projects/README.txt b/test_projects/README.txt new file mode 100644 index 000000000..4d6e9a490 --- /dev/null +++ b/test_projects/README.txt @@ -0,0 +1,4 @@ +These projects are used for leiningen's test suite, so don't change +any of these values without updating the relevant tests. If you +just want a basic project to work from, generate a new one with +"lein new". diff --git a/sample/checkouts/sample2/.gitignore b/test_projects/sample/checkouts/sample2/.gitignore similarity index 100% rename from sample/checkouts/sample2/.gitignore rename to test_projects/sample/checkouts/sample2/.gitignore diff --git a/sample/checkouts/sample2/README b/test_projects/sample/checkouts/sample2/README similarity index 100% rename from sample/checkouts/sample2/README rename to test_projects/sample/checkouts/sample2/README diff --git a/sample/checkouts/sample2/project.clj b/test_projects/sample/checkouts/sample2/project.clj similarity index 100% rename from sample/checkouts/sample2/project.clj rename to test_projects/sample/checkouts/sample2/project.clj diff --git a/sample/checkouts/sample2/src/sample2/core.clj b/test_projects/sample/checkouts/sample2/src/sample2/core.clj similarity index 100% rename from sample/checkouts/sample2/src/sample2/core.clj rename to test_projects/sample/checkouts/sample2/src/sample2/core.clj diff --git a/sample/checkouts/sample2/test/sample2/core_test.clj b/test_projects/sample/checkouts/sample2/test/sample2/core_test.clj similarity index 100% rename from sample/checkouts/sample2/test/sample2/core_test.clj rename to test_projects/sample/checkouts/sample2/test/sample2/core_test.clj diff --git a/sample/project.clj b/test_projects/sample/project.clj similarity index 100% rename from sample/project.clj rename to test_projects/sample/project.clj diff --git a/sample/src/nom/nom/nom.clj b/test_projects/sample/src/nom/nom/nom.clj similarity index 100% rename from sample/src/nom/nom/nom.clj rename to test_projects/sample/src/nom/nom/nom.clj diff --git a/sample/test/test_nom_nom_nom.clj b/test_projects/sample/test/test_nom_nom_nom.clj similarity index 100% rename from sample/test/test_nom_nom_nom.clj rename to test_projects/sample/test/test_nom_nom_nom.clj diff --git a/test_projects/sample_failing/project.clj b/test_projects/sample_failing/project.clj new file mode 100644 index 000000000..2984afec9 --- /dev/null +++ b/test_projects/sample_failing/project.clj @@ -0,0 +1,9 @@ +;; This project is used for leiningen's test suite, so don't change +;; any of these values without updating the relevant tests. If you +;; just want a basic project to work from, generate a new one with +;; "lein new". + +(def clj-version "1.1.0-master-SNAPSHOT") + +(defproject nomnomnom "0.5.0-SNAPSHOT" + :dependencies [[~(symbol "org.clojure" "clojure") ~clj-version]]) diff --git a/test_projects/sample_failing/src/nom/nom/nom.clj b/test_projects/sample_failing/src/nom/nom/nom.clj new file mode 100644 index 000000000..902535a2c --- /dev/null +++ b/test_projects/sample_failing/src/nom/nom/nom.clj @@ -0,0 +1,13 @@ +(ns nom.nom.nom + (:gen-class)) + +This noming squirrel will cause compilation of this file to fail. + + ,;;:;, + ;;;;; + ,:;;:; ,'=. + ;:;:;' .=" ,'_\ + ':;:;,/ ,__:=@ + ';;:; =./)_ + `"=\_ )_"` + ``'"