source: trunk/abcl/contrib/abcl-asdf/asdf-jar.lisp @ 13431

Last change on this file since 13431 was 13431, checked in by Mark Evenson, 12 years ago

Allow ASDF definitions for JAR-FILE to include ".jar".

This increases compatibility with the original version of JSS.

The only possible situation where this doesn't make sense would be if
a jar where to end in something other than ".jar", like perhaps ".zip"
or ".war". In this case, additional ASDF classes should be defined
extending JAR-FILE.

File size: 3.7 KB
Line 
1(in-package :abcl-asdf)
2
3(defvar *added-to-classpath* nil)
4
5(defvar *inhibit-add-to-classpath* nil)
6
7(defun add-directory-jars-to-class-path (directory recursive-p)
8  (loop :for jar :in (if recursive-p 
9                         (all-jars-below directory) 
10                         (directory (merge-pathnames "*.jar" directory)))
11     :do (java:add-to-classpath jar)))
12
13(defun all-jars-below (directory) 
14  (loop :with q = (system:list-directory directory) 
15     :while q :for top = (pop q)
16     :if (null (pathname-name top)) 
17       :do (setq q (append q (all-jars-below top))) 
18     :if (equal (pathname-type top) "jar") 
19       :collect top))
20
21(defun need-to-add-directory-jar? (directory recursive-p)
22  (loop :for jar :in (if recursive-p 
23                         (all-jars-below directory)
24                         (directory (merge-pathnames "*.jar" directory)))
25     :doing (if (not (member (namestring (truename jar)) 
26                             *added-to-classpath* :test 'equal))
27                (return-from need-to-add-directory-jar? t)))
28  nil)
29
30(in-package :asdf)
31
32(defclass jar-directory (static-file) ())
33
34(defmethod perform ((operation compile-op) (c jar-directory))
35  (unless abcl-asdf:*inhibit-add-to-classpath*
36    (abcl-asdf:add-directory-jars-to-class-path (truename (component-pathname c)) t)))
37
38(defmethod perform ((operation load-op) (c jar-directory))
39  (unless abcl-asdf:*inhibit-add-to-classpath*
40    (abcl-asdf:add-directory-jars-to-class-path (truename (component-pathname c)) t)))
41
42(defmethod operation-done-p ((operation load-op) (c jar-directory))
43  (or abcl-asdf:*inhibit-add-to-classpath*
44      (not (abcl-asdf:need-to-add-directory-jar? (component-pathname c) t))))
45
46(defmethod operation-done-p ((operation compile-op) (c jar-directory))
47  t)
48
49(defclass jar-file (static-file) ())
50
51(defmethod source-file-type ((c jar-file) (s module)) "jar")
52
53(defmethod perform ((operation compile-op) (c jar-file))
54  (java:add-to-classpath (component-pathname c)))
55
56(defmethod perform ((operation load-op) (c jar-file))
57  (or abcl-asdf:*inhibit-add-to-classpath*
58      (java:add-to-classpath (component-pathname c))))
59
60;;; The original JSS specified jar pathnames as having a NAME ending
61;;; in ".jar" without a TYPE.  If we encounter such a definition, we
62;;; clean it up.
63(defmethod perform :before ((operation load-op) (c jar-file))
64  (when (#"endsWith" (slot-value c 'name) ".jar")
65    (with-slots (name absolute-pathname) c
66      (let* ((new-name 
67              (subseq name 0 (- (length name) 4)))
68             (new-absolute-pathname 
69              (make-pathname :defaults absolute-pathname :name new-name)))
70        (setf name new-name
71              absolute-pathname new-absolute-pathname)))))
72
73(defmethod operation-done-p :before ((operation load-op) (c jar-file))
74  (when (#"endsWith" (slot-value c 'name) ".jar")
75    (with-slots (name absolute-pathname) c
76      (let* ((new-name 
77              (subseq name 0 (- (length name) 4)))
78             (new-absolute-pathname 
79              (make-pathname :defaults absolute-pathname :name new-name)))
80        (setf name new-name
81              absolute-pathname new-absolute-pathname)))))
82
83(defmethod operation-done-p ((operation load-op) (c jar-file))
84  (or abcl-asdf:*inhibit-add-to-classpath*
85      (member (namestring (truename (component-pathname c)))
86              abcl-asdf:*added-to-classpath* :test 'equal)))
87
88(defmethod operation-done-p ((operation compile-op) (c jar-file))
89  t)
90
91(defclass class-file-directory (static-file) ())
92
93(defmethod perform ((operation compile-op) (c class-file-directory))
94  (java:add-to-classpath (component-pathname c)))
95
96(defmethod perform ((operation load-op) (c class-file-directory))
97  (java:add-to-classpath (component-pathname c)))
98
99
100
101
102
Note: See TracBrowser for help on using the repository browser.