Skip to content

Commit

Permalink
eliminate reflection, update copyright statement
Browse files Browse the repository at this point in the history
  • Loading branch information
stuarthalloway committed Apr 28, 2011
1 parent 044f9bc commit 8b02684
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ Please note the changelog below.

## License

Copyright Stuart Sierra
Copyright Rich Hickey, Stuart Sierra, and contributors.

Licensed under the EPL. (See the file epl.html.)
27 changes: 16 additions & 11 deletions src/main/clojure/clojure/java/classpath.clj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
;; by Stuart Sierra, http://stuartsierra.com/
;; April 19, 2009

;; Copyright (c) Stuart Sierra, 2009. All rights reserved. The use
;; Copyright (c) Rich Hickey, Stuart Sierra, and contributors.
;; All rights reserved. The use
;; and distribution terms for this software are covered by the Eclipse
;; Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
;; which can be found in the file epl-v10.html at the root of this
Expand All @@ -16,37 +17,41 @@
^{:author "Stuart Sierra",
:doc "Utilities for dealing with the JVM's classpath"}
clojure.java.classpath
(:require [clojure.java.io :as io])
(:import (java.io File)
(java.util.jar JarFile)))
(java.util.jar JarFile JarEntry)))

(set! *warn-on-reflection* true)

(defn jar-file?
"Returns true if file is a normal file with a .jar or .JAR extension."
[^File file]
(and (.isFile file)
(or (.endsWith (.getName file) ".jar")
(.endsWith (.getName file) ".JAR"))))
[f]
(let [file (io/file f)]
(and (.isFile file)
(or (.endsWith (.getName file) ".jar")
(.endsWith (.getName file) ".JAR")))))

(defn filenames-in-jar
"Returns a sequence of Strings naming the non-directory entries in
the JAR file."
[^JarFile jar-file]
(map #(.getName %)
(filter #(not (.isDirectory %))
(map #(.getName ^JarEntry %)
(filter #(not (.isDirectory ^JarEntry %))
(enumeration-seq (.entries jar-file)))))

(defn classpath
"Returns a sequence of File objects of the elements on CLASSPATH."
[]
(map #(File. %)
(map #(File. ^String %)
(.split (System/getProperty "java.class.path")
(System/getProperty "path.separator"))))

(defn classpath-directories
"Returns a sequence of File objects for the directories on classpath."
[]
(filter #(.isDirectory %) (classpath)))
(filter #(.isDirectory ^File %) (classpath)))

(defn classpath-jarfiles
"Returns a sequence of JarFile objects for the JAR files on classpath."
[]
(map #(JarFile. %) (filter jar-file? (classpath))))
(map #(JarFile. ^File %) (filter jar-file? (classpath))))

0 comments on commit 8b02684

Please sign in to comment.