asciidoctor / asciidoctorj-pdf

AsciidoctorJ PDF bundles the Asciidoctor PDF RubyGem (asciidoctor-pdf) so it can be loaded into the JVM using JRuby.
Apache License 2.0
36 stars 17 forks source link

SOURCE_DATE_EPOCH environment variable not taken into account #46

Closed ldesgrange closed 3 years ago

ldesgrange commented 3 years ago

Hi,

In order to make reproducible PDF files for my tests, I'm trying to set the SOURCE_DATE_EPOCH environment variable as explained in the doc but from what I see, the generated PDF is still using the current date.

I tried using JUnit's annotation @SetEnvironmentVariable(key = "SOURCE_DATE_EPOCH", value = "1000000") or by running gradle with the environnement variable: $ SOURCE_DATE_EPOCH=1000000 ./gradlew test --tests *generatePdf, I also tried System.setProperty("SOURCE_DATE_EPOCH", "1000000");, but running mdls on the PDF shows:

kMDItemContentCreationDate             = 2020-12-03 17:52:58 +0000
kMDItemContentCreationDate_Ranking     = 2020-12-03 00:00:00 +0000
kMDItemContentModificationDate         = 2020-12-03 17:53:41 +0000
kMDItemContentModificationDate_Ranking = 2020-12-03 00:00:00 +0000
kMDItemDateAdded                       = 2020-12-03 17:52:58 +0000
kMDItemDateAdded_Ranking               = 2020-12-03 00:00:00 +0000
kMDItemFSContentChangeDate             = 2020-12-03 17:53:41 +0000
kMDItemFSCreationDate                  = 2020-12-03 17:52:58 +0000
kMDItemInterestingDate_Ranking         = 2020-12-03 00:00:00 +0000

Am I doing it wrong or is the environment variable not provided to JRuby (or something else)?

robertpanzer commented 3 years ago

I just tried converting a file with the Asciidoctor Gradle Plugin and an environment variable and it set the expected attributes. I don't think though that setting file metadata on OSX is the goal of SOURCE_DATE_EPOCH, but rather that you have an attribute with that timestamp that you can embed in the document.

You might want to file this in asciidoctor/asciidoctor. Therefore I am going to close this ticket here.

ldesgrange commented 3 years ago

Sorry, I was a bit tired and mixed up some things. Yes you are right it's not to set the file system metadata but the PDF metadata, what I wanted to say is that if I create the same document twice and do $ diff *.pdf I get:

7,8c7,8
< /ModDate (D:20201207151415+01'00')
< /CreationDate (D:20201207151415+01'00')
---
> /ModDate (D:20201207151143+01'00')
> /CreationDate (D:20201207151143+01'00')

After more tests, in fact it works with gradle (from the command line) but not the other cases (from within Java). Thanks.