abcl-asdf.lisp 3.2 KB
Newer Older
1
(in-package :asdf)
2

3 4 5 6 7 8
(defclass iri (component) 
  ((schema :initform nil)
   (authority :initform nil)
   (path :initform nil)
   (query :initform nil)
   (fragment :initform nil)))
9

10 11
(defclass mvn (iri) 
  ((group-id :initform nil)
12 13 14
   (artifact-id :initform nil)
;; inherited from ASDF:COMPONENT
#+nil   (version :initform nil)))
15 16 17 18

#+nil
(defmethod find-component ((component iri) path)
  component)
19

20
;;; We intercept compilation to ensure that load-op will succeed
21
(defmethod perform ((op compile-op) (c mvn))
22
  (maybe-parse-mvn c)
23
  (abcl-asdf:resolve c))
24
     
25
(defmethod perform ((operation load-op) (c mvn))
26 27 28
  (maybe-parse-mvn c)
  (java:add-to-classpath 
   (abcl-asdf:as-classpath 
29
    (abcl-asdf:resolve c))))
30 31 32 33

;;; A Maven URI has the form "mvn:group-id/artifact-id/version"
;;;
;;; Currently we "stuff" the group-id/artifact-id into the 'name' and
34 35 36 37
;;; use the component 'version' for the version.  Parts of ASDF 
;;; *reallY* want ASDF:VERSION to be a triple of intergers, and never
;;; anything more, so that is part of the motivation behind this effort.
;;; ??? rename me to ENSURE-MVN-PARSE ??
38
(defun maybe-parse-mvn (component)
39 40
  (with-slots (name group-id artifact-id
               version schema path) 
41
      component
42
    (when (null asdf::artifact-id) 
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
      (let ((parsed (abcl-asdf::split-string name "/"))
            (asdf-version-p (slot-boundp component 'version))
            (default-version "LATEST"))
        (cond ((= (length parsed) 3)
               (setf 
                group-id (first parsed)
                artifact-id (second parsed)
                version (third parsed)))
              ((= (length parsed) 2)
               (setf 
                group-id (first parsed)
                artifact-id (second parsed)
                version (if asdf-version-p
                            version
                            default-version)))
              (t
               (error "Failed to construct a mvn reference from name '~A' and version '~A'"
                      name version)))
        (setf schema "mvn")
        ;;; Always normalized path "on the way out" to contain group-id/artifact-id/version
        (setf path (format nil "~A/~A/~A" group-id artifact-id version))))))
64 65 66 67 68 69

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

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

71
(in-package #:abcl-asdf)
72

73
(defgeneric resolve (something)
74
 (:documentation "Returns a string in JVM CLASSPATH format as entries delimited by classpath separator string."))
75

76
(defmethod resolve ((mvn-component asdf::mvn))
77 78 79 80
  "Resolve all runtime dependencies of MVN-COMPONENT.

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

84
(defun as-classpath (classpath)
85
  "Break apart the JVM CLASSPATH string into a list of its consituents."
86 87
  (split-string classpath 
                (java:jfield "java.io.File" "pathSeparator")))
88

89 90 91 92
(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)
93
     :while j))