Skip to content
This repository has been archived by the owner on Jul 25, 2020. It is now read-only.

Commit

Permalink
refactor out clojure-contrib :require and :use declarations to provid…
Browse files Browse the repository at this point in the history
…e clojure 1.1/1.2 compatibility
  • Loading branch information
cemerick committed Apr 16, 2010
1 parent e1a5f58 commit 82f6b1c
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 14 deletions.
10 changes: 7 additions & 3 deletions blobstore/src/main/clojure/org/jclouds/blobstore.clj
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down
14 changes: 9 additions & 5 deletions compute/src/main/clojure/org/jclouds/compute.clj
Expand Up @@ -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]
Expand All @@ -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]
Expand Down Expand Up @@ -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]
Expand Down
15 changes: 9 additions & 6 deletions core/src/main/clojure/org/jclouds/core.clj
Expand Up @@ -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
Expand Down Expand Up @@ -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#]
Expand Down

0 comments on commit 82f6b1c

Please sign in to comment.