boot-clj / boot

Build tooling for Clojure.
https://boot-clj.github.io/
Eclipse Public License 1.0
1.75k stars 181 forks source link

Possible incompatibility with Java's ClassLoader/getResources #690

Closed anler closed 2 years ago

anler commented 6 years ago

Hello! I'm new to Boot and probably a lot of the answers to this issue is already in the Wiki, but I'm writing it here just in case and I'll read the docs afterwards.

Problem Description

I am trying to use Java's ClassLoader/getResources to find all the resource files with a given name in the classpath.

I have the current task:

(deftask dev []
  (set-env! :resource-paths #(conj % "dev-resources"))
  (set-env! :resource-paths #(conj % "test-resources"))
  (repl))

where both, dev-resources and test-resources contain a file named config.edn.

When I boot the REPL with boot dev I have that:

boot.user=> (boot/get-env :resource-paths)
#{"test-resources" "src" "dev-resources"}

but when I execute:

boot.user=> (count (enumeration-seq (-> (Thread/currentThread) .getContextClassLoader (.getResources "config.edn"))))
1

the result is 1 instead of the expected 2. I believe because Boot seems to merge all the resource-path files into a single temp directory: untitled 2

Also, I see that if the paths are stored in a set, the sense of ordering (which I use to shadow files) is lost right? so that would break any assumptions I have on the order of the classpath?

Steps to reproduce

  1. Create two directories each containing a file named the same
  2. Add those directories to the classpath
  3. Run Boot REPL with that classpath an try using Java's ClassLoader/getResources to find all the instances of that filename in the classpath

Platform details

Platform (macOS, Linux, Windows): macOS Platform version: macOS High Sierra Version 10.13.3 JRE/JDK version (java -version): java version "1.8.0_152"

Boot details

Boot version (2.7.1): 2.7.2 build.boot present? (yes/no): yes ~/.boot/profile present? (yes/no): no Task name? (if applicable): Custom task dev

Please also provide the contents of build.boot and ~/.boot/profile (if applicable).

burn2delete commented 5 years ago

You are spot on with the uncertainty of the file overlap, I would restructure your directories to be nested instead.

/resources/test
/resources/dev