Skip to content

Commit

Permalink
[JENKINS-23640] Validate regular expression
Browse files Browse the repository at this point in the history
Will now validate the regex
  • Loading branch information
emsa23 committed May 18, 2015
1 parent 972ffb5 commit 2cc5228
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
Expand Up @@ -28,17 +28,20 @@
import hudson.model.TopLevelItem;
import hudson.model.View;
import hudson.model.ViewGroup;
import hudson.util.FormValidation;
import hudson.util.ListBoxModel;

import java.util.Collection;
import java.util.logging.Logger;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;

import jenkins.advancedqueue.DecisionLogger;
import jenkins.advancedqueue.jobinclusion.JobInclusionStrategy;
import jenkins.model.Jenkins;

import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.QueryParameter;

/**
* @author Magnus Sandberg
Expand Down Expand Up @@ -73,6 +76,18 @@ private void addViews(String parent, ListBoxModel items, Collection<View> views)
}
}

public FormValidation doCheckJobPattern(@QueryParameter String jobPattern) {
if(jobPattern.isEmpty()) {
return FormValidation.ok("Empty pattern matches all Jobs.");
}
try {
Pattern.compile(jobPattern);
} catch (PatternSyntaxException exception) {
return FormValidation.error(exception.getDescription());
}
return FormValidation.ok("Pattern is valid.");
}

};

static public class JobPattern {
Expand Down
Expand Up @@ -6,7 +6,7 @@
</j:forEach>
<f:optionalBlock name="jobFilter" checked="${instance.useJobFilter}" title="Use a regular expression to only include a subset of the included Jobs">
<f:entry title="Regular Expression">
<f:textbox name="jobPattern" value="${instance.jobPattern}" checkUrl="'${rootURL}/descriptorByName/jenkins.advancedqueue.PriorityConfiguration/checkJobPattern?value='+encode(this.value)"/>
<f:textbox name="jobPattern" field="jobPattern" value="${instance.jobPattern}" />
</f:entry>
</f:optionalBlock>
</select>
Expand Down

0 comments on commit 2cc5228

Please sign in to comment.