Skip to content

Commit 3e7019c

Browse files
author
TheSnoozer
committed
add a convience method to dump properties into a file
1 parent 0af687f commit 3e7019c

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/main/java/pl/project13/core/util/PropertyManager.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,14 @@
1919

2020
import nu.studer.java.util.OrderedProperties;
2121
import pl.project13.core.CannotReadFileException;
22+
import pl.project13.core.PropertiesFileGenerator;
2223

2324
import javax.annotation.Nonnull;
2425
import javax.annotation.Nullable;
2526
import java.io.*;
2627
import java.nio.charset.Charset;
2728
import java.nio.charset.StandardCharsets;
29+
import java.nio.file.Files;
2830
import java.util.Map;
2931
import java.util.Properties;
3032

@@ -55,6 +57,16 @@ public static Properties readProperties(@Nonnull File propertiesFile, @Nonnull C
5557
}
5658
}
5759

60+
// For now used by the gradle plugin to expose properties to the project
61+
public static void dumpProperties(File gitPropsFile, Properties properties, boolean escapeUnicode) throws IOException {
62+
Files.createDirectories(gitPropsFile.getParentFile().toPath());
63+
try (OutputStream outputStream = new FileOutputStream(gitPropsFile)) {
64+
OrderedProperties sortedLocalProperties = PropertiesFileGenerator.createOrderedProperties();
65+
properties.forEach((key, value) -> sortedLocalProperties.setProperty((String) key, (String) value));
66+
PropertyManager.dumpProperties(outputStream, sortedLocalProperties, escapeUnicode);
67+
}
68+
}
69+
5870
public static void dumpProperties(OutputStream outputStream, OrderedProperties sortedLocalProperties, boolean escapeUnicode) throws IOException {
5971
try (Writer outputWriter = new OutputStreamWriter(outputStream, StandardCharsets.UTF_8)) {
6072
// use the OrderedProperties.store(Writer, ...)-method to avoid illegal reflective access warning

0 commit comments

Comments
 (0)