Merge pull request #1595 from stuartfehr/master

Add warning when Main-Class doesn't exist in output jar
This commit is contained in:
Phil Hagelberg 2014-07-09 19:13:07 -07:00
commit aa0e0d0aaa
2 changed files with 45 additions and 1 deletions

View file

@ -141,7 +141,19 @@
(FileOutputStream.)
(BufferedOutputStream.)
(JarOutputStream. (make-manifest project)))]
(reduce (partial copy-to-jar project jar-os) #{} filespecs)))
(let [jar-paths (reduce (partial copy-to-jar project jar-os)
#{}
filespecs)]
(if (:main project)
(let [main-path (str (-> (string/replace (:main project) "." "/")
(string/replace "-" "_"))
".class")]
(if (not (some #{main-path} jar-paths))
(main/info "Warning: The Main-Class specified does not exist"
"within the jar. It may not be executable as expected."
"A gen-class directive may be missing in the namespace"
"which contains the main method."))))
jar-paths)))
;; TODO: change in 3.0; this is hideous
(defn- filespecs [project]

View file

@ -54,3 +54,35 @@
(let [result (jar helper/overlapped-sourcepaths-project)]
(is result)
(is (not-any? #(re-find #"Warning" %) (mapcat identity @info-logs)))))))
(deftest test-write-jar
(testing (str "Confirm that a warning is output when the Main-Class is not "
"part of the output jar file")
(let [out-str (with-out-str
(write-jar mock-project
"/dev/null"
[{:type :bytes
:path "foo/one_two.class"
:bytes ""}
{:type :bytes
:path "foo/one_two_too.class"
:bytes ""}]))]
(is (.contains out-str
"Warning: The Main-Class specified does not exist"))))
(testing (str "Confirm that a warning is NOT output when the Main-Class is "
"not part of the output jar file")
(let [out-str (with-out-str
(write-jar mock-project
"/dev/null"
[{:type :bytes
:path "foo/one_two.class"
:bytes ""}
{:type :bytes
:path "foo/one_two_too.class"
:bytes ""}
{:type :bytes
:path "foo/one_two/three_four/bar.class"
:bytes ""}]))]
(is (not (.contains out-str
"Warning: The Main-Class specified does not exist"))))))