 
 ;; === lein entrypoint ===
 
+(defn wrap-expected-version-helper [kargset]
+  (->
+   (->>
+    (map name kargset)
+    (filter #(.startsWith ^String % "expected-version--")))
+   first
+   (s/replace-first #"expected-version--" "")
+   (ver-parse)))
+
+(defn- wrap-version-correction-helper
+  "Unfortunately, we need this fix forever...
+  The original voom versions created used a 12hr format, discarding
+  24hr information. Once this was fixed, voom was unable to satisfy
+  old, 12hr truncated dependencies. The this function detects this
+  case and will generate a 12hr truncated version if requested. It
+  still ensures that the sha is identical and will only adjust the
+  time when the old version of voom would have truncated the hours."
+  [expected-version found-version]
+  (if (= found-version expected-version)
+    found-version
+    (do
+      (assert (= (:sha expected-version) (:sha found-version)))
+      (let [^Date found-date (:ctime found-version)
+            ^Calendar found-cal (Calendar/getInstance
+                                 (java.util.SimpleTimeZone. 0 "GMT")
+                                 java.util.Locale/US)
+            _ (.setTime found-cal found-date)
+            adjusted-hours (mod (.get found-cal Calendar/HOUR_OF_DAY) 12)
+            _ (.set found-cal Calendar/HOUR_OF_DAY adjusted-hours)
+            ^Date adjusted-date (.getTime found-cal)]
+        (if (= adjusted-date (:ctime expected-version))
+          (do
+            ;; TODO: Unfortunately, the recursive build-deps calls are
+            ;; eating this warning. Find a way to get message back to user.
+            (binding [*out* *err*]
+              (println (str "Found and fixed 24hr->12hr legacy voom version: "
+                            (pr-str found-version :--> expected-version))))
+            expected-version)
+          (throw (ex-info "Could not resolve expected vs found timestamps."
+                          {:expected-version expected-version :found-version found-version})))))))
+
 (defn wrap
   "Execute any lein task, but using git info as this project's version qualifier.
 

     foo-1.2.3-20120219_223112-abc123f
     /path/to/foo-1.2.3-20120219_223112-gabc123f19ea8d29b13.jar"
  [ver-str]
  (let [[_ ctime sha] (re-matches #".*-?([0-9]{8}_?[0-9]{6})-g?([a-f0-9]{4,40})(?:\.jar)?$" ver-str)]
    (when (and ctime sha)
      {:ctime (s/replace ctime #"_" "") :sha sha})))

(defn dirty-wc?
  [path]

            sha-candidates)))

(defn install-versioned-artifact
  [version proot]
  (println "Calling recursive build-deps on:" proot)
  (print (:out (sh "lein" "voom" "build-deps" :dir proot)))
  ;; BEWARE: Allowing dirty working copy here is ONLY OK because the
  ;; working copy in question was just checked out and cleaned using
  ;; 'safe-checkout in 'find-matching-projects above:
  (let [install-cmd ["lein" "voom" "wrap" ":insanely-allow-dirty-working-copy"
                     (str ":expected-version--" version)
                     "install" :dir proot]
        _ (apply println "install-versioned-artifact:" install-cmd)
        rtn (apply sh install-cmd)]
