Skip to content

Commit

Permalink
JENKINS-29059: Update to use FormValidation.aggregate()
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisCanCompute committed Dec 2, 2015
1 parent cbf46fc commit 4d754c4
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 267 deletions.
30 changes: 12 additions & 18 deletions core/src/main/java/hudson/triggers/TimerTrigger.java
Expand Up @@ -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;
Expand Down Expand Up @@ -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()));
}
}
}
Expand Down
67 changes: 0 additions & 67 deletions core/src/main/java/hudson/util/ResponseObject.java

This file was deleted.

182 changes: 0 additions & 182 deletions test/src/test/java/hudson/util/ResponseObjectTest.java

This file was deleted.

0 comments on commit 4d754c4

Please sign in to comment.