Reconcile deprecated properties in Pipeline yaml

This commit is contained in:
Kris De Volder
2017-01-24 14:18:29 -08:00
parent e2401772af
commit e43da3d6d4
5 changed files with 31 additions and 10 deletions

View File

@@ -143,6 +143,9 @@ public class SchemaBasedYamlASTReconciler implements YamlASTReconciler {
if (prop==null) {
unknownBeanProperty(keyNode, type, key);
} else {
if (prop.isDeprecated()) {
problems.accept(YamlSchemaProblems.deprecatedProperty(keyNode, type, prop));
}
reconcile(doc, valueAt(path, key), entry.getValueNode(), prop.getType());
}
}
@@ -305,7 +308,7 @@ public class SchemaBasedYamlASTReconciler implements YamlASTReconciler {
}
}
}
private void valueParseError(YType type, Node node, String parseErrorMsg, ProblemType problemType) {
if (!StringUtil.hasText(parseErrorMsg)) {
parseErrorMsg= "Couldn't parse as '"+describe(type)+"'";
@@ -365,9 +368,9 @@ public class SchemaBasedYamlASTReconciler implements YamlASTReconciler {
private void problem(Node node, String msg) {
problems.accept(YamlSchemaProblems.schemaProblem(msg, node));
}
private void problem(Node node, String msg, ProblemType problemType) {
problems.accept(YamlSchemaProblems.problem(msg, node, problemType));
problems.accept(YamlSchemaProblems.problem(problemType, msg, node));
}
private void problem(DocumentRegion region, String msg) {

View File

@@ -8,7 +8,6 @@
* Contributors:
* Pivotal, Inc. - initial API and implementation
*******************************************************************************/
package org.springframework.ide.vscode.commons.yaml.reconcile;
import org.springframework.ide.vscode.commons.languageserver.reconcile.ProblemSeverity;
@@ -16,6 +15,8 @@ import org.springframework.ide.vscode.commons.languageserver.reconcile.ProblemTy
import org.springframework.ide.vscode.commons.languageserver.reconcile.ReconcileProblem;
import org.springframework.ide.vscode.commons.languageserver.reconcile.ReconcileProblemImpl;
import org.springframework.ide.vscode.commons.languageserver.util.DocumentRegion;
import org.springframework.ide.vscode.commons.yaml.schema.YType;
import org.springframework.ide.vscode.commons.yaml.schema.YTypedProperty;
import org.yaml.snakeyaml.nodes.Node;
/**
@@ -25,11 +26,12 @@ import org.yaml.snakeyaml.nodes.Node;
*/
public class YamlSchemaProblems {
public static final ProblemType SCHEMA_PROBLEM = problemType("YamlSchemaProblem");
public static final ProblemType SYNTAX_PROBLEM = problemType("YamlSyntaxProblem");
public static final ProblemType SCHEMA_PROBLEM = problemType("YamlSchemaProblem");
public static final ProblemType DEPRECATED_PROPERTY = problemType("DeprecatedProperty", ProblemSeverity.WARNING);
public static ProblemType problemType(final String typeName, ProblemSeverity defaultSeverity) {
return new ProblemType() {
@Override
public String toString() {
@@ -45,7 +47,7 @@ public class YamlSchemaProblems {
}
};
}
public static ProblemType problemType(final String typeName) {
return problemType(typeName, ProblemSeverity.ERROR);
}
@@ -63,8 +65,12 @@ public class YamlSchemaProblems {
public static ReconcileProblem schemaProblem(String msg, DocumentRegion node) {
return new ReconcileProblemImpl(SCHEMA_PROBLEM, msg, node.getStart(), node.getLength());
}
public static ReconcileProblem problem(String msg, Node node, ProblemType problemType) {
public static ReconcileProblem deprecatedProperty(Node node, YType bean, YTypedProperty property) {
return problem(DEPRECATED_PROPERTY, "Property '"+property.getName()+"' of '"+bean+"' is Deprecated", node);
}
public static ReconcileProblem problem(ProblemType problemType, String msg, Node node) {
int start = node.getStartMark().getIndex();
int end = node.getEndMark().getIndex();
return new ReconcileProblemImpl(problemType, msg, start, end-start);

View File

@@ -592,6 +592,11 @@ public class YTypeFactory {
public void isDeprecated(boolean isDeprecated) {
this.isDeprecated = isDeprecated;
}
@Override
public boolean isDeprecated() {
return this.isDeprecated;
}
}
public YAtomicType yatomic(String name) {

View File

@@ -20,4 +20,5 @@ public interface YTypedProperty {
YType getType();
Renderable getDescription();
default boolean isRequired() { return false; }
default boolean isDeprecated() { return false; }
}

View File

@@ -10,12 +10,15 @@
*******************************************************************************/
package org.springframework.ide.vscode.concourse;
import static org.junit.Assert.assertEquals;
import static org.springframework.ide.vscode.languageserver.testharness.TestAsserts.assertContains;
import java.io.InputStream;
import java.util.Arrays;
import java.util.stream.Collectors;
import org.eclipse.lsp4j.Diagnostic;
import org.eclipse.lsp4j.DiagnosticSeverity;
import org.junit.Before;
import org.junit.Test;
import org.springframework.ide.vscode.commons.util.IOUtil;
@@ -1250,6 +1253,8 @@ public class PipelineYamlEditorTest {
editor.assertProblems(
"cache-it|'boolean'",
"pull_repository|Deprecated",
"pull_tag|Deprecated",
"tag-latest|'boolean'",
"the-build-args|Expecting a 'Map'",
@@ -1257,6 +1262,8 @@ public class PipelineYamlEditorTest {
"tar-it|'boolean'",
"skip-it|'boolean'"
);
assertEquals(DiagnosticSeverity.Warning, editor.assertProblem("pull_repository").getSeverity());
assertEquals(DiagnosticSeverity.Warning, editor.assertProblem("pull_tag").getSeverity());
editor.assertHoverContains("build", "directory containing a `Dockerfile`");
editor.assertHoverContains("load", "directory containing an image");
@@ -1305,7 +1312,6 @@ public class PipelineYamlEditorTest {
);
}
//////////////////////////////////////////////////////////////////////////////
private void assertContextualCompletions(String conText, String textBefore, String... textAfter) throws Exception {