diff --git a/leiningen-core/src/leiningen/core/classpath.clj b/leiningen-core/src/leiningen/core/classpath.clj index 42023c3b..3d34e46e 100644 --- a/leiningen-core/src/leiningen/core/classpath.clj +++ b/leiningen-core/src/leiningen/core/classpath.clj @@ -252,9 +252,14 @@ (get project dependencies-key) (apply get-dependencies dependencies-key project options))) +;http://stackoverflow.com/questions/5154754/why-is-file-isabsolute-platform-dependent-when-the-file-class-is-platform-inde (defn- normalize-path [root path] (let [f (io/file path)] - (.getAbsolutePath (if (.isAbsolute f) f (io/file root path))))) + (.getAbsolutePath (cond + ;(.isAbsolute f) f + (or (.isAbsolute f) (.startsWith (.getPath f) "\\")) f + :else + (io/file root path))))) (defn ext-dependency? "Should the given dependency be loaded in the extensions classloader?" diff --git a/leiningen-core/src/leiningen/core/utils.clj b/leiningen-core/src/leiningen/core/utils.clj index 6097309f..6063857a 100644 --- a/leiningen-core/src/leiningen/core/utils.clj +++ b/leiningen-core/src/leiningen/core/utils.clj @@ -92,3 +92,30 @@ (io/file (if (= :windows (get-os)) "NUL" "/dev/null"))) + +(defn fix-path-delimiters [input-str] + (clojure.string/replace input-str "/" java.io.File/separator)) + +;so paths would work under windows too which adds a drive letter and changes path separator +(defn pathify + " +pass only absolute paths, will throw if not +because if not absolute then .getAbsolutePath will resolve them relative to current directory + " + [in-str-or-file] + (cond (or + (nil? in-str-or-file) + (not (or + (.startsWith in-str-or-file "/") + (and + (>= (.length in-str-or-file) 3) + (= ":\\" (.substring in-str-or-file 1 3)) + ) + ) + ) + ) + (throw (new RuntimeException (str "bad usage, passed: `" in-str-or-file "`"))) + :else + (.getAbsolutePath (io/as-file in-str-or-file)))) + + diff --git a/leiningen-core/test/leiningen/core/test/classpath.clj b/leiningen-core/test/leiningen/core/test/classpath.clj index c42252e2..fd65a7fa 100644 --- a/leiningen-core/test/leiningen/core/test/classpath.clj +++ b/leiningen-core/test/leiningen/core/test/classpath.clj @@ -4,7 +4,8 @@ (:require [clojure.java.io :as io] [clojure.set :as set] [leiningen.core.user :as user] - [leiningen.core.project :as project])) + [leiningen.core.project :as project] + [leiningen.core.utils :as utils])) (use-fixtures :once (fn [f] @@ -20,7 +21,7 @@ [ring/ring-core "1.0.0" :exclusions [commons-codec]]] :checkout-deps-shares [:source-paths :resource-paths - :compile-path #(str (:root %) "/foo")] + :compile-path #(utils/pathify (str (:root %) "/foo"))] :repositories project/default-repositories :root "/tmp/lein-sample-project" :target-path "/tmp/lein-sample-project/target" @@ -51,9 +52,10 @@ (dependency-hierarchy :dependencies project)))) (def directories + (vec (map utils/pathify ["/tmp/lein-sample-project/test" "/tmp/lein-sample-project/src" - "/tmp/lein-sample-project/resources"]) + "/tmp/lein-sample-project/resources"]))) (def libs #{(str (m2-file "commons-io/commons-io/1.4/commons-io-1.4.jar")) @@ -75,7 +77,7 @@ (spit (io/file d1 "project.clj") (pr-str '(defproject hello "1.0"))) (is (= (for [path ["src" "resources" "target/classes" "foo"]] - (format "/tmp/lein-sample-project/checkouts/d1/%s" path)) + (utils/pathify (format "/tmp/lein-sample-project/checkouts/d1/%s" path))) (#'leiningen.core.classpath/checkout-deps-paths project))) (finally ;; can't recur from finally diff --git a/leiningen-core/test/leiningen/core/test/project.clj b/leiningen-core/test/leiningen/core/test/project.clj index c02ed57b..ca81c69b 100755 --- a/leiningen-core/test/leiningen/core/test/project.clj +++ b/leiningen-core/test/leiningen/core/test/project.clj @@ -54,11 +54,11 @@ (is (= v (k actual)))) (doseq [[k path] paths :when (string? path)] - (is (= (str (:root actual) "/" path) + (is (= (utils/pathify (str (:root actual) "/" path)) (k actual)))) (doseq [[k path] paths :when (coll? path)] - (is (= (for [p path] (str (:root actual) "/" p)) + (is (= (for [p path] (utils/pathify (str (:root actual) "/" p))) (k actual)))))) ;; TODO: test omit-default @@ -267,14 +267,14 @@ (project-with-profiles-meta p (merge @test-profiles (:profiles p))))] - (is (= ["/etc/myapp" "test/hi" "blue-resources" "resources"] + (is (= (vec (map utils/fix-path-delimiters ["/etc/myapp" "test/hi" "blue-resources" "resources"])) (-> (make (test-project {:resource-paths ["resources"] :profiles {:blue {:resource-paths ["blue-resources"]}}})) (merge-profiles [:blue :tes :qa]) :resource-paths))) - (is (= ["/etc/myapp" "test/hi" "blue-resources"] + (is (= (vec (map utils/fix-path-delimiters ["/etc/myapp" "test/hi" "blue-resources"])) (-> (make (test-project {:resource-paths ^:displace ["resources"] diff --git a/src/leiningen/new/plugin.clj b/src/leiningen/new/plugin.clj index 6dd390bd..bdb76286 100644 --- a/src/leiningen/new/plugin.clj +++ b/src/leiningen/new/plugin.clj @@ -3,7 +3,7 @@ (defn plugin "A leiningen plugin project template." - [name] + [^String name] (let [render (renderer "plugin") unprefixed (if (.startsWith name "lein-") (subs name 5) diff --git a/test/leiningen/test/new/templates.clj b/test/leiningen/test/new/templates.clj index dceb9eed..ff4955dd 100644 --- a/test/leiningen/test/new/templates.clj +++ b/test/leiningen/test/new/templates.clj @@ -3,6 +3,7 @@ leiningen.new.templates) (:require [leiningen.test.helper :refer [abort-msg]] [leiningen.core.user :as user] + [leiningen.core.utils :as utils] [clojure.java.io :as io]) (:import [java.io File])) @@ -52,7 +53,7 @@ (is (= (multi-segment "multi.segment" "last") "multi.segment"))) (deftest paths - (is (= (name-to-path "foo-bar.baz") "foo_bar/baz"))) + (is (= (name-to-path "foo-bar.baz") (utils/fix-path-delimiters "foo_bar/baz")))) (deftest renderers (is (.contains (abort-msg (renderer "my-template") "boom" {}) diff --git a/test/leiningen/test/pom.clj b/test/leiningen/test/pom.clj index b88e2745..4b79d8ed 100644 --- a/test/leiningen/test/pom.clj +++ b/test/leiningen/test/pom.clj @@ -6,6 +6,7 @@ [leiningen.test.helper :only [sample-project]]) (:require [clojure.data.xml :as xml] [leiningen.core.project :as project] + [leiningen.core.utils :as utils] [leiningen.core.main :as main])) (use-fixtures :once (fn [f] @@ -96,7 +97,7 @@ "target directory is included") (is (= nil (first-in xml [:project :build :extensions])) "no extensions") - (is (= "target/classes" (first-in xml [:project :build :outputDirectory])) + (is (= (utils/fix-path-delimiters "target/classes") (first-in xml [:project :build :outputDirectory])) "classes directory is included") (is (= ["org.clojure" "rome" "ring" "org.clojure" "clojure-complete"] (map #(first-in % [:dependency :groupId]) @@ -275,7 +276,7 @@ (first-in [:project :classifier]))))) (deftest test-pom-adds-java-source-paths - (is (= ["java/src" "java/another"] + (is (= (vec (map utils/fix-path-delimiters ["java/src" "java/another"])) (-> (make-pom (with-profile sample-project {:java-source-paths ["java/src" "java/another"]})) xml/parse-str diff --git a/test/leiningen/test/repl.clj b/test/leiningen/test/repl.clj index ad081d0c..be6482c2 100644 --- a/test/leiningen/test/repl.clj +++ b/test/leiningen/test/repl.clj @@ -1,7 +1,7 @@ (ns leiningen.test.repl (:require [clojure.test :refer :all] [leiningen.repl :refer :all] - (leiningen.core [user :as user] [project :as project]))) + (leiningen.core [user :as user] [project :as project] [utils :as utils]))) (deftest test-merge-repl-profile (is (= (-> {:repl-options {:ack-port 4}} @@ -61,13 +61,13 @@ "http://localhost:20" "http://localhost:20")) (deftest test-options-for-reply - (is (= "/home/user/.lein-repl-history" + (is (= (utils/fix-path-delimiters "/home/user/.lein-repl-history") (:history-file (options-for-reply {:root "/home/user"})))) (let [prompt-fn (fn [ns] "hi ")] (are [in exp] (= (merge - {:history-file (str (user/leiningen-home) "/repl-history") + {:history-file (utils/pathify (str (user/leiningen-home) "/repl-history")) :input-stream System/in} exp) (let [[prj-k prj-v arg-k arg-v] in]