diff --git a/core/src/main/java/hudson/matrix/MatrixProject.java b/core/src/main/java/hudson/matrix/MatrixProject.java index bccd4092c9..00fd178be4 100644 --- a/core/src/main/java/hudson/matrix/MatrixProject.java +++ b/core/src/main/java/hudson/matrix/MatrixProject.java @@ -57,10 +57,12 @@ import hudson.tasks.Publisher; import hudson.triggers.Trigger; import hudson.util.CopyOnWriteMap; import hudson.util.DescribableList; +import hudson.util.FormValidation; import java.io.File; import java.io.FileFilter; import java.io.IOException; +import java.text.ParseException; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -83,6 +85,7 @@ import org.kohsuke.stapler.StaplerRequest; import org.kohsuke.stapler.StaplerResponse; import org.kohsuke.stapler.TokenList; import org.kohsuke.stapler.HttpResponse; +import org.kohsuke.stapler.QueryParameter; /** * {@link Job} that allows you to run multiple different configurations @@ -552,14 +555,21 @@ public class MatrixProject extends AbstractProject im super.submit(req, rsp); AxisList newAxes = new AxisList(); + HashSet axisNames = new HashSet(); // parse user axes if(req.getParameter("hasAxes")!=null) { newAxes.addAll(req.bindParametersToList(Axis.class,"axis.")); // get rid of empty values - for (Iterator itr = newAxes.iterator(); itr.hasNext();) { + for (Iterator itr = newAxes.iterator(); itr.hasNext();) try { Axis a = itr.next(); - if(a.values.isEmpty()) itr.remove(); + if(a.values.isEmpty()) { itr.remove(); continue; } + checkAxisName(a.name); + if (axisNames.contains(a.name)) + throw new FormException(Messages.MatrixProject_DuplicateAxisName(),"axis.name"); + axisNames.add(a.name); + } catch (ParseException e) { + throw new FormException(e.getMessage(),"axis.name"); } } @@ -606,6 +616,31 @@ public class MatrixProject extends AbstractProject im return rsp; } + /** + * Makes sure that the given name is good as a axis name. + */ + public FormValidation doCheckAxisName(@QueryParameter String value) { + checkPermission(CONFIGURE); + + if(Util.fixEmpty(value)==null) + return FormValidation.ok(); + + try { + checkAxisName(value); + return FormValidation.ok(); + } catch (ParseException e) { + return FormValidation.error(e.getMessage()); + } + } + + /** + * Makes sure that the given name is good as a axis name. + * TODO: maybe be even more restrictive since these are used as shell variables + */ + private static void checkAxisName(String name) throws ParseException { + Hudson.checkGoodName(name); + } + public DescriptorImpl getDescriptor() { return DESCRIPTOR; } diff --git a/core/src/main/resources/hudson/matrix/MatrixProject/configure-entries.jelly b/core/src/main/resources/hudson/matrix/MatrixProject/configure-entries.jelly index e3b2e5fb45..8e4f119f7a 100644 --- a/core/src/main/resources/hudson/matrix/MatrixProject/configure-entries.jelly +++ b/core/src/main/resources/hudson/matrix/MatrixProject/configure-entries.jelly @@ -90,7 +90,7 @@ THE SOFTWARE. - + diff --git a/core/src/main/resources/hudson/matrix/Messages.properties b/core/src/main/resources/hudson/matrix/Messages.properties index 88a5285b44..23cf1d4e98 100644 --- a/core/src/main/resources/hudson/matrix/Messages.properties +++ b/core/src/main/resources/hudson/matrix/Messages.properties @@ -21,6 +21,7 @@ # THE SOFTWARE. MatrixProject.DisplayName=Build multi-configuration project (alpha) +MatrixProject.DuplicateAxisName=Duplicate axis name MatrixBuild.Triggering=Triggering {0} MatrixBuild.AppearsCancelled={0} appears to be cancelled