Changeset 14236

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.

4 edited


  • trunk/abcl/contrib/abcl-asdf/README.markdown

    r13867 r14236  
    4747on the local filesystem).
    49 And we define MVN and IRI classes descend from ASDF-COMPONENT, but do not
     49The MVN and IRI classes descend from ASDF-COMPONENT, but do not
    5050directly have a filesystem location.
     52The IRI component is currently unused, but serves as a point to base
     53the inheritance of the MVN component while allowing other forms of
     54uri-like resources to be encapsulated in the future.
     56The MVN component should specifiy a [Maven URI][1] as its PATH.  A
     57Maven URI has the form "GROUP-ID/ARTIFACT-ID/VERSION" which specifies
     58the dependency to be satisfied for this component by resolution
     59through the Maven distributed dependency graph.  The scheme (the
     60initial "mvn://") is implied, usually omitted for brevity.  If a
     61VERSION is not specified (i.e. by a form like "GROUP-ID/ARTIFACT-ID"),
     62then the latest available version of the artifact will be retrieved
     63from the network.
     67The MVN component may specify a CLASSNAME which if present in the
     68current jvm, inhibits further loading from the network.  This may be
     69used to bypass the invocation of Maven.  Since classnames are not
     70unique to jar archives, this mechanism may not have the desired result
     71in all cases, but it is surpisingly, like the rest of Java, "good
     72enough" for everyday use.
     74The MVN component may specify an ALTERNATE-URI which will be added to
     75the jvm classpath if Maven cannot be located.  Since a Maven URI may
     76refer to more than one binary artifact, this may not work in all cases.
    5278For use outside of ASDF, we currently define the generic function
     165### 9.9.2 2012-11-09
    139170### 0.7.0 2012-02-05
    170201    Created: 2011-01-01
    171     Revised: 2012-02-06
     202    Revised: 2012-11-09
  • trunk/abcl/contrib/abcl-asdf/abcl-asdf.asd

    r14233 r14236  
    33(asdf:defsystem :abcl-asdf
    44  :author "Mark Evenson"
    5   :version "0.9.1"
     5  :version "0.9.2"
    66  :depends-on (jss)
    77  :components
  • 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 "") ;;; 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 "")
    124              (let ((uri #p"")))
    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)
  • trunk/abcl/contrib/mvn/jna.asd

    r14225 r14236  
    11;;;; -*- Mode: LISP -*-
    3 ;;;; Need to have jna.jar present for CFFI to have a chance of working.
     3;;;; Need to have jna.jar present for CFFI to work.
    44(asdf:defsystem :jna
    55    :version "3.5.1"
    66    :defsystem-depends-on (jss abcl-asdf)
    77;; FIXME: always seems to be resolving the LATEST maven artifact.
    8     :components ((:mvn "")))
     8    :components ((:mvn ""
     9                  :alternate-uri ""
     10                  :classname "com.sun.jna.Native")))
    1012(in-package :asdf)
    1315    (provide :jna)))
    15 ;;; After ASDF performs COMPILE-OP, one expects that the JNA Java
    16 ;;; classes can be instantiated.  If not, execute various loading strategies.
    17 (defmethod perform ((o compile-op) (c (eql (find-system :jna))))
    18   ;; Theoretically this should be the same thing as the MVN component.
    19   (format *debug-io* "~&Attemping to locate jvm binary artifacts for JNA...~&")
    20   (handler-case
    21       (jss:find-java-class "com.sun.jna.Native")
    22     (java:java-exception (e)
    23       (unless
    24           (java:add-to-classpath (abcl-asdf:resolve ""))
    25         (unless
    26             ;; Might want to download to local filesystem, then place in classpath
    27             (java:add-to-classpath #p"")
    28           (error "Failed to load jna-3.5.0.jar from the network via URI."))
    29         (error "Failed to load jna.jar via ABCL-ASDF.")))
    30     (t (e)
    31       (error "Failed to resolve 'jna.jar' because~&~A.~&" e))))
Note: See TracChangeset for help on using the changeset viewer.