source: trunk/abcl/contrib/abcl-asdf/mvn-module.lisp

Last change on this file was 15245, checked in by Mark Evenson, 5 months ago

abcl-asdf: use WITH-AETHER to ensure things are loaded

Unfortunately, since we can't easily "unload" jar files from the
classpath, it isn't easy to make the WITH-AETHER macro work with
differing versions of Aether. Still, it's a little cleaner to use a
WITH-AETHER form to ensure that the Maven initialization has been done
correctly.

TODO: ensure that WITH-AETHER invoked with a bogus Maven Aether
library location doesn't bork the system.

File size: 3.4 KB
RevLine 
[15018]1(in-package :abcl-asdf)
2
3;;; <https://maven.apache.org/guides/introduction/introduction-to-optional-and-excludes-dependencies.html>
4;;; If a artifact is root then its optional dependencies are
5;; collected. If the same artifact is not root, then the optional
6;;; dependencies are not collected. We don't need optionals since from
7;;; our point of view we are the top pom and everything specified are
8;;; dependencies
9;;; Used by asdf-mvn-module. 
10(defun resolve-multiple-maven-dependencies
11    (dependencies &optional managed-dependencies exclusions (first-is-root nil))
12  "Return a list of jar file paths that satisfy dependencies
13
14 dependencies: a list of maven artifacts. color or slash separated
15   components groupid:artifactid:versionid
16
17 managed-dependencies: a list of maven artifacts. If an dependency
18   with same groupid and artifactid are encountered, the version
19   specified here overrides.
20
21 exclusions: a list of partial maven artifacts
22   groupid:artifactid. Dependencies with same groupid and artifactid are
23   exluded
24
25 first-is-root: If the first dependency should include optional
26   dependencies, set this to t. Usually not.
27 "
[15245]28  (with-aether (nil)
29    (let ((collect-request (java:jnew (jss:find-java-class "CollectRequest")))
30          (exclusions-collection (jss:new 'java.util.HashSet))
31          (compile-scope (java:jfield (jss:find-java-class "JavaScopes") "COMPILE")))
32      (#"addRepository" collect-request (ensure-remote-repository))
33      (loop for e  in exclusions
34         for (groupid artifactid) = (abcl-build:split-string e #\:)
35         ;; If i have scope be compile-scope it doesn't get excluded!!
36         for exclusion = (jss:new 'aether.graph.Exclusion groupid artifactid "" "jar")
37         do (#"add" exclusions-collection exclusion))
38      (loop for a in dependencies
39         for artifact = (make-artifact (#"replaceAll" a "/" ":"))
40         for dependency = (jss:new 'aether.graph.Dependency artifact compile-scope)
41         do 
42         ;; setExclusions returns a new dependency. We have to use
43         ;; that. That passed dependency i not modified!
44         ;; http://grepcode.com/file/repo1.maven.org/maven2/org.eclipse.aether/aether-api/1.0.2.v0150114/org/eclipse/aether/graph/Dependency.java#Dependency.getOptional%28%29
[15018]45           ;; Nice of them to clearly document that :-/
[15245]46     (setq dependency (#"setExclusions" dependency exclusions-collection))
47     (if first-is-root
48         (#"setRoot" collect-request dependency)
49         (#"addDependency" collect-request dependency))
50     (setq first-is-root nil))
51      (loop for a in managed-dependencies
52         for artifact = (make-artifact (#"replaceAll" a "/" ":"))
53         for dependency = (jss:new 'aether.graph.Dependency artifact compile-scope)
54         do (setq dependency (#"setExclusions" dependency exclusions-collection))
55     (#"addManagedDependency" collect-request dependency))
56      (let ((dependencies (#"collectDependencies" (ensure-repository-system) (ensure-session) collect-request))
57            (nodelist-generator (jss:new 'PreorderNodeListGenerator))
58            (dependency-request (jss:new 'DependencyRequest)))
59        (#"setRoot" dependency-request (#"getRoot" dependencies))
60        (#"resolveDependencies" (ensure-repository-system) (ensure-session) dependency-request)
61        (#"accept" (#"getRoot" dependencies) nodelist-generator)
62        (abcl-build:split-string (#"getClassPath" nodelist-generator) #\:)))))
63
Note: See TracBrowser for help on using the repository browser.