Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

General cleanup.

Sneaking in just under 1000 LOC modulo lein-newnew.
  • Loading branch information...
commit b1046bc834565b0c840a8f9df8e8989a7cce1cfd 1 parent ec89737
@technomancy authored
View
2  doc/PLUGINS.md
@@ -54,6 +54,8 @@ user. Be sure to explain all these arguments in the docstring. Note
that all your arguments will be strings, so it's up to you to call
`read-string` on them if you want keywords, numbers, or symbols.
+TODO: document subtasks and subtask help
+
If your task returns an integer, it will be used as the exit code for
the process. If tasks are chained together, a nonzero integer return
value will halt the chain and exit immediately. Throwing an exception
View
10 doc/TUTORIAL.md
@@ -72,10 +72,6 @@ to setting `:dependencies`. Note that Clojure is just another
dependency here. Unlike most languages, it's easy to swap out any
version of Clojure.
-If you've got a simple pure-clojure project, you may be fine with the
-default of depending only on Clojure, but otherwise you'll need to
-list other dependencies.
-
## Dependencies
By default, Leiningen projects download dependencies from
@@ -135,9 +131,9 @@ in project.clj. See the
## Profiles
-Sometimes you want to pull in dependencies that are really only for
-your convenience while developing; they aren't strictly required for
-the project to function. You can do this by adding a `:dependencies`
+Sometimes you want to pull in dependencies that are really only
+necessary while developing; they aren't required for the project to
+function in production. You can do this by adding a `:dependencies`
entry to the `:dev` profile. These will be available by default unless
you specify another profile from the defaults, but they are not
brought along when another project depends on your project.
View
8 src/leiningen/classpath.clj
@@ -7,12 +7,6 @@
(str/join java.io.File/pathSeparatorChar (classpath/get-classpath project)))
(defn classpath
- "Print the classpath of the current project.
-
-Suitable for java's -classpath option.
-
-Warning: due to a bug in ant, calling this task with :local-repo-classpath set
-when the dependencies have not been fetched will result in spurious output before
-the classpath. In such cases, pipe to tail -n 1."
+ "Print the classpath of the current project. Suitable for java's -cp option."
[project]
(println (get-classpath-string project)))
View
2  src/leiningen/clean.clj
@@ -8,7 +8,7 @@ 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)]
- (if (.isDirectory f)
+ (when (.isDirectory f)
(doseq [child (.listFiles f)]
(delete-file-recursively child silently)))
(delete-file f silently)))
View
128 src/leiningen/compile.clj
@@ -8,12 +8,6 @@
(:refer-clojure :exclude [compile])
(:import (java.io PushbackReader)))
-(declare compile)
-
-(def ^:dynamic *silently* false)
-
-(def ^:dynamic *skip-auto-compile* false)
-
(defn- regex? [str-or-re]
(instance? java.util.regex.Pattern str-or-re))
@@ -57,57 +51,56 @@
;; .class file cleanup
-(defn- has-source-package?
- "Test if the class file's package exists as a directory in source-path."
- [project f source-path]
- (and source-path
- (let [[[parent] [_ _ proxy-mod-parent]]
- (->> f, (iterate #(.getParentFile %)),
- (take-while identity), rest,
- (split-with #(not (re-find #"^proxy\$" (.getName %)))))]
- (.isDirectory (io/file (.replace (.getPath (or proxy-mod-parent parent))
- (:compile-path project)
- source-path))))))
-
-(defn- class-in-project? [project f]
- (or (has-source-package? project f (:source-path project))
- (has-source-package? project f (:java-source-path project))
- (.exists (io/file (str (.replace (.getParent f)
- (:compile-path project)
- (:source-path project)) ".clj")))))
-
-(defn- relative-path [project f]
- (let [root-length (if (= \/ (last (:compile-path project)))
- (count (:compile-path project))
- (inc (count (:compile-path project))))]
- (subs (.getAbsolutePath f) root-length)))
-
-(defn- blacklisted-class? [project f]
- ;; true indicates all non-project classes are blacklisted
- (or (true? (:clean-non-project-classes project))
- (some #(re-find % (relative-path project f))
- (:clean-non-project-classes project))))
-
-(defn- whitelisted-class? [project f]
- (or (class-in-project? project f)
- (and (:class-file-whitelist project)
- (re-find (:class-file-whitelist project)
- (relative-path project f)))))
-
-(defn clean-non-project-classes [project]
- #_(when (:clean-non-project-classes project)
- (doseq [f (file-seq (io/file (:compile-path project)))
- :when (and (.isFile f)
- (not (whitelisted-class? project f))
- (blacklisted-class? project f))]
- (.delete f))))
+;; (defn- has-source-package?
+;; "Test if the class file's package exists as a directory in source-path."
+;; [project f source-path]
+;; (and source-path
+;; (let [[[parent] [_ _ proxy-mod-parent]]
+;; (->> f, (iterate #(.getParentFile %)),
+;; (take-while identity), rest,
+;; (split-with #(not (re-find #"^proxy\$" (.getName %)))))]
+;; (.isDirectory (io/file (.replace (.getPath (or proxy-mod-parent parent))
+;; (:compile-path project)
+;; source-path))))))
+
+;; (defn- class-in-project? [project f]
+;; (or (has-source-package? project f (:source-path project))
+;; (has-source-package? project f (:java-source-path project))
+;; (.exists (io/file (str (.replace (.getParent f)
+;; (:compile-path project)
+;; (:source-path project)) ".clj")))))
+
+;; (defn- relative-path [project f]
+;; (let [root-length (if (= \/ (last (:compile-path project)))
+;; (count (:compile-path project))
+;; (inc (count (:compile-path project))))]
+;; (subs (.getAbsolutePath f) root-length)))
+
+;; (defn- blacklisted-class? [project f]
+;; ;; true indicates all non-project classes are blacklisted
+;; (or (true? (:clean-non-project-classes project))
+;; (some #(re-find % (relative-path project f))
+;; (:clean-non-project-classes project))))
+
+;; (defn- whitelisted-class? [project f]
+;; (or (class-in-project? project f)
+;; (and (:class-file-whitelist project)
+;; (re-find (:class-file-whitelist project)
+;; (relative-path project f)))))
+
+;; (defn clean-non-project-classes [project]
+;; (when (:clean-non-project-classes project)
+;; (doseq [f (file-seq (io/file (:compile-path project)))
+;; :when (and (.isFile f)
+;; (not (whitelisted-class? project f))
+;; (blacklisted-class? project f))]
+;; (.delete f))))
;; actual task
(defn- status [code msg]
- (when-not *silently* ; TODO: should silently only affect success?
- (binding [*out* (if (zero? code) *out* *err*)]
- (println msg)))
+ (binding [*out* (if (zero? code) *out* *err*)]
+ (println msg))
code)
(def ^:private success (partial status 0))
@@ -123,22 +116,19 @@ as command-line arguments."
;; (javac/javac project))
(if (seq (compilable-namespaces project))
(if-let [namespaces (seq (stale-namespaces project))]
- (binding [*skip-auto-compile* true]
- (try
- (let [form `(doseq [namespace# '~namespaces]
- (when-not ~*silently*
- (println "Compiling" namespace#))
- (clojure.core/compile namespace#))]
- ;; TODO: should eval-in-project be allowed to return
- ;; non-integers?
- (if (zero? (eval/eval-in-project project form))
- (success "Compilation succeeded.")
- (failure "Compilation failed.")))
- (finally (clean-non-project-classes project))))
+ (try
+ (let [form `(doseq [namespace# '~namespaces]
+ (println "Compiling" namespace#)
+ (clojure.core/compile namespace#))]
+ ;; TODO: should eval-in-project be allowed to return
+ ;; non-integers?
+ (if (zero? (eval/eval-in-project project form))
+ (success "Compilation succeeded.")
+ (failure "Compilation failed.")))
+ #_(finally (clean-non-project-classes project)))
(success "All namespaces already :aot compiled."))
(success "No namespaces to :aot compile listed in project.clj.")))
([project & namespaces]
- (compile (assoc project
- :aot (if (= namespaces [":all"])
- :all
- (map symbol namespaces))))))
+ (compile (assoc project :aot (if (= namespaces [":all"])
+ :all
+ (map symbol namespaces))))))
View
13 src/leiningen/deploy.clj
@@ -6,19 +6,6 @@
[leiningen.pom :only [pom snapshot?]]
[clojure.java.io :only [file]]))
-(declare make-model make-artifact)
-
-(defn- make-maven-project [project]
-)
-
-(defn- get-repository [project repository-name]
- (let [deploy-repositories (repositories-for project :kind :deploy-repositories)
- repositories (repositories-for project)
- repository (or (deploy-repositories repository-name)
- (repositories repository-name)
- {:url repository-name})]
- #_(make-repository [repository-name repository])))
-
(defn deploy
"Build jar and deploy to remote repository.
View
60 src/leiningen/deps.clj
@@ -1,62 +1,8 @@
(ns leiningen.deps
"Download all dependencies."
- (:require [clojure.java.io :as io]
- [leiningen.clean :as clean]
- [leiningen.core.classpath :as classpath]
- [leiningen.core.user :as user])
- (:import (java.security MessageDigest)
- (java.util.jar JarFile)))
-
-(defn- sha1-digest [content]
- (.toString (BigInteger. 1 (-> (MessageDigest/getInstance "SHA1")
- (.digest (.getBytes content)))) 16))
-
-(defn- deps-checksum [project]
- (sha1-digest (pr-str (:dependencies project))))
-
-(defn- new-deps-checksum-file [project]
- (io/file (:target-path project) ".lein-deps-sum"))
-
-(defn- has-dependencies? [project]
- (some (comp seq project) [:dependencies :dev-dependencies]))
-
-;; TODO: is this necessary with keeping everything in ~/.m2?
-(defn fetch-deps?
- "Should we even bother fetching dependencies?"
- [project]
- (let [deps-checksum-file (new-deps-checksum-file project)]
- (and (has-dependencies? project)
- ;; There's got to be a better way to detect direct invocation?
- (or ;; (= "deps" *current-task*)
- (not (:checksum-deps project (:checksum-deps (user/settings) true)))
- (not (.exists deps-checksum-file))
- (not= (slurp deps-checksum-file) (deps-checksum project))))))
-
-(defn- jar-files [files]
- (for [file files
- :when (.endsWith (.getName file) ".jar")]
- (JarFile. file)))
-
-(defn extract-native-deps [project files]
- (doseq [jar (jar-files files)
- entry (enumeration-seq (.entries jar))
- :when (.startsWith (.getName entry) "native/")]
- (let [f (io/file (:native-path project)
- (subs (.getName entry) (count "native/")))]
- (if (.isDirectory entry)
- (.mkdirs f)
- (io/copy (.getInputStream jar entry) f)))))
+ (:require [leiningen.core.classpath :as classpath]))
(defn deps
- "Download :dependencies and put them in :library-path."
+ "Download all dependencies. You should never need to invoke this manually."
[project]
- (when (fetch-deps? project)
- (when-not (or (:disable-deps-clean project)
- (:disable-implicit-clean project))
- (clean/clean project))
- (let [files (classpath/resolve-dependencies project)]
- (extract-native-deps project files)
- (let [checksum-file (new-deps-checksum-file project)]
- (.mkdirs (.getParentFile checksum-file))
- (spit checksum-file (deps-checksum project)))
- files)))
+ (classpath/resolve-dependencies project))
View
4 src/leiningen/help.clj
@@ -84,7 +84,7 @@
(defn help
"Display a list of tasks or help for a given task.
-Also provides readme, tutorial, news, sample, deploying and copying documentation."
+Also provides readme, tutorial, news, sample, deploying and copying info."
([_ task] (println (or (static-help task) (help-for task))))
([_ ]
(println "Leiningen is a tool for working with Clojure projects.\n")
@@ -92,4 +92,4 @@ Also provides readme, tutorial, news, sample, deploying and copying documentatio
(doseq [task-ns tasks]
(println (help-summary-for task-ns)))
(println "\nRun lein help $TASK for details.")
- (println "See also: readme, tutorial, copying, sample, deploying and news.")))
+ (println "See also: readme, tutorial, news, sample, deploying and copying.")))
View
65 src/leiningen/install.clj
@@ -13,28 +13,28 @@
make-artifact add-metadata tmp-dir
get-os leiningen-home)
-(defn bin-path []
- (doto (file (leiningen-home) "bin") .mkdirs))
+;; (defn bin-path []
+;; (doto (file (leiningen-home) "bin") .mkdirs))
-(defn install-shell-wrappers [jarfile]
- (when-let [bin-name ((manifest-map (.getManifest jarfile))
- "Leiningen-shell-wrapper")]
- (let [entry-paths (if (= :windows (get-os))
- [bin-name (format "%s.bat" bin-name)]
- [bin-name])]
- (doseq [entry-path entry-paths]
- (let [bin-file (file (bin-path) (last (.split entry-path "/")))]
- (when-let [zip-entry (.getEntry jarfile entry-path)]
- (.mkdirs (.getParentFile bin-file))
- (println "Installing shell wrapper to" (.getAbsolutePath bin-file))
- (copy (.getInputStream jarfile zip-entry) bin-file)
- (.setExecutable bin-file true)))))))
+;; (defn install-shell-wrappers [jarfile]
+;; (when-let [bin-name ((manifest-map (.getManifest jarfile))
+;; "Leiningen-shell-wrapper")]
+;; (let [entry-paths (if (= :windows (get-os))
+;; [bin-name (format "%s.bat" bin-name)]
+;; [bin-name])]
+;; (doseq [entry-path entry-paths]
+;; (let [bin-file (file (bin-path) (last (.split entry-path "/")))]
+;; (when-let [zip-entry (.getEntry jarfile entry-path)]
+;; (.mkdirs (.getParentFile bin-file))
+;; (println "Installing shell wrapper to" (.getAbsolutePath bin-file))
+;; (copy (.getInputStream jarfile zip-entry) bin-file)
+;; (.setExecutable bin-file true)))))))
-(defn standalone-download [name group version]
- #_(.resolveAlways (.lookup container ArtifactResolver/ROLE)
- (make-remote-artifact name group version)
- (map make-remote-repo default-repos)
- (make-local-repo)))
+;; (defn standalone-download [name group version]
+;; (.resolveAlways (.lookup container ArtifactResolver/ROLE)
+;; (make-remote-artifact name group version)
+;; (map make-remote-repo default-repos)
+;; (make-local-repo)))
(defn install
"Install current project or download specified project.
@@ -56,24 +56,25 @@ shell wrappers in ~/.lein/bin when provided."
(if (number? jarfile)
;; if we failed to create the jar, return the status code for exit
jarfile
- (do (install-shell-wrappers (JarFile. jarfile))
+ (do ;; (install-shell-wrappers (JarFile. jarfile))
(.install installer (file jarfile) artifact local-repo)
0))))
([project-name version]
(let [[name group] ((juxt name namespace) (symbol project-name))
- _ (standalone-download name (or group name) version)
+ ;; _ (standalone-download name (or group name) version)
temp-project (format "%s/lein-%s" tmp-dir (UUID/randomUUID))
jarfile (local-repo-path (or group name) name version)]
- (install-shell-wrappers (JarFile. jarfile))
+ ;; (install-shell-wrappers (JarFile. jarfile))
;; TODO: reach in and pull out project.clj rather than
;; extracting it all
- (try ;; (extract-jar (file jarfile) temp-project)
- (when-let [p (read-project (str temp-project "/project.clj"))]
- (deps (dissoc p :dev-dependencies :native-dependencies)))
- (finally
- #_(delete-file-recursively temp-project :silently))))))
+ ;; (try (extract-jar (file jarfile) temp-project)
+ ;; (when-let [p (read-project (str temp-project "/project.clj"))]
+ ;; (deps (dissoc p :dev-dependencies :native-dependencies)))
+ ;; (finally
+ ;; (delete-file-recursively temp-project :silently)))
+ )))
-(defn get-jar-entry [jar-file entry-name]
- (let [jar (JarFile. jar-file true)
- entry (.getJarEntry jar entry-name)]
- (.getInputStream jar entry)))
+;; (defn get-jar-entry [jar-file entry-name]
+;; (let [jar (JarFile. jar-file true)
+;; entry (.getJarEntry jar entry-name)]
+;; (.getInputStream jar entry)))
View
28 src/leiningen/javac.clj
@@ -1,14 +1,9 @@
(ns leiningen.javac
"Compile Java source files."
- (:use [leiningen.classpath :only [get-classpath-string]]
- ;; [leiningen.util.paths :only [normalize-path]]
- )
- (:require [lancet.core :as lancet])
- (:import (java.io File)))
+ (:use [leiningen.classpath :only [get-classpath-string]]))
-(def ^{:doc "Default options for the java compiler."
- :dynamic true}
- *default-javac-options*
+(def ^:dynamic *default-javac-options*
+ "Default options for the java compiler."
{:debug "false" :fork "true"
:includejavaruntime "yes"
:includeantruntime "false"
@@ -31,18 +26,17 @@
(for [spec (if (string? specs) [[specs]] specs)]
(extract-javac-task project spec))))
-(defn- run-javac-task
- "Compile the given task spec."
- [task-spec]
- (lancet/mkdir {:dir (:destdir task-spec)})
- (lancet/javac task-spec))
+;; (defn- run-javac-task
+;; "Compile the given task spec."
+;; [task-spec]
+;; (lancet/mkdir {:dir (:destdir task-spec)})
+;; (lancet/javac task-spec))
(defn javac
"Compile Java source files.
Add a :java-source-path key to project.clj to specify where to find them."
- [project & [directory]]
- (doseq [task (extract-javac-tasks project)
- :when (or (nil? directory) (= directory (:srcdir task)))]
- (run-javac-task task)))
+ [project]
+ (doseq [task (extract-javac-tasks project)]
+ #_(run-javac-task task)))
View
9 src/leiningen/retest.clj
@@ -1,13 +1,10 @@
(ns leiningen.retest
- "Run only the test namespaces which failed last time around."
- (:require [leiningen.test]))
+ (:require [leiningen.test :as test]))
(defn retest
- "Run only the test namespaces which failed last time around.
-Requires loading leiningen.hooks.retest to :hooks in project.clj."
+ "Run only the test namespaces which failed last time around."
[project & selectors]
- ;; TODO: detect branch change; clear failure list
- (apply leiningen.test/test project
+ (apply test/test project
(concat (if (.exists (java.io.File. ".lein-failures"))
(->> (slurp ".lein-failures")
read-string sort (map name)))
View
11 src/leiningen/search.clj
@@ -43,7 +43,7 @@
;;; Searching
-(def ^{:private true} page-size (:search-page-size (user/settings) 25))
+(def ^:private page-size (:search-page-size (user/settings) 25))
(defn search-repository [[id {:keys [url]} :as repo] query page]
(if (ensure-fresh-index repo)
@@ -85,14 +85,7 @@ string matches or do more advanced queries such as this
Also accepts a second parameter for fetching successive
pages."
- ;; support running outside project
- ([query] (search {} query))
- ([project-or-query query-or-page]
- ;; this arity does double-duty: simple query inside project or
- ;; query+page outside project
- (if (string? project-or-query)
- (search {} project-or-query query-or-page)
- (search project-or-query query-or-page 1)))
+ ([project query] (search project query 1))
([project query page]
;; you know what would be just super? pattern matching.
(if (= "--update" query)
View
5 src/leiningen/templates.clj
@@ -11,8 +11,7 @@
;; just look up these templates on the classpath, require them, and then
;; get the metadata off of that function to list the names and docs
;; for all of the available templates.
-(defn ^{:no-project-needed true}
- templates
+(defn ^:no-project-needed templates
"List available 'lein new' templates"
[project]
(println "List of 'lein new' templates on the classpath:")
@@ -25,4 +24,4 @@
(ns-resolve (the-ns n)
(symbol (last (.split (str n) "\\.")))))]
(println (str (:name n-meta) ":")
- (or (:doc n-meta) "No documentation available.")))))
+ (:doc n-meta "No documentation available.")))))
View
8 src/leiningen/trampoline.clj
@@ -4,7 +4,7 @@
(:require [clojure.string :as string]
[leiningen.core.eval :as eval]))
-(def ^{:dynamic true} *trampoline?* false)
+(def ^:dynamic *trampoline?* false)
(defn win-batch? []
(.endsWith (System/getProperty "leiningen.trampoline-file") ".bat"))
@@ -24,14 +24,12 @@ task and runs it after Leiningen's own JVM process has exited rather
than as a subprocess of Leiningen's project.
Use this to save memory or to work around things like stdin issues.
-Not compatible with chaining.
-
-ALPHA: subject to change without warning."
+Not compatible with chaining."
[project task-name & args]
(let [command (atom nil)]
(when (:eval-in-leiningen project)
(println "Warning: trampoline has no effect with :eval-in-leiningen."))
- #_(binding [*trampoline?* true
+ (binding [*trampoline?* true
eval/sh (fn [& c] (reset! command c) 0)]
(apply-task task-name project args task-not-found))
(if @command
View
66 src/leiningen/util/ns.clj
@@ -1,66 +0,0 @@
-(ns leiningen.util.ns
- "Inspired by clojure.contrib.find-namespaces, but trimmed down to
- just what Leiningen needs."
- (:use [clojure.java.io :only [file reader]])
- (:import (java.util.jar JarFile)
- (java.io File BufferedReader PushbackReader InputStreamReader)))
-
-;; The contrib version has a couple issues: it searches the whole
-;; classpath rather than allowing you to specify a prefix, which means
-;; you can't use it in (for example) my $HOME dir, where ~/src is over
-;; 50 GB. Also it never looks past the first form to find a namespace
-;; declaration.
-
-(def classpath-files
- (for [f (.split (System/getProperty "java.class.path")
- (System/getProperty "path.separator"))]
- (file f)))
-
-(defn clj? [f]
- (.endsWith (.getName f) ".clj"))
-
-(defn jar? [f]
- (and (.isFile f) (.endsWith (.getName f) ".jar")))
-
-(defn read-ns-form [r f]
- ;; bug in Clojure 1.2 allows reading "{foo}" and throws when str'd
- (let [form (try (doto (read r false ::done) str)
- (catch Exception e ::done))]
- (if (and (list? form) (= 'ns (first form)))
- form
- (when-not (= ::done form)
- (recur r f)))))
-
-(defn find-ns-form [f]
- (when (and (.isFile (file f)) (clj? f))
- (read-ns-form (PushbackReader. (reader f)) f)))
-
-(defn namespaces-in-dir [dir]
- (sort (for [f (file-seq (file dir))
- :let [ns-form (find-ns-form f)]
- :when ns-form]
- (second ns-form))))
-
-(defn ns-in-jar-entry [jarfile entry]
- (with-open [rdr (-> jarfile
- (.getInputStream (.getEntry jarfile (.getName entry)))
- InputStreamReader.
- BufferedReader.
- PushbackReader.)]
- (read-ns-form rdr jarfile)))
-
-(defn namespaces-in-jar [jar]
- (let [jarfile (JarFile. jar)]
- (for [entry (enumeration-seq (.entries jarfile))
- :when (and (not (.isDirectory entry))
- (clj? entry))]
- (if-let [ns-form (ns-in-jar-entry jarfile entry)]
- (second ns-form)))))
-
-(defn namespaces-matching [prefix]
- (concat (mapcat namespaces-in-dir
- (for [dir classpath-files
- :when (.isDirectory dir)]
- (file dir (.replaceAll prefix "\\." "/"))))
- (filter #(and % (.startsWith (name %) prefix))
- (mapcat namespaces-in-jar (filter jar? classpath-files)))))
View
2  todo.org
@@ -44,6 +44,7 @@ See also https://github.com/technomancy/leiningen/issues
- [X] run
- [X] new (merge from lein-newnew)
- [X] help (needs tests)
+ - [X] search
- [ ] pom (steal from depot)
- [ ] install (minus shell wrappers)
- [ ] uberjar
@@ -54,7 +55,6 @@ See also https://github.com/technomancy/leiningen/issues
- [ ] shell wrappers
- [ ] deploy
- [ ] javac (can we do this without ant?)
- - [ ] search
- [ ] trampoline
* For 1.6.2
- [X] resources with eval-in-leiningen (#248)
Please sign in to comment.
Something went wrong with that request. Please try again.