|
19 | 19 | import org.hydev.mcpm.utils.PluginJarFile;
|
20 | 20 |
|
21 | 21 | import java.io.*;
|
| 22 | +import java.nio.file.Paths; |
22 | 23 | import java.util.*;
|
23 | 24 | import java.util.stream.Collectors;
|
24 | 25 |
|
@@ -80,6 +81,8 @@ public class SuperLocalPluginTracker implements SuperPluginTracker {
|
80 | 81 | // Directory containing the plugins
|
81 | 82 | private String pluginDirectory = "plugins";
|
82 | 83 |
|
| 84 | + final ObjectMapper mapper = new ObjectMapper(); |
| 85 | + |
83 | 86 | /*
|
84 | 87 | * Instantiates a LocalPluginTracker with default parameters for general use
|
85 | 88 | */
|
@@ -136,9 +139,49 @@ private ArrayList<PluginTrackerModel> readCsv() {
|
136 | 139 | }
|
137 | 140 |
|
138 | 141 | /**
|
139 |
| - * Save a hashmap's contents, overwriting a CSV file |
| 142 | + * Read a JSON file at the given location file and return a mapping between |
| 143 | + * plugin names and install |
| 144 | + * status |
| 145 | + * |
| 146 | + * @param csv The mapping between plugin name and boolean status |
| 147 | + */ |
| 148 | + private ArrayList<PluginTrackerModel> readJson() { |
| 149 | + try { |
| 150 | + // ObjectMapper mapper = new ObjectMapper(); |
| 151 | + // Reads the json file and converts it to a list of PluginTrackerModel objects |
| 152 | + return this.mapper.readValue(new File(mainLockFile), mapper.getTypeFactory() |
| 153 | + .constructCollectionType(ArrayList.class, PluginTrackerModel.class)); |
| 154 | + } catch (FileNotFoundException e) { |
| 155 | + |
| 156 | + return (new ArrayList<PluginTrackerModel>()); |
| 157 | + } catch (JsonParseException | JsonMappingException e) { |
| 158 | + throw new RuntimeException(e); |
| 159 | + } catch (IOException e) { |
| 160 | + throw new RuntimeException(e); |
| 161 | + } |
| 162 | + |
| 163 | + } |
| 164 | + |
| 165 | + /** |
| 166 | + * Save an ArrayList's contents into a JSON file by replacing all contents |
| 167 | + * |
| 168 | + * @param list ArrayList of PluginTrackerModel instances to save |
| 169 | + * |
| 170 | + */ |
| 171 | + private void saveJson(ArrayList<PluginTrackerModel> list) { |
| 172 | + try { |
| 173 | + this.mapper.writeValue(Paths.get(mainLockFile).toFile(), list); |
| 174 | + } catch (IOException e) { |
| 175 | + throw new RuntimeException(e); |
| 176 | + } catch (Exception ex) { |
| 177 | + ex.printStackTrace(); |
| 178 | + } |
| 179 | + } |
| 180 | + |
| 181 | + /** |
| 182 | + * Save an ArrayList's contents, overwriting a CSV file |
140 | 183 | *
|
141 |
| - * @param map Hashmap to save |
| 184 | + * @param list ArrayList of PluginTrackerModel instances to save |
142 | 185 | *
|
143 | 186 | */
|
144 | 187 | private void saveCsv(ArrayList<PluginTrackerModel> listToSave) {
|
|
0 commit comments