Permalink
Browse files

Standalone install task implemented.

  • Loading branch information...
1 parent 5a421d3 commit 3bd0e36e7c6441d5ec029478c10c748d1f823e88 @technomancy committed Aug 11, 2010
Showing with 61 additions and 26 deletions.
  1. +54 −20 src/leiningen/install.clj
  2. +4 −3 src/leiningen/jar.clj
  3. +3 −3 todo.org
View
@@ -1,22 +1,32 @@
(ns leiningen.install
"Install the project and its dependencies in your local repository."
- (:use [leiningen.jar :only [jar manifest-map]]
- [leiningen.pom :only [pom make-model]]
+ (:use [leiningen.jar :only [jar manifest-map local-repo-path]]
+ [leiningen.pom :only [pom make-model default-repos]]
[leiningen.core :only [home-dir]]
[clojure.java.io :only [file copy]])
(:import [org.apache.maven.artifact.installer ArtifactInstaller]
[org.apache.maven.project.artifact ProjectArtifactMetadata]
[org.apache.maven.settings MavenSettingsBuilder]
- [org.apache.maven.artifact.repository ArtifactRepositoryFactory]
+ [org.apache.maven.artifact.repository ArtifactRepositoryFactory
+ DefaultArtifactRepository]
[org.apache.maven.artifact.factory ArtifactFactory]
+ [org.apache.maven.artifact.repository ArtifactRepositoryPolicy]
[org.apache.maven.artifact.repository.layout
ArtifactRepositoryLayout]
- [org.codehaus.plexus.embed Embedder]
- [java.util.jar JarFile]))
+ [java.util.jar JarFile]
+ [org.apache.maven.artifact.resolver ArtifactResolver]
+ [org.codehaus.plexus.embed Embedder]))
;; Welcome to the absurdist self-parodying world of Dependency Injection
(def container (.getContainer (doto (Embedder.) (.start))))
+(def layout (.lookup container ArtifactRepositoryLayout/ROLE "default"))
+
+(def policy
+ (ArtifactRepositoryPolicy. true
+ ArtifactRepositoryPolicy/UPDATE_POLICY_DAILY
+ ArtifactRepositoryPolicy/CHECKSUM_POLICY_FAIL))
+
(defn make-settings []
(.buildSettings (.lookup container MavenSettingsBuilder/ROLE)))
@@ -25,8 +35,12 @@
url (if (.startsWith path "file:") path (str "file://" path))]
(-> (.lookup container ArtifactRepositoryFactory/ROLE)
(.createDeploymentArtifactRepository
- "local" url (.lookup container ArtifactRepositoryLayout/ROLE "default")
- true))))
+ "local" url layout true))))
+
+(defn make-remote-repo [[name url]]
+ (-> (.lookup container ArtifactRepositoryFactory/ROLE)
+ (.createArtifactRepository
+ name url layout policy policy)))
(defn add-metadata [artifact pomfile]
(.addMetadata artifact (ProjectArtifactMetadata. artifact pomfile)))
@@ -51,18 +65,38 @@
(copy (.getInputStream jarfile (.getEntry jarfile bin-name)) bin-file)
(.setExecutable bin-file true))))
-(defn install
- "Install the project and its dependencies in your local repository."
- [project]
- (let [jarfile (file (jar project))
- model (make-model project)
- artifact (make-artifact model)
- installer (.lookup container ArtifactInstaller/ROLE)
+(defn make-remote-artifact [name group version]
+ (.createArtifact
+ (.lookup container ArtifactFactory/ROLE)
+ (or group name) name
+ version "compile" "jar"))
+
+(defn standalone-install [name group version]
+ (let [resolver (.lookup container ArtifactResolver/ROLE)
+ artifact (make-remote-artifact name group version)
+ remote-repos (map make-remote-repo default-repos)
local-repo (make-local-repo)]
- ;; for packaging other than "pom" there should be "pom.xml"
- ;; generated and installed in local repo
- (if (not= "pom" (.getPackaging model))
- (add-metadata artifact (file (pom project))))
- (install-shell-wrapper (JarFile. jarfile))
- (.install installer jarfile artifact local-repo)))
+ (.resolveAlways resolver artifact remote-repos local-repo)
+ (println (local-repo-path name group version))
+ (-> (local-repo-path name group version)
+ file
+ JarFile.
+ install-shell-wrapper)))
+(defn install
+ "Install the project and its dependencies in your local repository."
+ ([project]
+ (let [jarfile (file (jar project))
+ model (make-model project)
+ artifact (make-artifact model)
+ installer (.lookup container ArtifactInstaller/ROLE)
+ local-repo (make-local-repo)]
+ ;; for packaging other than "pom" there should be "pom.xml"
+ ;; generated and installed in local repo
+ (if (not= "pom" (.getPackaging model))
+ (add-metadata artifact (file (pom project))))
+ (install-shell-wrapper (JarFile. jarfile))
+ (.install installer jarfile artifact local-repo)))
+ ([_ project-name version]
+ (let [[name group] ((juxt name namespace) (symbol project-name))]
+ (standalone-install name (or group name) version))))
View
@@ -13,21 +13,22 @@
(.getResourceAsStream "script-template")
(slurp*)))
-(defn- classpath-path [group name version]
+(defn local-repo-path [name group version]
(format "$HOME/.m2/repository/%s/%s/%s/%s-%s.jar"
group name version name version))
(defn- script-classpath-for [project]
- (str (classpath-path (:group project) (:name project) (:version project)) ":"
+ (str (local-repo-path (:name project) (:group project) (:version project)) ":"
(join ":" (for [[dep version] (:dependencies project)
:let [group (or (namespace dep) (name dep))
group (.replaceAll group "\\." "/")]]
- (classpath-path group (name dep) version)))))
+ (local-repo-path (name dep) group version)))))
(defn- shell-wrapper-bin [project]
(or (:bin (:shell-wrapper project)
(format "bin/%s" (:name project)))))
+;; TODO: look for a custom bin in resources before using default one
(defn- shell-wrapper-filespecs [project]
(when (:shell-wrapper project)
(let [main (or (:main (:shell-wrapper project)) (:main project))
View
@@ -13,10 +13,10 @@ Leiningen TODOs
** TODO re-compile all deps with current clojure version
** TODO specify min. lein version in project.clj
* For 1.3.0
-** TODO lein install $PROJECT (works outside project root)
+** DONE lein install $PROJECT (works outside project root)
Possibly take some of this from cljr?
-** TODO write shell wrappers on install
-** TODO include shell wrapper in jar file from template
+** DONE write shell wrappers on install
+** DONE include shell wrapper in jar file from template
** DONE set arbitrary jar metadata
** DONE errors in read-project should show filename
** DONE user-level plugin installation and activation

0 comments on commit 3bd0e36

Please sign in to comment.