refactor out clojure-contrib :require and :use declarations to provide clojure 1.1/1.2 compatibility

This commit is contained in:
Chas Emerick 2010-04-16 11:20:04 -04:00
parent e1a5f58bd4
commit 82f6b1c777
3 changed files with 25 additions and 14 deletions

View File

@ -36,8 +36,7 @@ Here's a quick example of how to view blob resources in rackspace
(pprint (blobs blobstore your_container_name)))
See http://code.google.com/p/jclouds for details."
(:use [org.jclouds.core]
[clojure.contrib.duck-streams :only [copy]])
(:use [org.jclouds.core])
(:import [java.io File FileOutputStream OutputStream]
[org.jclouds.blobstore
AsyncBlobStore BlobStore BlobStoreContext BlobStoreContextFactory
@ -47,6 +46,11 @@ See http://code.google.com/p/jclouds for details."
[java.util Arrays]
[com.google.common.collect ImmutableSet]))
(try
(require '[clojure.contrib.io :as io])
(catch Exception e
(require '[clojure.contrib.duck-streams :as io])))
(defn blobstore
"Create a logged in context.
Options for communication style
@ -265,7 +269,7 @@ container, name, string -> etag"
(let [blob (get-blob container-name name blobstore)
digest-stream (.md5OutputStream ;; TODO: not all clouds use MD5
*encryption-service* target)]
(copy (.getContent blob) digest-stream)
(io/copy (.getContent blob) digest-stream)
(let [digest (.getMD5 digest-stream)
metadata-digest (.getContentMD5 (.getMetadata blob))]
(when-not (Arrays/equals digest metadata-digest)

View File

@ -51,10 +51,7 @@ Here's an example of creating and running a small linux node with the tag webser
See http://code.google.com/p/jclouds for details."
(:use org.jclouds.core
clojure.contrib.duck-streams
clojure.contrib.logging
[clojure.contrib.str-utils2 :only [capitalize lower-case map-str]]
[clojure.contrib.java-utils :only [wall-hack-field]])
clojure.contrib.logging)
(:import java.io.File
java.util.Properties
[org.jclouds.domain Location]
@ -66,6 +63,13 @@ See http://code.google.com/p/jclouds for details."
org.jclouds.compute.options.TemplateOptions
[com.google.common.collect ImmutableSet]))
(try
(use '[clojure.contrib.reflect :only [get-field]])
(catch Exception e
(use '[clojure.contrib.java-utils
:only [wall-hack-field]
:rename {wall-hack-field get-field}])))
(defn compute-service
"Create a logged in context."
([#^String service #^String account #^String key & options]
@ -295,7 +299,7 @@ See http://code.google.com/p/jclouds for details."
(define-accessors NodeMetadata "node" credentials extra state tag)
(defn builder-options [builder]
(or (wall-hack-field org.jclouds.compute.internal.TemplateBuilderImpl :options builder)
(or (get-field org.jclouds.compute.internal.TemplateBuilderImpl :options builder)
(TemplateOptions.)))
(defmacro option-option-fn-0arg [key]

View File

@ -18,12 +18,15 @@
(ns org.jclouds.core
"Core functionality used across blobstore and compute."
(:use clojure.contrib.logging
[clojure.contrib.str-utils2 :only [capitalize lower-case map-str]]
[clojure.contrib.java-utils :only [wall-hack-field]])
(:use clojure.contrib.logging)
(:import java.io.File
(com.google.common.collect ImmutableSet)))
(try
(require '[clojure.contrib.string :as string])
(catch Exception e
(require '[clojure.contrib.str-utils2 :as string])))
(def module-lookup
{:log4j 'org.jclouds.logging.log4j.config.Log4JLoggingModule
:lognull 'org.jclouds.logging.config.NullLoggingModule
@ -59,14 +62,14 @@ Ensure the module is on the classpath. You are maybe missing a dependency on
(map #(.getValue %) set))
(defn dashed [a]
(apply str (interpose "-" (map lower-case (re-seq #"[A-Z][^A-Z]*" a)))))
(apply str (interpose "-" (map string/lower-case (re-seq #"[A-Z][^A-Z]*" a)))))
(defn camelize [a]
(map-str capitalize (.split a "-")))
(string/map-str string/capitalize (.split a "-")))
(defn camelize-mixed [a]
(let [c (.split a "-")]
(apply str (lower-case (first c)) (map capitalize (rest c)))))
(apply str (string/lower-case (first c)) (map string/capitalize (rest c)))))
(defmacro option-fn-0arg [key]
`(fn [builder#]