Skip to content

Commit

Permalink
t100: removed deprecated functions form c.c.java-utils
Browse files Browse the repository at this point in the history
removed: relative-path-string, as-file, file, as-str, delete-file,
         delete-file-recursively, as-url, wall-hack-method,
         wall-hack-field

use instead: clojure.java.io and clojure.contrib.reflections

Signed-off-by: Stuart Sierra <mail@stuartsierra.com>
  • Loading branch information
bpsm authored and Stuart Sierra committed Oct 2, 2010
1 parent c115db1 commit 456fbaa
Showing 1 changed file with 2 additions and 113 deletions.
115 changes: 2 additions & 113 deletions modules/java-utils/src/main/clojure/clojure/contrib/java_utils.clj
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
;;
;; CHANGELOG
;;
;; Most functions deprecated in 1.2. Some already exist in c.c.io, and
;; some replaced by c.c.reflections
;; Functions deprecated in 1.2, have been removed.
;; Some have migrated to clojure.java.io and others to c.c.reflections.

(ns
^{:author "Stuart Halloway, Stephen C. Gilardi, Shawn Hoover, Perry Trolard, Stuart Sierra",
Expand Down Expand Up @@ -46,65 +46,6 @@
[java.util Properties]
[java.net URI URL]))

(defmulti relative-path-string
"Interpret a String or java.io.File as a relative path string.
Building block for clojure.contrib.java-utils/file."
{:deprecated "1.2"}
class)

(defmethod relative-path-string String [^String s]
(relative-path-string (File. s)))

(defmethod relative-path-string File [^File f]
(if (.isAbsolute f)
(throw (IllegalArgumentException. (str f " is not a relative path")))
(.getPath f)))

(defmulti ^File as-file
"Interpret a String or a java.io.File as a File. Building block
for clojure.contrib.java-utils/file, which you should prefer
in most cases."
{:deprecated "1.2"}
class)
(defmethod as-file String [^String s] (File. s))
(defmethod as-file File [f] f)

(defn ^File file
"Returns a java.io.File from string or file args."
{:deprecated "1.2"}
([arg]
(as-file arg))
([parent child]
(File. ^File (as-file parent) ^String (relative-path-string child)))
([parent child & more]
(reduce file (file parent child) more)))

(defn as-str
"Like clojure.core/str, but if an argument is a keyword or symbol,
its name will be used instead of its literal representation.
Example:
(str :foo :bar) ;;=> \":foo:bar\"
(as-str :foo :bar) ;;=> \"foobar\"
Note that this does not apply to keywords or symbols nested within
data structures; they will be rendered as with str.
Example:
(str {:foo :bar}) ;;=> \"{:foo :bar}\"
(as-str {:foo :bar}) ;;=> \"{:foo :bar}\" "
{:deprecated "1.2"}
([] "")
([x] (if (instance? clojure.lang.Named x)
(name x)
(str x)))
([x & ys]
((fn [^StringBuilder sb more]
(if more
(recur (. sb (append (as-str (first more)))) (next more))
(str sb)))
(new StringBuilder ^String (as-str x)) ys)))

(defn get-system-property
"Get a system property."
([stringable]
Expand Down Expand Up @@ -165,55 +106,3 @@
(with-open [^FileOutputStream f (FileOutputStream. (file file-able))]
(doto (as-properties m)
(.store f ^String comments)))))

(defn delete-file
"Delete file f. Raise an exception if it fails unless silently is true."
{:deprecated "1.2"}
[f & [silently]]
(or (.delete (file f))
silently
(throw (java.io.IOException. (str "Couldn't delete " f)))))

(defn delete-file-recursively
"Delete file f. If it's a directory, recursively delete all its contents.
Raise an exception if any deletion fails unless silently is true."
{:deprecated "1.2"}
[f & [silently]]
(let [f (file f)]
(if (.isDirectory f)
(doseq [child (.listFiles f)]
(delete-file-recursively child silently)))
(delete-file f silently)))

(defmulti
^{:deprecated "1.2"
:doc "Coerces argument (URL, URI, or String) to a java.net.URL."
:arglists '([arg])}
as-url type)

(defmethod as-url URL [x] x)

(defmethod as-url URI [^URI x] (.toURL x))

(defmethod as-url String [^String x] (URL. x))

(defmethod as-url File [^File x] (.toURL x))

(defn wall-hack-method
"Calls a private or protected method.
params is a vector of class which correspond to the arguments to the method
obj is nil for static methods, the instance object otherwise
the method name is given as a symbol or a keyword (something Named)"
{:deprecated "1.2"}
[class-name method-name params obj & args]
(-> class-name (.getDeclaredMethod (name method-name) (into-array Class params))
(doto (.setAccessible true))
(.invoke obj (into-array Object args))))

(defn wall-hack-field
"Access to private or protected field."
{:deprecated "1.2"}
[class-name field-name obj]
(-> class-name (.getDeclaredField (name field-name))
(doto (.setAccessible true))
(.get obj)))

0 comments on commit 456fbaa

Please sign in to comment.