Permalink
Browse files

initial commit

  • Loading branch information...
0 parents commit 6a85d944b12ff1898cdf1c7f45715b5171170b12 @cemerick committed Oct 4, 2011
Showing with 572 additions and 0 deletions.
  1. +15 −0 .gitignore
  2. +73 −0 README.asciidoc
  3. +260 −0 epl-v10.html
  4. +99 −0 pom.xml
  5. +59 −0 src/main/clojure/cemerick/pomegranate.clj
  6. +66 −0 src/main/clojure/cemerick/pomegranate/aether.clj
15 .gitignore
@@ -0,0 +1,15 @@
+# emacs + vi backup files
+*~
+.*.sw*
+
+# various IDE junk
+*.ipr
+*.iml
+*.iws
+.project
+.classpath
+.settings
+
+target
+classes
+it-repo
73 README.asciidoc
@@ -0,0 +1,73 @@
+= Pomegranate
+
+http://github.com/cemerick/pomegranate[Pomegranate] is a library that provides:
+
+1. A very, _very_ incomplete wrapper for Sonatype https://github.com/sonatype/sonatype-aether[Aether] — really, just dependency resolution at this point.
+2. A re-implementation of http://clojure.github.com/clojure/clojure.core-api.html#clojure.core/add-classpath[`add-classpath`] (deprecated in Clojure core) that:
+
+ * is a little more comprehensive than core's `add-classpath` — it should work as expected in more circumstances, and
+ * optionally uses Aether to add a Maven artifact (and all of its transitive dependencies) to your Clojure runtime's classpath dynamically.
+
+Insofar as most useful Clojure libraries have dependencies, any reasonable implementation of the `add-classpath` concept must seamlessly support resolving those dependencies IMO.
+
+== Status
+
+This library is functionally completely new; literally, v0.0.1. There will be changes. In any case, it's obviously incomplete.
+
+== "Installation"
+
+Pomegranate is available in Maven central. Add it to your Leiningen/Cake `project.clj`:
+
+----
+[com.cemerick/pomegranate "0.0.1"]
+----
+
+or to your Maven project's `pom.xml`:
+
+----
+<dependency>
+ <groupId>com.cemerick</groupId>
+ <artifactId>pomegranate</artifactId>
+ <version>0.0.1</version>
+</dependency>
+----
+
+== Usage
+
+Just to set a stage: you're at the REPL, and you've got some useful data that you'd like to munge and analyze in various ways. Maybe it's something you've generated locally, maybe it's data on a production machine and you're logged in via http://github.com/clojure/tools.nrepl[nREPL]. In any case, you'd like to work with the data, but realize that you don't have the libraries you need do what you want. Your choices at this point are:
+
+1. Dump the data to disk via `pr` (assuming it's just Clojure data structures!), and start up a new Clojure process with the appropriate libraries on the classpath. This can really suck if the data is in a remote environment.
+2. There is no second choice. You _could_ use `add-claspath`, but the library you want has 12 bajillion dependencies, and there's no way you're going to hunt them down manually.
+
+Let's say we want to use [Incanter] (which has roughly 40 dependencies — close enough to a 12 bajillion for all practical purposes!):
+
+----
+=> (require '(incanter core stats charts))
+#<CompilerException java.io.FileNotFoundException:
+ Could not locate incanter/core__init.class or incanter/core.clj on classpath: (NO_SOURCE_FILE:0)>
+----
+
+Looks bleak. Assuming you've got Pomegranate on your classpath already, you can do this though:
+
+----
+=> (add-dependencies '[[incanter "1.2.3"]]
+ :repositories {"clojars" "http://clojars.org/repo"})
+nil
+=> (require '(incanter core stats charts))
+nil
+----
+
+Now you can analyze and chart away, Incanter having been added to your runtime. Note that `add-dependencies` may crunch along for a while — it may need to download dependencies, so you're waiting on the network. All resolved dependencies are stored in the default local repository (`~/.m2/repository`), and if they are found there, then they are not downloaded.
+
+The arguments to `add-dependencies` look like Leiningen-style notation, and they are. But support for that is definitely incomplete, e.g. repositories may only be string URLs (no authentication, mirroring, etc. is supported).
+
+== Need Help?
+
+Ping `cemerick` on freenode irc or twitter if you have questions
+or would like to contribute patches.
+
+== License
+
+Copyright © 2011 Chas Emerick
+
+Licensed under the EPL. (See the file epl-v10.html.)
260 epl-v10.html
@@ -0,0 +1,260 @@
+<?xml version="1.0" encoding="ISO-8859-1" ?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
+<title>Eclipse Public License - Version 1.0</title>
+<style type="text/css">
+ body {
+ size: 8.5in 11.0in;
+ margin: 0.25in 0.5in 0.25in 0.5in;
+ tab-interval: 0.5in;
+ }
+ p {
+ margin-left: auto;
+ margin-top: 0.5em;
+ margin-bottom: 0.5em;
+ }
+ p.list {
+ margin-left: 0.5in;
+ margin-top: 0.05em;
+ margin-bottom: 0.05em;
+ }
+ </style>
+
+</head>
+
+<body lang="EN-US">
+
+<p align=center><b>Eclipse Public License - v 1.0</b></p>
+
+<p>THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE
+PUBLIC LICENSE (&quot;AGREEMENT&quot;). ANY USE, REPRODUCTION OR
+DISTRIBUTION OF THE PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS
+AGREEMENT.</p>
+
+<p><b>1. DEFINITIONS</b></p>
+
+<p>&quot;Contribution&quot; means:</p>
+
+<p class="list">a) in the case of the initial Contributor, the initial
+code and documentation distributed under this Agreement, and</p>
+<p class="list">b) in the case of each subsequent Contributor:</p>
+<p class="list">i) changes to the Program, and</p>
+<p class="list">ii) additions to the Program;</p>
+<p class="list">where such changes and/or additions to the Program
+originate from and are distributed by that particular Contributor. A
+Contribution 'originates' from a Contributor if it was added to the
+Program by such Contributor itself or anyone acting on such
+Contributor's behalf. Contributions do not include additions to the
+Program which: (i) are separate modules of software distributed in
+conjunction with the Program under their own license agreement, and (ii)
+are not derivative works of the Program.</p>
+
+<p>&quot;Contributor&quot; means any person or entity that distributes
+the Program.</p>
+
+<p>&quot;Licensed Patents&quot; mean patent claims licensable by a
+Contributor which are necessarily infringed by the use or sale of its
+Contribution alone or when combined with the Program.</p>
+
+<p>&quot;Program&quot; means the Contributions distributed in accordance
+with this Agreement.</p>
+
+<p>&quot;Recipient&quot; means anyone who receives the Program under
+this Agreement, including all Contributors.</p>
+
+<p><b>2. GRANT OF RIGHTS</b></p>
+
+<p class="list">a) Subject to the terms of this Agreement, each
+Contributor hereby grants Recipient a non-exclusive, worldwide,
+royalty-free copyright license to reproduce, prepare derivative works
+of, publicly display, publicly perform, distribute and sublicense the
+Contribution of such Contributor, if any, and such derivative works, in
+source code and object code form.</p>
+
+<p class="list">b) Subject to the terms of this Agreement, each
+Contributor hereby grants Recipient a non-exclusive, worldwide,
+royalty-free patent license under Licensed Patents to make, use, sell,
+offer to sell, import and otherwise transfer the Contribution of such
+Contributor, if any, in source code and object code form. This patent
+license shall apply to the combination of the Contribution and the
+Program if, at the time the Contribution is added by the Contributor,
+such addition of the Contribution causes such combination to be covered
+by the Licensed Patents. The patent license shall not apply to any other
+combinations which include the Contribution. No hardware per se is
+licensed hereunder.</p>
+
+<p class="list">c) Recipient understands that although each Contributor
+grants the licenses to its Contributions set forth herein, no assurances
+are provided by any Contributor that the Program does not infringe the
+patent or other intellectual property rights of any other entity. Each
+Contributor disclaims any liability to Recipient for claims brought by
+any other entity based on infringement of intellectual property rights
+or otherwise. As a condition to exercising the rights and licenses
+granted hereunder, each Recipient hereby assumes sole responsibility to
+secure any other intellectual property rights needed, if any. For
+example, if a third party patent license is required to allow Recipient
+to distribute the Program, it is Recipient's responsibility to acquire
+that license before distributing the Program.</p>
+
+<p class="list">d) Each Contributor represents that to its knowledge it
+has sufficient copyright rights in its Contribution, if any, to grant
+the copyright license set forth in this Agreement.</p>
+
+<p><b>3. REQUIREMENTS</b></p>
+
+<p>A Contributor may choose to distribute the Program in object code
+form under its own license agreement, provided that:</p>
+
+<p class="list">a) it complies with the terms and conditions of this
+Agreement; and</p>
+
+<p class="list">b) its license agreement:</p>
+
+<p class="list">i) effectively disclaims on behalf of all Contributors
+all warranties and conditions, express and implied, including warranties
+or conditions of title and non-infringement, and implied warranties or
+conditions of merchantability and fitness for a particular purpose;</p>
+
+<p class="list">ii) effectively excludes on behalf of all Contributors
+all liability for damages, including direct, indirect, special,
+incidental and consequential damages, such as lost profits;</p>
+
+<p class="list">iii) states that any provisions which differ from this
+Agreement are offered by that Contributor alone and not by any other
+party; and</p>
+
+<p class="list">iv) states that source code for the Program is available
+from such Contributor, and informs licensees how to obtain it in a
+reasonable manner on or through a medium customarily used for software
+exchange.</p>
+
+<p>When the Program is made available in source code form:</p>
+
+<p class="list">a) it must be made available under this Agreement; and</p>
+
+<p class="list">b) a copy of this Agreement must be included with each
+copy of the Program.</p>
+
+<p>Contributors may not remove or alter any copyright notices contained
+within the Program.</p>
+
+<p>Each Contributor must identify itself as the originator of its
+Contribution, if any, in a manner that reasonably allows subsequent
+Recipients to identify the originator of the Contribution.</p>
+
+<p><b>4. COMMERCIAL DISTRIBUTION</b></p>
+
+<p>Commercial distributors of software may accept certain
+responsibilities with respect to end users, business partners and the
+like. While this license is intended to facilitate the commercial use of
+the Program, the Contributor who includes the Program in a commercial
+product offering should do so in a manner which does not create
+potential liability for other Contributors. Therefore, if a Contributor
+includes the Program in a commercial product offering, such Contributor
+(&quot;Commercial Contributor&quot;) hereby agrees to defend and
+indemnify every other Contributor (&quot;Indemnified Contributor&quot;)
+against any losses, damages and costs (collectively &quot;Losses&quot;)
+arising from claims, lawsuits and other legal actions brought by a third
+party against the Indemnified Contributor to the extent caused by the
+acts or omissions of such Commercial Contributor in connection with its
+distribution of the Program in a commercial product offering. The
+obligations in this section do not apply to any claims or Losses
+relating to any actual or alleged intellectual property infringement. In
+order to qualify, an Indemnified Contributor must: a) promptly notify
+the Commercial Contributor in writing of such claim, and b) allow the
+Commercial Contributor to control, and cooperate with the Commercial
+Contributor in, the defense and any related settlement negotiations. The
+Indemnified Contributor may participate in any such claim at its own
+expense.</p>
+
+<p>For example, a Contributor might include the Program in a commercial
+product offering, Product X. That Contributor is then a Commercial
+Contributor. If that Commercial Contributor then makes performance
+claims, or offers warranties related to Product X, those performance
+claims and warranties are such Commercial Contributor's responsibility
+alone. Under this section, the Commercial Contributor would have to
+defend claims against the other Contributors related to those
+performance claims and warranties, and if a court requires any other
+Contributor to pay any damages as a result, the Commercial Contributor
+must pay those damages.</p>
+
+<p><b>5. NO WARRANTY</b></p>
+
+<p>EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS
+PROVIDED ON AN &quot;AS IS&quot; BASIS, WITHOUT WARRANTIES OR CONDITIONS
+OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION,
+ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY
+OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is solely
+responsible for determining the appropriateness of using and
+distributing the Program and assumes all risks associated with its
+exercise of rights under this Agreement , including but not limited to
+the risks and costs of program errors, compliance with applicable laws,
+damage to or loss of data, programs or equipment, and unavailability or
+interruption of operations.</p>
+
+<p><b>6. DISCLAIMER OF LIABILITY</b></p>
+
+<p>EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT
+NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT,
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING
+WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF
+LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OR
+DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
+HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.</p>
+
+<p><b>7. GENERAL</b></p>
+
+<p>If any provision of this Agreement is invalid or unenforceable under
+applicable law, it shall not affect the validity or enforceability of
+the remainder of the terms of this Agreement, and without further action
+by the parties hereto, such provision shall be reformed to the minimum
+extent necessary to make such provision valid and enforceable.</p>
+
+<p>If Recipient institutes patent litigation against any entity
+(including a cross-claim or counterclaim in a lawsuit) alleging that the
+Program itself (excluding combinations of the Program with other
+software or hardware) infringes such Recipient's patent(s), then such
+Recipient's rights granted under Section 2(b) shall terminate as of the
+date such litigation is filed.</p>
+
+<p>All Recipient's rights under this Agreement shall terminate if it
+fails to comply with any of the material terms or conditions of this
+Agreement and does not cure such failure in a reasonable period of time
+after becoming aware of such noncompliance. If all Recipient's rights
+under this Agreement terminate, Recipient agrees to cease use and
+distribution of the Program as soon as reasonably practicable. However,
+Recipient's obligations under this Agreement and any licenses granted by
+Recipient relating to the Program shall continue and survive.</p>
+
+<p>Everyone is permitted to copy and distribute copies of this
+Agreement, but in order to avoid inconsistency the Agreement is
+copyrighted and may only be modified in the following manner. The
+Agreement Steward reserves the right to publish new versions (including
+revisions) of this Agreement from time to time. No one other than the
+Agreement Steward has the right to modify this Agreement. The Eclipse
+Foundation is the initial Agreement Steward. The Eclipse Foundation may
+assign the responsibility to serve as the Agreement Steward to a
+suitable separate entity. Each new version of the Agreement will be
+given a distinguishing version number. The Program (including
+Contributions) may always be distributed subject to the version of the
+Agreement under which it was received. In addition, after a new version
+of the Agreement is published, Contributor may elect to distribute the
+Program (including its Contributions) under the new version. Except as
+expressly stated in Sections 2(a) and 2(b) above, Recipient receives no
+rights or licenses to the intellectual property of any Contributor under
+this Agreement, whether expressly, by implication, estoppel or
+otherwise. All rights in the Program not expressly granted under this
+Agreement are reserved.</p>
+
+<p>This Agreement is governed by the laws of the State of New York and
+the intellectual property laws of the United States of America. No party
+to this Agreement will bring a legal action under this Agreement more
+than one year after the cause of action arose. Each party waives its
+rights to a jury trial in any resulting litigation.</p>
+
+</body>
+</html>
99 pom.xml
@@ -0,0 +1,99 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>com.cemerick</groupId>
+ <artifactId>pomegranate</artifactId>
+ <version>0.0.1-SNAPSHOT</version>
+ <name>pomegranate</name>
+ <description></description>
+ <url>http://github.com/cemerick/pomegranate</url>
+
+ <parent>
+ <groupId>org.clojure</groupId>
+ <artifactId>pom.contrib</artifactId>
+ <version>0.0.20</version>
+ </parent>
+
+ <developers>
+ <developer>
+ <name>Chas Emerick</name>
+ <url>http://cemerick.com</url>
+ <email>cemerick@snowtide.com</email>
+ <timezone>-5</timezone>
+ </developer>
+ </developers>
+
+ <scm>
+ <connection>scm:git:git@github.com:cemerick/pomegranate.git</connection>
+ <developerConnection>scm:git:git@github.com:cemerick/pomegranate.git</developerConnection>
+ <url>git@github.com:cemerick/pomegranate.git</url>
+ </scm>
+
+ <properties>
+ <clojure.version>1.2.0</clojure.version>
+
+ <aetherVersion>1.13</aetherVersion>
+ <mavenVersion>3.0.3</mavenVersion>
+ <wagonVersion>1.0-beta-7</wagonVersion>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.sonatype.aether</groupId>
+ <artifactId>aether-api</artifactId>
+ <version>${aetherVersion}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.sonatype.aether</groupId>
+ <artifactId>aether-util</artifactId>
+ <version>${aetherVersion}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.sonatype.aether</groupId>
+ <artifactId>aether-impl</artifactId>
+ <version>${aetherVersion}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.sonatype.aether</groupId>
+ <artifactId>aether-connector-file</artifactId>
+ <version>${aetherVersion}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.sonatype.aether</groupId>
+ <artifactId>aether-connector-asynchttpclient</artifactId>
+ <version>${aetherVersion}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.sonatype.aether</groupId>
+ <artifactId>aether-connector-wagon</artifactId>
+ <version>${aetherVersion}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-aether-provider</artifactId>
+ <version>${mavenVersion}</version>
+ </dependency>
+
+ <!-- wagons for dependency resolution -->
+ <dependency>
+ <groupId>org.apache.maven.wagon</groupId>
+ <artifactId>wagon-http-lightweight</artifactId>
+ <version>${wagonVersion}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven.wagon</groupId>
+ <artifactId>wagon-ssh</artifactId>
+ <version>${wagonVersion}</version>
+ <optional>true</optional>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <resources>
+ <resource>
+ <directory>src/main/clojure</directory>
+ </resource>
+ </resources>
+ </build>
+
+</project>
59 src/main/clojure/cemerick/pomegranate.clj
@@ -0,0 +1,59 @@
+(ns cemerick.pomegranate
+ (:import (clojure.lang DynamicClassLoader)
+ (java.net URL URLClassLoader))
+ (:require [clojure.java.io :as io]
+ [cemerick.pomegranate.aether :as aether])
+ (:refer-clojure :exclude (add-classpath)))
+
+;; call-method pulled from clojure.contrib.reflect, (c) 2010 Stuart Halloway & Contributors
+(defn- call-method
+ "Calls a private or protected method.
+
+ params is a vector of classes which correspond to the arguments to
+ the method e
+
+ obj is nil for static methods, the instance object otherwise.
+
+ The method-name is given a symbol or a keyword (something Named)."
+ [klass method-name params obj & args]
+ (-> klass (.getDeclaredMethod (name method-name)
+ (into-array Class params))
+ (doto (.setAccessible true))
+ (.invoke obj (into-array Object args))))
+
+(def ^{:private true} dynamic-classloaders #{DynamicClassLoader URLClassLoader})
+
+(defn- find-eldest-classloader
+ ([]
+ (find-eldest-classloader (clojure.lang.RT/baseLoader)))
+ ([tip]
+ (when (dynamic-classloaders (class tip))
+ (or (find-eldest-classloader (.getParent tip)) tip))))
+
+(defn add-classpath
+ "A corollary to the (deprecated) `add-classpath` in clojure.core. This implementation
+ requires a java.io.File or String path to a jar file or directory, and will attempt
+ to add that path to the current thread's context classloader (by default)."
+ ([jar-or-dir classloader]
+ (let [url (.toURL (io/file jar-or-dir))]
+ (cond
+ (instance? DynamicClassLoader classloader) (.addURL classloader url)
+ (instance? URLClassLoader) (call-method URLClassLoader 'addURL [URL] classloader url)
+ :else (throw (IllegalStateException.
+ (format "Thread context classloader is of type %s; needs to be a DynamicClassLoader or URLClassLoader"
+ (class classloader)))))))
+ ([jar-or-dir]
+ (if-let [classloader (find-eldest-classloader)]
+ (add-classpath jar-or-dir classloader)
+ (throw (IllegalStateException. "Could not find a DynamicClassLoader or URLClassLoader to modify")))))
+
+(defn add-dependencies
+ "Resolves a set of dependencies, optionally against a set of additional Maven repositories
+ (Maven central is always added in automatically), and adds all of the resulting artifacts
+ (jar files) to the current runtime via `cemerick.pomegranate/add-classpath`. e.g.
+
+ (add-dependencies '[[incanter \"1.2.3\"]]
+ :repositories {\"clojars\" \"http://clojars.org/repo\"})"
+ [coordinates & {:keys [repositories]}]
+ (doseq [artifact-file (aether/resolve-dependencies :coordinates coordinates :repositories repositories)]
+ (add-classpath artifact-file)))
66 src/main/clojure/cemerick/pomegranate/aether.clj
@@ -0,0 +1,66 @@
+(ns cemerick.pomegranate.aether
+ (:require [clojure.java.io :as io])
+ (:import org.apache.maven.repository.internal.DefaultServiceLocator
+ org.sonatype.aether.RepositorySystem
+ org.sonatype.aether.spi.connector.RepositoryConnectorFactory
+ org.apache.maven.wagon.providers.http.LightweightHttpWagon
+ (org.sonatype.aether.connector.wagon WagonProvider WagonRepositoryConnectorFactory)
+ (org.sonatype.aether.connector.file FileRepositoryConnectorFactory)
+
+ org.apache.maven.repository.internal.MavenRepositorySystemSession
+ (org.sonatype.aether.repository LocalRepository RemoteRepository)
+ (org.sonatype.aether.graph Dependency)
+ (org.sonatype.aether.collection CollectRequest)
+ (org.sonatype.aether.resolution DependencyRequest)
+ (org.sonatype.aether.util.graph PreorderNodeListGenerator)
+ (org.sonatype.aether.util.artifact DefaultArtifact)))
+
+(deftype HttpProvider []
+ WagonProvider
+ (release [_ wagon])
+ (lookup [_ role-hint]
+ (and (= "http" role-hint) (LightweightHttpWagon.))))
+
+(defn repository-system
+ []
+ (.getService (doto (DefaultServiceLocator.)
+ (.addService RepositoryConnectorFactory FileRepositoryConnectorFactory)
+ (.addService RepositoryConnectorFactory WagonRepositoryConnectorFactory)
+ (.setServices WagonProvider (into-array WagonProvider [(HttpProvider.)])))
+ RepositorySystem))
+
+(defn repository-session
+ [repository-system]
+ (doto (MavenRepositorySystemSession.)
+ (.setLocalRepositoryManager (.newLocalRepositoryManager repository-system
+ (-> (io/file (System/getProperty "user.home") ".m2" "repository")
+ .getAbsolutePath
+ LocalRepository.)))))
+
+(defn- coordinate-string
+ ([group-artifact version]
+ (let [group (or (namespace group-artifact) (name group-artifact))
+ artifact (name group-artifact)]
+ (str group \: artifact \: version)))
+ ([[group-artifact version]]
+ (coordinate-string group-artifact version)))
+
+(defn repository
+ ([[id config]] (repository id config))
+ ([id config]
+ (RemoteRepository. id "default" config)))
+
+(defn resolve-dependencies
+ [& {:keys [repositories coordinates]}]
+ (let [system (repository-system)
+ session (repository-session system)
+ collect-request (CollectRequest. (map #(Dependency. (DefaultArtifact. (coordinate-string %)) "compile") coordinates)
+ nil
+ (map repository (merge {"central" "http://repo1.maven.org/maven2/"}
+ repositories)))
+ dep-node (.getRoot (.collectDependencies system session collect-request))
+ dep-req (DependencyRequest. dep-node nil)
+ nodelist-gen (PreorderNodeListGenerator.)]
+ (.resolveDependencies system session dep-req)
+ (.accept dep-node nodelist-gen)
+ (set (.getFiles nodelist-gen))))

0 comments on commit 6a85d94

Please sign in to comment.