Quit using :use.

This commit is contained in:
Phil Hagelberg 2012-03-07 14:54:20 -08:00
parent f7795cebd6
commit ee47831461
10 changed files with 71 additions and 75 deletions

View file

@ -1,17 +1,17 @@
(ns leiningen.clean
"Remove all files from project's target-path."
(:use [clojure.java.io :only [file delete-file]]))
(:require [clojure.java.io :as io]))
(defn delete-file-recursively
"Delete file f. If it's a directory, recursively delete all its contents.
Raise an exception if any deletion fails unless silently is true."
[f & [silently]]
(System/gc) ; This sometimes helps release files for deletion on windows.
(let [f (file f)]
(let [f (io/file f)]
(when (.isDirectory f)
(doseq [child (.listFiles f)]
(delete-file-recursively child silently)))
(delete-file f silently)))
(io/delete-file f silently)))
(defn clean
"Remove all files from project's target-path."

View file

@ -1,10 +1,10 @@
(ns leiningen.deploy
"Build and deploy jar to remote repository."
(:require [cemerick.pomegranate.aether :as aether]
[leiningen.core.classpath :as classpath])
(:use [leiningen.jar :only [jar]]
[leiningen.pom :only [pom snapshot?]]
[clojure.java.io :only [file]]))
[leiningen.core.classpath :as classpath]
[clojure.java.io :as io]
[leiningen.pom :as pom]
[leiningen.jar :as jar]))
(defn deploy
"Build jar and deploy to remote repository.
@ -19,10 +19,9 @@ the repository URL directly.
\"releases\" \"https://internal.repo/releases\"
\"alternate\" \"https://other.server/repo\"}
You should set authentication options keyed by repository URL
(or, by regex matching repository URLs) in the :deploy profile in
~/.lein/profiles.clj to avoid checking sensitive information into
source control:
You should set authentication options keyed by repository URL or regex
matching repository URLs in the :auth profile in ~/.lein/profiles.clj
to avoid checking sensitive information into source control:
{:user {:plugins [...]}
:auth {:repository-auth {#\"https://internal.repo/.*\"
@ -30,8 +29,8 @@ source control:
\"s3://s3-repo-bucket/releases\"
{:username \"AKIAIN...\" :passphrase \"1TChrGK4s...\"}}}"
([project repository-name]
(let [jarfile (jar project)
pomfile (pom project)
(let [jarfile (jar/jar project)
pomfile (pom/pom project)
repo-opts (or (get (:deploy-repositories project) repository-name)
(get (:repositories project) repository-name))
repo (classpath/add-repo-auth (cond
@ -45,12 +44,12 @@ source control:
(aether/deploy :coordinates [(symbol (:group project)
(:name project))
(:version project)]
:jar-file (file jarfile)
:pom-file (file pomfile)
:jar-file (io/file jarfile)
:pom-file (io/file pomfile)
:transfer-listener :stdout
:repository [repo])
0))))
([project]
(deploy project (if (snapshot? project)
(deploy project (if (pom/snapshot? project)
"snapshots"
"releases"))))

View file

@ -1,10 +1,10 @@
(ns leiningen.install
"Install the current project to the local repository."
(:require [cemerick.pomegranate.aether :as aether]
[leiningen.core.project :as project])
(:use [leiningen.jar :only [jar]]
[leiningen.pom :only [pom]]
[clojure.java.io :only [file copy]])
[leiningen.core.project :as project]
[leiningen.jar :as jar]
[leiningen.pom :as pom]
[clojure.java.io :as io])
(:import (java.util.jar JarFile)
(java.util UUID)))
@ -29,8 +29,8 @@
(defn install
"Install current project to the local repository."
([project]
(let [jarfile (jar project)
pomfile (pom project)]
(let [jarfile (jar/jar project)
pomfile (pom/pom project)]
(if (number? jarfile)
;; if we failed to create the jar, return the status code for exit
jarfile
@ -38,8 +38,8 @@
(aether/install :coordinates [(symbol (:group project)
(:name project))
(:version project)]
:jar-file (file jarfile)
:pom-file (file pomfile))
:jar-file (io/file jarfile)
:pom-file (io/file pomfile))
0))))
([_ project-name version]
(let [[name group] ((juxt name namespace) (symbol project-name))

View file

@ -1,11 +1,10 @@
(ns leiningen.jar
"Package up all the project's files into a jar file."
(:require [leiningen.compile :as compile]
[leiningen.pom :as pom]
[leiningen.core.classpath :as classpath]
[clojure.string :as string]
[clojure.java.io :as io])
(:use [leiningen.pom :only [make-pom make-pom-properties]]
[leiningen.deps :only [deps]])
(:import (java.util.jar Manifest JarEntry JarOutputStream)
(java.util.regex Pattern)
(java.util.jar JarFile)
@ -148,11 +147,11 @@
(concat [{:type :bytes
:path (format "META-INF/maven/%s/%s/pom.xml"
(:group project) (:name project))
:bytes (.getBytes (make-pom project))}
:bytes (.getBytes (pom/make-pom project))}
{:type :bytes
:path (format "META-INF/maven/%s/%s/pom.properties"
(:group project) (:name project))
:bytes (.getBytes (make-pom-properties project))}
:bytes (.getBytes (pom/make-pom-properties project))}
{:type :bytes :path "project.clj"
:bytes (.getBytes (slurp (str (:root project) "/project.clj")))}]
[{:type :path :path (:compile-path project)}

View file

@ -1,8 +1,7 @@
(ns leiningen.javac
"Compile Java source files."
(:use [leiningen.classpath :only [get-classpath-string]]
[clojure.string :only [join]]
[clojure.java.io :only [file]])
(:require [leiningen.classpath :as classpath]
[clojure.java.io :as io])
(:import javax.tools.ToolProvider))
;; There is probably a more efficient way to do this, but this is cool
@ -11,21 +10,21 @@
"Find all of the Java source files in a directory."
[dir]
(filter #(.endsWith % ".java")
(map #(.getPath %) (file-seq (file dir)))))
(map #(.getPath %) (file-seq (io/file dir)))))
;; Tool's .run method expects the last argument to be an array of
;; strings, so that's what we'll return here.
(defn javac-options
(defn javac-options
"Compile all sources of possible options and add important defaults.
Result is a String java array of options."
[project files args]
(into-array
String
(concat (:javac-options project)
args
["-cp" (get-classpath-string project)
"-d" (:compile-path project)]
files)))
(into-array
String
(concat (:javac-options project)
args
["-cp" (classpath/get-classpath-string project)
"-d" (:compile-path project)]
files)))
;; We can't really control what is printed here. We're just going to
;; allow `.run` to attach in, out, and err to the standard streams. This
@ -38,9 +37,9 @@
(let [files (mapcat extract-java-source (:java-source-paths project))
compile-path (:compile-path project)]
(when (pos? (count files))
(println "Compiling" (count files) "source files to" compile-path)
(.mkdirs (file compile-path))
(.run (ToolProvider/getSystemJavaCompiler)
(println "Compiling" (count files) "source files to" compile-path)
(.mkdirs (io/file compile-path))
(.run (ToolProvider/getSystemJavaCompiler)
nil nil nil
(javac-options project files args)))))
@ -52,4 +51,3 @@ Any options passed will be given to javac. One place where this can be useful
is `lein javac -verbose`."
[project & args]
(run-javac-task project args))

View file

@ -1,11 +1,11 @@
(ns leiningen.pom
"Write a pom.xml file to disk for Maven interoperability."
(:use [useful.string :only [camelize dasherize]])
(:require [leiningen.core.main :as main]
[leiningen.core.project :as project]
[clojure.java.io :as io]
[clojure.string :as s]
[clojure.data.xml :as xml]))
[clojure.data.xml :as xml]
[useful.string :as useful]))
;; git scm
@ -75,7 +75,7 @@
[dep version (assoc opts :scope "test")])
(defn pomify [key]
(->> key name camelize keyword))
(->> key name useful/camelize keyword))
(defmulti xml-tags
(fn [tag value] (keyword "leiningen.pom" (name tag))))

View file

@ -8,8 +8,8 @@
[clojure.tools.nrepl.ack :as nrepl.ack]
[clojure.tools.nrepl.server :as nrepl.server]
[leiningen.core.user :as user]
[leiningen.core.classpath :as classpath])
(:use [leiningen.core.main :only [abort]]))
[leiningen.core.classpath :as classpath]
[leiningen.core.main :as main]))
(def profile {:dependencies '[[org.clojure/tools.nrepl "0.2.0-beta1"
:exclusions [org.clojure/clojure]]
@ -77,4 +77,4 @@ This will launch an nREPL server and wait, rather than connecting reply to it."
(ack-port project))
(while true
(Thread/sleep Long/MAX_VALUE)))
(abort "Unrecognized flag:" flag))))
(main/abort "Unrecognized flag:" flag))))

View file

@ -1,7 +1,7 @@
(ns leiningen.run
"Run a -main function with optional command-line arguments."
(:use [leiningen.core.eval :only [eval-in-project]]
[leiningen.core.main :only [abort]])
(:require [leiningen.core.eval :as eval]
[leiningen.core.main :as main])
(:import (java.io FileNotFoundException)
(clojure.lang Reflector)))
@ -21,9 +21,9 @@
"Loads the project namespaces as well as all its dependencies and then calls
ns/f, passing it the args."
[project given & args]
(eval-in-project project (run-form given args)
`(try (require '~(symbol (namespace (normalize-main given))))
(catch FileNotFoundException _#))))
(eval/eval-in-project project (run-form given args)
`(try (require '~(symbol (namespace (normalize-main given))))
(catch FileNotFoundException _#))))
(defn ^{:help-arglists '([])} run
"Run the project's -main function.
@ -50,6 +50,6 @@ See also \"lein help trampoline\" for a way to save memory using this task."
(cond alias (apply run project "-m" (cons alias args))
(= flag "-m") (if (first args)
(apply run-main project args)
(abort "Option -m requires a namespace argument."))
(main/abort "Option -m requires a namespace argument."))
(:main project) (apply run-main project (:main project) all-args)
:else (abort "No :main namespace specified in project.clj."))))
:else (main/abort "No :main namespace specified in project.clj."))))

View file

@ -1,8 +1,8 @@
(ns leiningen.trampoline
(:refer-clojure :exclude [trampoline])
(:use [leiningen.core.main :only [apply-task task-not-found abort]])
(:require [clojure.string :as string]
[leiningen.core.eval :as eval]
[leiningen.core.main :as main]
[clojure.pprint :as pprint]))
(def ^:dynamic *trampoline?* false)
@ -34,9 +34,10 @@ Not compatible with chaining."
(when (:eval-in-leiningen project)
(println "Warning: trampoline has no effect with :eval-in-leiningen."))
(binding [*trampoline?* true]
(apply-task task-name (assoc project
:eval-in :trampoline
:trampoline-promise command) args))
(main/apply-task task-name (assoc project
:eval-in :trampoline
:trampoline-promise command) args))
(if (realized? command)
(write-trampoline @command)
(abort task-name "did not run any project code for trampolining."))))
(main/abort task-name "did not run any project code for trampolining."))))

View file

@ -1,19 +1,18 @@
(ns leiningen.uberjar
"Package up the project files and dependencies into a jar file."
(:require [clojure.xml :as xml]
[leiningen.core.classpath :as classpath])
(:use [clojure.zip :only [xml-zip children]]
[clojure.java.io :only [file copy]]
[leiningen.core.main :only [abort]]
[leiningen.clean :only [clean]]
[leiningen.jar :only [get-jar-filename jar]])
[clojure.zip :as zip]
[clojure.java.io :as io]
[leiningen.core.classpath :as classpath]
[leiningen.core.main :as main]
[leiningen.jar :as jar])
(:import (java.util.zip ZipFile ZipOutputStream ZipEntry)
(java.io File FileOutputStream PrintWriter)))
(defn read-components [zipfile]
(when-let [entry (.getEntry zipfile "META-INF/plexus/components.xml")]
(->> (xml-zip (xml/parse (.getInputStream zipfile entry)))
children
(->> (zip/xml-zip (xml/parse (.getInputStream zipfile entry)))
zip/children
(filter #(= (:tag %) :components))
first
:content)))
@ -34,7 +33,7 @@
(do
(.setCompressedSize file -1) ; some jars report size incorrectly
(.putNextEntry out file)
(copy (.getInputStream in file) out)
(io/copy (.getInputStream in file) out)
(.closeEntry out)
(.getName file))))
@ -81,16 +80,16 @@ as well as defining a -main function."
project)
project (update-in project [:jar-inclusions]
concat (:uberjar-inclusions project))]
(let [res (jar project)]
(let [res (jar/jar project)]
(when (and (number? res) (pos? res))
(abort "Uberjar aborting because jar/compilation failed."))))
(let [standalone-filename (get-jar-filename project :uberjar)]
(main/abort "Uberjar aborting because jar/compilation failed."))))
(let [standalone-filename (jar/get-jar-filename project :uberjar)]
(with-open [out (-> standalone-filename
(FileOutputStream.)
(ZipOutputStream.))]
(let [deps (->> (classpath/resolve-dependencies :dependencies project)
(filter #(.endsWith (.getName %) ".jar")))
jars (cons (file (get-jar-filename project)) deps)]
jars (cons (io/file (jar/get-jar-filename project)) deps)]
(write-components project jars out)))
(println "Created" standalone-filename)
standalone-filename))