|
11 | 11 | import java.util.TreeMap; |
12 | 12 |
|
13 | 13 | public class AppInfo { |
14 | | - public Map<String, String> dependencies; |
| 14 | + private Map<String, Object> json; |
| 15 | + public Map<String, String> dependencies = new TreeMap<>(); |
15 | 16 |
|
16 | 17 | public static final String APP_INFO_FILE = "app.json"; |
17 | 18 |
|
| 19 | + public String[] getDependencyGAVs() { |
| 20 | + return dependencies.entrySet().stream() |
| 21 | + .map(e -> e.getKey() + ":" + e.getValue()) |
| 22 | + .toArray(String[]::new); |
| 23 | + } |
| 24 | + |
18 | 25 | public static AppInfo read() throws IOException { |
19 | 26 | Path prjJson = Path.of(APP_INFO_FILE); |
20 | | - AppInfo prj; |
| 27 | + AppInfo appInfo = new AppInfo(); |
21 | 28 | if (Files.isRegularFile(prjJson)) { |
22 | 29 | try (Reader in = Files.newBufferedReader(prjJson)) { |
23 | 30 | Gson parser = new GsonBuilder().create(); |
24 | | - prj = parser.fromJson(in, AppInfo.class); |
| 31 | + appInfo.json = parser.fromJson(in, Map.class); |
25 | 32 | } |
26 | 33 | } else { |
27 | | - prj = new AppInfo(); |
| 34 | + appInfo = new AppInfo(); |
28 | 35 | } |
29 | | - if (prj.dependencies == null) { |
30 | | - prj.dependencies = new TreeMap<>(); |
31 | | - } else { |
32 | | - prj.dependencies = new TreeMap<>(prj.dependencies); |
| 36 | + // WARNING awful code ahead |
| 37 | + if (appInfo.json.containsKey("dependencies") |
| 38 | + && appInfo.json.get("dependencies") instanceof Map) { |
| 39 | + appInfo.dependencies.putAll((Map<String, String>) appInfo.json.get("dependencies")); |
33 | 40 | } |
34 | | - return prj; |
| 41 | + return appInfo; |
35 | 42 | } |
36 | 43 |
|
37 | | - public static void write(AppInfo prj) throws IOException { |
| 44 | + public static void write(AppInfo appInfo) throws IOException { |
38 | 45 | Path prjJson = Path.of(APP_INFO_FILE); |
39 | 46 | try (Writer out = Files.newBufferedWriter(prjJson)) { |
40 | 47 | Gson parser = new GsonBuilder().setPrettyPrinting().create(); |
41 | | - parser.toJson(prj, out); |
| 48 | + // WARNING awful code ahead |
| 49 | + appInfo.json.put("dependencies", (Map<String, Object>) (Map) appInfo.dependencies); |
| 50 | + parser.toJson(appInfo.json, out); |
42 | 51 | } |
43 | 52 | } |
44 | 53 | } |
0 commit comments