-
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
13 changed files
with
125 additions
and
84 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
50 changes: 50 additions & 0 deletions
50
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,50 @@ | ||
/******************************************************************************* | ||
* 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.BufferedOutputStream; | ||
import java.io.ByteArrayOutputStream; | ||
import java.io.File; | ||
import java.io.FileOutputStream; | ||
import java.io.IOException; | ||
import java.io.OutputStream; | ||
import java.nio.charset.StandardCharsets; | ||
import java.util.Properties; | ||
import java.util.stream.Collectors; | ||
|
||
/** | ||
* 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 file. | ||
* @param file | ||
* the file to write to. | ||
* @throws IOException | ||
* if writing the property list to the specified output stream throws an | ||
* IOException. | ||
*/ | ||
public static void storeProperties(Properties properties, File file) throws IOException { | ||
final ByteArrayOutputStream baos = new ByteArrayOutputStream(); | ||
properties.store(baos, null); | ||
final String content = baos.toString(StandardCharsets.ISO_8859_1).lines().filter(line -> !line.startsWith("#")) | ||
.sorted().collect(Collectors.joining("\n", "", "\n")); | ||
try (OutputStream os = new BufferedOutputStream(new FileOutputStream(file))) { | ||
os.write(content.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
Oops, something went wrong.