abcl-asdf.lisp 2.49 KB
Newer Older
1
(in-package :asdf)
2 3 4 5 6 7
(defclass iri (component) 
  ((schema :initform nil)
   (authority :initform nil)
   (path :initform nil)
   (query :initform nil)
   (fragment :initform nil)))
8

9 10 11 12 13 14 15
(defclass mvn (iri) 
  ((group-id :initform nil)
   (artifact-id :initform nil)))

#+nil
(defmethod find-component ((component iri) path)
  component)
16 17

;;; We interpret compilation to ensure that load-op will succeed
18
(defmethod perform ((op compile-op) (c mvn))
19 20 21
  (maybe-parse-mvn c)
  (abcl-asdf:satisfy c))
     
22
(defmethod perform ((operation load-op) (c mvn))
23 24 25
  (maybe-parse-mvn c)
  (java:add-to-classpath 
   (abcl-asdf:as-classpath 
26
    (abcl-asdf:satisfy c))))
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43

;;; A Maven URI has the form "mvn:group-id/artifact-id/version"
;;;
;;; Currently we "stuff" the group-id/artifact-id into the 'name' and
;;; use the component 'version' for the version string.
(defun maybe-parse-mvn (component)
  (with-slots (asdf::name asdf::group-id asdf::artifact-id
               asdf::version asdf::schema asdf::path) component
    (when (null asdf::artifact-id) 
      (let ((slash (search "/" name)))
        (unless (and (integerp slash)
                     asdf::version)
          (error "Failed to construct a mvn reference from name '~A' and version '~A'"
                 asdf::name asdf::version))
        (setf asdf::group-id (subseq asdf::name 0 slash)
              asdf::artifact-id (subseq asdf::name (1+ slash))
              asdf::schema "mvn"
44 45 46
              asdf::version (if (eq asdf::version :latest)
                                "LATEST"
                                asdf::version)
47 48 49 50 51 52 53
              asdf::path (format nil "~A/~A" asdf::name asdf::version))))))

(defmethod source-file-type ((component iri) (system system))
  nil)

(defmethod component-relative-pathname ((component iri))
  nil)
54

55
(in-package #:abcl-asdf)
56

57
(defun satisfy (mvn-component)
58 59 60 61
  "Resolve all runtime dependencies of MVN-COMPONENT.

Returns a string in JVM CLASSPATH format as entries delimited by classpath separator string."
  
62 63 64
  (with-slots (asdf::group-id asdf::artifact-id asdf::version) mvn-component
    (resolve-dependencies asdf::group-id asdf::artifact-id asdf::version)))

65
(defun as-classpath (classpath)
66
  "Break apart the JVM CLASSPATH string into a list of its consituents."
67 68
  (split-string classpath 
                (java:jfield "java.io.File" "pathSeparator")))
69

70 71 72 73
(defun split-string (string split-char)
  (loop :for i = 0 :then (1+ j)
     :as j = (position split-char string :test #'string-equal :start i)
     :collect (subseq string i j)
74
     :while j))