         cake.core
         [bake.core :only [log]]
         [clojure.string :only [join]]
-        [clojure.java.io :only [file copy reader]])
-  (:require [sherlock.core :as sherlock]))
+        [clojure.java.io :only [as-url file copy reader]])
+  (:require [sherlock.core :as sherlock])
+  (:import java.net.HttpURLConnection))
 
 (defn select-repos [repos]
   (let [repositories (:repositories *project*)]

      repositories)))

(defn hash-url [url]
  (str (sherlock/remote-index-url url) ".md5"))

(defn hash-location [url]
  (file (str (sherlock/index-location url) ".md5")))

(defn new-hash [url]
  (copy (reader (hash-url url)) (hash-location url)))

(defn published? [url]
  (try
    (= HttpURLConnection/HTTP_OK
       (.getResponseCode
        (doto (.openConnection (hash-url url))
          (.setRequestMethod "HEAD"))))
    (catch Exception _ false)))

(defn download-index [url]
  (sherlock/update-index url)
  (new-hash url))

(defn init-index [id url]
  (when (sherlock/download-needed? url)
    (log (str "Downloading index for " id ". This might take a bit."))
    (download-index url)))

(defn update-message [id url]
  (let [hash-location (hash-location url)]
    (when (and (.exists hash-location)
               (not= (slurp hash-location)
                     (slurp (hash-url url))))
      (println (format "The index for %s is out of date. Pass --update to update it." id)))))

(defn update-repo [id url]
  (log (str "Updating index for " id ". This might take a bit."))
  (download-index url))

(defn identifier [{:keys [group-id artifact-id]}]
  (if group-id
