jar-file.lisp 10.2 KB
Newer Older
1 2
(in-package #:abcl.test.lisp)

3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
(defvar *jar-file-init* nil)

;;; From CL-FAD
(defvar *stream-buffer-size* 8192)
(defun cl-fad-copy-stream (from to &optional (checkp t))
  "Copies into TO \(a stream) from FROM \(also a stream) until the end
of FROM is reached, in blocks of *stream-buffer-size*.  The streams
should have the same element type.  If CHECKP is true, the streams are
checked for compatibility of their types."
  (when checkp
    (unless (subtypep (stream-element-type to) (stream-element-type from))
      (error "Incompatible streams ~A and ~A." from to)))
  (let ((buf (make-array *stream-buffer-size*
                         :element-type (stream-element-type from))))
    (loop
     (let ((pos (read-sequence buf from)))
       (when (zerop pos) (return))
       (write-sequence buf to :end pos))))
  (values))

(defun cl-fad-copy-file (from to &key overwrite)
  "Copies the file designated by the non-wild pathname designator FROM
to the file designated by the non-wild pathname designator TO.  If
OVERWRITE is true overwrites the file designtated by TO if it exists."
  (let ((element-type '(unsigned-byte 8)))
    (with-open-file (in from :element-type element-type)
      (with-open-file (out to :element-type element-type
                              :direction :output
                              :if-exists (if overwrite
                                           :supersede :error))
        (cl-fad-copy-stream in out))))
  (values))

(defun jar-file-init ()
  (let* ((*default-pathname-defaults*  *abcl-test-directory*)
         (asdf::*verbose-out* *standard-output*))
39 40 41
    (compile-file "foo.lisp")
    (compile-file "bar.lisp")
    (compile-file "eek.lisp")
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
    (let* ((dir (merge-pathnames "tmp/" *abcl-test-directory*))
           (sub (merge-pathnames "a/b/" dir)))
      (when (probe-directory dir)
        (delete-directory-and-files dir))
      (ensure-directories-exist sub)
      (sys:unzip (merge-pathnames "foo.abcl")
                 dir)
      (sys:unzip (merge-pathnames "foo.abcl")
                 sub)
      (cl-fad-copy-file (merge-pathnames "bar.abcl")
                 (merge-pathnames "bar.abcl" dir))
      (cl-fad-copy-file (merge-pathnames "bar.abcl")
                 (merge-pathnames "bar.abcl" sub))
      (cl-fad-copy-file (merge-pathnames "eek.lisp")
                 (merge-pathnames "eek.lisp" dir))
      (cl-fad-copy-file (merge-pathnames "eek.lisp")
                 (merge-pathnames "eek.lisp" sub))
      (sys:zip (merge-pathnames "baz.jar")
               (append
                (directory (merge-pathnames "*" dir))
                (directory (merge-pathnames "*" sub)))
               dir)
      (delete-directory-and-files dir)))
65 66 67
  (setf *jar-file-init* t))

(defmacro with-jar-file-init (&rest body)
68
  `(let ((*default-pathname-defaults* *abcl-test-directory*))
69 70
     (progn
       (unless *jar-file-init*
71
         (jar-file-init))
72 73
       ,@body)))

74 75 76 77 78 79 80 81
#+nil
(defmacro with-jar-file-init (&rest body)
  `(progv '(*default-pathname-defaults*) '(,*abcl-test-directory*)
    (unless *jar-file-init*
      (load-init))
    ,@body))

(deftest jar-file.load.1
82
    (with-jar-file-init
83
      (load "jar:file:baz.jar!/foo"))
84 85
  t)

86
(deftest jar-file.load.2
87
    (with-jar-file-init
88
      (load "jar:file:baz.jar!/bar"))
89 90
  t)

91
(deftest jar-file.load.3
92
    (with-jar-file-init
93
      (load "jar:file:baz.jar!/bar.abcl"))
94 95
  t)

96
(deftest jar-file.load.4
97
    (with-jar-file-init
98
      (load "jar:file:baz.jar!/eek"))
99 100
  t)

101
(deftest jar-file.load.5
102
    (with-jar-file-init
103
      (load "jar:file:baz.jar!/eek.lisp"))
104 105
  t)

106
(deftest jar-file.load.6
107
    (with-jar-file-init
108
      (load "jar:file:baz.jar!/a/b/foo"))
109 110
  t)

111
(deftest jar-file.load.7
112
    (with-jar-file-init
113
      (load "jar:file:baz.jar!/a/b/bar"))
114 115
  t)

116
(deftest jar-file.load.8
117
    (with-jar-file-init
118
      (load "jar:file:baz.jar!/a/b/bar.abcl"))
119 120
  t)

121 122 123 124 125 126 127 128 129
(deftest jar-file.load.9
    (with-jar-file-init
      (load "jar:file:baz.jar!/a/b/eek"))
  t)

(deftest jar-file.load.10
    (with-jar-file-init
      (load "jar:file:baz.jar!/a/b/eek.lisp"))
  t)
130

131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174
;;; wrapped in PROGN for easy disabling without a network connection
;;; XXX come up with a better abstraction
(progn 
  (deftest jar-file.load.11
      (load "jar:http://abcl-dynamic-install.googlecode.com/files/baz.jar!/foo")
    t)

  (deftest jar-file.load.12
      (load "jar:http://abcl-dynamic-install.googlecode.com/files/baz.jar!/bar")
    t)

  (deftest jar-file.load.13
      (load "jar:http://abcl-dynamic-install.googlecode.com/files/baz.jar!/bar.abcl")
    t)

  (deftest jar-file.load.14
      (load "jar:http://abcl-dynamic-install.googlecode.com/files/baz.jar!/eek")
    t)

  (deftest jar-file.load.15
      (load "jar:http://abcl-dynamic-install.googlecode.com/files/baz.jar!/eek.lisp")
    t)

  (deftest jar-file.load.16
      (load "jar:http://abcl-dynamic-install.googlecode.com/files/baz.jar!/a/b/foo")
    t)

  (deftest jar-file.load.17
      (load "jar:http://abcl-dynamic-install.googlecode.com/files/baz.jar!/a/b/bar")
    t)

  (deftest jar-file.load.18
      (load "jar:http://abcl-dynamic-install.googlecode.com/files/baz.jar!/a/b/bar.abcl")
    t)

  (deftest jar-file.load.19
      (load "jar:http://abcl-dynamic-install.googlecode.com/files/baz.jar!/a/b/eek")
    t)

  (deftest jar-file.load.20
      (load "jar:http://abcl-dynamic-install.googlecode.com/files/baz.jar!/a/b/eek.lisp")
    t))


175
(deftest jar-file.probe-file.1
176 177
    (with-jar-file-init
        (probe-file "jar:file:baz.jar!/eek.lisp"))
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202
  #p#.(format nil "jar:file:~A/baz.jar!/eek.lisp" 
              (namestring *abcl-test-directory*)))

(deftest jar-file.probe-file.2
    (with-jar-file-init
        (probe-file "jar:file:baz.jar!/a/b/bar.abcl"))
  #p#.(format nil "jar:file:~A/baz.jar!/a/b/bar.abcl"
              (namestring *abcl-test-directory*)))

(deftest jar-file.probe-file.3
    (with-jar-file-init
        (probe-file "jar:jar:file:baz.jar!/a/b/bar.abcl!/bar._"))
   #p#.(format nil "jar:jar:file:~Abaz.jar!/a/b/bar.abcl!/bar._"
                       (namestring *abcl-test-directory*)))

(deftest jar-file.probe-file.4
    (with-jar-file-init
        (probe-file "jar:file:baz.jar!/a/b"))
  nil)

(deftest jar-file.probe-file.5
    (with-jar-file-init
        (probe-file "jar:file:baz.jar!/a/b/"))
  #p#.(format nil "jar:file:~Abaz.jar!/a/b/"
                       (namestring *abcl-test-directory*)))
203

204 205 206 207 208 209 210
(deftest jar-file.merge-pathnames.1
    (merge-pathnames 
     "/bar.abcl" #p"jar:file:baz.jar!/foo")
  #p"jar:file:baz.jar!/bar.abcl")

(deftest jar-file.merge-pathnames.2
    (merge-pathnames 
211
     "bar.abcl" #p"jar:file:baz.jar!/foo/")
212
  #p"jar:file:baz.jar!/foo/bar.abcl")
213

214
(deftest jar-file.merge-pathnames.3
215
    (merge-pathnames 
216
     "jar:file:baz.jar!/foo" "bar")
217 218
  #p"jar:file:baz.jar!/foo")

219 220 221 222 223
(deftest jar-file.merge-pathnames.4
    (merge-pathnames 
     "jar:file:baz.jar!/foo" "/a/b/c")
  #p"jar:file:/a/b/baz.jar!/foo")

224 225 226 227
(deftest jar-file.merge-pathnames.5
    (merge-pathnames "jar:file:/a/b/c/foo.jar!/bar/baz.lisp")
  #p"jar:file:/a/b/c/foo.jar!/bar/baz.lisp")

228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320
(deftest jar-file.truename.1
    (signals-error (truename "jar:file:baz.jar!/foo")
                   'file-error)
  t)

(deftest jar-file.pathname.1
    (let* ((p #p"jar:file:foo/baz.jar!/")
           (d (first (pathname-device p))))
      (values
       (pathname-directory d) (pathname-name d) (pathname-type d)))
  (:relative "foo") "baz" "jar")

(deftest jar-file.pathname.2
    (let* ((p #p"jar:file:baz.jar!/foo.abcl")
           (d (first (pathname-device p))))
      (values
       (pathname-name d) (pathname-type d) 
       (pathname-directory p) (pathname-name p) (pathname-type p)))
  "baz" "jar"
   nil "foo" "abcl")
   
(deftest jar-file.pathname.3
    (let* ((p #p"jar:jar:file:baz.jar!/foo.abcl!/")
           (d0 (first (pathname-device p)))
           (d1 (second (pathname-device p))))
      (values 
       (pathname-name d0) (pathname-type d0)
       (pathname-name d1) (pathname-type d1)))
  "baz" "jar"
  "foo" "abcl")

(deftest jar-file.pathname.4
    (let* ((p #p"jar:jar:file:a/baz.jar!/b/c/foo.abcl!/this/that/foo-20.cls")
           (d0 (first (pathname-device p)))
           (d1 (second (pathname-device p))))
      (values 
       (pathname-directory d0) (pathname-name d0) (pathname-type d0)
       (pathname-directory d1) (pathname-name d1) (pathname-type d1)
       (pathname-directory p) (pathname-name p) (pathname-type p)))
  (:relative "a") "baz" "jar"
  (:relative "b" "c") "foo" "abcl"
  (:relative "this" "that") "foo-20" "cls")

(deftest jar-file.pathname.5
    (let* ((p #p"jar:jar:file:a/foo/baz.jar!/b/c/foo.abcl!/armed/bear/bar-1.cls")
           (d0 (first (pathname-device p)))
           (d1 (second (pathname-device p))))
      (values 
       (pathname-directory d0) (pathname-name d0) (pathname-type d0)
       (pathname-directory d1) (pathname-name d1) (pathname-type d1)
       (pathname-directory p) (pathname-name p) (pathname-type p)))
  (:relative "a" "foo" ) "baz" "jar"
  (:relative "b" "c") "foo" "abcl"
  (:relative "armed" "bear") "bar-1" "cls")

(deftest jar-file.pathname.6
    (let* ((p #p"jar:http://example.org/abcl.jar!/org/armedbear/lisp/Version.class")
           (d (first (pathname-device p))))

      (values 
       d
       (pathname-directory p) (pathname-name p) (pathname-type p)))
  "http://example.org/abcl.jar" 
  (:relative "org" "armedbear" "lisp") "Version" "class")

(deftest jar-file.pathname.7
    (let* ((p #p"jar:jar:http://example.org/abcl.jar!/foo.abcl!/foo-1.cls")
           (d (pathname-device p))
           (d0 (first d))
           (d1 (second d)))
      (values
       d0 
       (pathname-name d1) (pathname-type d1)
       (pathname-name p) (pathname-type p)))
  "http://example.org/abcl.jar"
  "foo" "abcl"
  "foo-1" "cls")

(deftest jar-file.pathname.8
    (let* ((p #p"jar:file:/a/b/foo.jar!/")
           (d (first (pathname-device p))))
      (values
       (pathname-directory d) (pathname-name d) (pathname-type d)))
  (:ABSOLUTE "a" "b") "foo" "jar")

(deftest jar-file.pathname.9
    (let* ((p #p"jar:file:a/b/foo.jar!/c/d/foo.lisp")
           (d (first (pathname-device p))))
      (values
       (pathname-directory d) (pathname-name d) (pathname-type d)
       (pathname-directory p) (pathname-name p) (pathname-type p)))
  (:RELATIVE "a" "b") "foo" "jar"
  (:RELATIVE "c" "d") "foo" "lisp")
321

322 323 324
      
      
             
325

326 327
       
        
328 329