Skip to content

Commit 9fe7a70

Browse files
fp7bbatsov
authored andcommitted
Ignore non file URLs when checking for directory or file extensions
In a URLClassLoader not all URLs have to be files or directories. Eg. Spring boot's fat jars add entries like "jar:file:..." to the classpath
1 parent f960bee commit 9fe7a70

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## master (unreleased)
44

5+
### Bugs fixed
6+
7+
* [#83](https://github.com/clojure-emacs/orchard/pull/83): Ignore non file URLs when checking for directory or file extensions.
8+
59
## 0.5.6 (2020-02-14)
610

711
### Bugs fixed

src/orchard/misc.clj

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,27 @@
2020
[]
2121
(not (nil? (boot-fake-classpath))))
2222

23+
(defn url?
24+
"Check whether the argument is an url"
25+
[u]
26+
(instance? java.net.URL u))
27+
2328
(defn directory?
24-
"Whether the argument is a directory"
29+
"Whether the argument is a directory or an url that points to a directory"
2530
[f]
26-
(.isDirectory (io/as-file f)))
31+
(if (url? f)
32+
(and (= (.getProtocol ^java.net.URL f) "file")
33+
(.isDirectory (io/as-file f)))
34+
(.isDirectory (io/as-file f))))
2735

2836
(defn file-ext?
2937
"Whether the argument's path ends in one of the specified case-insensitive
3038
file extensions"
3139
[f & exts]
32-
(let [file (io/as-file f)]
40+
(when-let [file (if (url? f)
41+
(when (= (.getProtocol ^java.net.URL f) "file")
42+
(io/as-file f))
43+
(io/as-file f))]
3344
(some (fn [ext]
3445
(.endsWith (.. file getName toLowerCase) ext))
3546
exts)))

test/orchard/misc_test.clj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,11 @@
5757
(is (nil? (misc/namespace-sym nil)))
5858
(is (= 'unqualified (misc/namespace-sym 'unqualified)))
5959
(is (= 'qualified (misc/namespace-sym 'qualified/sym))))
60+
61+
(deftest file-ext?
62+
(is (misc/file-ext? (java.net.URL. "file:/tmp/foo.jar") ".jar"))
63+
(is (not (misc/file-ext? (java.net.URL. "file:/tmp/foo.war") ".jar")))
64+
(is (not (misc/file-ext? (java.net.URL. "jar:file:/tmp/foo.jar!/BOOT-INF/lib/test.jar") ".jar"))))
65+
66+
(deftest directory?
67+
(is (misc/directory? (.toURL (.toURI (java.io.File. ""))))))

0 commit comments

Comments
 (0)