abcl-asdf.lisp 2.17 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 44 45 46 47 48 49 50

;;; 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"
              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)
51

52
(in-package #:abcl-asdf)
53

54 55 56 57
(defun satisfy (mvn-component)
  (with-slots (asdf::group-id asdf::artifact-id asdf::version) mvn-component
    (resolve-dependencies asdf::group-id asdf::artifact-id asdf::version)))

58
(defun as-classpath (classpath)
59 60
  "For a given MVN entry, return a list of loadable archives 
 suitable for addition to the classpath."
61
  (split-string classpath ":"))
62

63 64 65 66 67
(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)
     :while j))