Support for time resource type
This commit is contained in:
@@ -74,4 +74,24 @@ public class ConcourseValueParsers {
|
||||
+ " '2h45m'. Valid time units are 'ns', 'us' (or 'µs'), 'ms', 's', "
|
||||
+ "'m', 'h'."
|
||||
);
|
||||
|
||||
public static final ValueParser TIME_OF_DAY = new RegexpParser(
|
||||
createTimeRegexp(),
|
||||
"Time",
|
||||
"Supported time formats are: 3:04 PM, 3PM, 3 PM, 15:04, and 1504. "
|
||||
+ "Deprecation: an offset may be appended, e.g. +0700 or -0400, but "
|
||||
+ "you should use location instead."
|
||||
);
|
||||
|
||||
private static String createTimeRegexp() {
|
||||
String hours = "([0-2]?[0-9])";
|
||||
String minutes = "([0-6][0-9])";
|
||||
String time = hours+"((:"+minutes+")|"+minutes+")?";
|
||||
String pm = "(\\s?[AP]M)?";
|
||||
String zone = "(\\s(\\+|\\-)[0-9][0-9][0-9][0-9])?";
|
||||
|
||||
return time + pm + zone;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -70,6 +70,7 @@ public class PipelineYmlSchema implements YamlSchema {
|
||||
.collect(Collectors.toSet())
|
||||
.block();
|
||||
|
||||
|
||||
private final AbstractType TOPLEVEL_TYPE;
|
||||
private final YTypeUtil TYPE_UTIL;
|
||||
|
||||
@@ -103,6 +104,8 @@ public class PipelineYmlSchema implements YamlSchema {
|
||||
|
||||
public final YType t_duration = f.yatomic("Duration")
|
||||
.parseWith(ConcourseValueParsers.DURATION);
|
||||
public final YType t_time_of_day = f.yatomic("TimeOfDay")
|
||||
.parseWith(ConcourseValueParsers.TIME_OF_DAY);
|
||||
|
||||
public final AbstractType task;
|
||||
|
||||
@@ -123,6 +126,10 @@ public class PipelineYmlSchema implements YamlSchema {
|
||||
"us-east-2"
|
||||
);
|
||||
|
||||
public final YType t_day = f.yenum("Day",
|
||||
//See https://github.com/concourse/time-resource#source-configuration
|
||||
"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"
|
||||
);
|
||||
|
||||
public PipelineYmlSchema(ConcourseModel models) {
|
||||
this.models = models;
|
||||
@@ -531,6 +538,24 @@ public class PipelineYmlSchema implements YamlSchema {
|
||||
|
||||
resourceTypes.def("semver", source, get, put);
|
||||
}
|
||||
//time:
|
||||
{
|
||||
AbstractType source = f.ybean("TimeSource");
|
||||
addProp(source, "interval", t_duration);
|
||||
addProp(source, "location", t_ne_string);
|
||||
addProp(source, "start", t_time_of_day);
|
||||
addProp(source, "stop", t_time_of_day);
|
||||
addProp(source, "days", f.yseq(t_day));
|
||||
|
||||
AbstractType get = f.ybean("TimeGetParams");
|
||||
//get params deliberately left empty
|
||||
|
||||
AbstractType put = f.ybean("TimePutParams");
|
||||
//put params deliberately left empty
|
||||
|
||||
resourceTypes.def("time", source, get, put);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private String getSemverDriverName(DynamicSchemaContext dc) {
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
*Optional.* Run only on these day(s). Supported days are: `Sunday`,
|
||||
`Monday`, `Tuesday`, `Wednesday`, `Thursday`, `Friday` and `Saturday`.
|
||||
|
||||
e.g.
|
||||
|
||||
days: [Monday, Wednesday]
|
||||
@@ -0,0 +1,2 @@
|
||||
*Optional.* The interval on which to report new versions. Valid
|
||||
values: `60s`, `90m`, `1h`.
|
||||
@@ -0,0 +1,7 @@
|
||||
*Optional. Default `UTC`.* The
|
||||
[location](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones) in
|
||||
which to interpret `start`, `stop`, and `days`.
|
||||
|
||||
e.g.
|
||||
|
||||
location: Africa/Abidjan
|
||||
@@ -0,0 +1,11 @@
|
||||
*Optional.* Only create new time versions between `start` and `stop`
|
||||
time range. The supported time formats are: `3:04 PM`, `3PM`, `3 PM`,
|
||||
`15:04`, and `1504`.
|
||||
|
||||
e.g.
|
||||
|
||||
start: 8:00 PM
|
||||
stop: 9:00 PM
|
||||
|
||||
**Deprecation: an offset may be appended, e.g. `+0700` or `-0400`, but you
|
||||
should use `location` instead.**
|
||||
@@ -0,0 +1,11 @@
|
||||
*Optional.* Only create new time versions between `start` and `stop`
|
||||
time range. The supported time formats are: `3:04 PM`, `3PM`, `3 PM`,
|
||||
`15:04`, and `1504`.
|
||||
|
||||
e.g.
|
||||
|
||||
start: 8:00 PM
|
||||
stop: 9:00 PM
|
||||
|
||||
**Deprecation: an offset may be appended, e.g. `+0700` or `-0400`, but you
|
||||
should use `location` instead.**
|
||||
@@ -742,6 +742,63 @@ public class ConcourseEditorTest {
|
||||
);
|
||||
}
|
||||
|
||||
@Test public void timeResourceCompletions() throws Exception {
|
||||
assertContextualCompletions(
|
||||
"resources:\n" +
|
||||
"- name: every5minutes\n" +
|
||||
" type: time\n" +
|
||||
" source:\n" +
|
||||
" <*>"
|
||||
, // ======================
|
||||
"<*>"
|
||||
, // =>
|
||||
"days:\n"+
|
||||
" - <*>",
|
||||
"interval: <*>",
|
||||
"location: <*>",
|
||||
"start: <*>",
|
||||
"stop: <*>"
|
||||
);
|
||||
|
||||
assertContextualCompletions(
|
||||
"resources:\n" +
|
||||
"- name: every5minutes\n" +
|
||||
" type: time\n" +
|
||||
" source:\n" +
|
||||
" days:\n" +
|
||||
" - <*>"
|
||||
, // ======================
|
||||
"<*>"
|
||||
, // =>
|
||||
"Friday<*>",
|
||||
"Monday<*>",
|
||||
"Saturday<*>",
|
||||
"Sunday<*>",
|
||||
"Thursday<*>",
|
||||
"Tuesday<*>",
|
||||
"Wednesday<*>"
|
||||
);
|
||||
}
|
||||
|
||||
@Test public void timeResourceSourceHovers() throws Exception {
|
||||
Editor editor = harness.newEditor(
|
||||
"resources:\n" +
|
||||
"- name: timed-trigger\n" +
|
||||
" type: time\n" +
|
||||
" source:\n" +
|
||||
" interval: 5m\n" +
|
||||
" location: UTC\n" +
|
||||
" start: 8:00PM\n" +
|
||||
" stop: 9:00PM\n" +
|
||||
" days: [Monday, Wednesday, Friday]"
|
||||
);
|
||||
editor.assertHoverContains("interval", "interval on which to report new versions");
|
||||
editor.assertHoverContains("location", "*Optional. Default `UTC`");
|
||||
editor.assertHoverContains("start", "The supported time formats are");
|
||||
editor.assertHoverContains("stop", "The supported time formats are");
|
||||
editor.assertHoverContains("days", "Run only on these day(s)");
|
||||
}
|
||||
|
||||
@Test public void gitResourceSourceReconcile() throws Exception {
|
||||
Editor editor = harness.newEditor(
|
||||
"resources:\n" +
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2017 Pivotal, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Pivotal, Inc. - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.springframework.ide.vscode.concourse;
|
||||
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.springframework.ide.vscode.languageserver.testharness.TestAsserts.assertContains;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.ide.vscode.commons.util.ExceptionUtil;
|
||||
import org.springframework.ide.vscode.commons.util.ValueParser;
|
||||
|
||||
public class TimeOfDayParserTest {
|
||||
|
||||
private ValueParser parser = ConcourseValueParsers.TIME_OF_DAY;
|
||||
|
||||
@Test
|
||||
public void goodExamples() throws Exception {
|
||||
String[] examples = {
|
||||
"3:04 PM -0700",
|
||||
"3:04 PM +0700",
|
||||
"3:04 AM +0700",
|
||||
"00:00 AM +0700",
|
||||
"23:59 PM +0800",
|
||||
|
||||
"3PM -0700",
|
||||
"0AM +0800",
|
||||
"24AM +0800",
|
||||
|
||||
"3 PM -0700",
|
||||
"0 AM -0700",
|
||||
"24 PM -1234",
|
||||
|
||||
"15:04 -0700",
|
||||
"0:00 -0700",
|
||||
"23:59 -0700",
|
||||
|
||||
"304 -0700",
|
||||
"1504 -0700",
|
||||
"0004 -0700",
|
||||
"2359 -0700",
|
||||
|
||||
"3:04 PM",
|
||||
"0:00 AM",
|
||||
"11:59 PM",
|
||||
|
||||
"3PM",
|
||||
"1AM",
|
||||
"23PM",
|
||||
|
||||
"3 PM",
|
||||
"1 AM",
|
||||
"23 PM",
|
||||
|
||||
"15:04",
|
||||
"0:00",
|
||||
"00:00",
|
||||
"23:59",
|
||||
|
||||
"1504",
|
||||
"0000",
|
||||
"2359"
|
||||
};
|
||||
for (String string : examples) {
|
||||
System.out.println(string);
|
||||
parser.parse(string);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void badExamples() {
|
||||
does_not_parse("arbirary garbage");
|
||||
does_not_parse("3:04 PM -0700 extra");
|
||||
}
|
||||
|
||||
private void does_not_parse(String string) {
|
||||
try {
|
||||
parser.parse(string);
|
||||
fail("Should have failed parsing!");
|
||||
} catch (Exception e) {
|
||||
assertContains("Time", ExceptionUtil.getMessage(e));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user