source: tags/1.5.0/contrib/abcl-asdf/mvn-module.lisp

Last change on this file was 15018, checked in by Mark Evenson, 7 years ago

asdf-mvn-module: enable use of MVN-MODULE in ASDF definitions

The MVN-MODULE component allows finer control over Maven's
behavior when the transitive dependency graph contains conflicting
requirements.

(:mvn-module NAME

:dependencies DEPENDENCIES
:managed-dependencies MANAGED-DEPENDENCIES
:exclusions EXCLUSIONS)

where

DEPENDENCIES

A list of Maven artifacts in the form of colon or slash separated
components GROUPID:ARTIFACTID:VERSIONID.

MANAGED-DEPENDENCIES

A List of maven artifacts. If an dependency with same GROUPID and
ARTIFACTID are encountered, the version specified here overrides.

EXCLUSIONS

A list of partial maven artifacts groupid:artifactid. Dependencies
with same groupid and artifactid are exluded

An example of a MVN-MODULE ASDF declaration:

(defsystem foo

:defsystem-depends-on (asdf-mvn-module)
:components ((:mvn-module maven

:dependencies
("net.sourceforge.owlapi/pellet-cli-ignazio1977/2.4.0-ignazio1977"

"org.semanticweb.elk/elk-owlapi/0.4.3"
"net.sourceforge.owlapi/org.semanticweb.hermit/1.3.8.413"
"net.sourceforge.owlapi/owlapi-distribution/4.2.6"
"net.sourceforge.owlapi/owlexplanation/2.0.0"
"de.sciss/prefuse-core/1.0.1"
"de.sciss/prefuse-demos/1.0.1")

:managed-dependencies
("org.slf4j/slf4j-api/1.7.21"

"net.sourceforge.owlapi:owlapi-distribution:4.2.6")

:exclusions
("net.sourceforge.owlapi:owlapi-osgidistribution"

"edu.stanford.protege:org.protege.editor.owl")))

c.f. <https://mailman.common-lisp.net/pipermail/armedbear-devel/2017-April/003810.html>

Originally from <https://github.com/alanruttenberg/abcl/blob/stage/contrib/abcl-asdf/>.

File size: 3.4 KB
Line 
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 "
28  (let (aether)
29    (with-aether (aether)
30      (let ((collect-request (java:jnew (jss:find-java-class "CollectRequest")))
31            (exclusions-collection (jss:new 'hashset) )
32            (compile-scope (java:jfield (jss:find-java-class "JavaScopes") "COMPILE")))
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
45           ;; Nice of them to clearly document that :-/
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) #\:))))))
Note: See TracBrowser for help on using the repository browser.