Search in sources :

Example 6 with YamlFileAST

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();
    }
}
Also used : ScannerException(org.yaml.snakeyaml.scanner.ScannerException) ParserException(org.yaml.snakeyaml.parser.ParserException) YamlFileAST(org.springframework.ide.vscode.commons.yaml.ast.YamlFileAST) Mark(org.yaml.snakeyaml.error.Mark) ParserException(org.yaml.snakeyaml.parser.ParserException) ScannerException(org.yaml.snakeyaml.scanner.ScannerException)

Example 7 with YamlFileAST

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;
}
Also used : YamlPath(org.springframework.ide.vscode.commons.yaml.path.YamlPath) YamlFileAST(org.springframework.ide.vscode.commons.yaml.ast.YamlFileAST)

Example 8 with YamlFileAST

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());
        }
    };
}
Also used : StringUtil(org.springframework.ide.vscode.commons.util.StringUtil) Stream(java.util.stream.Stream) CollectorUtil(org.springframework.ide.vscode.commons.util.CollectorUtil) YamlTraversal(org.springframework.ide.vscode.commons.yaml.path.YamlTraversal) BoshCliConfig(org.springframework.ide.vscode.bosh.BoshCliConfig) YamlFileAST(org.springframework.ide.vscode.commons.yaml.ast.YamlFileAST) Duration(java.time.Duration) Collection(java.util.Collection) ExternalCommand(org.springframework.ide.vscode.commons.util.ExternalCommand) NodeUtil(org.springframework.ide.vscode.commons.yaml.ast.NodeUtil) YamlPath(org.springframework.ide.vscode.commons.yaml.path.YamlPath) DynamicSchemaContext(org.springframework.ide.vscode.commons.yaml.schema.DynamicSchemaContext) YamlFileAST(org.springframework.ide.vscode.commons.yaml.ast.YamlFileAST) YamlTraversal(org.springframework.ide.vscode.commons.yaml.path.YamlTraversal)

Example 9 with YamlFileAST

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));
                        }
                    }
                }
            }
        }
    }
}
Also used : YamlPath(org.springframework.ide.vscode.commons.yaml.path.YamlPath) YamlFileAST(org.springframework.ide.vscode.commons.yaml.ast.YamlFileAST) MappingNode(org.yaml.snakeyaml.nodes.MappingNode) Node(org.yaml.snakeyaml.nodes.Node)

Example 10 with YamlFileAST

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);
}
Also used : YamlFileAST(org.springframework.ide.vscode.commons.yaml.ast.YamlFileAST) Node(org.yaml.snakeyaml.nodes.Node)

Aggregations

YamlFileAST (org.springframework.ide.vscode.commons.yaml.ast.YamlFileAST)10 YamlPath (org.springframework.ide.vscode.commons.yaml.path.YamlPath)5 Node (org.yaml.snakeyaml.nodes.Node)3 TextDocument (org.springframework.ide.vscode.commons.util.text.TextDocument)2 MappingNode (org.yaml.snakeyaml.nodes.MappingNode)2 File (java.io.File)1 URI (java.net.URI)1 Duration (java.time.Duration)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Stream (java.util.stream.Stream)1 ASTNode (org.eclipse.jdt.core.dom.ASTNode)1 Location (org.eclipse.lsp4j.Location)1 Position (org.eclipse.lsp4j.Position)1 Range (org.eclipse.lsp4j.Range)1 BoshCliConfig (org.springframework.ide.vscode.bosh.BoshCliConfig)1 StemcellModel (org.springframework.ide.vscode.bosh.models.StemcellModel)1 BadLocationException (org.springframework.ide.vscode.commons.util.BadLocationException)1 CollectorUtil (org.springframework.ide.vscode.commons.util.CollectorUtil)1 ExternalCommand (org.springframework.ide.vscode.commons.util.ExternalCommand)1