BrunoBonacci / lein-binplus

A Leiningen plugin for producing standalone console executables that work on OS X, Linux, and Windows.
68 stars 5 forks source link

adding jar offset rewriting and support for preamble scripts from files #7

Closed mbjarland closed 6 years ago

mbjarland commented 6 years ago

After realizing that the original lein-bin repository was dead and failing to find this one for months, I finally did. This PR is replicating the following PR I did in that repo a while back:

https://github.com/Raynes/lein-bin/pull/29

The original comment from that PR pasted below for reference (in case the original lein-bin repo goes away etc).

TLDR: rewriting jar files the way this lib currently does (prepending data to the jar) leaves the jar file integrity compromised. You can see this by issuing:

$> unzip -l bad_prelude.zip 
Archive:  bad_prelude.zip
warning [bad_prelude.zip]:  317 extra bytes at beginning or within zipfile
  (attempting to process anyway)
  Length      Date    Time    Name
...
$>

on a jar file created with lein-binplus. We can see that the file is processed anyway, but unzip gives us a warning. Other tools such as zipdetails does not fare so well:

$> zipdetails bad_prelude.zip 
No Central Directory found
$>

this PR uses clj-zip-meta to rewrite the jar-internal offsets so that the jar file integrity is regained.

Should be noted that clj-zip-meta is not as performant as I would have liked. It can take a few seconds to rewrite the offsets. I know how to increase performance of clj-zip-meta, just haven't had the time. Still, I would rather have it correct and a few seconds slow than incorrect and fast : )

I also added the ability to use external prelude scripts (from files) as some of the preludes I've come up with (drip jvm launcher support for exapmle) turned out to be so complex I would rather not hard code them into the project.clj file.

I submit this pull request in all humbleness and I have to say I'm quite happy to find a maintained fork of lein-bin on github.

Original Pull Request Comment

First of all, thank you for this library. I have been looking for a way to do this for ages and this really solves the problem in an elegant and once-and-for-all way.

With that being said, the current state of this library still left me with two items missing from my wish list of perfection:

I'm somewhat new to clojure and solving this problem led me down quite a journey. In (not so) short:

apologies for the rambling. It was some journey and I would like to thank the writers of this library for writing something so good that it was worth the above trouble to improve on.

If you deem this change acceptable, great. If not, this still solves my local problem so again, many thanks for this library.

BrunoBonacci commented 6 years ago

thanks @mbjarland for this PR, I will review/merge it hopefully tomorrow.

BrunoBonacci commented 6 years ago

thanks @mbjarland, the PR is now merged and available in clojars as lein-binplus 0.6.4 https://clojars.org/lein-binplus/versions/0.6.4

mbjarland commented 6 years ago

that was quick work! Many thanks. I have a couple of lein templates waiting for this release.