@Test public void bugfix_72_outline_simple_kubernetes_example() { StringBuilder sb = new StringBuilder(); sb.append("apiVersion: v1\n"); sb.append("kind: Pod\n"); sb.append("metadata:\n"); sb.append(" name: busybox-sleep\n"); YamlScriptModel result = builderToTest.build(sb.toString()); List<YamlNode> rootChildren = result.getRootNode().getChildren(); assertEquals(3, rootChildren.size()); Iterator<YamlNode> iterator = rootChildren.iterator(); YamlNode apiVersion = iterator.next(); assertEquals("apiVersion",apiVersion.getName()); assertEquals(1,apiVersion.getChildren().size()); assertEquals("v1",apiVersion.getChildren().iterator().next().getName()); YamlNode kind = iterator.next(); assertEquals("kind",kind.getName()); assertEquals(1,kind.getChildren().size()); assertEquals("Pod",kind.getChildren().iterator().next().getName()); YamlNode metadata = iterator.next(); assertEquals("metadata", metadata.getName()); List<YamlNode> metaDataChildren = metadata.getChildren(); assertEquals(1, metaDataChildren.size()); YamlNode metaDataName = metaDataChildren.iterator().next(); assertEquals("name", metaDataName.getName()); }
public YamlScriptModel build(String unsafeSourceCode) { YamlScriptModel model = new YamlScriptModel(); try { YamlSanitizerContext context = new YamlSanitizerContext(); String escapedSource = unsafeSourceCode; for (YamlSanitizer yamlSanitizer : this.sanitizers) { escapedSource = yamlSanitizer.sanitize(escapedSource,context); } model.getMessages().addAll(context.getSanitizerMessages()); StringReader reader = new StringReader(escapedSource); YamlNode root = model.getRootNode(); Iterable<Node> nodes = yamlParser.composeAll(reader); for (Node node : nodes) { buildNode(model, root, node); } if (calculateFoldings) { IndentionBlockBuilder builder = new IndentionBlockBuilder(); List<IndentionBlock> blocks = builder.build(escapedSource); transformIndentionsToFoldings(model, blocks); } } catch (MarkedYAMLException e) { String message = e.getMessage(); Mark problem = e.getProblemMark(); int start = problem.getIndex(); int end = start + 1; YamlError error = new YamlError(start, end, message); model.errors.add(error); } return model; }
YamlScriptModelBuilder { public YamlScriptModel build(String unsafeSourceCode) { YamlScriptModel model = new YamlScriptModel(); try { YamlSanitizerContext context = new YamlSanitizerContext(); String escapedSource = unsafeSourceCode; for (YamlSanitizer yamlSanitizer : this.sanitizers) { escapedSource = yamlSanitizer.sanitize(escapedSource,context); } model.getMessages().addAll(context.getSanitizerMessages()); StringReader reader = new StringReader(escapedSource); YamlNode root = model.getRootNode(); Iterable<Node> nodes = yamlParser.composeAll(reader); for (Node node : nodes) { buildNode(model, root, node); } if (calculateFoldings) { IndentionBlockBuilder builder = new IndentionBlockBuilder(); List<IndentionBlock> blocks = builder.build(escapedSource); transformIndentionsToFoldings(model, blocks); } } catch (MarkedYAMLException e) { String message = e.getMessage(); Mark problem = e.getProblemMark(); int start = problem.getIndex(); int end = start + 1; YamlError error = new YamlError(start, end, message); model.errors.add(error); } return model; } }
YamlScriptModelBuilder { public YamlScriptModel build(String unsafeSourceCode) { YamlScriptModel model = new YamlScriptModel(); try { YamlSanitizerContext context = new YamlSanitizerContext(); String escapedSource = unsafeSourceCode; for (YamlSanitizer yamlSanitizer : this.sanitizers) { escapedSource = yamlSanitizer.sanitize(escapedSource,context); } model.getMessages().addAll(context.getSanitizerMessages()); StringReader reader = new StringReader(escapedSource); YamlNode root = model.getRootNode(); Iterable<Node> nodes = yamlParser.composeAll(reader); for (Node node : nodes) { buildNode(model, root, node); } if (calculateFoldings) { IndentionBlockBuilder builder = new IndentionBlockBuilder(); List<IndentionBlock> blocks = builder.build(escapedSource); transformIndentionsToFoldings(model, blocks); } } catch (MarkedYAMLException e) { String message = e.getMessage(); Mark problem = e.getProblemMark(); int start = problem.getIndex(); int end = start + 1; YamlError error = new YamlError(start, end, message); model.errors.add(error); } return model; } YamlScriptModelBuilder(); }
YamlScriptModelBuilder { public YamlScriptModel build(String unsafeSourceCode) { YamlScriptModel model = new YamlScriptModel(); try { YamlSanitizerContext context = new YamlSanitizerContext(); String escapedSource = unsafeSourceCode; for (YamlSanitizer yamlSanitizer : this.sanitizers) { escapedSource = yamlSanitizer.sanitize(escapedSource,context); } model.getMessages().addAll(context.getSanitizerMessages()); StringReader reader = new StringReader(escapedSource); YamlNode root = model.getRootNode(); Iterable<Node> nodes = yamlParser.composeAll(reader); for (Node node : nodes) { buildNode(model, root, node); } if (calculateFoldings) { IndentionBlockBuilder builder = new IndentionBlockBuilder(); List<IndentionBlock> blocks = builder.build(escapedSource); transformIndentionsToFoldings(model, blocks); } } catch (MarkedYAMLException e) { String message = e.getMessage(); Mark problem = e.getProblemMark(); int start = problem.getIndex(); int end = start + 1; YamlError error = new YamlError(start, end, message); model.errors.add(error); } return model; } YamlScriptModelBuilder(); YamlScriptModelBuilder setSanitizers(YamlSanitizer... sanitizers); YamlScriptModelBuilder setCalculateFoldings(boolean calculateFoldings); YamlScriptModel build(String unsafeSourceCode); }
YamlScriptModelBuilder { public YamlScriptModel build(String unsafeSourceCode) { YamlScriptModel model = new YamlScriptModel(); try { YamlSanitizerContext context = new YamlSanitizerContext(); String escapedSource = unsafeSourceCode; for (YamlSanitizer yamlSanitizer : this.sanitizers) { escapedSource = yamlSanitizer.sanitize(escapedSource,context); } model.getMessages().addAll(context.getSanitizerMessages()); StringReader reader = new StringReader(escapedSource); YamlNode root = model.getRootNode(); Iterable<Node> nodes = yamlParser.composeAll(reader); for (Node node : nodes) { buildNode(model, root, node); } if (calculateFoldings) { IndentionBlockBuilder builder = new IndentionBlockBuilder(); List<IndentionBlock> blocks = builder.build(escapedSource); transformIndentionsToFoldings(model, blocks); } } catch (MarkedYAMLException e) { String message = e.getMessage(); Mark problem = e.getProblemMark(); int start = problem.getIndex(); int end = start + 1; YamlError error = new YamlError(start, end, message); model.errors.add(error); } return model; } YamlScriptModelBuilder(); YamlScriptModelBuilder setSanitizers(YamlSanitizer... sanitizers); YamlScriptModelBuilder setCalculateFoldings(boolean calculateFoldings); YamlScriptModel build(String unsafeSourceCode);  }