use of org.springframework.ide.vscode.commons.yaml.ast.YamlFileAST in project sts4 by spring-projects.
the class YamlReconcileEngine method reconcile.
@Override
public void reconcile(IDocument doc, IProblemCollector problemCollector) {
problemCollector.beginCollecting();
try {
YamlFileAST ast = parser.getAST(doc);
YamlASTReconciler reconciler = getASTReconciler(doc, problemCollector);
if (reconciler != null) {
reconciler.reconcile(ast);
}
} catch (ParserException e) {
String msg = e.getProblem();
Mark mark = e.getProblemMark();
problemCollector.accept(syntaxError(msg, mark.getIndex(), 1));
} catch (ScannerException e) {
String msg = e.getProblem();
Mark mark = e.getProblemMark();
problemCollector.accept(syntaxError(msg, mark.getIndex(), 1));
} catch (Exception e) {
logger.error("unexpected error during reconcile", e);
} finally {
problemCollector.endCollecting();
}
}
use of org.springframework.ide.vscode.commons.yaml.ast.YamlFileAST in project sts4 by spring-projects.
the class BoshDeploymentManifestSchema method getCurrentEntityProperty.
private String getCurrentEntityProperty(DynamicSchemaContext dc, String propName) {
YamlPath path = dc.getPath();
YamlFileAST ast = asts.getSafeAst(dc.getDocument(), true);
if (ast != null) {
return NodeUtil.asScalar(path.dropLast().thenValAt(propName).traverseToNode(ast));
}
return null;
}
use of org.springframework.ide.vscode.commons.yaml.ast.YamlFileAST in project sts4 by spring-projects.
the class BoshCommandCloudConfigProvider method getModel.
@Override
public CloudConfigModel getModel(DynamicSchemaContext dc) throws Exception {
String block = getBlock();
YamlFileAST ast = parseYaml(block);
return new CloudConfigModel() {
@Override
public Collection<String> getVMTypes() {
return getNames(VM_TYPE_NAMES);
}
@Override
public Collection<String> getNetworkNames() {
return getNames(NETWORK_NAMES);
}
@Override
public Collection<String> getAvailabilityZones() {
return getNames(AVAILABILITY_ZONES);
}
@Override
public Collection<String> getDiskTypes() {
return getNames(DISK_TYPES);
}
@Override
public Collection<String> getVMExtensions() {
return getNames(VM_EXTENSIONS);
}
private Collection<String> getNames(YamlTraversal namesPath) {
return namesPath.traverseAmbiguously(ast).flatMap(nameNode -> {
String name = NodeUtil.asScalar(nameNode);
return StringUtil.hasText(name) ? Stream.of(name) : Stream.empty();
}).collect(CollectorUtil.toMultiset());
}
};
}
use of org.springframework.ide.vscode.commons.yaml.ast.YamlFileAST in project sts4 by spring-projects.
the class ConcourseModel method passedJobHasInteractionWithResource.
/**
* Verification of contraint: a job used in the 'passed' attribute of a step
* must interact with the resource in question.
*/
public final void passedJobHasInteractionWithResource(DynamicSchemaContext dc, Node parent, Node node, YType type, IProblemCollector problems) {
YamlPath path = dc.getPath();
// Expecting a path like this: YamlPath([0], .jobs, [1], .plan, [0], .passed, [0])
path = path.dropLast();
if (YamlPathSegment.valueAt("passed").equals(path.getLastSegment())) {
String jobName = NodeUtil.asScalar(node);
JobModel job = getJob(dc.getDocument(), jobName);
if (job != null) {
// Only check if the job exists. Otherwise the extra checks will show 'redundant' errors (e.g.
// complaining that 'some-job' doesn't ineract with a resource (because the resource doesn't exist).
YamlFileAST root = asts.getSafeAst(dc.getDocument());
if (root != null) {
Node stepNode = path.dropLast().traverseToNode(root);
if (stepNode != null) {
StepModel step = newStep(stepNode);
String resourceName = step.getResourceName();
if (resourceName != null && getResource(dc.getDocument(), resourceName) != null) {
Set<String> interactions = job.getInteractedResources();
if (interactions != null && !interactions.contains(resourceName)) {
problems.accept(YamlSchemaProblems.schemaProblem("Job '" + jobName + "' does not interact with resource '" + resourceName + "'", node));
}
}
}
}
}
}
}
use of org.springframework.ide.vscode.commons.yaml.ast.YamlFileAST in project sts4 by spring-projects.
the class YamlAstTest method assertNodeTextAt.
/**
* Check that node at given offset exactly covers the expected text
* snippet in the document.
*/
public void assertNodeTextAt(MockYamlEditor input, int offset, String expectText) throws Exception {
YamlFileAST ast = input.parse();
Node node = ast.findNode(offset);
String actualText = input.textUnder(node);
assertEquals(expectText, actualText);
}
Aggregations