From 73b62f096cb20f69ee54100c82ba87025fc34cef Mon Sep 17 00:00:00 2001 From: Roman Date: Fri, 1 Apr 2011 12:34:06 +0200 Subject: [PATCH 1/2] Added support for projects that have java sources by using Leiningen's get-classpath fn. --- .gitignore | 1 + project.clj | 9 ++-- src/leiningen/eclipse.clj | 110 +++++++++++++++----------------------- 3 files changed, 47 insertions(+), 73 deletions(-) diff --git a/.gitignore b/.gitignore index 27f74e3..57723e2 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ classes lein-eclipse.jar lib pom.xml +/lein-eclipse-1.1.0-SNAPSHOT.jar diff --git a/project.clj b/project.clj index 503e1d1..b9e92a3 100644 --- a/project.clj +++ b/project.clj @@ -1,6 +1,5 @@ -(defproject lein-eclipse "1.0.0" +(defproject lein-eclipse "1.1.0-SNAPSHOT" :description "A leiningen plugin to create Eclipse project descriptor files." - :dev-dependencies [[org.clojure/clojure "1.1.0"] - [org.clojure/clojure-contrib "1.1.0"] - [leiningen "1.1.0"] - [lein-clojars "0.5.0"]]) + :dependencies [[org.clojure/clojure "1.2.0"] + [org.clojure/clojure-contrib "1.2.0"]] + :dev-dependencies [[leiningen "1.5.0"]]) diff --git a/src/leiningen/eclipse.clj b/src/leiningen/eclipse.clj index ca17912..17871ae 100644 --- a/src/leiningen/eclipse.clj +++ b/src/leiningen/eclipse.clj @@ -1,90 +1,64 @@ (ns leiningen.eclipse "Create Eclipse project descriptor files." - (:use [clojure.contrib.duck-streams :only [with-out-writer]]) - (:use [clojure.contrib.java-utils :only [file]]) - (:use [clojure.contrib.prxml :only [prxml *prxml-indent*]]) - (:use [clojure.contrib.str-utils :only [re-sub]]) - (:use [leiningen.deps :only [deps]]) - (:import [java.io File]) - (:import [java.util.regex Pattern])) - -;; copied from jar.clj -(defn- unix-path - [path] - (.replaceAll path "\\\\" "/")) + (:import [java.io File] + [java.util.regex Pattern]) + (:use [clojure.contrib.duck-streams :only [with-out-writer]] + [clojure.contrib.java-utils :only [file]] + [clojure.contrib.prxml :only [prxml *prxml-indent*]] + [clojure.contrib.str-utils :only [re-sub]] + [leiningen.classpath :only (get-classpath)] + [leiningen.deps :only [deps]] + [leiningen.jar :only (unix-path)])) ;; copied from jar.clj (defn- trim-leading-str [s to-trim] (re-sub (re-pattern (str "^" (Pattern/quote to-trim))) "" s)) -(defn- directory? - [arg] - (.isDirectory (File. arg))) - -(defn- list-libraries - [project] - (map #(.getPath %) (.listFiles (File. (:library-path project))))) - -(defn- create-classpath +(defn- print-classpath "Print .classpath to *out*." [project] (let [root (str (unix-path (:root project)) \/) - noroot #(trim-leading-str (unix-path %) root) - [resources-path compile-path source-path test-path] - (map noroot (map project [:resources-path - :compile-path - :source-path - :test-path]))] - (prxml [:decl!] - [:classpath - (if (directory? source-path) - [:classpathentry {:kind "src" - :path source-path}]) - (if (directory? resources-path) - [:classpathentry {:kind "src" - :path resources-path}]) - (if (directory? test-path) - [:classpathentry {:kind "src" - :path test-path}]) - [:classpathentry {:kind "con" - :path "org.eclipse.jdt.launching.JRE_CONTAINER"}] - (for [library (list-libraries project)] - [:classpathentry {:kind "lib" - :path (noroot library)}]) - [:classpathentry {:kind "output" - :path compile-path}] - ]))) + noroot #(trim-leading-str (unix-path (str %)) root)] + (prxml + [:decl!] + [:classpath + [:classpathentry + {:kind "con" :path "org.eclipse.jdt.launching.JRE_CONTAINER"}] + [:classpathentry + {:kind "output" :path (noroot (:compile-path project))}] + (for [library (get-classpath project)] + [:classpathentry + {:kind "lib" :path (noroot library)}])]))) -(defn- create-project +(defn- print-project "Print .project to *out*." [project] - (prxml [:decl!] - [:projectDescription - [:name (:name project)] - [:comment (:description project)] - [:projects] - [:buildSpec - [:buildCommand - [:name "ccw.builder"] - [:arguments]] - [:buildCommand - [:name "org.eclipse.jdt.core.javabuilder"] - [:arguments]]] - [:natures - [:nature "ccw.nature"] - [:nature "org.eclipse.jdt.core.javanature"]]])) + (prxml + [:decl!] + [:projectDescription + [:name (:name project)] + [:comment (:description project)] + [:projects] + [:buildSpec + [:buildCommand + [:name "ccw.builder"] + [:arguments]] + [:buildCommand + [:name "org.eclipse.jdt.core.javabuilder"] + [:arguments]]] + [:natures + [:nature "ccw.nature"] + [:nature "org.eclipse.jdt.core.javanature"]]])) (defn eclipse "Create Eclipse project descriptor files." [project] (deps project) (binding [*prxml-indent* 2] - (with-out-writer - (file (:root project) ".classpath") - (create-classpath project)) + (with-out-writer (file (:root project) ".classpath") + (print-classpath project)) (println "Created .classpath") - (with-out-writer - (file (:root project) ".project") - (create-project project)) + (with-out-writer (file (:root project) ".project") + (print-project project)) (println "Created .project"))) From 4a7292c44c4495c4a664d2d07ea95dfe299f9c56 Mon Sep 17 00:00:00 2001 From: Roman Date: Fri, 1 Apr 2011 13:13:08 +0200 Subject: [PATCH 2/2] Add directories as source type, not lib. --- src/leiningen/eclipse.clj | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/leiningen/eclipse.clj b/src/leiningen/eclipse.clj index 17871ae..afa2e3b 100644 --- a/src/leiningen/eclipse.clj +++ b/src/leiningen/eclipse.clj @@ -15,6 +15,10 @@ [s to-trim] (re-sub (re-pattern (str "^" (Pattern/quote to-trim))) "" s)) +(defn- directory? + [arg] + (.isDirectory (File. arg))) + (defn- print-classpath "Print .classpath to *out*." [project] @@ -25,11 +29,15 @@ [:classpath [:classpathentry {:kind "con" :path "org.eclipse.jdt.launching.JRE_CONTAINER"}] + (if (directory? (:java-source-path project)) + [:classpathentry {:kind "src" :path (noroot (:java-source-path project))}]) [:classpathentry {:kind "output" :path (noroot (:compile-path project))}] - (for [library (get-classpath project)] + (for [path (get-classpath project)] [:classpathentry - {:kind "lib" :path (noroot library)}])]))) + (if (.isDirectory (File. (str path))) + {:kind "src" :path (noroot path)} + {:kind "lib" :path (noroot path)})])]))) (defn- print-project "Print .project to *out*."