diff --git a/blobstore/project.clj b/blobstore/project.clj deleted file mode 100644 index 57010ea0d2..0000000000 --- a/blobstore/project.clj +++ /dev/null @@ -1,14 +0,0 @@ -(defproject org.jclouds/clj-blobstore "0.1-SNAPSHOT" - :description "clojure binding for jclouds blobstore library" - :source-path "src/main/clojure" - :test-path "src/test/clojure" - :compile-path "target/classes" - :library-path "target" - :dependencies [[org.clojure/clojure "1.1.0"] - [org.clojure/clojure-contrib "1.1.0"] - [org.jclouds/jclouds-blobstore "1.0-beta-4"] - [org.jclouds/jclouds-log4j "1.0-beta-4"] - [log4j/log4j "1.2.14"]] - :dev-dependencies [[org.clojure/swank-clojure "1.0"]] - :repositories [["jclouds" "http://jclouds.googlecode.com/svn/repo"] - ["jclouds-snapshot" "http://jclouds.rimuhosting.com/maven2/snapshots"]]) diff --git a/compute/project.clj b/compute/project.clj deleted file mode 100644 index 74c36e0383..0000000000 --- a/compute/project.clj +++ /dev/null @@ -1,17 +0,0 @@ -(defproject org.jclouds/clj-compute "0.1-SNAPSHOT" - :description "clojure binding for jclouds compute library" - :source-path "src/main/clojure" - :test-path "src/test/clojure" - :compile-path "target/classes" - :library-path "target" - :dependencies [[org.clojure/clojure "1.1.0"] - [org.clojure/clojure-contrib "1.1.0"] - [org.jclouds/jclouds-compute "1.0-beta-4"] - [org.jclouds/jclouds-jsch "1.0-beta-4"] - [org.jclouds/jclouds-log4j "1.0-beta-4"] - [org.jclouds/jclouds-enterprise "1.0-beta-4"] - [log4j/log4j "1.2.14"] - [com.jcraft/jsch "0.1.42"]] - :dev-dependencies [[org.clojure/swank-clojure "1.0"]] - :repositories [["jclouds" "http://jclouds.googlecode.com/svn/repo"] - ["jclouds-snapshot" "http://jclouds.rimuhosting.com/maven2/snapshots"]]) diff --git a/compute/src/main/clojure/org/jclouds/compute.clj b/compute/src/main/clojure/org/jclouds/compute.clj index b4da820878..4d70662a3b 100644 --- a/compute/src/main/clojure/org/jclouds/compute.clj +++ b/compute/src/main/clojure/org/jclouds/compute.clj @@ -25,6 +25,7 @@ Here's an example of getting some compute configuration from rackspace: "} org.jclouds.compute (:use 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]]) (:import java.io.File @@ -39,18 +40,29 @@ Here's an example of getting some compute configuration from rackspace: (com.google.common.collect ImmutableSet))) (def module-lookup - {:log4j org.jclouds.logging.log4j.config.Log4JLoggingModule - :ssh org.jclouds.ssh.jsch.config.JschSshClientModule - :enterprise org.jclouds.enterprise.config.EnterpriseConfigurationModule}) + {:log4j 'org.jclouds.logging.log4j.config.Log4JLoggingModule + :ssh 'org.jclouds.ssh.jsch.config.JschSshClientModule + :enterprise 'org.jclouds.enterprise.config.EnterpriseConfigurationModule}) + +(defn- instantiate [sym] + (let [loader (.getContextClassLoader (Thread/currentThread))] + (try + (.newInstance #^Class (.loadClass loader (name sym))) + (catch java.lang.ClassNotFoundException e + (warn (str "Could not find " (name sym) " module. +Ensure the module is on the classpath. You are maybe missing a dependency on + org.jclouds/jclouds-jsch + org.jclouds/jclouds-log4j + or org.jclouds/jclouds-enterprise.")))))) (defn modules "Build a list of modules suitable for passing to compute-context" [& modules] (.build #^com.google.common.collect.ImmutableSet$Builder - (reduce #(.add #^com.google.common.collect.ImmutableSet$Builder %1 - (.newInstance #^Class (%2 module-lookup))) + (reduce #(.add #^com.google.common.collect.ImmutableSet$Builder %1 %2) (com.google.common.collect.ImmutableSet/builder) - modules))) + (filter (complement nil?) + (map (comp instantiate module-lookup) modules))))) (defn compute-context "Create a logged in context." diff --git a/compute/src/test/clojure/org/jclouds/compute_test.clj b/compute/src/test/clojure/org/jclouds/compute_test.clj index 14a1e2c0ca..a60450012d 100644 --- a/compute/src/test/clojure/org/jclouds/compute_test.clj +++ b/compute/src/test/clojure/org/jclouds/compute_test.clj @@ -2,5 +2,31 @@ (:use [org.jclouds.compute] :reload-all) (:use clojure.test)) +(defmacro with-private-vars [[ns fns] & tests] + "Refers private fns from ns and runs tests in context. From users mailing +list, Alan Dipert and MeikelBrandmeyer." + `(let ~(reduce #(conj %1 %2 `@(ns-resolve '~ns '~%2)) [] fns) + ~@tests)) + +(with-private-vars [org.jclouds.compute [instantiate]] + (deftest instantiate-test + (is (instance? String (instantiate 'java.lang.String))))) + (deftest os-families-test (is (some #{"centos"} (map str (os-families))))) + +(deftest modules-empty-test + (is (.isEmpty (modules)))) + +(deftest modules-instantiate-test + (binding [org.jclouds.compute/module-lookup + (assoc org.jclouds.compute/module-lookup + :string 'java.lang.String)] + (is (instance? String (first (modules :string)))) + (is (= 1 (count (modules :string)))))) + +(deftest modules-instantiate-fail-test + (binding [org.jclouds.compute/module-lookup + (assoc org.jclouds.compute/module-lookup + :non-existing 'this.doesnt.Exist)] + (is (.isEmpty (modules :non-existing)))))