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; }
@Before public void SetUp() { jsonCollection = new JsonConfigCollection(); pipe1 = new JsonObject(); pipe1.addProperty("name", "pipe1"); pipe2 = new JsonObject(); pipe2.addProperty("name", "pipe2"); pipeInGroup = new JsonObject(); pipeInGroup.addProperty("name", "pipe3"); pipeInGroup.addProperty("group", "mygroup"); devEnv = new JsonObject(); devEnv.addProperty("name", "dev"); }
public JsonConfigCollection transform(Object rootObj, String location) { JsonConfigCollection partialConfig = new JsonConfigCollection(); Map<String, Object> rootMap = (Map<String, Object>) rootObj; for (Map.Entry<String, Object> pe : rootMap.entrySet()) {
private GoPluginApiResponse handlingErrors(Supplier<GoPluginApiResponse> exec) { try { return exec.get(); } catch (ParsedRequest.RequestParseException e) { return badRequest(e.getMessage()); } catch (Exception e) { LOGGER.error("Unexpected error occurred in YAML configuration plugin.", e); JsonConfigCollection config = new JsonConfigCollection(); config.addError(new PluginError(e.toString(), "YAML config plugin")); return error(gson.toJson(config.getJsonObject())); } }
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())); }); }
JsonConfigCollection collection = new JsonConfigCollection(); parser.parseStream(collection, getFileAsStream(syntax.file), getLocation(syntax.file));