abcl-asdf.lisp 3.43 KB
Newer Older
1 2 3
;;;; The ABCL specific overrides in ASDF.  
;;;;
;;;; Done separate from asdf.lisp for stability.
4
(in-package :asdf)
5

6 7 8 9 10 11
(defclass iri (component) 
  ((schema :initform nil)
   (authority :initform nil)
   (path :initform nil)
   (query :initform nil)
   (fragment :initform nil)))
12

13 14
(defclass mvn (iri) 
  ((group-id :initform nil)
15
   (artifact-id :initform nil)
16 17
   (repository :initform "http://repo1.maven.org/maven2/") ;;; XXX unimplmented
;; inherited from ASDF:COMPONENT ??? what are the CL semantics on overriding -- ME 2012-04-01
18
#+nil   (version :initform nil)))
19 20 21 22

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

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

;;; A Maven URI has the form "mvn:group-id/artifact-id/version"
;;;
;;; Currently we "stuff" the group-id/artifact-id into the 'name' and
38 39 40 41
;;; 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 ??
42
(defun maybe-parse-mvn (component)
43 44
  (with-slots (name group-id artifact-id
               version schema path) 
45
      component
46
    (when (null asdf::artifact-id) 
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
      (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))))))
68 69 70 71 72 73

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

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

75
(in-package #:abcl-asdf)
76

77
(defgeneric resolve (something)
78
 (:documentation "Returns a string in JVM CLASSPATH format as entries delimited by classpath separator string."))
79

80
(defmethod resolve ((mvn-component asdf::mvn))
81 82 83 84
  "Resolve all runtime dependencies of MVN-COMPONENT.

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

88
(defun as-classpath (classpath)
89
  "Break apart the JVM CLASSPATH string into a list of its consituents."
90 91
  (split-string classpath 
                (java:jfield "java.io.File" "pathSeparator")))
92

93 94 95 96
(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)
97
     :while j))