annotate src/clojure/contrib/jar.clj @ 10:ef7dbbd6452c

added clojure source goodness
author Robert McIntyre <rlm@mit.edu>
date Sat, 21 Aug 2010 06:25:44 -0400
parents
children
rev   line source
rlm@10 1 ;;; jar.clj: utilities for working with Java JAR files
rlm@10 2
rlm@10 3 ;; by Stuart Sierra, http://stuartsierra.com/
rlm@10 4 ;; April 19, 2009
rlm@10 5
rlm@10 6 ;; Copyright (c) Stuart Sierra, 2009. All rights reserved. The use
rlm@10 7 ;; and distribution terms for this software are covered by the Eclipse
rlm@10 8 ;; Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
rlm@10 9 ;; which can be found in the file epl-v10.html at the root of this
rlm@10 10 ;; distribution. By using this software in any fashion, you are
rlm@10 11 ;; agreeing to be bound by the terms of this license. You must not
rlm@10 12 ;; remove this notice, or any other, from this software.
rlm@10 13
rlm@10 14
rlm@10 15 (ns
rlm@10 16 ^{:author "Stuart Sierra",
rlm@10 17 :doc "Utilities for working with Java JAR files"}
rlm@10 18 clojure.contrib.jar
rlm@10 19 (:import (java.io File)
rlm@10 20 (java.util.jar JarFile)))
rlm@10 21
rlm@10 22 (defn jar-file?
rlm@10 23 "Returns true if file is a normal file with a .jar or .JAR extension."
rlm@10 24 [^File file]
rlm@10 25 (and (.isFile file)
rlm@10 26 (or (.endsWith (.getName file) ".jar")
rlm@10 27 (.endsWith (.getName file) ".JAR"))))
rlm@10 28
rlm@10 29 (defn filenames-in-jar
rlm@10 30 "Returns a sequence of Strings naming the non-directory entries in
rlm@10 31 the JAR file."
rlm@10 32 [^JarFile jar-file]
rlm@10 33 (map #(.getName %)
rlm@10 34 (filter #(not (.isDirectory %))
rlm@10 35 (enumeration-seq (.entries jar-file)))))