|
9 | 9 | import java.nio.file.StandardOpenOption;
|
10 | 10 | import java.util.List;
|
11 | 11 | import java.util.Map;
|
| 12 | +import java.util.Map.Entry; |
12 | 13 | import java.util.Properties;
|
13 | 14 | import java.util.stream.Collectors;
|
14 | 15 |
|
@@ -46,35 +47,62 @@ public void run() {
|
46 | 47 |
|
47 | 48 | Path target = file_path.getParent().resolve("ide.properties");
|
48 | 49 | Properties devonProperties = new Properties();
|
49 |
| - try (InputStream devonInputStream = Files.newInputStream(file_path)) { |
50 |
| - devonProperties.load(devonInputStream); |
51 |
| - |
52 |
| - for (String name : devonProperties.stringPropertyNames()) { |
53 |
| - if (name.contains("DEVON_")) { |
54 |
| - devonProperties.put(name.replace("DEVON_", ""), devonProperties.get(name)); |
55 |
| - devonProperties.remove(name); |
| 50 | + try { |
| 51 | + List<String> readLines = Files.readAllLines(file_path); |
| 52 | + String[] split; |
| 53 | + for (String line : readLines) { |
| 54 | + if (!line.contains("#") && !line.isEmpty()) { |
| 55 | + if (line.contains("DEVON_")) { |
| 56 | + line.replace("DEVON_", ""); |
| 57 | + } |
| 58 | + split = line.split("[ =]"); |
| 59 | + if (split.length == 3) { |
| 60 | + devonProperties.put(split[1], new String[] { split[0], split[2] }); |
| 61 | + } |
| 62 | + if (split.length == 2) { |
| 63 | + devonProperties.put(split[0], split[1]); |
| 64 | + } |
56 | 65 | }
|
57 | 66 | }
|
| 67 | + |
58 | 68 | } catch (IOException e) {
|
59 | 69 | throw new RuntimeException(e);
|
60 | 70 | }
|
61 | 71 |
|
62 | 72 | if (context.getFileAccess().findFirst(file_path.getParent(), path -> path.getFileName().toString().equals("ide.properties"), false) != null) {
|
63 | 73 | try {
|
| 74 | + List<String> readLines = Files.readAllLines(target); |
| 75 | + String[] split; |
| 76 | + |
64 | 77 | Properties ideProperties = new Properties();
|
65 |
| - try (InputStream ideInputStream = Files.newInputStream(target)) { |
66 |
| - ideProperties.load(ideInputStream); |
| 78 | + for (String line : readLines) { |
| 79 | + if (!line.contains("#") && !line.isEmpty()) { |
| 80 | + split = line.split("[ =]"); |
| 81 | + if (split.length == 3) { |
| 82 | + ideProperties.put(split[1], new String[] { split[0], split[2] }); |
| 83 | + } |
| 84 | + if (split.length == 2) { |
| 85 | + ideProperties.put(split[0], split[1]); |
| 86 | + } |
| 87 | + } |
67 | 88 | }
|
68 | 89 |
|
69 | 90 | Properties mergedProperties = new Properties();
|
70 |
| - mergedProperties.putAll(ideProperties.entrySet().stream().collect(Collectors.toMap(e -> e.getKey().toString(), e -> e.getValue().toString()))); |
71 |
| - mergedProperties.putAll(devonProperties.entrySet().stream().collect(Collectors.toMap(e -> e.getKey().toString(), e -> e.getValue().toString()))); |
| 91 | + mergedProperties.putAll(ideProperties.entrySet().stream().collect(Collectors.toMap(e -> e.getKey().toString(), e -> e.getValue()))); |
| 92 | + mergedProperties.putAll(devonProperties.entrySet().stream().collect(Collectors.toMap(e -> e.getKey().toString(), e -> e.getValue()))); |
72 | 93 | for (String name : ideProperties.stringPropertyNames()) {
|
73 | 94 | mergedProperties.remove(name);
|
74 | 95 | }
|
75 | 96 |
|
76 |
| - Files.write(target, mergedProperties.entrySet().stream().map(entry -> entry.getKey() + "=" + entry.getValue()).collect(Collectors.toList()), |
77 |
| - StandardOpenOption.APPEND); |
| 97 | + for (Entry<Object, Object> set : mergedProperties.entrySet()) { |
| 98 | + if (set.getValue() instanceof String) { |
| 99 | + Files.write(target, ("\n" + set.getKey().toString() + "=" + set.getValue().toString()).getBytes(), StandardOpenOption.APPEND); |
| 100 | + } |
| 101 | + if (set.getValue() instanceof String[]) { |
| 102 | + String[] values = (String[]) set.getValue(); |
| 103 | + Files.write(target, ("\n" + values[0] + " " + set.getKey().toString() + "=" + values[1]).getBytes(), StandardOpenOption.APPEND); |
| 104 | + } |
| 105 | + } |
78 | 106 |
|
79 | 107 | this.context.success("Successfully merged and updated ide.properties: " + file_path);
|
80 | 108 |
|
@@ -103,8 +131,15 @@ public void run() {
|
103 | 131 | + "# In case you are sitting behind a proxy these JVM options may help:\n"
|
104 | 132 | + "#export JAVA_OPTS=-Dhttp.proxyHost=myproxy.com -Dhttp.proxyPort=8080\n";
|
105 | 133 | Files.write(file_path, comment.getBytes());
|
106 |
| - Files.write(file_path, devonProperties.entrySet().stream().map(entry -> entry.getKey() + "=" + entry.getValue()).collect(Collectors.toList()), |
107 |
| - StandardOpenOption.APPEND); |
| 134 | + for (Entry<Object, Object> set : devonProperties.entrySet()) { |
| 135 | + if (set.getValue() instanceof String) { |
| 136 | + Files.write(file_path, ("\n" + set.getKey().toString() + "=" + set.getValue().toString()).getBytes(), StandardOpenOption.APPEND); |
| 137 | + } |
| 138 | + if (set.getValue() instanceof String[]) { |
| 139 | + String[] values = (String[]) set.getValue(); |
| 140 | + Files.write(file_path, ("\n" + values[0] + " " + set.getKey().toString() + "=" + values[1]).getBytes(), StandardOpenOption.APPEND); |
| 141 | + } |
| 142 | + } |
108 | 143 | Files.move(file_path, target);
|
109 | 144 | this.context.success("Updated file name: " + file_path + "\n-> " + target);
|
110 | 145 | } catch (IOException e) {
|
|
0 commit comments