提交 cdfdb177 编写于 作者: L lucinka 提交者: Kohsuke Kawaguchi

Add new extension point (class hudson.matrix.MatrixConfigurationSorter) for...

Add new extension point (class hudson.matrix.MatrixConfigurationSorter) for enbling to sort configurations of matrix job.
上级 8affa6d9
......@@ -48,6 +48,7 @@ import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.TreeSet;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse;
import org.kohsuke.stapler.export.Exported;
......@@ -260,6 +261,12 @@ public class MatrixBuild extends AbstractBuild<MatrixProject,MatrixBuild> {
for (MatrixAggregator a : aggregators)
if(!a.startBuild())
return Result.FAILURE;
MatrixConfigurationSorter sorter = p.getSorter();
if(p.getSorter()!=null){
touchStoneConfigurations = new TreeSet<MatrixConfiguration>(touchStoneConfigurations);
delayedConfigurations = new TreeSet<MatrixConfiguration>(delayedConfigurations);
}
try {
if(!p.isRunSequentially())
......
......@@ -56,7 +56,7 @@ import java.util.Map;
*
* @author Kohsuke Kawaguchi
*/
public class MatrixConfiguration extends Project<MatrixConfiguration,MatrixRun> implements SCMedItem, NonBlockingTask {
public class MatrixConfiguration extends Project<MatrixConfiguration,MatrixRun> implements SCMedItem, NonBlockingTask, Comparable {
/**
* The actual value combination.
*/
......@@ -289,6 +289,21 @@ public class MatrixConfiguration extends Project<MatrixConfiguration,MatrixRun>
public void setLogRotator(LogRotator logRotator) {
throw new UnsupportedOperationException();
}
public int compareTo(Object object){
MatrixConfigurationSorter sorter = getParent().getSorter();
try{
if(sorter!=null){
return getParent().getSorter().compare(this, (MatrixConfiguration)object);
}
else{
return getDisplayName().compareTo(((MatrixConfiguration)object).getDisplayName());
}
}
catch(Exception e){
throw new IllegalArgumentException(e);
}
}
/**
* Returns true if this configuration is a configuration
......
package hudson.matrix;
import hudson.ExtensionPoint;
import hudson.model.Describable;
import hudson.model.Descriptor;
import hudson.model.Hudson;
import java.util.List;
import jenkins.model.Jenkins;
/**
* Add sorting for configurations {@link MatrixConfiguration}s of matrix job {@link MatrixProject}
*
* @since 1.437
* @author Lucie Votypkova
*/
public abstract class MatrixConfigurationSorter implements ExtensionPoint, Describable<MatrixConfigurationSorter> {
/**
*
* @param matrix configuration1, matrix configuration2
* The configurations that are compared.
* @return
* int number for their comparing
*/
public abstract int compare(MatrixConfiguration configuration1, MatrixConfiguration configuration2);
public abstract String getDisplayName();
/**
*
* @param List of chosen axes by user
*
* @return
* true if the sorting of this axes by this sorter is possible (for example if the list of axes is not empty or contains axis which is needed for sorting.
* false if the sorting is impossible
*/
public abstract boolean isSortingPossible(List<Axis> axes);
/**
*
* @return String message which will be displayed to user if sorting is impossible (method isSortingPossible(List<Axis> axes) return false)
*
*/
public abstract String getErrorFormMessage();
public Descriptor<MatrixConfigurationSorter> getDescriptor() {
return Jenkins.getInstance().getDescriptorOrDie(getClass());
}
public static List<MatrixConfigurationSorter> all() {
return Hudson.getInstance().getExtensionList(MatrixConfigurationSorter.class);
}
}
......@@ -143,6 +143,8 @@ public class MatrixProject extends AbstractProject<MatrixProject,MatrixBuild> im
* continue with the rest
*/
private Result touchStoneResultCondition;
private MatrixConfigurationSorter sorter;
public MatrixProject(String name) {
this(Jenkins.getInstance(), name);
......@@ -151,6 +153,18 @@ public class MatrixProject extends AbstractProject<MatrixProject,MatrixBuild> im
public MatrixProject(ItemGroup parent, String name) {
super(parent, name);
}
public MatrixConfigurationSorter getSorter(){
return sorter;
}
public void setSorter(MatrixConfigurationSorter sorter){
this.sorter = sorter;
}
public List<MatrixConfigurationSorter> getAllSorters(){
return MatrixConfigurationSorter.all();
}
public AxisList getAxes() {
return axes;
......@@ -574,7 +588,26 @@ public class MatrixProject extends AbstractProject<MatrixProject,MatrixBuild> im
newAxes.rebuildHetero(req, json, Axis.all(),"axis");
checkAxisNames(newAxes);
this.axes = new AxisList(newAxes.toList());
// set sorter if any sorter is chosen
String sorterClassName = req.getParameter("sorter");
for(MatrixConfigurationSorter s: MatrixConfigurationSorter.all()){
if(sorterClassName.equals("None")){
sorter = null;
break;
}
if(s.getClass().getName().equals(sorterClassName)){
if(s.isSortingPossible(axes)){
sorter = s;
}
else{
sorter = null;
throw new FormException(s.getErrorFormMessage(),"sorter.getDisplayName");
}
break;
}
}
runSequentially = json.has("runSequentially");
buildWrappers.rebuild(req, json, BuildWrappers.getFor(this));
......
......@@ -59,6 +59,17 @@ THE SOFTWARE.
addCaption="${%Add axis}"/>
</f:block>
<j:if test="${(it.allSorters.size() > 0)}">
<f:entry title="Sort axis">
<select name="sorter">
<f:option selected="${it.sorter==null}" value="${none}">None</f:option>
<j:forEach var="inst" items="${it.allSorters}">
<f:option selected="${inst.class.isInstance(it.sorter)}" value="${inst.class.name}">${inst.displayName}</f:option>
</j:forEach>
</select>
</f:entry>
</j:if>
<f:optionalBlock field="runSequentially" title="${%Run each configuration sequentially}"/>
<f:optionalBlock name="hasCombinationFilter" title="${%Combination Filter}" checked="${!empty(it.combinationFilter)}"
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册