Changeset 15018


Ignore:
Timestamp:
05/25/17 06:27:14 (2 months ago)
Author:
mevenson
Message:

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/>.

Location:
trunk/abcl
Files:
8 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/abcl/contrib/abcl-asdf/abcl-asdf.asd

    r15010 r15018  
    44  :description "Extensions to ASDF for handling Java binary artifacts."
    55  :long-description "<urn:abcl.org/release/1.5.0/contrib/abcl-asdf#>"
    6   :version "2.0.0"
     6  :version "2.1.0"
    77  :depends-on (jss abcl-build)
    88  :components
     
    1717   (:module maven
    1818            :pathname ""
    19             :components ((:file "maven"))
     19            :components ((:file "maven")
     20                         (:file "mvn-module"))
    2021            :depends-on (base)))
    2122  :in-order-to ((test-op (test-op abcl-asdf-tests))))
  • trunk/abcl/contrib/abcl-asdf/maven.lisp

    r15017 r15018  
    617617      (t
    618618       (destructuring-bind (group-id artifact-id &optional version repository)
    619            (split-string string "/")
     619           (abcl-build:split-string string "/")
    620620         (setf result
    621621               (apply #'resolve-dependencies group-id artifact-id
     
    625625                                `(:repository ,repository))))))))))
    626626
     627
     628(defun resolve-multiple-maven-dependencies (dependencies &optional managed-dependencies exclusions (first-is-root nil))
     629  "Return a list of jar file paths that satisfy dependencies
     630
     631 dependencies: a list of maven artifacts. color or slash separated
     632   components groupid:artifactid:versionid
     633
     634 managed-dependencies: a list of maven artifacts. If an dependency
     635   with same groupid and artifactid are encountered, the version
     636   specified here overrides.
     637
     638 exclusions: a list of partial maven artifacts
     639   groupid:artifactid. Dependencies with same groupid and artifactid are
     640   exluded
     641
     642 first-is-root: If the first dependency should include optional
     643   dependencies, set this to t. Usually not.
     644 "
     645  (let (aether)
     646    (with-aether (aether)
     647      (let ((collect-request (java:jnew (jss:find-java-class "CollectRequest")))
     648            (exclusions-collection (jss:new 'hashset) )
     649            (compile-scope (java:jfield (jss:find-java-class "JavaScopes") "COMPILE")))
     650        (loop for e  in exclusions
     651           for (groupid artifactid) = (abcl-build:split-string e #\:)
     652           ;; If i have scope be compile-scope it doesn't get excluded!!
     653           for exclusion = (jss:new 'aether.graph.Exclusion groupid artifactid "" "jar")
     654           do (#"add" exclusions-collection exclusion))
     655        (loop for a in dependencies
     656           for artifact = (make-artifact (#"replaceAll" a "/" ":"))
     657           for dependency = (jss:new 'aether.graph.Dependency artifact compile-scope)
     658           do 
     659           ;; setExclusions returns a new dependency. We have to use that. That passed dependency i not modified!
     660           ;; 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
     661           ;; Nice of them to clearly document that :-/
     662       (setq dependency (#"setExclusions" dependency exclusions-collection))
     663       (if first-is-root
     664     (#"setRoot" collect-request dependency)
     665     (#"addDependency" collect-request dependency))
     666       (setq first-is-root nil))
     667        (loop for a in managed-dependencies
     668           for artifact = (make-artifact (#"replaceAll" a "/" ":"))
     669           for dependency = (jss:new 'aether.graph.Dependency artifact compile-scope)
     670           do (setq dependency (#"setExclusions" dependency exclusions-collection))
     671       (#"addManagedDependency" collect-request dependency))
     672        (let ((dependencies (#"collectDependencies" (ensure-repository-system) (ensure-session) collect-request))
     673              (nodelist-generator (jss:new 'PreorderNodeListGenerator))
     674              (dependency-request (jss:new 'DependencyRequest)))
     675          (#"setRoot" dependency-request (#"getRoot" dependencies))
     676          (#"resolveDependencies" (ensure-repository-system) (ensure-session) dependency-request)
     677          (#"accept" (#"getRoot" dependencies) nodelist-generator)
     678          (abcl-build:split-string (#"getClassPath" nodelist-generator) #\:))))))
     679
    627680;;; Currently the last file listed in ASDF
    628681(provide 'abcl-asdf)
     682
  • trunk/abcl/contrib/abcl-asdf/package.lisp

    r15017 r15018  
    3333   #:resolve-artifact
    3434   #:resolve-dependencies
     35   #:resolve-multiple-maven-dependencies
    3536
    3637   #:as-classpath
  • trunk/abcl/contrib/abcl-asdf/t/resolve-multiple-maven-dependencies.lisp

    r15015 r15018  
    11(in-package :cl-user)
    2 (require :jss)
    3 
    4 ;; https://maven.apache.org/guides/introduction/introduction-to-optional-and-excludes-dependencies.html
    5 ;; if a artifact is root then its optional dependencies are
    6 ;; collected. If the same artifact is not root, then the optional
    7 ;; dependencies are not collected. We don't need optionals since from
    8 ;; our point of view we are the top pom and everything specified are
    9 ;; dependencies
    10 
    11 (defun resolve-multiple-maven-dependencies (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 ((collect-request (java:jnew (jss:find-java-class "CollectRequest")))
    29   (exclusions-collection (jss:new 'hashset) )
    30   (compile-scope #"JavaScopes.COMPILE"))
    31     (loop for e  in exclusions
    32     for (groupid artifactid) = (abcl/build:split-string e #\:)
    33     ;; If i have scope be compile-scope it doesn't get excluded!!
    34     for exclusion = (jss:new 'aether.graph.Exclusion groupid artifactid "" "jar")
    35     do (#"add" exclusions-collection exclusion))
    36     (loop for a in dependencies
    37     for artifact = (abcl-asdf::make-artifact (#"replaceAll" a "/" ":"))
    38     for dependency = (jss:new 'aether.graph.Dependency artifact compile-scope)
    39     do 
    40        ;; setExclusions returns a new dependency. We have to use that. That passed dependency is not modified!
    41        ;; http://grepcode.com/file/repo1.maven.org/maven2/org.eclipse.aether/aether-api/1.0.2.v20150114/org/eclipse/aether/graph/Dependency.java#Dependency.getOptional%28%29
    42        ;; Nice of them to clearly document that :-/
    43        (setq dependency (#"setExclusions" dependency exclusions-collection))
    44        (if first-is-root
    45      (#"setRoot" collect-request dependency)
    46      (#"addDependency" collect-request dependency))
    47        (setq first-is-root nil))
    48     (loop for a in managed-dependencies
    49     for artifact = (abcl-asdf::make-artifact (#"replaceAll" a "/" ":"))
    50     for dependency = (jss:new 'aether.graph.Dependency artifact compile-scope)
    51     do (setq dependency (#"setExclusions" dependency exclusions-collection))
    52        (#"addManagedDependency" collect-request dependency))
    53     (let ((dependencies (#"collectDependencies"
    54        (abcl-asdf::ensure-repository-system)
    55        (abcl-asdf::ensure-session) collect-request))
    56     (nodelist-generator (jss:new 'PreorderNodeListGenerator))
    57     (dependency-request (jss:new 'DependencyRequest)))
    58       (#"setRoot" dependency-request
    59                   (#"getRoot" dependencies))
    60       (#"resolveDependencies" (abcl-asdf::ensure-repository-system)
    61                               (abcl-asdf::ensure-session)
    62                               dependency-request)
    63       (#"accept" (#"getRoot" dependencies)
    64                  nodelist-generator)
    65       (abcl/build:split-string (#"getClassPath" nodelist-generator) #\:))))
    66 
    672
    683(prove:plan 3)
Note: See TracChangeset for help on using the changeset viewer.