implemented user-defined axis support.

git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@3533 71c3de6d-444a-0410-be80-ed276b4c234a
This commit is contained in:
kohsuke committed 2007-06-23 23:23:36 +00:00
1 parent fff52d4b09
commit da9b00a783
5 files changed
+95 -17

No files matched your search

@@ -2,11 +2,14 @@ package hudson.matrix;
import hudson.Util;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.DataBoundConstructor;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.List;
import java.util.StringTokenizer;
import java.util.Arrays;
/**
* Configuration axis.
@@ -38,6 +41,25 @@ public final class Axis implements Comparable<Axis>, Iterable<String> {
throw new IllegalArgumentException(); // bug in the code
}
/**
* Used to build {@link Axis} from form.
*
* Axis with empty values need to be removed later.
*/
@DataBoundConstructor
public Axis(String name, String value) {
this.name = name;
this.values = new ArrayList<String>(Arrays.asList(Util.tokenize(value)));
}
/**
* Returns ture if this axis is a system-reserved axis
* that has special treatment.
*/
public boolean isSystem() {
return name.equals("jdk") || name.equals("label");
}
public Iterator<String> iterator() {
return values.iterator();
}
@@ -62,6 +84,18 @@ public final class Axis implements Comparable<Axis>, Iterable<String> {
return new StringBuilder().append(name).append("={").append(Util.join(values,",")).append('}').toString();
}
/**
* Used for generating the config UI.
* If the axis is big and occupies a lot of space, use NL for separator
* to display multi-line text
*/
public String getValueString() {
int len=0;
for (String value : values)
len += value.length();
return Util.join(values, len>30 ?"\n":" ");
}
/**
* Parses the submitted form (where possible values are
* presented as a list of checkboxes) and creates an axis
@@ -25,7 +25,6 @@ public class AxisList extends ArrayList<Axis> {
return null;
}
public boolean add(Axis axis) {
return axis!=null && super.add(axis);
}
@@ -1,14 +1,9 @@
package hudson.matrix;
import hudson.FilePath;
import hudson.maven.ModuleName;
import hudson.tasks.Builder;
import hudson.tasks.Publisher;
import hudson.tasks.BuildWrapper;
import hudson.tasks.BuildWrappers;
import hudson.tasks.BuildStep;
import hudson.model.AbstractProject;
import hudson.model.DependencyGraph;
import hudson.model.Descriptor;
import hudson.model.Descriptor.FormException;
import hudson.model.Hudson;
import hudson.model.Item;
@@ -21,7 +16,11 @@ import hudson.model.Node;
import hudson.model.SCMedItem;
import hudson.model.TopLevelItem;
import hudson.model.TopLevelItemDescriptor;
import hudson.model.Descriptor;
import hudson.tasks.BuildStep;
import hudson.tasks.BuildWrapper;
import hudson.tasks.BuildWrappers;
import hudson.tasks.Builder;
import hudson.tasks.Publisher;
import hudson.util.CopyOnWriteMap;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse;
@@ -33,10 +32,12 @@ import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.List;
import java.util.Vector;
import java.util.ArrayList;
import java.util.Iterator;
/**
* @author Kohsuke Kawaguchi
@@ -82,6 +83,17 @@ public class MatrixProject extends AbstractProject<MatrixProject,MatrixBuild> im
return axes;
}
/**
* Gets the subset of {@link AxisList} that are not system axes.
*/
public List<Axis> getUserAxes() {
List<Axis> r = new ArrayList<Axis>();
for (Axis a : axes)
if(!a.isSystem())
r.add(a);
return r;
}
public Layouter getLayouter() {
return new Layouter(axes);
}
@@ -239,8 +251,19 @@ public class MatrixProject extends AbstractProject<MatrixProject,MatrixBuild> im
super.submit(req, rsp);
AxisList newAxes = new AxisList();
// parse user axes
newAxes.addAll(req.bindParametersToList(Axis.class,"axis."));
// get rid of empty values
for (Iterator<Axis> itr = newAxes.iterator(); itr.hasNext();) {
Axis a = itr.next();
if(a.values.isEmpty()) itr.remove();
}
// parse system axes
newAxes.add(Axis.parsePrefixed(req,"jdk"));
newAxes.add(Axis.parsePrefixed(req,"label"));
if(req.getParameter("multipleNodes")!=null)
newAxes.add(Axis.parsePrefixed(req,"label"));
this.axes = newAxes;
buildWrappers = buildDescribable(req, BuildWrappers.WRAPPERS, "wrapper");
@@ -57,12 +57,33 @@
</f:optionalBlock>
</j:if>
<!-- build config pane -->
<j:getStatic var="builders" className="hudson.tasks.BuildStep" field="BUILDERS" />
<f:descriptorList title="Build"
descriptors="${builders}"
instances="${it.builders}"
varName="builder" />
<j:set var="userAxes" value="${it.userAxes}" />
<f:optionalBlock name="hasAxes" title="Variables" checked="${!empty(userAxes)}">
<f:entry>
<f:repeatable var="axis" items="${userAxes}" noAddButton="true" minimum="1">
<table>
<f:entry title="Name">
<f:textbox name="axis.name" value="${axis.name}" />
</f:entry>
<f:entry title="Values">
<f:expandableTextBox name="axis.value" value="${axis.valueString}" />
</f:entry>
<f:entry>
<div align="right">
<input type="button" value="Add more axis" class="repeatable-add show-if-last" />
<input type="button" value="Delete" class="repeatable-delete" style="margin-left: 1em;" />
</div>
</f:entry>
</table>
</f:repeatable>
</f:entry>
</f:optionalBlock>
</f:section>
<!-- build config pane -->
<j:getStatic var="builders" className="hudson.tasks.BuildStep" field="BUILDERS" />
<f:descriptorList title="Build"
descriptors="${builders}"
instances="${it.builders}"
varName="builder" />
</j:jelly>
@@ -67,6 +67,7 @@
<j:if test="${minimum}">
<j:forEach begin="${h.size2(items)}" end="${minimum-1}" var="i">
<j:set var="${var}" value="${null}" />
<div class="repeated-chunk">
<d:invokeBody />
</div>