Skip to content
This repository has been archived by the owner on Jan 3, 2023. It is now read-only.

Leiningen projects with java sources. #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ classes
lein-eclipse.jar
lib
pom.xml
/lein-eclipse-1.1.0-SNAPSHOT.jar
9 changes: 4 additions & 5 deletions project.clj
Original file line number Diff line number Diff line change
@@ -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"]])
110 changes: 46 additions & 64 deletions src/leiningen/eclipse.clj
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
(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
Expand All @@ -22,69 +19,54 @@
[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"}]
(if (directory? (:java-source-path project))
[:classpathentry {:kind "src" :path (noroot (:java-source-path project))}])
[:classpathentry
{:kind "output" :path (noroot (:compile-path project))}]
(for [path (get-classpath project)]
[:classpathentry
(if (.isDirectory (File. (str path)))
{:kind "src" :path (noroot path)}
{:kind "lib" :path (noroot path)})])])))

(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")))