-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSort profile settings.jsh
35 lines (27 loc) · 1.17 KB
/
Sort profile settings.jsh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Files;
import java.util.Collections;
import java.util.stream.Collectors;
void sort(Path path) throws IOException {
var lines = Files.readAllLines(path);
int size = lines.size();
assert lines.get(0).startsWith("<?xml") : lines.get(0);
assert lines.get(1).startsWith("<profiles") : lines.get(1);
assert lines.get(2).trim().startsWith("<profile") : lines.get(2);
var settingsLines = lines.subList(3, size - 2);
var notSettings = settingsLines.stream().filter(s -> !s.trim().startsWith("<setting id=\"org.eclipse.jdt.core.")).collect(Collectors.toList());
assert notSettings.isEmpty() : "Not settings: " + notSettings;
assert lines.get(size - 2).trim().equals("</profile>") : lines.get(size - 2);
assert lines.get(size - 1).trim().equals("</profiles>") : lines.get(size - 1);
Collections.sort(settingsLines);
var trimmed = lines.stream().map(String::trim).collect(Collectors.toList());
Files.write(path, trimmed);
System.out.println("Sorted " + path + ".");
}
void main() throws Exception {
String file = System.getProperty("file", "Untitled.xml");
Path path = Path.of(file);
sort(path);
}
main();