source: trunk/abcl/contrib/abcl-asdf/abcl-asdf.lisp @ 13903

Last change on this file since 13903 was 13903, checked in by Mark Evenson, 9 years ago

abcl-asdf: Final touches on 0.8.0.

File size: 3.8 KB
Line 
1;;;; The ABCL specific overrides in ASDF. 
2;;;;
3;;;; Done separate from asdf.lisp for stability.
4(in-package :asdf)
5
6(defclass iri (component) 
7  ((schema :initform nil)
8   (authority :initform nil)
9   (path :initform nil)
10   (query :initform nil)
11   (fragment :initform nil)))
12
13(defclass mvn (iri) 
14  ((group-id :initform nil)
15   (artifact-id :initform nil)
16   (repository :initform "http://repo1.maven.org/maven2/") ;;; XXX unimplmented
17;; inherited from ASDF:COMPONENT ??? what are the CL semantics on overriding -- ME 2012-04-01
18#+nil   (version :initform nil)))
19
20#+nil
21(defmethod find-component ((component iri) path)
22  component)
23
24;;; We intercept compilation to ensure that load-op will succeed
25(defmethod perform ((op compile-op) (c mvn))
26  (ensure-parsed-mvn c)
27  (abcl-asdf:resolve c))
28     
29(defmethod perform ((operation load-op) (c mvn))
30  (ensure-parsed-mvn c)
31  (java:add-to-classpath 
32   (abcl-asdf:as-classpath 
33    (abcl-asdf:resolve c))))
34
35;;; A Maven URI has the form "mvn:group-id/artifact-id/version"
36;;;
37;;; Sometimes people write "group-id:artifact-id:version" to refer to
38;;; Maven artifacts.  One can use ABCL-ASDF:RESOLVE directly for
39;;; serialized references to artifacts of this form.
40;;;
41;;; Currently we "stuff" the group-id/artifact-id into the 'name' and
42;;; use the component 'version' for the version.  Parts of ASDF
43;;; *reallY* want ASDF:VERSION to be a triple of intergers, and never
44;;; anything more, so that is part of the motivation behind this effort.
45(defparameter *mvn-repositories* nil
46  "A list of all Maven repositories encountered in the lifetime of this instance of the implementation.")
47
48(defun ensure-parsed-mvn (component)
49  (with-slots (name group-id artifact-id
50               version schema path repository) 
51      component
52    (when (null asdf::artifact-id) 
53      (let ((parsed (abcl-asdf::split-string name "/"))
54            (asdf-version-p (slot-boundp component 'version))
55            (default-version "LATEST"))
56        (cond ((= (length parsed) 3)
57               (setf 
58                group-id (first parsed)
59                artifact-id (second parsed)
60                version (third parsed)))
61              ((= (length parsed) 2)
62               (setf 
63                group-id (first parsed)
64                artifact-id (second parsed)
65                version (if asdf-version-p
66                            version
67                            default-version)))
68              (t
69               (error "Failed to construct a mvn reference from name '~A' and version '~A'"
70                      name version)))
71        (setf schema "mvn")
72        (pushnew repository *mvn-repositories*)
73        ;;; Always normalized path "on the way out" to contain group-id/artifact-id/version
74        (setf path (format nil "~A/~A/~A" group-id artifact-id version))))))
75
76(defmethod source-file-type ((component iri) (system system))
77  nil)
78
79(defmethod component-relative-pathname ((component iri))
80  nil)
81
82(in-package #:abcl-asdf)
83
84(defgeneric resolve (something)
85 (:documentation "Returns a string in JVM CLASSPATH format as entries delimited by classpath separator string."))
86
87(defmethod resolve ((mvn-component asdf::mvn))
88  "Resolve all runtime dependencies of MVN-COMPONENT.
89
90Returns a string in JVM CLASSPATH format as entries delimited by classpath separator string."
91 
92  (with-slots (asdf::group-id asdf::artifact-id asdf::version) mvn-component
93    (resolve-dependencies asdf::group-id asdf::artifact-id asdf::version)))
94
95(defun as-classpath (classpath)
96  "Break apart the JVM CLASSPATH string into a list of its consituents."
97  (split-string classpath 
98                (java:jfield "java.io.File" "pathSeparator")))
99
100(defun split-string (string split-char)
101  (loop :for i = 0 :then (1+ j)
102     :as j = (position split-char string :test #'string-equal :start i)
103     :collect (subseq string i j)
104     :while j))
Note: See TracBrowser for help on using the repository browser.