mirror of
https://github.com/jenkinsci/jenkins.git
synced 2026-11-16 21:42:27 +00:00
fixing up the semantics and adding a test.
This commit is contained in:
1 parent
a3489b5bc9
commit
e5e163f26f
7 files changed
+119
-39
No files matched your search
@@ -29,15 +29,16 @@ import hudson.matrix.listeners.MatrixBuildListener;
|
||||
import hudson.model.AbstractBuild;
|
||||
import hudson.model.AbstractProject;
|
||||
import hudson.model.BuildListener;
|
||||
import hudson.model.Cause.UpstreamCause;
|
||||
import hudson.model.Executor;
|
||||
import hudson.model.Fingerprint;
|
||||
import jenkins.model.Jenkins;
|
||||
import hudson.model.JobProperty;
|
||||
import hudson.model.ParametersAction;
|
||||
import hudson.model.Queue;
|
||||
import hudson.model.Result;
|
||||
import hudson.model.Cause.UpstreamCause;
|
||||
import hudson.tasks.Publisher;
|
||||
import jenkins.model.Jenkins;
|
||||
import org.kohsuke.stapler.StaplerRequest;
|
||||
import org.kohsuke.stapler.StaplerResponse;
|
||||
import org.kohsuke.stapler.export.Exported;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@@ -45,13 +46,10 @@ import java.io.PrintStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Collection;
|
||||
import java.util.Comparator;
|
||||
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;
|
||||
|
||||
/**
|
||||
* Build of {@link MatrixProject}.
|
||||
@@ -261,11 +259,11 @@ 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);
|
||||
|
||||
MatrixConfigurationSorter sorter = p.getSorter();
|
||||
if (sorter != null) {
|
||||
touchStoneConfigurations = createTreeSet(touchStoneConfigurations, sorter);
|
||||
delayedConfigurations = createTreeSet(delayedConfigurations,sorter);
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -401,6 +399,12 @@ public class MatrixBuild extends AbstractBuild<MatrixProject,MatrixBuild> {
|
||||
}
|
||||
}
|
||||
|
||||
private <T> TreeSet<T> createTreeSet(Collection<T> items, Comparator<T> sorter) {
|
||||
TreeSet<T> r = new TreeSet<T>(sorter);
|
||||
r.addAll(items);
|
||||
return r;
|
||||
}
|
||||
|
||||
/**
|
||||
* A private exception to help maintain the correct control flow after extracting the 'waitForCompletion' method
|
||||
*/
|
||||
|
||||
@@ -56,7 +56,7 @@ import java.util.Map;
|
||||
*
|
||||
* @author Kohsuke Kawaguchi
|
||||
*/
|
||||
public class MatrixConfiguration extends Project<MatrixConfiguration,MatrixRun> implements SCMedItem, NonBlockingTask, Comparable<MatrixConfiguration> {
|
||||
public class MatrixConfiguration extends Project<MatrixConfiguration,MatrixRun> implements SCMedItem, NonBlockingTask {
|
||||
/**
|
||||
* The actual value combination.
|
||||
*/
|
||||
@@ -290,19 +290,6 @@ public class MatrixConfiguration extends Project<MatrixConfiguration,MatrixRun>
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public int compareTo(MatrixConfiguration that) {
|
||||
MatrixConfigurationSorter sorter = getParent().getSorter();
|
||||
try {
|
||||
if (sorter != null) {
|
||||
return getParent().getSorter().compare(this, that);
|
||||
} else {
|
||||
return getDisplayName().compareTo(((MatrixConfiguration) that).getDisplayName());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new IllegalArgumentException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this configuration is a configuration
|
||||
* currently in use today (as opposed to the ones that are
|
||||
|
||||
@@ -153,8 +153,11 @@ public class MatrixProject extends AbstractProject<MatrixProject,MatrixBuild> im
|
||||
public MatrixProject(ItemGroup parent, String name) {
|
||||
super(parent, name);
|
||||
}
|
||||
|
||||
public MatrixConfigurationSorter getSorter(){
|
||||
|
||||
/**
|
||||
* @return can be null (to indicate that the configurations should be left to their natural order.)
|
||||
*/
|
||||
public MatrixConfigurationSorter getSorter() {
|
||||
return sorter;
|
||||
}
|
||||
|
||||
@@ -586,12 +589,18 @@ public class MatrixProject extends AbstractProject<MatrixProject,MatrixBuild> im
|
||||
checkAxisNames(newAxes);
|
||||
this.axes = new AxisList(newAxes.toList());
|
||||
|
||||
// set sorter if any sorter is chosen
|
||||
MatrixConfigurationSorter s = req.bindJSON(MatrixConfigurationSorter.class,json.optJSONObject("sorter"));
|
||||
s.validate(this);
|
||||
setSorter(s);
|
||||
runSequentially = json.optBoolean("runSequentially");
|
||||
|
||||
// set sorter if any sorter is chosen
|
||||
if (runSequentially) {
|
||||
MatrixConfigurationSorter s = req.bindJSON(MatrixConfigurationSorter.class,json.optJSONObject("sorter"));
|
||||
if (s!=null) s.validate(this);
|
||||
if (s instanceof NoopMatrixConfigurationSorter) s=null;
|
||||
setSorter(s);
|
||||
} else {
|
||||
setSorter(null);
|
||||
}
|
||||
|
||||
runSequentially = json.has("runSequentially");
|
||||
|
||||
buildWrappers.rebuild(req, json, BuildWrappers.getFor(this));
|
||||
builders.rebuildHetero(req, json, Builder.all(), "builder");
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
package hudson.matrix;
|
||||
|
||||
import hudson.Extension;
|
||||
import hudson.util.FormValidation;
|
||||
import org.kohsuke.stapler.DataBoundConstructor;
|
||||
|
||||
/**
|
||||
* Place holder for default "do not sort" {@link MatrixConfigurationSorter}.
|
||||
*
|
||||
* @author Kohsuke Kawaguchi
|
||||
*/
|
||||
public class NoopMatrixConfigurationSorter extends MatrixConfigurationSorter {
|
||||
@DataBoundConstructor
|
||||
public NoopMatrixConfigurationSorter() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validate(MatrixProject p) throws FormValidation {
|
||||
// nothing
|
||||
}
|
||||
|
||||
public int compare(MatrixConfiguration o1, MatrixConfiguration o2) {
|
||||
return o1.getDisplayName().compareTo(o2.getDisplayName());
|
||||
}
|
||||
|
||||
@Extension(ordinal=100) // this is the default
|
||||
public static class DescriptorImpl extends MatrixConfigurationSorterDescriptor {
|
||||
@Override
|
||||
public String getDisplayName() {
|
||||
return "Doesn't care";
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user