Merge branch 'stable-2.16'
* stable-2.16: SiteProgram: Normalize site path ScheduleConfig: Explicitly log when interval or initial delay value is invalid ScheduleConfig: Log at severe when startTime or interval cannot be parsed Clarify that schedule config's startTime hour must be zero-padded ScheduleConfigTest: Extend tests for schedule interval Highlight "starlark" as python Change-Id: I5edde38092cbd66c6a45e8bd39b318c99dcb6341
This commit is contained in:
@@ -4769,7 +4769,7 @@ The placeholders can have the following values:
|
|||||||
|
|
||||||
+
|
+
|
||||||
The time zone cannot be specified but is always the system default
|
The time zone cannot be specified but is always the system default
|
||||||
time zone.
|
time zone. Hours must be zero-padded, i.e. `06:00` rather than `6:00`.
|
||||||
|
|
||||||
The section (and optionally the subsection) in which the `interval` and
|
The section (and optionally the subsection) in which the `interval` and
|
||||||
`startTime` keys must be set depends on the background job for which a
|
`startTime` keys must be set depends on the background job for which a
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ public abstract class SiteProgram extends AbstractProgram {
|
|||||||
aliases = {"-d"},
|
aliases = {"-d"},
|
||||||
usage = "Local directory containing site data")
|
usage = "Local directory containing site data")
|
||||||
private void setSitePath(String path) {
|
private void setSitePath(String path) {
|
||||||
sitePath = Paths.get(path);
|
sitePath = Paths.get(path).normalize();
|
||||||
}
|
}
|
||||||
|
|
||||||
private Path sitePath = Paths.get(".");
|
private Path sitePath = Paths.get(".");
|
||||||
@@ -55,7 +55,7 @@ public abstract class SiteProgram extends AbstractProgram {
|
|||||||
protected SiteProgram() {}
|
protected SiteProgram() {}
|
||||||
|
|
||||||
protected SiteProgram(Path sitePath) {
|
protected SiteProgram(Path sitePath) {
|
||||||
this.sitePath = sitePath;
|
this.sitePath = sitePath.normalize();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @return the site path specified on the command line. */
|
/** @return the site path specified on the command line. */
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ import org.eclipse.jgit.lib.Config;
|
|||||||
* executions are {@code Wed 10:30}, {@code Fri 10:30}. etc.
|
* executions are {@code Wed 10:30}, {@code Fri 10:30}. etc.
|
||||||
* <li>
|
* <li>
|
||||||
* <pre>
|
* <pre>
|
||||||
* foo.startTime = 6:00
|
* foo.startTime = 06:00
|
||||||
* foo.interval = 1 day
|
* foo.interval = 1 day
|
||||||
* </pre>
|
* </pre>
|
||||||
* Assuming that the server is started on {@code Mon 7:00} then this yields the first run on
|
* Assuming that the server is started on {@code Mon 7:00} then this yields the first run on
|
||||||
@@ -174,7 +174,18 @@ public abstract class ScheduleConfig {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (interval <= 0 || initialDelay < 0) {
|
if (interval != INVALID_CONFIG && interval <= 0) {
|
||||||
|
logger.atSevere().log("Invalid interval value \"%d\" for \"%s\": must be > 0", interval, key);
|
||||||
|
interval = INVALID_CONFIG;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (initialDelay != INVALID_CONFIG && initialDelay < 0) {
|
||||||
|
logger.atSevere().log(
|
||||||
|
"Invalid initial delay value \"%d\" for \"%s\": must be >= 0", initialDelay, key);
|
||||||
|
initialDelay = INVALID_CONFIG;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (interval == INVALID_CONFIG || initialDelay == INVALID_CONFIG) {
|
||||||
logger.atSevere().log("Invalid schedule configuration for \"%s\" is ignored. ", key);
|
logger.atSevere().log("Invalid schedule configuration for \"%s\" is ignored. ", key);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -216,6 +227,9 @@ public abstract class ScheduleConfig {
|
|||||||
return ConfigUtil.getTimeUnit(
|
return ConfigUtil.getTimeUnit(
|
||||||
rc, section, subsection, keyInterval, MISSING_CONFIG, TimeUnit.MILLISECONDS);
|
rc, section, subsection, keyInterval, MISSING_CONFIG, TimeUnit.MILLISECONDS);
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
|
// We only need to log the exception message; it already includes the
|
||||||
|
// section.subsection.key and bad value.
|
||||||
|
logger.atSevere().log("%s", e.getMessage());
|
||||||
return INVALID_CONFIG;
|
return INVALID_CONFIG;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -258,6 +272,7 @@ public abstract class ScheduleConfig {
|
|||||||
}
|
}
|
||||||
return delay;
|
return delay;
|
||||||
} catch (DateTimeParseException e) {
|
} catch (DateTimeParseException e) {
|
||||||
|
logger.atSevere().log("Invalid start time: %s", e.getMessage());
|
||||||
return INVALID_CONFIG;
|
return INVALID_CONFIG;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,15 +41,18 @@ public class ScheduleConfigTest extends GerritBaseTests {
|
|||||||
@Test
|
@Test
|
||||||
public void initialDelay() throws Exception {
|
public void initialDelay() throws Exception {
|
||||||
assertThat(initialDelay("11:00", "1h")).isEqualTo(ms(1, HOURS));
|
assertThat(initialDelay("11:00", "1h")).isEqualTo(ms(1, HOURS));
|
||||||
|
assertThat(initialDelay("11:00", "1 hour")).isEqualTo(ms(1, HOURS));
|
||||||
assertThat(initialDelay("05:30", "1h")).isEqualTo(ms(30, MINUTES));
|
assertThat(initialDelay("05:30", "1h")).isEqualTo(ms(30, MINUTES));
|
||||||
assertThat(initialDelay("09:30", "1h")).isEqualTo(ms(30, MINUTES));
|
assertThat(initialDelay("09:30", "1h")).isEqualTo(ms(30, MINUTES));
|
||||||
assertThat(initialDelay("13:30", "1h")).isEqualTo(ms(30, MINUTES));
|
assertThat(initialDelay("13:30", "1h")).isEqualTo(ms(30, MINUTES));
|
||||||
assertThat(initialDelay("13:59", "1h")).isEqualTo(ms(59, MINUTES));
|
assertThat(initialDelay("13:59", "1h")).isEqualTo(ms(59, MINUTES));
|
||||||
|
|
||||||
assertThat(initialDelay("11:00", "1d")).isEqualTo(ms(1, HOURS));
|
assertThat(initialDelay("11:00", "1d")).isEqualTo(ms(1, HOURS));
|
||||||
|
assertThat(initialDelay("11:00", "1 day")).isEqualTo(ms(1, HOURS));
|
||||||
assertThat(initialDelay("05:30", "1d")).isEqualTo(ms(19, HOURS) + ms(30, MINUTES));
|
assertThat(initialDelay("05:30", "1d")).isEqualTo(ms(19, HOURS) + ms(30, MINUTES));
|
||||||
|
|
||||||
assertThat(initialDelay("11:00", "1w")).isEqualTo(ms(1, HOURS));
|
assertThat(initialDelay("11:00", "1w")).isEqualTo(ms(1, HOURS));
|
||||||
|
assertThat(initialDelay("11:00", "1 week")).isEqualTo(ms(1, HOURS));
|
||||||
assertThat(initialDelay("05:30", "1w")).isEqualTo(ms(7, DAYS) - ms(4, HOURS) - ms(30, MINUTES));
|
assertThat(initialDelay("05:30", "1w")).isEqualTo(ms(7, DAYS) - ms(4, HOURS) - ms(30, MINUTES));
|
||||||
|
|
||||||
assertThat(initialDelay("Mon 11:00", "1w")).isEqualTo(ms(3, DAYS) + ms(1, HOURS));
|
assertThat(initialDelay("Mon 11:00", "1w")).isEqualTo(ms(3, DAYS) + ms(1, HOURS));
|
||||||
@@ -200,6 +203,9 @@ public class ScheduleConfigTest extends GerritBaseTests {
|
|||||||
|
|
||||||
rc.setString("a", null, ScheduleConfig.KEY_STARTTIME, "0100");
|
rc.setString("a", null, ScheduleConfig.KEY_STARTTIME, "0100");
|
||||||
assertThat(ScheduleConfig.builder(rc, "a").buildSchedule()).isEmpty();
|
assertThat(ScheduleConfig.builder(rc, "a").buildSchedule()).isEmpty();
|
||||||
|
|
||||||
|
rc.setString("a", null, ScheduleConfig.KEY_STARTTIME, "1:00");
|
||||||
|
assertThat(ScheduleConfig.builder(rc, "a").buildSchedule()).isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@@ -209,6 +209,7 @@ spreadsheet = text/x-spreadsheet
|
|||||||
sql = text/x-sql
|
sql = text/x-sql
|
||||||
ss = text/x-scheme
|
ss = text/x-scheme
|
||||||
st = text/x-stsrc
|
st = text/x-stsrc
|
||||||
|
starlark = text/x-python
|
||||||
stex = text/x-stex
|
stex = text/x-stex
|
||||||
sv = text/x-systemverilog
|
sv = text/x-systemverilog
|
||||||
svh = text/x-systemverilog
|
svh = text/x-systemverilog
|
||||||
|
|||||||
Reference in New Issue
Block a user