1 | (in-package :asdf) |
---|
2 | (defclass iri (component) |
---|
3 | ((schema :initform nil) |
---|
4 | (authority :initform nil) |
---|
5 | (path :initform nil) |
---|
6 | (query :initform nil) |
---|
7 | (fragment :initform nil))) |
---|
8 | |
---|
9 | (defclass mvn (iri) |
---|
10 | ((group-id :initform nil) |
---|
11 | (artifact-id :initform nil))) |
---|
12 | |
---|
13 | #+nil |
---|
14 | (defmethod find-component ((component iri) path) |
---|
15 | component) |
---|
16 | |
---|
17 | ;;; We interpret compilation to ensure that load-op will succeed |
---|
18 | (defmethod perform ((op compile-op) (c mvn)) |
---|
19 | (maybe-parse-mvn c) |
---|
20 | (abcl-asdf:satisfy c)) |
---|
21 | |
---|
22 | (defmethod perform ((operation load-op) (c mvn)) |
---|
23 | (maybe-parse-mvn c) |
---|
24 | (java:add-to-classpath |
---|
25 | (abcl-asdf:as-classpath |
---|
26 | (abcl-asdf:satisfy c)))) |
---|
27 | |
---|
28 | ;;; A Maven URI has the form "mvn:group-id/artifact-id/version" |
---|
29 | ;;; |
---|
30 | ;;; Currently we "stuff" the group-id/artifact-id into the 'name' and |
---|
31 | ;;; use the component 'version' for the version string. |
---|
32 | (defun maybe-parse-mvn (component) |
---|
33 | (with-slots (asdf::name asdf::group-id asdf::artifact-id |
---|
34 | asdf::version asdf::schema asdf::path) component |
---|
35 | (when (null asdf::artifact-id) |
---|
36 | (let ((slash (search "/" name))) |
---|
37 | (unless (and (integerp slash) |
---|
38 | asdf::version) |
---|
39 | (error "Failed to construct a mvn reference from name '~A' and version '~A'" |
---|
40 | asdf::name asdf::version)) |
---|
41 | (setf asdf::group-id (subseq asdf::name 0 slash) |
---|
42 | asdf::artifact-id (subseq asdf::name (1+ slash)) |
---|
43 | asdf::schema "mvn" |
---|
44 | asdf::path (format nil "~A/~A" asdf::name asdf::version)))))) |
---|
45 | |
---|
46 | (defmethod source-file-type ((component iri) (system system)) |
---|
47 | nil) |
---|
48 | |
---|
49 | (defmethod component-relative-pathname ((component iri)) |
---|
50 | nil) |
---|
51 | |
---|
52 | (in-package #:abcl-asdf) |
---|
53 | |
---|
54 | (defun satisfy (mvn-component) |
---|
55 | "Resolve all runtime dependencies of MVN-COMPONENT. |
---|
56 | |
---|
57 | Returns a string in JVM CLASSPATH format as entries delimited by classpath separator string." |
---|
58 | |
---|
59 | (with-slots (asdf::group-id asdf::artifact-id asdf::version) mvn-component |
---|
60 | (resolve-dependencies asdf::group-id asdf::artifact-id asdf::version))) |
---|
61 | |
---|
62 | (defun as-classpath (classpath) |
---|
63 | "Break apart the JVM CLASSPATH string into a list of its consituents." |
---|
64 | ;;; XXX Maybe doesn't work under Windows? |
---|
65 | (split-string classpath ":")) |
---|
66 | |
---|
67 | (defun split-string (string split-char) |
---|
68 | (loop :for i = 0 :then (1+ j) |
---|
69 | :as j = (position split-char string :test #'string-equal :start i) |
---|
70 | :collect (subseq string i j) |
---|
71 | :while j)) |
---|