private GoPluginApiResponse handleParseContentRequest(GoPluginApiRequest request) { return handlingErrors(() -> { ParsedRequest parsed = ParsedRequest.parse(request); YamlConfigParser parser = new YamlConfigParser(); Map<String, String> contents = parsed.getParam("contents"); JsonConfigCollection result = new JsonConfigCollection(); contents.forEach((filename, content) -> { parser.parseStream(result, new ByteArrayInputStream(content.getBytes()), filename); }); result.updateTargetVersionFromFiles(); return success(gson.toJson(result.getJsonObject())); }); }
private GoPluginApiResponse handleParseDirectoryRequest(GoPluginApiRequest request) { return handlingErrors(() -> { ParsedRequest parsed = ParsedRequest.parse(request); File baseDir = new File(parsed.getStringParam("directory")); String pattern = parsed.getConfigurationKey(PLUGIN_SETTINGS_FILE_PATTERN); if (isBlank(pattern)) { pattern = getFilePattern(); } YamlConfigParser parser = new YamlConfigParser(); String[] files = new AntDirectoryScanner().getFilesMatchingPattern(baseDir, pattern); JsonConfigCollection config = parser.parseFiles(baseDir, files); config.updateTargetVersionFromFiles(); return success(gson.toJson(config.getJsonObject())); }); }
public JsonConfigCollection parseFiles(File baseDir, String[] files) { JsonConfigCollection collection = new JsonConfigCollection(); for (String file : files) { try { parseStream(collection, new FileInputStream(new File(baseDir, file)), file); } catch (FileNotFoundException ex) { collection.addError("File matching GoCD YAML pattern disappeared", file); } } return collection; }
YamlConfigParser parser = new YamlConfigParser(); JsonConfigCollection collection = new JsonConfigCollection(); parser.parseStream(collection, getFileAsStream(syntax.file), getLocation(syntax.file));