Codebase list java-classpath-clojure / 8b02684
eliminate reflection, update copyright statement Stuart Halloway 12 years ago
2 changed file(s) with 17 addition(s) and 12 deletion(s). Raw diff Collapse all Expand all
2121
2222 ## License
2323
24 Copyright Stuart Sierra
24 Copyright Rich Hickey, Stuart Sierra, and contributors.
2525
2626 Licensed under the EPL. (See the file epl.html.)
22 ;; by Stuart Sierra, http://stuartsierra.com/
33 ;; April 19, 2009
44
5 ;; Copyright (c) Stuart Sierra, 2009. All rights reserved. The use
5 ;; Copyright (c) Rich Hickey, Stuart Sierra, and contributors.
6 ;; All rights reserved. The use
67 ;; and distribution terms for this software are covered by the Eclipse
78 ;; Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
89 ;; which can be found in the file epl-v10.html at the root of this
1516 ^{:author "Stuart Sierra",
1617 :doc "Utilities for dealing with the JVM's classpath"}
1718 clojure.java.classpath
19 (:require [clojure.java.io :as io])
1820 (:import (java.io File)
19 (java.util.jar JarFile)))
21 (java.util.jar JarFile JarEntry)))
22
23 (set! *warn-on-reflection* true)
2024
2125 (defn jar-file?
2226 "Returns true if file is a normal file with a .jar or .JAR extension."
23 [^File file]
24 (and (.isFile file)
25 (or (.endsWith (.getName file) ".jar")
26 (.endsWith (.getName file) ".JAR"))))
27 [f]
28 (let [file (io/file f)]
29 (and (.isFile file)
30 (or (.endsWith (.getName file) ".jar")
31 (.endsWith (.getName file) ".JAR")))))
2732
2833 (defn filenames-in-jar
2934 "Returns a sequence of Strings naming the non-directory entries in
3035 the JAR file."
3136 [^JarFile jar-file]
32 (map #(.getName %)
33 (filter #(not (.isDirectory %))
37 (map #(.getName ^JarEntry %)
38 (filter #(not (.isDirectory ^JarEntry %))
3439 (enumeration-seq (.entries jar-file)))))
3540
3641 (defn classpath
3742 "Returns a sequence of File objects of the elements on CLASSPATH."
3843 []
39 (map #(File. %)
44 (map #(File. ^String %)
4045 (.split (System/getProperty "java.class.path")
4146 (System/getProperty "path.separator"))))
4247
4348 (defn classpath-directories
4449 "Returns a sequence of File objects for the directories on classpath."
4550 []
46 (filter #(.isDirectory %) (classpath)))
51 (filter #(.isDirectory ^File %) (classpath)))
4752
4853 (defn classpath-jarfiles
4954 "Returns a sequence of JarFile objects for the JAR files on classpath."
5055 []
51 (map #(JarFile. %) (filter jar-file? (classpath))))
56 (map #(JarFile. ^File %) (filter jar-file? (classpath))))