Skip to content

Commit

Permalink
Refactor clean task. Fixes #64.
Browse files Browse the repository at this point in the history
  • Loading branch information
technomancy committed Jul 22, 2010
1 parent 8fe309d commit 6c36bbb
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 29 deletions.
3 changes: 2 additions & 1 deletion README.md
Expand Up @@ -209,7 +209,8 @@ See the [complete list of known issues](http://github.com/technomancy/leiningen/

## License

Copyright (C) 2009-2010 Phil Hagelberg, Alex Osborne, and Dan Larkin
Copyright (C) 2009-2010 Phil Hagelberg, Alex Osborne, Dan Larkin, and
contributors.

Thanks to Stuart Halloway for Lancet and Tim Dysinger for convincing
me that good builds are important.
Expand Down
31 changes: 11 additions & 20 deletions src/leiningen/clean.clj
@@ -1,23 +1,14 @@
(ns leiningen.clean
"Remove compiled files and dependencies from project."
(:use [clojure.contrib.io :only [file delete-file delete-file-recursively]]))
(:use [leiningen.jar :only [get-jar-filename get-default-jar-name
get-default-uberjar-name]]
[clojure.contrib.io :only [file delete-file delete-file-recursively]]))

(defn empty-directory
"Recursively delete all the files in f, but not f itself.
Raise an exception if any deletion fails unless silently is true."
[f & [silently]]
(let [f (file f)]
(when (.isDirectory f)
(doseq [child (.listFiles f)]
(delete-file-recursively child silently)))))

(defn clean [project]
(println "Cleaning up")
(delete-file (str (:jar-dir project) "/" (:name project) ".jar") true)
(delete-file (str (:jar-dir project) "/" (:name project) "-standalone.jar")
true)
(doseq [d [(:compile-path project)
(:library-path project)
;; This must be hard-coded since it's needed in bin/lein
"lib/dev"]]
(empty-directory (file d) true)))
(defn clean
"Remove compiled files and dependencies from project."
[project]
(println "Cleaning up.")
(doseq [f [(get-jar-filename project (get-default-jar-name project))
(get-jar-filename project (get-default-uberjar-name project))
(:compile-path project)]]
(delete-file-recursively f true)))
5 changes: 2 additions & 3 deletions src/leiningen/deps.clj
Expand Up @@ -2,8 +2,7 @@
"Install jars for all dependencies in lib."
(:require [lancet])
(:use [leiningen.pom :only [default-repos make-dependency]]
[leiningen.clean :only [empty-directory]]
[clojure.java.io :only [file]])
[clojure.contrib.io :only [file delete-file-recursively]])
(:import [org.apache.maven.artifact.ant Authentication
DependenciesTask
RemoteRepository]
Expand Down Expand Up @@ -57,7 +56,7 @@
With an argument it will skip development dependencies."
([project skip-dev set]
(when-not (:disable-implicit-clean project)
(empty-directory (:library-path project)))
(delete-file-recursively (:library-path project) true))
(let [deps-task (DependenciesTask.)]
(.setBasedir lancet/ant-project (:root project))
(.setFilesetId deps-task "dependency.fileset")
Expand Down
4 changes: 4 additions & 0 deletions src/leiningen/jar.clj
Expand Up @@ -71,6 +71,10 @@
(.mkdirs (file jar-dir))
(str jar-dir "/" jar-name)))

(defn get-default-uberjar-name [project]
(or (:uberjar-name project)
(str (:name project) \- (:version project) "-standalone.jar")))

(defn jar
"Create a $PROJECT-$VERSION.jar file containing the compiled .class files as
well as the source .clj files. If project.clj contains a :main symbol, it will
Expand Down
7 changes: 2 additions & 5 deletions src/leiningen/uberjar.clj
Expand Up @@ -5,7 +5,8 @@
[clojure.java.io :only [file copy]]
[clojure.contrib.zip-filter.xml :only [xml-> tag=]]
[leiningen.clean :only [clean]]
[leiningen.jar :only [get-default-jar-name get-jar-filename jar]])
[leiningen.jar :only [get-default-jar-name get-jar-filename
get-default-uberjar-name jar]])
(:import [java.util.zip ZipFile ZipOutputStream ZipEntry]
[java.io File FileOutputStream PrintWriter]))

Expand Down Expand Up @@ -38,10 +39,6 @@
[(into skip-set (copy-entries zipfile out #(skip-set (.getName %))))
(concat components (read-components zipfile))]))

(defn get-default-uberjar-name [project]
(or (:uberjar-name project)
(str (:name project) \- (:version project) "-standalone.jar")))

(defn uberjar
"Create a jar like the jar task, but including the contents of each of
the dependency jars. Suitable for standalone distribution."
Expand Down

0 comments on commit 6c36bbb

Please sign in to comment.