EwenG / badigeon

A Clojure build library based on tools.deps.
144 stars 19 forks source link

Merging of uberjar resources #19

Open weavejester opened 4 years ago

weavejester commented 4 years ago

Does this library support merging of uberjar resources, such as data_readers.clj?

EwenG commented 4 years ago

The badigeon.uberjar/bundle function ignores resources conflicts (it does not copy them) and optionally prints a warning when conflicts are found. The badigeon.uberjar/find-resource-conflicts function returns the path of all the resources that are in conflict. Then it's up to the user of the library to handle conflicts, typically by doing some file manipulation between a call to badigeon.uberjar/bundle and badigeon.zip/zip. See also the uberjar example.

weavejester commented 4 years ago

Okay, so there's no automatic conflict resolution like lein uberjar. Is that a planned/wishlist feature, or not on the roadmap?

EwenG commented 4 years ago

That's definitely something that could be implemented. What merging strategy would you like to see implemented ?

weavejester commented 4 years ago

Something configurable would be ideal. Leiningen uses a map of filename strings/patterns to a vector of read, merge and write functions. By default it defines the following:

(def components-merger
  [components-read into components-write])

(def clj-map-merger
  [(comp read-string slurp) merge #(spit %1 (pr-str %2))])

(def concat-merger
  [slurp #(str %1 "\n" %2) spit])

(def default-mergers
  {"META-INF/plexus/components.xml" components-merger
   "data_readers.clj"               clj-map-merger
   #"META-INF/services/.*"          concat-merger}

(See the leiningen.uberjar for the definition of components-read and components-write.)

EwenG commented 4 years ago

There is a first version of badigeon.uberjar/merge-resource-conflicts on master

weavejester commented 4 years ago

Oh thanks! I'll check it out!

jlesquembre commented 4 years ago

I was testing it, and I got an error calling badigeon.uberjar/merge-resource-conflicts:

(err) Execution error (FileNotFoundException) at java.io.FileOutputStream/open0 (FileOutputStream.java:-2).
(err) /.../target/lib-0.0.1/META-INF/services/com.fasterxml.jackson.core.JsonFactory (No such file or directory)

You can reproduce the error if you add cheshire to your dependencies.

I think the problem is here: https://github.com/EwenG/badigeon/blob/4bcfd073b7ffe7113ece3daa92f31a5bdfe71379/src/badigeon/uberjar.clj#L267-L269 First time, the file doesn't exist yet

I also notice that there is an error in the example file here: https://github.com/EwenG/badigeon/blob/4bcfd073b7ffe7113ece3daa92f31a5bdfe71379/sample/badigeon/sample.clj#L266 But the function expects out-path as its first argument: https://github.com/EwenG/badigeon/blob/4bcfd073b7ffe7113ece3daa92f31a5bdfe71379/src/badigeon/uberjar.clj#L281

EwenG commented 4 years ago

@jlesquembre Thank you, this is fixed on master