Search in sources :

Example 1 with YamlTraversal

use of org.springframework.ide.vscode.commons.yaml.path.YamlTraversal in project sts4 by spring-projects.

the class ManifestConstraints method getConflictingNodesTraversal.

private static YamlTraversal getConflictingNodesTraversal(YamlPath path, String[] propertyIds) {
    Assert.isLegal(propertyIds.length > 0);
    YamlTraversal properties = null;
    for (String id : propertyIds) {
        properties = properties == null ? YamlPathSegment.keyAt(id) : properties.or(YamlPathSegment.keyAt(id));
    }
    YamlTraversal traversal = path.then(properties);
    if (path.size() > 2) {
        traversal = traversal.or(path.dropLast(2).then(properties));
    }
    return traversal;
}
Also used : YamlTraversal(org.springframework.ide.vscode.commons.yaml.path.YamlTraversal)

Example 2 with YamlTraversal

use of org.springframework.ide.vscode.commons.yaml.path.YamlTraversal 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)

Aggregations

YamlTraversal (org.springframework.ide.vscode.commons.yaml.path.YamlTraversal)2 Duration (java.time.Duration)1 Collection (java.util.Collection)1 Stream (java.util.stream.Stream)1 BoshCliConfig (org.springframework.ide.vscode.bosh.BoshCliConfig)1 CollectorUtil (org.springframework.ide.vscode.commons.util.CollectorUtil)1 ExternalCommand (org.springframework.ide.vscode.commons.util.ExternalCommand)1 StringUtil (org.springframework.ide.vscode.commons.util.StringUtil)1 NodeUtil (org.springframework.ide.vscode.commons.yaml.ast.NodeUtil)1 YamlFileAST (org.springframework.ide.vscode.commons.yaml.ast.YamlFileAST)1 YamlPath (org.springframework.ide.vscode.commons.yaml.path.YamlPath)1 DynamicSchemaContext (org.springframework.ide.vscode.commons.yaml.schema.DynamicSchemaContext)1