diff --git a/vscode-extensions/vscode-concourse/src/main/java/org/springframework/ide/vscode/concourse/PipelineYmlSchema.java b/vscode-extensions/vscode-concourse/src/main/java/org/springframework/ide/vscode/concourse/PipelineYmlSchema.java index 4534de454..b1fd17c89 100644 --- a/vscode-extensions/vscode-concourse/src/main/java/org/springframework/ide/vscode/concourse/PipelineYmlSchema.java +++ b/vscode-extensions/vscode-concourse/src/main/java/org/springframework/ide/vscode/concourse/PipelineYmlSchema.java @@ -40,6 +40,9 @@ public class PipelineYmlSchema implements YamlSchema { public final YTypeFactory f = new YTypeFactory(); public final YType t_string = f.yatomic("String"); + public final YType t_ne_string = f.yatomic("String") + .parseWith(ValueParsers.NE_STRING); + public final YType t_strings = f.yseq(t_string); public final YType t_pair = f.ybean("NameValuePair", f.yprop("name", t_string), @@ -64,9 +67,6 @@ public class PipelineYmlSchema implements YamlSchema { // define schema types TOPLEVEL_TYPE = f.ybean("Pipeline"); - YAtomicType t_ne_string = f.yatomic("String"); - t_ne_string.parseWith(ValueParsers.NE_STRING); - YAtomicType t_duration = f.yatomic("Duration"); t_duration.parseWith(ConcourseValueParsers.DURATION); @@ -132,16 +132,19 @@ public class PipelineYmlSchema implements YamlSchema { addProp(getStep, "resource", t_string); addProp(getStep, "version", t_version); addProp(getStep, "passed", f.yseq(jobName)); - addProp(getStep, "params", f.contextAware("GetParams", (dc) -> + YType t_get_params = f.contextAware("GetParams", (dc) -> resourceTypes.getInParamsType(getResourceType("get", models, dc)) - )); + ); + addProp(getStep, "params", t_get_params); addProp(getStep, "trigger", t_boolean); YBeanType putStep = f.ybean("PutStep"); addProp(putStep, "put", resourceName); addProp(putStep, "resource", jobName); - addProp(putStep, "params", t_params); - addProp(putStep, "get_params", t_params); + addProp(putStep, "params", f.contextAware("PutParams", (dc) -> + resourceTypes.getOutParamsType(getResourceType("put", models, dc)) + )); + addProp(putStep, "get_params", t_get_params); YBeanType taskStep = f.ybean("TaskStep"); addProp(taskStep, "task", t_ne_string); @@ -219,7 +222,8 @@ public class PipelineYmlSchema implements YamlSchema { } private void initializeDefaultResourceTypes() { - // git resource + //////////////////////////////////////////////////// + // git YBeanType gitSource = f.ybean("GitResourceSource"); addProp(gitSource, "uri", t_string).isRequired(true); addProp(gitSource, "branch", t_string).isRequired(true); @@ -242,8 +246,15 @@ public class PipelineYmlSchema implements YamlSchema { addProp(gitGetParams, "disable_git_lfs", t_boolean); YBeanType gitPutParams = f.ybean("GitPutParams"); - resourceTypes.def("git", gitSource, gitGetParams, gitPutParams); + addProp(gitPutParams, "repository", t_ne_string).isRequired(true); + addProp(gitPutParams, "rebase", t_boolean); + addProp(gitPutParams, "tag", t_ne_string); + addProp(gitPutParams, "only_tag", t_boolean); + addProp(gitPutParams, "tag_prefix", t_string); + addProp(gitPutParams, "force", t_boolean); + addProp(gitPutParams, "annotate", t_ne_string); + resourceTypes.def("git", gitSource, gitGetParams, gitPutParams); } private String getResourceType(String resourceNameProp, ConcourseModel models, DynamicSchemaContext dc) { diff --git a/vscode-extensions/vscode-concourse/src/main/java/org/springframework/ide/vscode/concourse/ResourceTypeRegistry.java b/vscode-extensions/vscode-concourse/src/main/java/org/springframework/ide/vscode/concourse/ResourceTypeRegistry.java index 43483b5c5..1f67c1abd 100644 --- a/vscode-extensions/vscode-concourse/src/main/java/org/springframework/ide/vscode/concourse/ResourceTypeRegistry.java +++ b/vscode-extensions/vscode-concourse/src/main/java/org/springframework/ide/vscode/concourse/ResourceTypeRegistry.java @@ -18,8 +18,7 @@ import org.springframework.ide.vscode.commons.yaml.schema.YType; import org.springframework.ide.vscode.commons.yaml.schema.YTypeFactory.YBeanType; /** - * Keeps track of known resource types. For now this only keeps track of the resource-types that - * are built-in to concourse. + * Keeps track of known resource types. * * @author Kris De Volder */ @@ -81,4 +80,14 @@ public class ResourceTypeRegistry { return null; } + public YType getOutParamsType(String typeTag) { + if (typeTag!=null) { + ResourceTypeInfo v = resourceTypes.get(typeTag); + if (v!=null) { + return v.getOut(); + } + } + return null; + } + } diff --git a/vscode-extensions/vscode-concourse/src/main/resources/desc/GitPutParams/annotate.md b/vscode-extensions/vscode-concourse/src/main/resources/desc/GitPutParams/annotate.md new file mode 100644 index 000000000..0e9c7ef40 --- /dev/null +++ b/vscode-extensions/vscode-concourse/src/main/resources/desc/GitPutParams/annotate.md @@ -0,0 +1,5 @@ +*Optional.* If specified the tag will be an +[annotated](https://git-scm.com/book/en/v2/Git-Basics-Tagging#Annotated-Tags) +tag rather than a +[lightweight](https://git-scm.com/book/en/v2/Git-Basics-Tagging#Lightweight-Tags) +tag. The value should be a path to a file containing the annotation message. \ No newline at end of file diff --git a/vscode-extensions/vscode-concourse/src/main/resources/desc/GitPutParams/force.md b/vscode-extensions/vscode-concourse/src/main/resources/desc/GitPutParams/force.md new file mode 100644 index 000000000..e4a4af8a0 --- /dev/null +++ b/vscode-extensions/vscode-concourse/src/main/resources/desc/GitPutParams/force.md @@ -0,0 +1,2 @@ +*Optional.* When set to 'true' this will force the branch to be +pushed regardless of the upstream state. \ No newline at end of file diff --git a/vscode-extensions/vscode-concourse/src/main/resources/desc/GitPutParams/only_tag.md b/vscode-extensions/vscode-concourse/src/main/resources/desc/GitPutParams/only_tag.md new file mode 100644 index 000000000..93e82f426 --- /dev/null +++ b/vscode-extensions/vscode-concourse/src/main/resources/desc/GitPutParams/only_tag.md @@ -0,0 +1 @@ +*Optional.* When set to 'true' push only the tags of a repo. \ No newline at end of file diff --git a/vscode-extensions/vscode-concourse/src/main/resources/desc/GitPutParams/rebase.md b/vscode-extensions/vscode-concourse/src/main/resources/desc/GitPutParams/rebase.md new file mode 100644 index 000000000..14a019fe3 --- /dev/null +++ b/vscode-extensions/vscode-concourse/src/main/resources/desc/GitPutParams/rebase.md @@ -0,0 +1,2 @@ +*Optional.* If pushing fails with non-fast-forward, continuously +attempt rebasing and pushing. diff --git a/vscode-extensions/vscode-concourse/src/main/resources/desc/GitPutParams/repository.md b/vscode-extensions/vscode-concourse/src/main/resources/desc/GitPutParams/repository.md new file mode 100644 index 000000000..898005d5b --- /dev/null +++ b/vscode-extensions/vscode-concourse/src/main/resources/desc/GitPutParams/repository.md @@ -0,0 +1 @@ +*Required.* The path of the repository to push to the source. \ No newline at end of file diff --git a/vscode-extensions/vscode-concourse/src/main/resources/desc/GitPutParams/tag.md b/vscode-extensions/vscode-concourse/src/main/resources/desc/GitPutParams/tag.md new file mode 100644 index 000000000..0e7b837b5 --- /dev/null +++ b/vscode-extensions/vscode-concourse/src/main/resources/desc/GitPutParams/tag.md @@ -0,0 +1,2 @@ +*Optional.* If this is set then HEAD will be tagged. The value should be +a path to a file containing the name of the tag. \ No newline at end of file diff --git a/vscode-extensions/vscode-concourse/src/main/resources/desc/GitPutParams/tag_prefix.md b/vscode-extensions/vscode-concourse/src/main/resources/desc/GitPutParams/tag_prefix.md new file mode 100644 index 000000000..9bb7c5f3c --- /dev/null +++ b/vscode-extensions/vscode-concourse/src/main/resources/desc/GitPutParams/tag_prefix.md @@ -0,0 +1,3 @@ +*Optional.* If specified, the tag read from the file will be +prepended with this string. This is useful for adding `v` in front of +version numbers. \ No newline at end of file diff --git a/vscode-extensions/vscode-concourse/src/test/java/org/springframework/ide/vscode/concourse/PipelineYamlEditorTest.java b/vscode-extensions/vscode-concourse/src/test/java/org/springframework/ide/vscode/concourse/PipelineYamlEditorTest.java index 1e42b6218..618397354 100644 --- a/vscode-extensions/vscode-concourse/src/test/java/org/springframework/ide/vscode/concourse/PipelineYamlEditorTest.java +++ b/vscode-extensions/vscode-concourse/src/test/java/org/springframework/ide/vscode/concourse/PipelineYamlEditorTest.java @@ -853,7 +853,6 @@ public class PipelineYamlEditorTest { ); } - @Ignore @Test public void gitResourcePutParamsCompletions() throws Exception { String context = "resources:\n" + @@ -869,19 +868,19 @@ public class PipelineYamlEditorTest { assertContextualCompletions(context, "<*>" , // ===> - "repository: <*>" - , - "rebase: <*>" - , - "tag: <*>\n" - , - "only_tag: <*>" - , - "tag_prefix: <*>" + "annotate: <*>" , "force: <*>" , - "annotate: <*>" + "only_tag: <*>" + , + "rebase: <*>" + , + "repository: <*>" + , + "tag: <*>" + , + "tag_prefix: <*>" ); assertContextualCompletions(context, "rebase: <*>" @@ -903,6 +902,70 @@ public class PipelineYamlEditorTest { ); } + @Test public void gitResourcePutParamsReconcile() throws Exception { + Editor editor; + + editor = harness.newEditor( + "resources:\n" + + "- name: my-git\n" + + " type: git\n" + + "jobs:\n" + + "- name: do-stuff\n" + + " plan:\n" + + " - put: my-git\n" + + " params: {}\n" + ); + editor.assertProblems("{}|'repository' is required"); + + editor = harness.newEditor( + "resources:\n" + + "- name: my-git\n" + + " type: git\n" + + "jobs:\n" + + "- name: do-stuff\n" + + " plan:\n" + + " - put: my-git\n" + + " params:\n" + + " repository: some-other-repo\n" + + " rebase: do-rebase\n" + + " only_tag: do-tag\n" + + " force: force-it\n" + ); + editor.assertProblems( + "do-rebase|'boolean'", + "do-tag|'boolean'", + "force-it|'boolean'" + ); + } + + @Test public void gitResourcePutParamsHovers() throws Exception { + Editor editor = harness.newEditor( + "resources:\n" + + "- name: my-git\n" + + " type: git\n" + + "jobs:\n" + + "- name: do-stuff\n" + + " plan:\n" + + " - put: my-git\n" + + " params:\n" + + " repository: some-other-repo\n" + + " rebase: do-rebase\n" + + " tag: the-tag-file\n" + + " only_tag: do-tag\n" + + " tag_prefix: RELEASE\n" + + " force: force-it\n" + + " annotate: release-annotion\n" + ); + + editor.assertHoverContains("repository", "The path of the repository"); + editor.assertHoverContains("rebase", "attempt rebasing"); + editor.assertHoverContains("tag", "HEAD will be tagged"); + editor.assertHoverContains("only_tag", "push only the tags"); + editor.assertHoverContains("tag_prefix", "prepended with this string"); + editor.assertHoverContains("force", "pushed regardless of the upstream state"); + editor.assertHoverContains("annotate", "path to a file containing the annotation message"); + } + @Test public void contentAssistJobNames() throws Exception { assertContextualCompletions(