Permalink
Browse files

write build config into pom

-  makes pom-as-project work in NetBeans Enclojure
  • Loading branch information...
1 parent 5961500 commit 1bbcf902f040d5b823647961cb8d35181b65716d @stuarthalloway stuarthalloway committed Mar 16, 2010
Showing with 28 additions and 2 deletions.
  1. +10 −2 src/leiningen/pom.clj
  2. +18 −0 test/test_pom.clj
View
@@ -3,7 +3,7 @@
(:use [clojure.contrib.duck-streams :only [reader copy]]
[clojure.contrib.java-utils :only [file as-properties]])
(:import [java.io StringWriter ByteArrayOutputStream]
- [org.apache.maven.model Model Parent Dependency Repository Scm]
+ [org.apache.maven.model Build Model Parent Dependency Repository Scm]
[org.apache.maven.project MavenProject]))
(def #^{:doc "A notice to place at the bottom of generated files."} disclaimer
@@ -85,14 +85,22 @@
"clojure-snapshots" "http://build.clojure.org/snapshots"
"clojars" "http://clojars.org/repo/"})
+(defn relative-path
+ [project path-key]
+ (.replace (path-key project) (str (:root project) "/") ""))
+
(defn make-model [project]
(let [model (doto (Model.)
(.setModelVersion "4.0.0")
(.setArtifactId (:name project))
(.setName (:name project))
(.setVersion (:version project))
(.setGroupId (:group project))
- (.setDescription (:description project)))]
+ (.setDescription (:description project)))
+ build (doto (Build.)
+ (.setSourceDirectory (relative-path project :source-path))
+ (.setTestSourceDirectory (relative-path project :test-path)))]
+ (.setBuild model build)
;; TODO: add leiningen as a test-scoped dependency
(doseq [dep (:dependencies project)]
(.addDependency model (make-dependency dep)))
View
@@ -0,0 +1,18 @@
+(ns test-pom
+ (:use [leiningen.core :only [read-project defproject]]
+ [leiningen.pom :only [pom make-model]])
+ (:use [clojure.test]
+ [clojure.contrib.java-utils :only [file delete-file]]))
+
+(def test-project (read-project "sample/project.clj"))
+
+(deftest test-pom
+ (let [pom-file (file (:root test-project) "pom.xml")]
+ (delete-file pom-file true)
+ (pom test-project)
+ (is (.exists pom-file))))
+
+(deftest test-make-model-includes-build-settings
+ (let [model (make-model test-project)]
+ (is (= "src" (-> model .getBuild .getSourceDirectory)))
+ (is (= "test" (-> model .getBuild .getTestSourceDirectory)))))

0 comments on commit 1bbcf90

Please sign in to comment.