use of com.chimbori.hermitcrab.schema.library.LibraryTag in project lite-apps by chimbori.
the class TagsCollector method updateTagsJson.
public static void updateTagsJson() throws IOException {
Gson gson = GsonInstance.getPrettyPrinter();
// Read the list of all known tags from the tags.json file. In case we discover any new tags,
// we will add them to this file, taking care not to overwrite those that already exist.
LibraryTagsList tagsGson = LibraryTagsList.fromGson(gson, new FileReader(FilePaths.LITE_APPS_TAGS_JSON));
Map<String, LibraryTag> globalTags = new HashMap<>();
File[] liteAppDirs = FilePaths.LITE_APPS_SRC_DIR.listFiles();
for (File liteAppDirectory : liteAppDirs) {
if (!liteAppDirectory.isDirectory()) {
// Probably a temporary file, like .DS_Store.
continue;
}
File manifestJsonFile = new File(liteAppDirectory, FilePaths.MANIFEST_JSON_FILE_NAME);
if (!manifestJsonFile.exists()) {
throw new MissingManifestException(liteAppDirectory.getName());
}
Manifest manifest;
try {
manifest = gson.fromJson(new FileReader(manifestJsonFile), Manifest.class);
} catch (JsonSyntaxException e) {
System.err.println("Failed to parse JSON: " + liteAppDirectory.getName());
throw e;
}
// For all tags applied to this manifest, check if they exist in the global tags list.
if (manifest.tags != null) {
for (String tagName : manifest.tags) {
LibraryTag tag = globalTags.get(tagName);
if (tag == null) {
// If this is the first time we are seeing this tag, create a new JSONArray to hold its contents.
LibraryTag newTag = new LibraryTag(tagName);
globalTags.put(tagName, newTag);
tagsGson.addTag(newTag);
}
}
}
}
// Write the tags to JSON
FileUtils.writeFile(FilePaths.LITE_APPS_TAGS_JSON, tagsGson.toJson(gson));
}
Aggregations