PT 162499688 - Fixed error with marking deprecated property

This commit is contained in:
nsingh@pivotal.io
2018-12-12 12:07:00 -08:00
parent 89ab018588
commit 41d30ae7a9
2 changed files with 19 additions and 11 deletions

View File

@@ -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<String, String> messageFormatter) {
public static Constraint deprecateProperty(Function<String, String> 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 {
}
}
}
};
};
}
/**

View File

@@ -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");