Skip to content

Commit

Permalink
Enhanced directory-list to work with JAR files from the classpath
Browse files Browse the repository at this point in the history
This should allow FW/1 to find controllers when run from source and when
run from inside a JAR file on the classpath.
  • Loading branch information
seancorfield committed Nov 16, 2016
1 parent 0756c2e commit 9206576
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
2 changes: 1 addition & 1 deletion resources/fw1.version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.10.0
0.10.1
31 changes: 30 additions & 1 deletion src/framework/one.clj
Original file line number Diff line number Diff line change
Expand Up @@ -539,10 +539,39 @@
(reify java.io.FilenameFilter
(accept [_ dir name] (not (nil? (re-find re name))))))

(defn jar-file-list
"Given a JAR file and a regex, return a seq of matching filenames."
[jar-file re]
(->> jar-file
(java.util.jar.JarFile.)
(.entries)
(iterator-seq)
(filter #(re-find re (.getName %)))
(map #(.getName %))))

(defn path-file-list
"Given a class path element (probably a jar file) and a regex, return a
sequence of matching filenames."
[path re]
(when (str/ends-with? path ".jar")
(jar-file-list (io/file path) re)))

(defn class-path-list
"Given a regex, look in all the class path files for matching files."
[re]
(mapcat #(path-file-list % re)
(seq (.split (System/getProperty "java.class.path")
(System/getProperty "path.separator")))))

(defn directory-list
"Given a directory and a regex, return a sorted seq of matching filenames."
[dir re]
(sort (.list (io/file (io/resource dir)) (wildcard-filter re))))
(let [r (io/resource dir)]
(if (= "file" (.getProtocol r))
(sort (.list (io/file r) (wildcard-filter re)))
(let [dir-re (re-pattern (str "^" dir "/.*" re))
skip (inc (count dir))]
(sort (map #(subs % skip) (class-path-list dir-re)))))))

(defn configure-router
"Given the application configuration, return a router function that takes a
Expand Down

0 comments on commit 9206576

Please sign in to comment.