11/09/12 14:44:33 (8 years ago)
Mark Evenson

abcl-asdf: Enable bypassing of loading from network if a given class already exists.

An ASDF:MVN component can now optionally specify a CLASSNAME that if
able to be found in the current jvm process, inhbits further loading
from the network.

An ASDF:MVN component may also optionally specify an ALTERNATE-URI
that will be added to the current jvm classpath if Maven cannot be
invoked. Most jvm implementations won't access such jar archives from
the network by default, so this is an intermediate step before
actually writing the code to download the jar to the local filesystem
to then be added.

Refresh documentation in README.markdown.

1 edited


  • trunk/abcl/contrib/abcl-asdf/abcl-asdf.lisp

    r14205 r14236  
    1 ;;;; The ABCL specific overrides in ASDF. 
     1s;;;; The ABCL specific overrides in ASDF. 
    33;;;; Done separate from asdf.lisp for stability.
    1616   (artifact-id :initarg :artifact-id :initform nil)
    1717   (repository :initform "http://repo1.maven.org/maven2/") ;;; XXX unimplmented
     18   (classname :initarg :classname :initform nil)
     19   (alternate-uri :initarg :alternate-uri :initform nil)
    1820;; inherited from ASDF:COMPONENT ??? what are the CL semantics on overriding -- ME 2012-04-01
    1921#+nil   (version :initform nil)))
    3133(defmethod perform ((operation load-op) (c mvn))
    32   (java:add-to-classpath
    33    (abcl-asdf:as-classpath
    34     (abcl-asdf:resolve
    35      (ensure-parsed-mvn c)))))
     34  (let ((resolved-path
     35         (abcl-asdf:resolve (ensure-parsed-mvn c))))
     36    (when (stringp resolved-path)
     37      (java:add-to-classpath (abcl-asdf:as-classpath resolved-path)))))
    3739;;; A Maven URI has the form "mvn:group-id/artifact-id/version"
    101103  "Resolve all runtime dependencies of MVN-COMPONENT.
    103 Returns a string in JVM CLASSPATH format as entries delimited by
    104 classpath separator string.  Can possibly be a single entry denoting a
    105 remote binary artifact."
     105Returns either a string in jvm classpath format as entries delimited
     106by classpath separator string or T.  If the value T is returned, it
     107denotes that current JVM already has already loaded a given class. Can possibly be a
     108single entry denoting a remote binary artifact."
    106109  (macrolet ((aif (something consequence alternative))
    107110             `(let ((it ,(something)))
    112115          (group-id (slot-value mvn-component 'asdf::group-id))
    113116          (artifact-id (slot-value mvn-component 'asdf::artifact-id))
     117          (classname (slot-value mvn-component 'asdf::classname))
     118          (alternate-uri (slot-value mvn-component 'asdf::alternate-uri))
    114119          (version (let ((it (slot-value mvn-component 'asdf::version)))
    115120                     (cond
    118123                       (t
    119124                        "LATEST")))))
    120       (if (find-mvn)
    121           (resolve-dependencies group-id artifact-id version)
    122           (cond
    123             ((string= name "net.java.dev.jna/jna/3.4.0")
    124              (let ((uri #p"http://repo1.maven.org/maven2/net/java/dev/jna/jna/3.4.0/jna-3.4.0.jar")))
    125                         (values (namestring uri) uri))
    126             (t
    127              (error "Failed to resolve MVN component name ~A." name)))))))
     125      (handler-case
     126          (when (and classname
     127                     (jss:find-java-class classname))
     128            (warn "Not loading ~A from the network because ~A is present in classpath."
     129                  name classname)
     130            (return-from resolve t))
     131        (java:java-exception (e)
     132          (unless (java:jinstance-of-p (java:java-exception-cause e)
     133                                  "java.lang.ClassNotFoundException")
     134            (error "Unexpected Java exception~&~A.~&" e))
     135          (if (find-mvn)
     136              (resolve-dependencies group-id artifact-id version)
     137              (if alternate-uri
     138                  (values (namestring alternate-uri) alternate-uri)
     139                  (t
     140                   (error "Failed to resolve MVN component name ~A." name)))))))))
    129142(defun as-classpath (classpath)
Note: See TracChangeset for help on using the changeset viewer.