diff --git a/headless-services/commons/commons-yaml/src/main/java/org/springframework/ide/vscode/commons/yaml/schema/constraints/Constraints.java b/headless-services/commons/commons-yaml/src/main/java/org/springframework/ide/vscode/commons/yaml/schema/constraints/Constraints.java index 6e7783b30..be19b6694 100644 --- a/headless-services/commons/commons-yaml/src/main/java/org/springframework/ide/vscode/commons/yaml/schema/constraints/Constraints.java +++ b/headless-services/commons/commons-yaml/src/main/java/org/springframework/ide/vscode/commons/yaml/schema/constraints/Constraints.java @@ -35,7 +35,6 @@ import org.springframework.ide.vscode.commons.yaml.schema.YType; import org.yaml.snakeyaml.nodes.MappingNode; import org.yaml.snakeyaml.nodes.Node; import org.yaml.snakeyaml.nodes.NodeTuple; -import org.yaml.snakeyaml.nodes.ScalarNode; import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.ImmutableSet; @@ -47,7 +46,7 @@ import com.google.common.collect.Multimap; * @author Kris De Volder */ public class Constraints { - + public static Constraint requireOneOf(String... properties) { return new RequireOneOf(properties); } @@ -55,7 +54,7 @@ public class Constraints { public static Constraint requireAtMostOneOf(String... properties) { return new RequireOneOf(properties).allowFewer(true); } - + public static Constraint requireAtLeastOneOf(String... properties) { return new RequireOneOf(properties).allowMultiple(true); } @@ -127,12 +126,21 @@ public class Constraints { }; } - public static Constraint deprecatedScalar(Function messageFormatter) { + public static Constraint deprecateProperty(Function messageFormatter, String deprecatedProperty) { return (DynamicSchemaContext dc, Node parent, Node node, YType type, IProblemCollector problems) -> { - if (node instanceof ScalarNode) { - ScalarNode scalarNode = (ScalarNode) node; - String name = NodeUtil.asScalar(scalarNode); - problems.accept(YamlSchemaProblems.deprecatedProperty(messageFormatter.apply(name), node)); + // the `node` is the VALUE off the property, not the property itself. We don't want to deprecate this. + // Instead we want to deprecate the associated keynode, which represents the property. + // Find the corresponding tuple in the parent, as we want to deprecate + // the keyNode (so the actual property) + if (parent instanceof MappingNode) { + MappingNode map = (MappingNode) parent; + for (NodeTuple prop : map.getValue()) { + Node keyNode = prop.getKeyNode(); + String name = NodeUtil.asScalar(keyNode); + if (deprecatedProperty.equals(name)) { + problems.accept(YamlSchemaProblems.deprecatedProperty(messageFormatter.apply(name), keyNode)); + } + } } }; } @@ -169,7 +177,7 @@ public class Constraints { } } } - }; + }; } /** diff --git a/headless-services/manifest-yaml-language-server/src/main/java/org/springframework/ide/vscode/manifest/yaml/ManifestYmlSchema.java b/headless-services/manifest-yaml-language-server/src/main/java/org/springframework/ide/vscode/manifest/yaml/ManifestYmlSchema.java index a64b49937..8143d86f1 100644 --- a/headless-services/manifest-yaml-language-server/src/main/java/org/springframework/ide/vscode/manifest/yaml/ManifestYmlSchema.java +++ b/headless-services/manifest-yaml-language-server/src/main/java/org/springframework/ide/vscode/manifest/yaml/ManifestYmlSchema.java @@ -131,8 +131,8 @@ public final class ManifestYmlSchema implements YamlSchema { YAtomicType t_buildpack = f.yatomic("Buildpack"); if (t_buildpack != null) { t_buildpack.setHintProvider(buildpackProvider); - t_buildpack.require(Constraints.deprecatedScalar((name) -> - "Deprecated: Use `buildpacks` instead.")); + t_buildpack.require(Constraints.deprecateProperty((name) -> + "Deprecated: Use `buildpacks` instead.", "buildpack")); } YAtomicType t_stack = f.yatomic("Stack");