diff 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
line wrap: on
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/clojure/contrib/jar.clj	Sat Aug 21 06:25:44 2010 -0400
     1.3 @@ -0,0 +1,35 @@
     1.4 +;;; jar.clj: utilities for working with Java JAR files
     1.5 +
     1.6 +;; by Stuart Sierra, http://stuartsierra.com/
     1.7 +;; April 19, 2009
     1.8 +
     1.9 +;; Copyright (c) Stuart Sierra, 2009. All rights reserved.  The use
    1.10 +;; and distribution terms for this software are covered by the Eclipse
    1.11 +;; Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
    1.12 +;; which can be found in the file epl-v10.html at the root of this
    1.13 +;; distribution.  By using this software in any fashion, you are
    1.14 +;; agreeing to be bound by the terms of this license.  You must not
    1.15 +;; remove this notice, or any other, from this software.
    1.16 +
    1.17 +
    1.18 +(ns 
    1.19 +  ^{:author "Stuart Sierra",
    1.20 +     :doc "Utilities for working with Java JAR files"}
    1.21 +  clojure.contrib.jar
    1.22 +  (:import (java.io File)
    1.23 +           (java.util.jar JarFile)))
    1.24 +
    1.25 +(defn jar-file?
    1.26 +  "Returns true if file is a normal file with a .jar or .JAR extension."
    1.27 +  [^File file]
    1.28 +  (and (.isFile file)
    1.29 +       (or (.endsWith (.getName file) ".jar")
    1.30 +           (.endsWith (.getName file) ".JAR"))))
    1.31 +
    1.32 +(defn filenames-in-jar
    1.33 +  "Returns a sequence of Strings naming the non-directory entries in
    1.34 +  the JAR file."
    1.35 +  [^JarFile jar-file]
    1.36 +  (map #(.getName %)
    1.37 +       (filter #(not (.isDirectory %))
    1.38 +               (enumeration-seq (.entries jar-file)))))