2 | 2 |
;; by Stuart Sierra, http://stuartsierra.com/
|
3 | 3 |
;; April 19, 2009
|
4 | 4 |
|
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
|
6 | 7 |
;; and distribution terms for this software are covered by the Eclipse
|
7 | 8 |
;; Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
|
8 | 9 |
;; which can be found in the file epl-v10.html at the root of this
|
|
15 | 16 |
^{:author "Stuart Sierra",
|
16 | 17 |
:doc "Utilities for dealing with the JVM's classpath"}
|
17 | 18 |
clojure.java.classpath
|
|
19 |
(:require [clojure.java.io :as io])
|
18 | 20 |
(:import (java.io File)
|
19 | |
(java.util.jar JarFile)))
|
|
21 |
(java.util.jar JarFile JarEntry)))
|
|
22 |
|
|
23 |
(set! *warn-on-reflection* true)
|
20 | 24 |
|
21 | 25 |
(defn jar-file?
|
22 | 26 |
"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")))))
|
27 | 32 |
|
28 | 33 |
(defn filenames-in-jar
|
29 | 34 |
"Returns a sequence of Strings naming the non-directory entries in
|
30 | 35 |
the JAR file."
|
31 | 36 |
[^JarFile jar-file]
|
32 | |
(map #(.getName %)
|
33 | |
(filter #(not (.isDirectory %))
|
|
37 |
(map #(.getName ^JarEntry %)
|
|
38 |
(filter #(not (.isDirectory ^JarEntry %))
|
34 | 39 |
(enumeration-seq (.entries jar-file)))))
|
35 | 40 |
|
36 | 41 |
(defn classpath
|
37 | 42 |
"Returns a sequence of File objects of the elements on CLASSPATH."
|
38 | 43 |
[]
|
39 | |
(map #(File. %)
|
|
44 |
(map #(File. ^String %)
|
40 | 45 |
(.split (System/getProperty "java.class.path")
|
41 | 46 |
(System/getProperty "path.separator"))))
|
42 | 47 |
|
43 | 48 |
(defn classpath-directories
|
44 | 49 |
"Returns a sequence of File objects for the directories on classpath."
|
45 | 50 |
[]
|
46 | |
(filter #(.isDirectory %) (classpath)))
|
|
51 |
(filter #(.isDirectory ^File %) (classpath)))
|
47 | 52 |
|
48 | 53 |
(defn classpath-jarfiles
|
49 | 54 |
"Returns a sequence of JarFile objects for the JAR files on classpath."
|
50 | 55 |
[]
|
51 | |
(map #(JarFile. %) (filter jar-file? (classpath))))⏎
|
|
56 |
(map #(JarFile. ^File %) (filter jar-file? (classpath))))
|