1 | (in-package :system) |
---|
2 | |
---|
3 | (require :asdf) |
---|
4 | |
---|
5 | (defconstant +get-classloader+ |
---|
6 | (java:jmethod "java.lang.Class" "getClassLoader")) |
---|
7 | |
---|
8 | (defun boot-classloader () |
---|
9 | (let ((boot-class (java:jclass "org.armedbear.lisp.Main"))) |
---|
10 | (java:jcall +get-classloader+ boot-class))) |
---|
11 | |
---|
12 | (defun system-jar-p (p) |
---|
13 | (named-jar-p "abcl" p)) |
---|
14 | |
---|
15 | (defun contrib-jar-p (p) |
---|
16 | (named-jar-p "abcl-contrib" p)) |
---|
17 | |
---|
18 | (defun named-jar-p (name p) |
---|
19 | (and (pathnamep p) |
---|
20 | (equal (pathname-type p) "jar") |
---|
21 | (or |
---|
22 | (java:jstatic "matches" |
---|
23 | "java.util.regex.Pattern" |
---|
24 | (concatenate 'string name "(-[0-9]\\.[0-9]\\.[0-9]([+~-].+)?)?") |
---|
25 | (pathname-name p)) |
---|
26 | (java:jstatic "matches" |
---|
27 | "java.util.regex.Pattern" |
---|
28 | (concatenate 'string name "(-[0-9]\\.[0-9]\\.[0-9]\\.[0-9]([+~-]+)?)?") |
---|
29 | (pathname-name p))) |
---|
30 | p)) |
---|
31 | |
---|
32 | (defun find-system () |
---|
33 | "Find the location of the system. |
---|
34 | |
---|
35 | Used to determine relative pathname to find 'abcl-contrib.jar'." |
---|
36 | (or |
---|
37 | (ignore-errors |
---|
38 | (find-system-jar)) |
---|
39 | (ignore-errors |
---|
40 | (some |
---|
41 | (lambda (u) |
---|
42 | (probe-file (make-pathname |
---|
43 | :defaults (java:jcall "toString" u) |
---|
44 | :name "abcl"))) |
---|
45 | (java:jcall "getURLs" (boot-classloader)))) |
---|
46 | (ignore-errors |
---|
47 | #p"http://abcl.org/releases/current/abcl.jar"))) |
---|
48 | |
---|
49 | (defun find-jar (predicate) |
---|
50 | (dolist (loader (java:dump-classpath)) |
---|
51 | (let ((jar (some predicate loader))) |
---|
52 | (when jar |
---|
53 | (return jar))))) |
---|
54 | |
---|
55 | (defun find-system-jar () |
---|
56 | "Return the pathname of the system jar, one of `abcl.jar` or |
---|
57 | `abcl-m.n.p.jar` or `abcl-m.n.p[.~-]something.jar`." |
---|
58 | (find-jar #'system-jar-p)) |
---|
59 | |
---|
60 | (defun find-contrib-jar () |
---|
61 | "Return the pathname of the contrib jar, one of `abcl-contrib.jar` or |
---|
62 | `abcl-contrib-m.n.p.jar` or `abcl-contrib-m.n.p[.~-]something.jar`." |
---|
63 | (find-jar #'contrib-jar-p)) |
---|
64 | |
---|
65 | (defvar *abcl-contrib* nil |
---|
66 | "Pathname of the ABCL contrib. |
---|
67 | Initialized via SYSTEM:FIND-CONTRIB.") |
---|
68 | |
---|
69 | (defparameter *verbose* t) |
---|
70 | |
---|
71 | (defun add-contrib (abcl-contrib-jar) |
---|
72 | "Introspects ABCL-CONTRIB-JAR for asdf systems to add to ASDF:*CENTRAL-REGISTRY*" |
---|
73 | (when abcl-contrib-jar |
---|
74 | (dolist (asdf-file |
---|
75 | (directory (make-pathname :device (list abcl-contrib-jar) |
---|
76 | :directory '(:absolute :wild) |
---|
77 | :name :wild |
---|
78 | :type "asd"))) |
---|
79 | (let ((asdf-directory (make-pathname :defaults asdf-file :name nil :type nil))) |
---|
80 | (unless (find asdf-directory asdf:*central-registry* :test #'equal) |
---|
81 | (push asdf-directory asdf:*central-registry*) |
---|
82 | (format *verbose* "~&Added ~A to ASDF.~&" asdf-directory)))))) |
---|
83 | |
---|
84 | (defun find-and-add-contrib (&key (verbose nil)) |
---|
85 | "Attempt to find the ABCL contrib jar and add its contents to ASDF. |
---|
86 | Returns the pathname of the contrib if it can be found." |
---|
87 | (if *abcl-contrib* |
---|
88 | (format verbose "~&Using already initialized value of abcl-contrib:~&'~A'.~%" |
---|
89 | *abcl-contrib*) |
---|
90 | (progn |
---|
91 | (setf *abcl-contrib* (find-contrib)) |
---|
92 | (format verbose "~&Using probed value of abcl-contrib:~&'~A'.~%" |
---|
93 | *abcl-contrib*))) |
---|
94 | (add-contrib *abcl-contrib*)) |
---|
95 | |
---|
96 | (defun find-contrib () |
---|
97 | "Introspect runtime classpaths to find a loadable ABCL-CONTRIB." |
---|
98 | (or (ignore-errors |
---|
99 | (find-contrib-jar)) |
---|
100 | (ignore-errors |
---|
101 | (let ((system-jar (find-system-jar))) |
---|
102 | (when system-jar |
---|
103 | (probe-file (make-pathname |
---|
104 | :defaults system-jar |
---|
105 | :name (concatenate 'string |
---|
106 | "abcl-contrib" |
---|
107 | (subseq (pathname-name system-jar) 4))))))) |
---|
108 | (some |
---|
109 | (lambda (u) |
---|
110 | (probe-file (make-pathname |
---|
111 | :defaults (java:jcall "toString" u) |
---|
112 | :name "abcl-contrib"))) |
---|
113 | (java:jcall "getURLs" (boot-classloader))))) |
---|
114 | |
---|
115 | (export `(find-system |
---|
116 | find-contrib |
---|
117 | *abcl-contrib*)) |
---|
118 | |
---|
119 | (when (find-and-add-contrib :verbose t) |
---|
120 | (provide :abcl-contrib)) |
---|