Merge pull request #91 from ahgittin/704-clojure13

Issue 704: clojure13
This commit is contained in:
Adrian Cole 2011-10-04 00:49:43 -07:00
commit 04a5aa8f71
13 changed files with 48 additions and 103 deletions

View File

@ -22,7 +22,6 @@
:doc "A clojure binding to the jclouds EBS service interface."} :doc "A clojure binding to the jclouds EBS service interface."}
org.jclouds.ec2.ebs org.jclouds.ec2.ebs
(:require (org.jclouds [compute :as compute])) (:require (org.jclouds [compute :as compute]))
(:use (clojure.contrib def core))
(:import org.jclouds.aws.domain.Region (:import org.jclouds.aws.domain.Region
org.jclouds.compute.domain.NodeMetadata org.jclouds.compute.domain.NodeMetadata
(org.jclouds.ec2.domain Volume Volume$Status Snapshot Snapshot$Status AvailabilityZoneInfo) (org.jclouds.ec2.domain Volume Volume$Status Snapshot Snapshot$Status AvailabilityZoneInfo)

View File

@ -22,7 +22,6 @@
:doc "A clojure binding to the jclouds EBS service interface."} :doc "A clojure binding to the jclouds EBS service interface."}
org.jclouds.ec2.ebs2 org.jclouds.ec2.ebs2
(:use [org.jclouds.compute2]) (:use [org.jclouds.compute2])
(:use (clojure.contrib def core))
(:import org.jclouds.aws.domain.Region (:import org.jclouds.aws.domain.Region
org.jclouds.compute.domain.NodeMetadata org.jclouds.compute.domain.NodeMetadata
(org.jclouds.ec2.domain Volume Volume$Status Snapshot Snapshot$Status AvailabilityZoneInfo) (org.jclouds.ec2.domain Volume Volume$Status Snapshot Snapshot$Status AvailabilityZoneInfo)

View File

@ -23,7 +23,6 @@
org.jclouds.ec2.elastic-ip org.jclouds.ec2.elastic-ip
(:require (org.jclouds [compute :as compute]) (:require (org.jclouds [compute :as compute])
[org.jclouds.ec2.ebs :as ebs]) [org.jclouds.ec2.ebs :as ebs])
(:use (clojure.contrib def core))
(:import org.jclouds.compute.domain.NodeMetadata (:import org.jclouds.compute.domain.NodeMetadata
(org.jclouds.ec2.domain PublicIpInstanceIdPair))) (org.jclouds.ec2.domain PublicIpInstanceIdPair)))

View File

@ -23,7 +23,6 @@
org.jclouds.ec2.elastic-ip2 org.jclouds.ec2.elastic-ip2
(:require (org.jclouds [compute2 :as compute]) (:require (org.jclouds [compute2 :as compute])
[org.jclouds.ec2.ebs :as ebs]) [org.jclouds.ec2.ebs :as ebs])
(:use (clojure.contrib def core))
(:import org.jclouds.compute.domain.NodeMetadata (:import org.jclouds.compute.domain.NodeMetadata
(org.jclouds.ec2.domain PublicIpInstanceIdPair))) (org.jclouds.ec2.domain PublicIpInstanceIdPair)))

View File

@ -53,11 +53,6 @@ See http://code.google.com/p/jclouds for details."
[java.security DigestOutputStream MessageDigest] [java.security DigestOutputStream MessageDigest]
com.google.common.collect.ImmutableSet)) com.google.common.collect.ImmutableSet))
(try
(require '[clojure.contrib.io :as io])
(catch Exception e
(require '[clojure.contrib.duck-streams :as io])))
(defn blobstore (defn blobstore
"Create a logged in context. "Create a logged in context.
Options for communication style Options for communication style

View File

@ -56,11 +56,6 @@ See http://code.google.com/p/jclouds for details."
com.google.common.collect.ImmutableSet com.google.common.collect.ImmutableSet
org.jclouds.encryption.internal.JCECrypto)) org.jclouds.encryption.internal.JCECrypto))
(try
(require '[clojure.contrib.io :as io])
(catch Exception e
(require '[clojure.contrib.duck-streams :as io])))
(def ^{:private true} (def ^{:private true}
crypto-impl crypto-impl
;; BouncyCastle might not be present. Try to load it, but fall back to ;; BouncyCastle might not be present. Try to load it, but fall back to
@ -77,11 +72,6 @@ See http://code.google.com/p/jclouds for details."
;; Payload support for creating Blobs. ;; Payload support for creating Blobs.
;; ;;
(def ^{:doc "Type object for a Java primitive byte array, for use in the
PayloadSource protocol."
:private true}
byte-array-type (class (make-array Byte/TYPE 0)))
(defprotocol PayloadSource (defprotocol PayloadSource
"Various types can have PayloadSource extended onto them so that they are "Various types can have PayloadSource extended onto them so that they are
easily coerced into a Payload." easily coerced into a Payload."
@ -92,8 +82,6 @@ See http://code.google.com/p/jclouds for details."
(payload [p] p) (payload [p] p)
java.io.InputStream java.io.InputStream
(payload [is] (Payloads/newInputStreamPayload is)) (payload [is] (Payloads/newInputStreamPayload is))
byte-array-type
(payload [ba] (Payloads/newByteArrayPayload ba))
String String
(payload [s] (Payloads/newStringPayload s)) (payload [s] (Payloads/newStringPayload s))
java.io.File java.io.File
@ -106,6 +94,13 @@ See http://code.google.com/p/jclouds for details."
(writeTo [this output-stream] (writeTo [this output-stream]
(func output-stream)))))) (func output-stream))))))
;; something in clojure 1.3 (namespaces?) does not like a private type called byte-array-type,
;; so we refer to (class (make-array ...)) directly; and it only parses if it is its own block,
;; hence separating it from the above
(extend-protocol PayloadSource
(class (make-array Byte/TYPE 0))
(payload [ba] (Payloads/newByteArrayPayload ba)))
(defn blobstore (defn blobstore
"Create a logged in context. "Create a logged in context.
Options for communication style Options for communication style

View File

@ -30,7 +30,6 @@ Current supported providers are:
Here's an example of getting some compute configuration from rackspace: Here's an example of getting some compute configuration from rackspace:
(use 'org.jclouds.compute) (use 'org.jclouds.compute)
(use 'clojure.contrib.pprint)
(def provider \"cloudservers\") (def provider \"cloudservers\")
(def provider-identity \"username\") (def provider-identity \"username\")
@ -57,10 +56,7 @@ webserver:
(create-node \"webserver\" compute) (create-node \"webserver\" compute)
See http://code.google.com/p/jclouds for details." See http://code.google.com/p/jclouds for details."
(:use org.jclouds.core (:use org.jclouds.core (clojure.core incubator))
(clojure.contrib logging core))
(:require
[clojure.contrib.condition :as condition])
(:import java.io.File (:import java.io.File
java.util.Properties java.util.Properties
[org.jclouds.domain Location] [org.jclouds.domain Location]
@ -74,13 +70,6 @@ See http://code.google.com/p/jclouds for details."
NodePredicates] NodePredicates]
[com.google.common.collect ImmutableSet])) [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}])))
(defmacro deprecate-fwd [old-name new-name] `(defn ~old-name {:deprecated "beta-9"} [& args#] (apply ~new-name args#))) (defmacro deprecate-fwd [old-name new-name] `(defn ~old-name {:deprecated "beta-9"} [& args#] (apply ~new-name args#)))
(defn compute-service (defn compute-service
@ -455,19 +444,15 @@ Options correspond to TemplateBuilder methods."
(let [builder (.. compute (templateBuilder))] (let [builder (.. compute (templateBuilder))]
(doseq [[option value] options] (doseq [[option value] options]
(when-not (known-template-options option) (when-not (known-template-options option)
(condition/raise (throw (Exception. (format "Invalid template builder option : %s" option))))
:type :invalid-template-builder-option
:message (format "Invalid template builder option : %s" option)))
;; apply template builder options ;; apply template builder options
(try (try
(apply-option builder template-map option value) (apply-option builder template-map option value)
(catch Exception e (catch Exception e
(condition/raise (throw (Exception. (format
:type :invalid-template-builder
:message (format
"Problem applying template builder %s with value %s: %s" "Problem applying template builder %s with value %s: %s"
option (pr-str value) (.getMessage e)) option (pr-str value) (.getMessage e))
:cause e)))) e)))))
(let [template (.build builder) (let [template (.build builder)
template-options (.getOptions template)] template-options (.getOptions template)]
(doseq [[option value] options] (doseq [[option value] options]
@ -475,10 +460,9 @@ Options correspond to TemplateBuilder methods."
(try (try
(apply-option template-options options-map option value) (apply-option template-options options-map option value)
(catch Exception e (catch Exception e
(condition/raise (throw (Exception.
:type :invalid-template-option (format
:message (format
"Problem applying template option %s with value %s: %s" "Problem applying template option %s with value %s: %s"
option (pr-str value) (.getMessage e)) option (pr-str value) (.getMessage e))
:cause e)))) e)))))
template))) template)))

View File

@ -60,10 +60,7 @@ Here's an example of creating and running a small linux node in the group webser
See http://code.google.com/p/jclouds for details. See http://code.google.com/p/jclouds for details.
" "
(:use org.jclouds.core (:use org.jclouds.core
(clojure.contrib logging core) (org.jclouds predicate) (clojure.core incubator))
(org.jclouds predicate))
(:require
[clojure.contrib.condition :as condition])
(:import java.io.File (:import java.io.File
java.util.Properties java.util.Properties
[org.jclouds.domain Location] [org.jclouds.domain Location]
@ -79,13 +76,6 @@ Here's an example of creating and running a small linux node in the group webser
[com.google.common.collect ImmutableSet]) [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 (defn compute-service
"Create a logged in context." "Create a logged in context."
([#^String provider #^String provider-identity #^String provider-credential ([#^String provider #^String provider-identity #^String provider-credential
@ -407,19 +397,16 @@ Options correspond to TemplateBuilder methods."
(let [builder (.. compute (templateBuilder))] (let [builder (.. compute (templateBuilder))]
(doseq [[option value] options] (doseq [[option value] options]
(when-not (known-template-options option) (when-not (known-template-options option)
(condition/raise (throw (Exception. (format "Invalid template builder option : %s" option))))
:type :invalid-template-builder-option
:message (format "Invalid template builder option : %s" option)))
;; apply template builder options ;; apply template builder options
(try (try
(apply-option builder template-map option value) (apply-option builder template-map option value)
(catch Exception e (catch Exception e
(condition/raise (throw (Exception.
:type :invalid-template-builder (format
:message (format
"Problem applying template builder %s with value %s: %s" "Problem applying template builder %s with value %s: %s"
option (pr-str value) (.getMessage e)) option (pr-str value) (.getMessage e))
:cause e)))) e)))))
(let [template (.build builder) (let [template (.build builder)
template-options (.getOptions template)] template-options (.getOptions template)]
(doseq [[option value] options] (doseq [[option value] options]
@ -427,10 +414,9 @@ Options correspond to TemplateBuilder methods."
(try (try
(apply-option template-options options-map option value) (apply-option template-options options-map option value)
(catch Exception e (catch Exception e
(condition/raise (throw (Exception.
:type :invalid-template-option (format
:message (format
"Problem applying template option %s with value %s: %s" "Problem applying template option %s with value %s: %s"
option (pr-str value) (.getMessage e)) option (pr-str value) (.getMessage e))
:cause e)))) e)))))
template))) template)))

View File

@ -23,7 +23,6 @@
(:require [org.jclouds.ssh-test :as ssh-test]) (:require [org.jclouds.ssh-test :as ssh-test])
(:import (:import
org.jclouds.compute.domain.OsFamily org.jclouds.compute.domain.OsFamily
clojure.contrib.condition.Condition
java.net.InetAddress java.net.InetAddress
org.jclouds.scriptbuilder.domain.Statements org.jclouds.scriptbuilder.domain.Statements
org.jclouds.compute.options.TemplateOptions org.jclouds.compute.options.TemplateOptions
@ -158,4 +157,4 @@ list, Alan Dipert and MeikelBrandmeyer."
(-> (build-template service {:inbound-ports [22 8080]}) (-> (build-template service {:inbound-ports [22 8080]})
bean :options bean :inboundPorts)))) bean :options bean :inboundPorts))))
(testing "invalid" (testing "invalid"
(is (thrown? Condition (build-template service {:xx :yy})))))) (is (thrown? Exception (build-template service {:xx :yy}))))))

View File

@ -21,8 +21,7 @@
(:use [org.jclouds.compute] :reload-all) (:use [org.jclouds.compute] :reload-all)
(:use clojure.test) (:use clojure.test)
(:import (:import
org.jclouds.compute.domain.OsFamily org.jclouds.compute.domain.OsFamily))
clojure.contrib.condition.Condition))
(defmacro with-private-vars [[ns fns] & tests] (defmacro with-private-vars [[ns fns] & tests]
"Refers private fns from ns and runs tests in context. From users mailing "Refers private fns from ns and runs tests in context. From users mailing
@ -128,4 +127,4 @@ list, Alan Dipert and MeikelBrandmeyer."
(-> (build-template service {:inbound-ports [22 8080]}) (-> (build-template service {:inbound-ports [22 8080]})
bean :options bean :inboundPorts)))) bean :options bean :inboundPorts))))
(testing "invalid" (testing "invalid"
(is (thrown? Condition (build-template service {:xx :yy})))))) (is (thrown? Exception (build-template service {:xx :yy}))))))

View File

@ -19,7 +19,7 @@
(ns org.jclouds.ssh-test (ns org.jclouds.ssh-test
(:require (:require
[clojure.contrib.logging :as logging]) [clojure.tools.logging :as logging])
(:import (:import
org.jclouds.ssh.SshClient org.jclouds.ssh.SshClient
org.jclouds.domain.Credentials org.jclouds.domain.Credentials

View File

@ -19,14 +19,10 @@
(ns org.jclouds.core (ns org.jclouds.core
"Core functionality used across blobstore and compute." "Core functionality used across blobstore and compute."
(:use clojure.contrib.logging) (:use clojure.tools.logging)
(:import java.io.File (:import java.io.File
(com.google.common.collect ImmutableSet))) (com.google.common.collect ImmutableSet))
(:require [clojure.string :as string]))
(try
(require '[clojure.contrib.string :as string])
(catch Exception e
(require '[clojure.contrib.str-utils2 :as string])))
(def module-lookup (def module-lookup
{:log4j 'org.jclouds.logging.log4j.config.Log4JLoggingModule {:log4j 'org.jclouds.logging.log4j.config.Log4JLoggingModule
@ -73,11 +69,17 @@ Ensure the module is on the classpath. You are maybe missing a dependency on
(apply (apply
str (interpose "-" (map string/lower-case (re-seq #"[A-Z][^A-Z]*" a))))) str (interpose "-" (map string/lower-case (re-seq #"[A-Z][^A-Z]*" a)))))
(defn ^String map-str
"Apply f to each element of coll, concatenate all results into a
String."
[f coll]
(apply str (map f coll)))
(defn camelize (defn camelize
"Takes a string, or anything named, and converts it to camel case "Takes a string, or anything named, and converts it to camel case
(capitalised initial component" (capitalised initial component"
[a] [a]
(string/map-str string/capitalize (.split (name a) "-"))) (map-str string/capitalize (.split (name a) "-")))
(defn camelize-mixed (defn camelize-mixed
"Takes a string, or anything named, and converts it to mixed camel case "Takes a string, or anything named, and converts it to mixed camel case

View File

@ -236,8 +236,14 @@
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.clojure</groupId> <groupId>org.clojure</groupId>
<artifactId>clojure-contrib</artifactId> <artifactId>tools.logging</artifactId>
<version>1.2.0</version> <version>0.2.3</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.clojure</groupId>
<artifactId>core.incubator</artifactId>
<version>0.1.0</version>
<optional>true</optional> <optional>true</optional>
</dependency> </dependency>
<dependency> <dependency>
@ -689,23 +695,6 @@ pageTracker._trackPageview();
</plugins> </plugins>
</build> </build>
</profile> </profile>
<profile>
<id>clojure-1.1</id>
<dependencies>
<dependency>
<groupId>org.clojure</groupId>
<artifactId>clojure</artifactId>
<version>1.1.0</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.clojure</groupId>
<artifactId>clojure-contrib</artifactId>
<version>1.1.0</version>
<optional>true</optional>
</dependency>
</dependencies>
</profile>
<profile> <profile>
<id>site</id> <id>site</id>
<build> <build>