Add deprecated warning for 'image_resource' and 'image' in embedded task

This commit is contained in:
Kris De Volder
2017-04-03 09:40:35 -07:00
parent 2790976983
commit 18c5fc2ebc
4 changed files with 61 additions and 3 deletions

View File

@@ -76,8 +76,12 @@ public class YamlSchemaProblems {
return new ReconcileProblemImpl(SCHEMA_PROBLEM, msg, node.getStart(), node.getLength());
}
public static ReconcileProblem deprecatedProperty(String msg, Node node) {
return problem(DEPRECATED_PROPERTY, msg, node);
}
public static ReconcileProblem deprecatedProperty(Node node, YType bean, YTypedProperty property) {
return problem(DEPRECATED_PROPERTY, "Property '"+property.getName()+"' of '"+bean+"' is Deprecated", node);
return deprecatedProperty("Property '"+property.getName()+"' of '"+bean+"' is Deprecated", node);
}
public static ReconcileProblem problem(ProblemType problemType, String msg, Node node) {
@@ -85,4 +89,5 @@ public class YamlSchemaProblems {
int end = node.getEndMark().getIndex();
return new ReconcileProblemImpl(problemType, msg, start, end-start);
}
}

View File

@@ -17,14 +17,19 @@ import static org.springframework.ide.vscode.commons.yaml.reconcile.YamlSchemaPr
import java.util.Arrays;
import java.util.List;
import java.util.Set;
import java.util.function.Function;
import org.springframework.ide.vscode.commons.languageserver.reconcile.IProblemCollector;
import org.springframework.ide.vscode.commons.util.Assert;
import org.springframework.ide.vscode.commons.yaml.ast.NodeUtil;
import org.springframework.ide.vscode.commons.yaml.reconcile.YamlSchemaProblems;
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 com.google.common.collect.ImmutableSet;
/**
* Various static methods for constructing/composing {@link Constraint}s.
*
@@ -78,4 +83,17 @@ public class Constraints {
}
}
}
public static Constraint deprecated(Function<String, String> messageFormatter, String... _deprecatedNames) {
Set<String> deprecatedNames = ImmutableSet.copyOf(_deprecatedNames);
return (MappingNode map, YType type, Set<String> foundProps, IProblemCollector problems) -> {
for (NodeTuple prop : map.getValue()) {
Node keyNode = prop.getKeyNode();
String name = NodeUtil.asScalar(keyNode);
if (deprecatedNames.contains(name)) {
problems.accept(YamlSchemaProblems.deprecatedProperty(messageFormatter.apply(name), keyNode));
}
}
};
}
}

View File

@@ -222,8 +222,11 @@ public class PipelineYmlSchema implements YamlSchema {
if (parentImageDef==null) {
return Constraints.requireOneOf("image_resource", "image");
} else {
// TODO: something like this: return Constraints.deprecated("image_resource", "image");
return null;
return Constraints.deprecated((name) ->
"Deprecated: This attribute in the task config will be ignored! "+
"The 'image' attribute on the task itself takes precedence.",
"image_resource", "image"
);
}
} else {
return Constraints.requireAtMostOneOf("image_resource", "image");

View File

@@ -2565,6 +2565,38 @@ public class ConcourseEditorTest {
editor.assertProblems(/*NONE*/);
}
@Test public void resourceInEmbeddedTaskConfigDeprecated() throws Exception {
Editor editor = harness.newEditor(
"resources:\n" +
"- name: docker-image\n" +
" type: docker-image\n" +
" source:\n" +
" username: {{docker_hub_username}}\n" +
" password: {{docker_hub_password}}\n" +
" repository: kdvolder/sts3-build-env\n" +
"jobs:\n" +
"- name: build-commons-update-site\n" +
" plan:\n" +
" - task: hello-world\n" +
" image: docker-image\n" +
" config:\n" +
" image: blah\n" +
" image_resource:\n" +
" type: docker-image\n" +
" inputs:\n" +
" - name: commons-git\n" +
" platform: linux\n" +
" run:\n" +
" path: which\n" +
" args:\n" +
" - mvn"
);
editor.assertProblems(
"image|Deprecated",
"image_resource|Deprecated"
);
}
@Ignore @Test public void relaxedIndentContextMoreSpaces() throws Exception {
Editor editor;