Skip to content
Permalink
Browse files

JENKINS-29059: Update to use FormValidation.aggregate()

  • Loading branch information...
ChrisCanCompute committed Dec 2, 2015
1 parent cbf46fc commit 4d754c494b999e805239987c942d4c931748fd05
@@ -34,8 +34,10 @@
import hudson.scheduler.Hash;
import hudson.util.FormValidation;
import java.text.DateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import hudson.util.ResponseObject;
import java.util.Collection;

import org.kohsuke.stapler.AncestorInPath;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.QueryParameter;
@@ -84,38 +86,30 @@ public FormValidation doCheck(@QueryParameter String value, @AncestorInPath Item
public FormValidation doCheckSpec(@QueryParameter String value, @AncestorInPath Item item) {
try {
CronTabList ctl = CronTabList.create(fixNull(value), item != null ? Hash.from(item.getFullName()) : null);
ResponseObject response = new ResponseObject();
response = getResponseForSanity(response, ctl);
response = getResponseForNextRun(response, ctl);
if (response.hasWarning()) {
return FormValidation.warning(response.getWarningAndMessge());
} else {
return FormValidation.ok(response.getMessage());
}
Collection<FormValidation> validations = new ArrayList<>();
updateValidationsForSanity(validations, ctl);
updateValidationsForNextRun(validations, ctl);
return FormValidation.aggregate(validations);
} catch (ANTLRException e) {
if (value.trim().indexOf('\n')==-1 && value.contains("**"))
return FormValidation.error(Messages.TimerTrigger_MissingWhitespace());
return FormValidation.error(e.getMessage());
}
}

private ResponseObject getResponseForSanity(ResponseObject response, CronTabList ctl) {
private void updateValidationsForSanity(Collection<FormValidation> validations, CronTabList ctl) {
String msg = ctl.checkSanity();
if(msg!=null) {
return response.withExtraWarning(msg);
} else {
return response;
}
if(msg!=null) validations.add(FormValidation.warning(msg));
}

private ResponseObject getResponseForNextRun(ResponseObject response, CronTabList ctl) {
private void updateValidationsForNextRun(Collection<FormValidation> validations, CronTabList ctl) {
Calendar prev = ctl.previous();
Calendar next = ctl.next();
if (prev != null && next != null) {
DateFormat fmt = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL);
return response.withExtraMessage(Messages.TimerTrigger_would_last_have_run_at_would_next_run_at(fmt.format(prev.getTime()), fmt.format(next.getTime())));
validations.add(FormValidation.ok(Messages.TimerTrigger_would_last_have_run_at_would_next_run_at(fmt.format(prev.getTime()), fmt.format(next.getTime()))));
} else {
return response.withExtraWarning(Messages.TimerTrigger_no_schedules_so_will_never_run());
validations.add(FormValidation.warning(Messages.TimerTrigger_no_schedules_so_will_never_run()));
}
}
}

This file was deleted.

This file was deleted.

0 comments on commit 4d754c4

Please sign in to comment.
You can’t perform that action at this time.