source: trunk/abcl/test/lisp/abcl/jar-file.lisp @ 12607

Last change on this file since 12607 was 12607, checked in by Mark Evenson, 13 years ago

URL pathnames working for OPEN for built-in schemas.

Still need to decide with URI escaping issues, as we currently rely on
the URL Stream handlers to do the right thing. And we still need to
retrofit jar pathname's use of a string to represent a URL.

Updates for URL and jar pathname design documents.

Implemented URL-PATHNAME and JAR-PATHNAME as subtypes of PATHNAME.

Adjusted ABCL-TEST-LISP to use functions provided in
"pathname-test.lisp" in "jar-file.lisp". Added one test for url
pathnames.

Constructor in Java added for a Cons by copying references from the
orignal Cons.

File size: 11.2 KB
Line 
1(in-package #:abcl.test.lisp)
2
3(defvar *jar-file-init* nil)
4
5;;; From CL-FAD
6(defvar *stream-buffer-size* 8192)
7(defun cl-fad-copy-stream (from to &optional (checkp t))
8  "Copies into TO \(a stream) from FROM \(also a stream) until the end
9of FROM is reached, in blocks of *stream-buffer-size*.  The streams
10should have the same element type.  If CHECKP is true, the streams are
11checked for compatibility of their types."
12  (when checkp
13    (unless (subtypep (stream-element-type to) (stream-element-type from))
14      (error "Incompatible streams ~A and ~A." from to)))
15  (let ((buf (make-array *stream-buffer-size*
16                         :element-type (stream-element-type from))))
17    (loop
18     (let ((pos (read-sequence buf from)))
19       (when (zerop pos) (return))
20       (write-sequence buf to :end pos))))
21  (values))
22
23(defun cl-fad-copy-file (from to &key overwrite)
24  "Copies the file designated by the non-wild pathname designator FROM
25to the file designated by the non-wild pathname designator TO.  If
26OVERWRITE is true overwrites the file designtated by TO if it exists."
27  (let ((element-type '(unsigned-byte 8)))
28    (with-open-file (in from :element-type element-type)
29      (with-open-file (out to :element-type element-type
30                              :direction :output
31                              :if-exists (if overwrite
32                                           :supersede :error))
33        (cl-fad-copy-stream in out))))
34  (values))
35
36(defun jar-file-init ()
37  (let* ((*default-pathname-defaults*  *abcl-test-directory*)
38         (asdf::*verbose-out* *standard-output*))
39    (compile-file "foo.lisp")
40    (compile-file "bar.lisp")
41    (compile-file "eek.lisp")
42    (let* ((dir (merge-pathnames "tmp/" *abcl-test-directory*))
43           (sub (merge-pathnames "a/b/" dir)))
44      (when (probe-directory dir)
45        (delete-directory-and-files dir))
46      (ensure-directories-exist sub)
47      (sys:unzip (merge-pathnames "foo.abcl")
48                 dir)
49      (sys:unzip (merge-pathnames "foo.abcl")
50                 sub)
51      (cl-fad-copy-file (merge-pathnames "bar.abcl")
52                 (merge-pathnames "bar.abcl" dir))
53      (cl-fad-copy-file (merge-pathnames "bar.abcl")
54                 (merge-pathnames "bar.abcl" sub))
55      (cl-fad-copy-file (merge-pathnames "eek.lisp")
56                 (merge-pathnames "eek.lisp" dir))
57      (cl-fad-copy-file (merge-pathnames "eek.lisp")
58                 (merge-pathnames "eek.lisp" sub))
59      (sys:zip (merge-pathnames "baz.jar")
60               (append
61                (directory (merge-pathnames "*" dir))
62                (directory (merge-pathnames "*" sub)))
63               dir)
64      (delete-directory-and-files dir)))
65  (setf *jar-file-init* t))
66
67(defmacro with-jar-file-init (&rest body)
68  `(let ((*default-pathname-defaults* *abcl-test-directory*))
69     (progn
70       (unless *jar-file-init*
71         (jar-file-init))
72       ,@body)))
73
74#+nil
75(defmacro with-jar-file-init (&rest body)
76  `(progv '(*default-pathname-defaults*) '(,*abcl-test-directory*)
77    (unless *jar-file-init*
78      (load-init))
79    ,@body))
80
81(deftest jar-file.load.1
82    (with-jar-file-init
83      (load "jar:file:baz.jar!/foo"))
84  t)
85
86(deftest jar-file.load.2
87    (with-jar-file-init
88      (load "jar:file:baz.jar!/bar"))
89  t)
90
91(deftest jar-file.load.3
92    (with-jar-file-init
93      (load "jar:file:baz.jar!/bar.abcl"))
94  t)
95
96(deftest jar-file.load.4
97    (with-jar-file-init
98      (load "jar:file:baz.jar!/eek"))
99  t)
100
101(deftest jar-file.load.5
102    (with-jar-file-init
103      (load "jar:file:baz.jar!/eek.lisp"))
104  t)
105
106(deftest jar-file.load.6
107    (with-jar-file-init
108      (load "jar:file:baz.jar!/a/b/foo"))
109  t)
110
111(deftest jar-file.load.7
112    (with-jar-file-init
113      (load "jar:file:baz.jar!/a/b/bar"))
114  t)
115
116(deftest jar-file.load.8
117    (with-jar-file-init
118      (load "jar:file:baz.jar!/a/b/bar.abcl"))
119  t)
120
121(deftest jar-file.load.9
122    (with-jar-file-init
123      (load "jar:file:baz.jar!/a/b/eek"))
124  t)
125
126(deftest jar-file.load.10
127    (with-jar-file-init
128      (load "jar:file:baz.jar!/a/b/eek.lisp"))
129  t)
130
131;;; wrapped in PROGN for easy disabling without a network connection
132;;; XXX come up with a better abstraction
133
134(progn 
135  (deftest jar-file.load.11
136      (load "jar:http://abcl-dynamic-install.googlecode.com/files/baz.jar!/foo")
137    t)
138
139  (deftest jar-file.load.12
140      (load "jar:http://abcl-dynamic-install.googlecode.com/files/baz.jar!/bar")
141    t)
142
143  (deftest jar-file.load.13
144      (load "jar:http://abcl-dynamic-install.googlecode.com/files/baz.jar!/bar.abcl")
145    t)
146
147  (deftest jar-file.load.14
148      (load "jar:http://abcl-dynamic-install.googlecode.com/files/baz.jar!/eek")
149    t)
150
151  (deftest jar-file.load.15
152      (load "jar:http://abcl-dynamic-install.googlecode.com/files/baz.jar!/eek.lisp")
153    t)
154
155  (deftest jar-file.load.16
156      (load "jar:http://abcl-dynamic-install.googlecode.com/files/baz.jar!/a/b/foo")
157    t)
158
159  (deftest jar-file.load.17
160      (load "jar:http://abcl-dynamic-install.googlecode.com/files/baz.jar!/a/b/bar")
161    t)
162
163  (deftest jar-file.load.18
164      (load "jar:http://abcl-dynamic-install.googlecode.com/files/baz.jar!/a/b/bar.abcl")
165    t)
166
167  (deftest jar-file.load.19
168      (load "jar:http://abcl-dynamic-install.googlecode.com/files/baz.jar!/a/b/eek")
169    t)
170
171  (deftest jar-file.load.20
172      (load "jar:http://abcl-dynamic-install.googlecode.com/files/baz.jar!/a/b/eek.lisp")
173    t))
174
175
176(deftest jar-file.probe-file.1
177    (with-jar-file-init
178        (probe-file "jar:file:baz.jar!/eek.lisp"))
179  #p#.(format nil "jar:file:~A/baz.jar!/eek.lisp" 
180              (namestring *abcl-test-directory*)))
181
182(deftest jar-file.probe-file.2
183    (with-jar-file-init
184        (probe-file "jar:file:baz.jar!/a/b/bar.abcl"))
185  #p#.(format nil "jar:file:~A/baz.jar!/a/b/bar.abcl"
186              (namestring *abcl-test-directory*)))
187
188(deftest jar-file.probe-file.3
189    (with-jar-file-init
190        (probe-file "jar:jar:file:baz.jar!/a/b/bar.abcl!/bar._"))
191   #p#.(format nil "jar:jar:file:~Abaz.jar!/a/b/bar.abcl!/bar._"
192                       (namestring *abcl-test-directory*)))
193
194(deftest jar-file.probe-file.4
195    (with-jar-file-init
196        (probe-file "jar:file:baz.jar!/a/b"))
197  nil)
198
199(deftest jar-file.probe-file.5
200    (with-jar-file-init
201        (probe-file "jar:file:baz.jar!/a/b/"))
202  #p#.(format nil "jar:file:~Abaz.jar!/a/b/"
203                       (namestring *abcl-test-directory*)))
204
205(deftest jar-file.merge-pathnames.1
206    (merge-pathnames 
207     "/bar.abcl" #p"jar:file:baz.jar!/foo")
208  #p"jar:file:baz.jar!/bar.abcl")
209
210(deftest jar-file.merge-pathnames.2
211    (merge-pathnames 
212     "bar.abcl" #p"jar:file:baz.jar!/foo/")
213  #p"jar:file:baz.jar!/foo/bar.abcl")
214
215(deftest jar-file.merge-pathnames.3
216    (merge-pathnames 
217     "jar:file:baz.jar!/foo" "bar")
218  #p"jar:file:baz.jar!/foo")
219
220(deftest jar-file.merge-pathnames.4
221    (merge-pathnames 
222     "jar:file:baz.jar!/foo" "/a/b/c")
223  #p"jar:file:/a/b/baz.jar!/foo")
224
225(deftest jar-file.merge-pathnames.5
226    (merge-pathnames "jar:file:/a/b/c/foo.jar!/bar/baz.lisp")
227  #p"jar:file:/a/b/c/foo.jar!/bar/baz.lisp")
228
229(deftest jar-file.truename.1
230    (signals-error (truename "jar:file:baz.jar!/foo")
231                   'file-error)
232  t)
233
234(deftest jar-file.pathname.1
235    (let* ((p #p"jar:file:foo/baz.jar!/")
236           (d (first (pathname-device p))))
237      (values
238       (pathname-directory d) (pathname-name d) (pathname-type d)))
239  (:relative "foo") "baz" "jar")
240
241(deftest jar-file.pathname.2
242    (let* ((p #p"jar:file:baz.jar!/foo.abcl")
243           (d (first (pathname-device p))))
244      (values
245       (pathname-name d) (pathname-type d) 
246       (pathname-directory p) (pathname-name p) (pathname-type p)))
247  "baz" "jar"
248   (:absolute) "foo" "abcl")
249   
250(deftest jar-file.pathname.3
251    (let* ((p #p"jar:jar:file:baz.jar!/foo.abcl!/")
252           (d0 (first (pathname-device p)))
253           (d1 (second (pathname-device p))))
254      (values 
255       (pathname-name d0) (pathname-type d0)
256       (pathname-name d1) (pathname-type d1)))
257  "baz" "jar"
258  "foo" "abcl")
259
260(deftest jar-file.pathname.4
261    (let* ((p #p"jar:jar:file:a/baz.jar!/b/c/foo.abcl!/this/that/foo-20.cls")
262           (d0 (first (pathname-device p)))
263           (d1 (second (pathname-device p))))
264      (values 
265       (pathname-directory d0) (pathname-name d0) (pathname-type d0)
266       (pathname-directory d1) (pathname-name d1) (pathname-type d1)
267       (pathname-directory p) (pathname-name p) (pathname-type p)))
268  (:relative "a") "baz" "jar"
269  (:relative "b" "c") "foo" "abcl"
270  (:absolute "this" "that") "foo-20" "cls")
271
272(deftest jar-file.pathname.5
273    (let* ((p #p"jar:jar:file:a/foo/baz.jar!/b/c/foo.abcl!/armed/bear/bar-1.cls")
274           (d0 (first (pathname-device p)))
275           (d1 (second (pathname-device p))))
276      (values 
277       (pathname-directory d0) (pathname-name d0) (pathname-type d0)
278       (pathname-directory d1) (pathname-name d1) (pathname-type d1)
279       (pathname-directory p) (pathname-name p) (pathname-type p)))
280  (:relative "a" "foo" ) "baz" "jar"
281  (:relative "b" "c") "foo" "abcl"
282  (:absolute "armed" "bear") "bar-1" "cls")
283
284(deftest jar-file.pathname.6
285    (let* ((p #p"jar:http://example.org/abcl.jar!/org/armedbear/lisp/Version.class")
286           (d (first (pathname-device p))))
287
288      (values 
289       d
290       (pathname-directory p) (pathname-name p) (pathname-type p)))
291  "http://example.org/abcl.jar" 
292  (:absolute "org" "armedbear" "lisp") "Version" "class")
293
294(deftest jar-file.pathname.7
295    (let* ((p #p"jar:jar:http://example.org/abcl.jar!/foo.abcl!/foo-1.cls")
296           (d (pathname-device p))
297           (d0 (first d))
298           (d1 (second d)))
299      (values
300       d0 
301       (pathname-name d1) (pathname-type d1)
302       (pathname-name p) (pathname-type p)))
303  "http://example.org/abcl.jar"
304  "foo" "abcl"
305  "foo-1" "cls")
306
307(deftest jar-file.pathname.8
308    (let* ((p #p"jar:file:/a/b/foo.jar!/")
309           (d (first (pathname-device p))))
310      (values
311       (pathname-directory d) (pathname-name d) (pathname-type d)))
312  (:ABSOLUTE "a" "b") "foo" "jar")
313
314(deftest jar-file.pathname.9
315    (let* ((p #p"jar:file:a/b/foo.jar!/c/d/foo.lisp")
316           (d (first (pathname-device p))))
317      (values
318       (pathname-directory d) (pathname-name d) (pathname-type d)
319       (pathname-directory p) (pathname-name p) (pathname-type p)))
320  (:relative "a" "b") "foo" "jar"
321  (:absolute "c" "d") "foo" "lisp")
322
323(deftest jar-file.pathname-match-p.1
324    (pathname-match-p "jar:file:/a/b/some.jar!/a/system/def.asd"
325                      "jar:file:/**/*.jar!/**/*.asd")
326  t)
327
328(deftest jar-file.pathname-match-p.2
329    (pathname-match-p "/a/system/def.asd"
330                      "jar:file:/**/*.jar!/**/*.asd")
331  nil)
332
333(deftest jar-file.pathname-match-p.3
334    (pathname-match-p "jar:file:/a/b/some.jar!/a/system/def.asd"
335                      "/**/*.asd")
336  nil)
337
338(deftest jar-file.translate-pathname.1
339    (namestring
340     (translate-pathname "jar:file:/a/b/c.jar!/d/e/f.lisp" 
341                         "jar:file:/**/*.jar!/**/*.*" 
342                         "/foo/**/*.*"))
343  "/foo/d/e/f.lisp")
344
345;; URL Pathname tests
346(deftest pathname-url.1
347    (let* ((p #p"http://example.org/a/b/foo.lisp")
348           (host (pathname-host p)))
349      (values 
350       (check-physical-pathname p '(:absolute "a" "b") "foo" "lisp")
351       (and (consp host)
352            (equal (getf host :scheme) 
353                   "http")
354            (equal (getf host :authority)
355                   "example.org"))))
356  (t t))
357
358     
359
360       
361
362 
Note: See TracBrowser for help on using the repository browser.