This repository has been archived by the owner on Aug 1, 2024. It is now read-only.
forked from GradleUp/shadow
-
Notifications
You must be signed in to change notification settings - Fork 1
Fix for PropertiesFileTransformer breaks Reproducible builds in 8.1.1 #102
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
fbcd41e
Add test to validate PropertiesFileTransformer supports reproducible …
agascon a7ef65b
Fix CleanProperties mechanism to strip Properties timestamp and suppo…
agascon eac5748
Merge branch 'main' into main
agascon 57c7895
Apply suggestions from code review
Goooler 9d7d97e
Apply suggestions from code review
Goooler 666b57c
Apply suggestions from code review
Goooler File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
32 changes: 17 additions & 15 deletions
32
src/main/groovy/com/github/jengelman/gradle/plugins/shadow/internal/CleanProperties.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,34 @@ | ||
/* | ||
* Source https://stackoverflow.com/a/39043903/519333 | ||
*/ | ||
package com.github.jengelman.gradle.plugins.shadow.internal | ||
|
||
class CleanProperties extends Properties { | ||
private static class StripFirstLineStream extends FilterOutputStream { | ||
|
||
private boolean firstLineSeen = false | ||
private static class StripCommentsWithTimestampBufferedWriter extends BufferedWriter { | ||
|
||
StripFirstLineStream(final OutputStream out) { | ||
private final int lengthOfExpectedTimestamp | ||
|
||
StripCommentsWithTimestampBufferedWriter(final Writer out) { | ||
super(out) | ||
|
||
lengthOfExpectedTimestamp = ("#" + new Date().toString()).length() | ||
} | ||
|
||
@Override | ||
void write(final int b) throws IOException { | ||
if (firstLineSeen) { | ||
super.write(b) | ||
} else if (b == '\n') { | ||
super.write(b) | ||
|
||
firstLineSeen = true | ||
void write(final String str) throws IOException { | ||
if (couldBeCommentWithTimestamp(str)) { | ||
return | ||
} | ||
super.write(str) | ||
} | ||
|
||
private boolean couldBeCommentWithTimestamp(final String str) { | ||
return str != null && | ||
str.startsWith("#") && | ||
str.length() == lengthOfExpectedTimestamp | ||
} | ||
} | ||
|
||
@Override | ||
void store(final OutputStream out, final String comments) throws IOException { | ||
super.store(new StripFirstLineStream(out), null) | ||
void store(final Writer writer, final String comments) throws IOException { | ||
super.store(new StripCommentsWithTimestampBufferedWriter(writer), comments) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This
Date
is related to your locale, how can we make sure the device locale is matched with the jar locale?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The idea of this is to just remove the comment lines which include the timestamp, which is generated when the properties file is written, so I assume locale is the same. Timestamp is not coming from other jar files. Either way I agree is a bit tricky.
Another option could be try to parse the date to see if it's a date or not, or maybe keep it simple and strip all comment lines.
Probably these changes are a mitigation as the real solution should come from the component writing the properties file, but anyway is more solid than the previous one which was removing only the first line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this case, seems the fix is solid.
In this case, seems we still have to determine the real locale is.