-
Notifications
You must be signed in to change notification settings - Fork 194
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Write Properties files in a reproducible way
- Loading branch information
Showing
14 changed files
with
128 additions
and
27 deletions.
There are no files selected for viewing
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
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
54 changes: 54 additions & 0 deletions
54
tycho-api/src/main/java/org/eclipse/tycho/ReproducibleUtils.java
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 |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/******************************************************************************* | ||
* This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License 2.0 | ||
* which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*******************************************************************************/ | ||
package org.eclipse.tycho; | ||
|
||
import java.io.ByteArrayOutputStream; | ||
import java.io.IOException; | ||
import java.io.OutputStream; | ||
import java.nio.charset.StandardCharsets; | ||
import java.util.Properties; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
|
||
/** | ||
* Utility methods for reproducible builds. | ||
*/ | ||
public class ReproducibleUtils { | ||
private ReproducibleUtils() { | ||
} | ||
|
||
/** | ||
* Writes the property list to the output stream in a reproducible way. The java.util.Properties | ||
* class writes the lines in a non-reproducible order, adds a non-reproducible timestamp and | ||
* uses platform-dependent new line characters. | ||
* | ||
* @param properties | ||
* the properties object to write to the output stream. | ||
* @param out | ||
* an output stream. | ||
* @param comments | ||
* a description of the property list. | ||
* @throws IOException | ||
* if writing the property list to the specified output stream throws an | ||
* IOException. | ||
*/ | ||
public static void storeProperties(Properties properties, OutputStream out, String comments) throws IOException { | ||
final ByteArrayOutputStream baos = new ByteArrayOutputStream(); | ||
properties.store(baos, comments); | ||
final String originalContent = baos.toString(StandardCharsets.ISO_8859_1); | ||
// Keep the comment lines if any | ||
final long commentLinesNb = (comments != null) ? comments.lines().count() : 0; | ||
final Stream<String> commentLinesStream = originalContent.lines().limit(commentLinesNb); | ||
// Drop the timestamp comment, order the lines and use a system-independent new line | ||
final String contentFixed = Stream | ||
.concat(commentLinesStream, originalContent.lines().skip(commentLinesNb + 1).sorted()) | ||
.collect(Collectors.joining("\n", "", "\n")); | ||
out.write(contentFixed.getBytes(StandardCharsets.ISO_8859_1)); | ||
} | ||
} |
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
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
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
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
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
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
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
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
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
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
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