Skip to content
This repository has been archived by the owner on Jun 2, 2018. It is now read-only.

Commit

Permalink
Make pom a top-level command.
Browse files Browse the repository at this point in the history
  • Loading branch information
technomancy committed Jul 8, 2009
1 parent 233487f commit a2ac3d0
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 52 deletions.
4 changes: 4 additions & 0 deletions README.markdown
Expand Up @@ -52,6 +52,10 @@ try to fetch them from the Internet.

Starts a REPL with the project's classpath and dependencies set up.

$ corkscrew pom [project-dir]

Write the pom.xml file to the project root. Intended for debugging.

## Planned Features

$ corkscrew compile [project-dir] [output-jar]
Expand Down
1 change: 1 addition & 0 deletions bin/corkscrew
Expand Up @@ -15,6 +15,7 @@ case $1 in
build) CLASS=cork.screw.build;;
deps) CLASS=cork.screw.deps;;
install) CLASS=cork.screw.install;;
pom) CLASS=cork.screw.pom;;
repl)
CLASSPATH="src/:target/classes/:target/dependency/:$CLASSPATH"
cd "$PROJECT_ROOT"
Expand Down
53 changes: 3 additions & 50 deletions src/cork/screw/deps/maven.clj
@@ -1,56 +1,9 @@
(ns cork.screw.deps.maven
(:require [clojure.xml :as xml])
;; (:import [org.apache.maven.cli MavenCli])
(:use [clojure.contrib.duck-streams :only [spit writer]]
[clojure.contrib.shell-out :only [sh]]
(:use [clojure.contrib.shell-out :only [sh]]
[clojure.contrib.java-utils :only [file]]
[cork.screw.utils :only [with-preserving-file]]))

(defn dependency-xml
"A tree structure (for XML conversion) representing a single dependency."
[[artifact version & [group]]]
{:tag :dependency :content [{:tag :artifactId :content [artifact]}
{:tag :groupId :content [(or group artifact)]}
{:tag :version :content [version]}]})

(defn pom-for
"A tree structure representing the project's POM for XML conversion."
[project]
(let [name (:name project)
version (:version project)
group (or (:group project) (:name project))
dependencies (:dependencies project)]
{:tag :project
:attrs {:xmlns "http://maven.apache.org/POM/4.0.0"
:xmlns:xsi "http://www.w3.org/2001/XMLSchema-instance"
:xsi:schemaLocation (str "http://maven.apache.org/POM/4.0.0 "
"http://maven.apache.org/xsd/maven-4.0.0.xsd")}
:content [{:tag :modelVersion :content ["4.0.0"]}
{:tag :parent
:content [{:tag :artifactId :content ["clojure-pom"]}
{:tag :groupId :content ["org.clojure"]}
{:tag :version :content ["1.0-SNAPSHOT"]}]}
{:tag :artifactId :content [name]}
{:tag :name :content [name]}
{:tag :groupId :content [group]}
{:tag :version :content [version]}
{:tag :dependencies
:content (map dependency-xml dependencies)}
{:tag :repositories
:content [{:tag :repository
:content [{:tag :id :content ["technomancy"]}
{:tag :url :content
["http://repo.technomancy.us/maven2"]}]}
{:tag :repository
:content [{:tag :id :content ["central"]}
{:tag :url :content
["http://repo1.maven.org/maven2"]}]}]}]}))

(defn write-pom [project]
(binding [*out* (writer (str (:root project) "/pom.xml"))
println print]
(xml/emit (pom-for project))
(flush)))
[cork.screw.utils :only [with-preserving-file]]
[cork.screw.pom :only [write-pom]]))

;; TODO: Shelling out to mvn is laaame. We should eventually be able
;; to call the Maven API from Java, possibly by constructing a
Expand Down
2 changes: 1 addition & 1 deletion src/cork/screw/deps/svn.clj
Expand Up @@ -5,7 +5,7 @@
(defmethod cork.screw.deps/fetch-source-dependency :svn
[[name version type url]]
(let [dir (file (str cork.screw.deps/corkscrew-dir
"svn/" name "/" version "/"))]
"/svn/" name "/" version "/"))]
(when (or cork.screw.deps/*force-fetch*
(not (.exists dir)))
(.mkdirs (.getParentFile dir))
Expand Down
55 changes: 55 additions & 0 deletions src/cork/screw/pom.clj
@@ -0,0 +1,55 @@
(ns cork.screw.pom
(:use [clojure.contrib.duck-streams :only [writer]]
[clojure.contrib.java-utils :only [file]]
[cork.screw.utils :only [read-project]])
(:require [clojure.xml :as xml])
(:gen-class))

(defn dependency-xml
"A tree structure (for XML conversion) representing a single dependency."
[[artifact version & [group]]]
{:tag :dependency :content [{:tag :artifactId :content [artifact]}
{:tag :groupId :content [(or group artifact)]}
{:tag :version :content [version]}]})

(defn repository-xml
"A seq of trees represeting XML for repository list."
[[id url]]
{:tag :repository :content [{:tag :id :content [id]}
{:tag :url :content [url]}]})

(defn pom-for
"A tree structure representing the project's POM for XML conversion."
[project]
(let [name (:name project)
version (:version project)
group (or (:group project) (:name project))
dependencies (:dependencies project)
repositories (:repositories project)]
{:tag :project
:attrs {:xmlns "http://maven.apache.org/POM/4.0.0"
:xmlns:xsi "http://www.w3.org/2001/XMLSchema-instance"
:xsi:schemaLocation (str "http://maven.apache.org/POM/4.0.0 "
"http://maven.apache.org/xsd/maven-4.0.0.xsd")}
:content [{:tag :modelVersion :content ["4.0.0"]}
{:tag :artifactId :content [name]}
{:tag :name :content [name]}
{:tag :groupId :content [group]}
{:tag :version :content [version]}
{:tag :dependencies
:content (map dependency-xml dependencies)}
{:tag :repositories
:content (map repository-xml
(assoc repositories "technomancy"
"http://repo.technomancy.us/"))}]}))

(defn write-pom [project]
(binding [*out* (writer (str (:root project) "/pom.xml"))
println print]
(xml/emit (pom-for project))
(flush)))

(defn -main
([] (-main "."))
([target-dir]
(write-pom (read-project (file target-dir "project.clj")))))
2 changes: 1 addition & 1 deletion src/cork/screw/utils.clj
Expand Up @@ -50,4 +50,4 @@
(finally
(if (.exists temp-file#)
(copy-file temp-file# ~file-name)
(.delete (file ~file-name)))))))
(.delete (file temp-file#)))))))

0 comments on commit a2ac3d0

Please sign in to comment.