 
 (defn start-process-directly
   [process path func]
-  (let [project-map-orig (read-project-clj path)
-        jvm-opts (conj (:jvm-opts project-map-orig)
+  (let [project-orig (read-project-clj path)
+        jvm-opts (conj (:jvm-opts project-orig)
                        (str "-agentlib:jdwp="
                             "transport=dt_socket,"
                             "server=y,"
                             "suspend=n,"
                             "address="
                             debug-port))
-        project-map (-> project-map-orig
-                        (assoc :eval-in :trampoline
-                               :jvm-opts jvm-opts))
+        project (-> project-orig
+                    (assoc :eval-in :trampoline
+                           :jvm-opts jvm-opts))
         forms leiningen.core.eval/trampoline-forms
         profiles leiningen.core.eval/trampoline-profiles]
     (reset! forms [])
     (reset! profiles [])
-    (func path project-map)
+    (func path project)
     (doseq [i (range (count @forms))]
-      (->> (leiningen.core.eval/shell-command project-map (nth @forms i))
+      (->> (leiningen.core.eval/shell-command project (nth @forms i))
            (start-process process path)))))
 
 (defn stop-process

; low-level commands

(defn run-project-task
  [path project-map]
  (if (is-android-project? path)
    (doseq [sub-cmd ["build" "apk" "install" "run"]]
      (leiningen.droid/droid (add-sdk-path project-map) sub-cmd))
    (leiningen.run/run project-map)))

(defn run-repl-project-task
  [path project-map]
  (if (is-android-project? path)
    (doseq [sub-cmd ["doall" "repl"]]
      (leiningen.droid/droid (add-sdk-path project-map) sub-cmd)
      (Thread/sleep 10000))
    (leiningen.repl/repl project-map)))

(defn build-project-task
  [path project-map]
  (if (is-android-project? path)
    (-> (leiningen.droid/transform-into-release project-map)
        add-sdk-path
        leiningen.droid/execute-release-routine)
    (leiningen.uberjar/uberjar project-map)))

(defn test-project-task
  [path project-map]
  (leiningen.test/test project-map))

(defn clean-project-task
  [path project-map]
  (leiningen.clean/clean project-map))

(defn cljsbuild-project-task
  [path project-map]
  (leiningen.cljsbuild/cljsbuild project-map "auto"))

(defn hot-swap-project-task
  [path project-map]
  (when-let [conn (->> (Bootstrap/virtualMachineManager)
                       .attachingConnectors
                       (filter #(= (.name (.transport %)) "dt_socket"))
                       first)]
     (let [prm (.defaultArguments conn)
           stale-classes (-> (:java-source-paths project-map)
                             (stale-java-classes (:compile-path project-map))
                             doall)]
       (.setValue (.get prm "port") debug-port)
       (.setValue (.get prm "hostname") "127.0.0.1")
       (when-let [vm (try (.attach conn prm) (catch Exception _))]
         (leiningen.javac/javac project-map)
         (->> stale-classes
              (create-class-map (.allClasses vm))
              (.redefineClasses vm))

           (leiningen.new.templates/->files data)))))

(defn stale-java-classes
  [project]
  (for [dir (:java-source-paths project)
        source (filter #(-> % (.getName) (.endsWith ".java"))
                       (file-seq (java.io/file dir)))
        :let [rel-source (.substring (.getPath source) (inc (count dir)))
              rel-compiled (.replaceFirst rel-source "\\.java$" ".class")
              compiled (java.io/file (:compile-path project) rel-compiled)]
        :when (>= (.lastModified source) (.lastModified compiled))]
    (.getPath compiled)))

