diff --git a/core/src/main/java/hudson/matrix/DefaultMatrixRunCheckoutStrategyImpl.java b/core/src/main/java/hudson/matrix/DefaultMatrixRunCheckoutStrategyImpl.java new file mode 100644 index 0000000000000000000000000000000000000000..852e3ba3d6fbaa435d3826053fe04e456a22dfa3 --- /dev/null +++ b/core/src/main/java/hudson/matrix/DefaultMatrixRunCheckoutStrategyImpl.java @@ -0,0 +1,35 @@ +package hudson.matrix; + +import hudson.Extension; +import hudson.Launcher; +import hudson.model.BuildListener; + +import java.io.IOException; + +import org.kohsuke.stapler.DataBoundConstructor; + +public class DefaultMatrixRunCheckoutStrategyImpl extends MatrixRunCheckoutStrategy { + + @DataBoundConstructor + public DefaultMatrixRunCheckoutStrategyImpl() { + } + + @Override + protected boolean preCheckout(MatrixRun build, Launcher launcher, BuildListener listener) + throws IOException, InterruptedException { + return true; + } + + @Override + protected boolean checkout(MatrixRun build, Launcher launcher, BuildListener listener) throws Exception { + return true; + } + + @Extension + public static class DescriptorImpl extends MatrixRunCheckoutStrategyDescriptor { + @Override + public String getDisplayName() { + return "Classic"; + } + } +} diff --git a/core/src/main/java/hudson/matrix/MatrixProject.java b/core/src/main/java/hudson/matrix/MatrixProject.java index 497bf363eba7bfed53052ab2543d5512269dd01d..2cefe6c8b19ddad4fa5aaebe545a9a0460f0c04a 100644 --- a/core/src/main/java/hudson/matrix/MatrixProject.java +++ b/core/src/main/java/hudson/matrix/MatrixProject.java @@ -160,6 +160,8 @@ public class MatrixProject extends AbstractProject im private MatrixExecutionStrategy executionStrategy; + private MatrixRunCheckoutStrategy matrixRunCheckoutStrategy; + /** * Custom workspace location for {@link MatrixConfiguration}s. * @@ -280,6 +282,16 @@ public class MatrixProject extends AbstractProject im save(); } + public MatrixRunCheckoutStrategy getMatrixRunCheckoutStrategy() { + return matrixRunCheckoutStrategy == null ? new DefaultMatrixRunCheckoutStrategyImpl() : matrixRunCheckoutStrategy; + } + + public void setMatrixRunCheckoutStrategy(MatrixRunCheckoutStrategy matrixRunCheckoutStrategy) throws IOException { + if (matrixRunCheckoutStrategy ==null) throw new IllegalArgumentException(); + this.matrixRunCheckoutStrategy = matrixRunCheckoutStrategy; + save(); + } + /** * @deprecated as of 1.456 * Use {@link DefaultMatrixExecutionStrategyImpl#isRunSequentially()}. @@ -763,6 +775,19 @@ public class MatrixProject extends AbstractProject im else executionStrategy = req.bindJSON(esd.get(0).clazz,json.getJSONObject("executionStrategy")); + try { + List mrcsd = MatrixRunCheckoutStrategyDescriptor + .all(); + if (mrcsd.size() > 1) + matrixRunCheckoutStrategy = req.bindJSON(MatrixRunCheckoutStrategy.class, + json.getJSONObject("matrixRunCheckoutStrategy")); + else + matrixRunCheckoutStrategy = req.bindJSON(mrcsd.get(0).clazz, + json.getJSONObject("matrixRunCheckoutStrategy")); + } catch (Exception exc) { + matrixRunCheckoutStrategy = new DefaultMatrixRunCheckoutStrategyImpl(); + } + // parse system axes DescribableList newAxes = new DescribableList(this); newAxes.rebuildHetero(req, json, Axis.all(),"axis"); @@ -843,6 +868,10 @@ public class MatrixProject extends AbstractProject im public List getExecutionStrategyDescriptors() { return MatrixExecutionStrategyDescriptor.all(); } + + public List getMatrixRunCheckoutStrategyDescriptors() { + return MatrixRunCheckoutStrategyDescriptor.all(); + } } private static final Logger LOGGER = Logger.getLogger(MatrixProject.class.getName()); diff --git a/core/src/main/java/hudson/matrix/MatrixRun.java b/core/src/main/java/hudson/matrix/MatrixRun.java index 02feccc8b34dc3be8a2a84a876c6e75a328e7b77..efd668edbfd83cd9d16a0864ef623d3590376211 100644 --- a/core/src/main/java/hudson/matrix/MatrixRun.java +++ b/core/src/main/java/hudson/matrix/MatrixRun.java @@ -25,10 +25,14 @@ package hudson.matrix; import hudson.EnvVars; import hudson.FilePath; +import hudson.Launcher; import hudson.model.AbstractBuild; +import hudson.model.BuildListener; +import hudson.model.BuildableItemWithBuildWrappers; import hudson.model.TopLevelItem; import hudson.slaves.WorkspaceList; import hudson.slaves.WorkspaceList.Lease; +import hudson.tasks.BuildWrapper; import hudson.model.Build; import hudson.model.Node; import org.kohsuke.stapler.Ancestor; @@ -182,5 +186,24 @@ public class MatrixRun extends Build { String childWs = mp.getChildCustomWorkspace(); return Lease.createLinkedDummyLease(baseDir.child(env.expand(childWs)),baseLease); } + @Override + protected void preCheckout(Launcher launcher, BuildListener listener) + throws IOException, InterruptedException { + MatrixProject mp = getParent().getParent(); + MatrixRunCheckoutStrategy strategy = mp.getMatrixRunCheckoutStrategy(); + boolean invokeSuper = strategy.preCheckout(MatrixRun.this, launcher, listener); + if(invokeSuper) { + super.preCheckout(launcher, listener); + } + } + @Override + protected void checkout(BuildListener listener) throws Exception { + MatrixProject mp = getParent().getParent(); + MatrixRunCheckoutStrategy strategy = mp.getMatrixRunCheckoutStrategy(); + boolean invokeSuper = strategy.checkout(MatrixRun.this, launcher, listener); + if(invokeSuper) { + super.checkout(listener); + } + } } } diff --git a/core/src/main/java/hudson/matrix/MatrixRunCheckoutStrategy.java b/core/src/main/java/hudson/matrix/MatrixRunCheckoutStrategy.java new file mode 100644 index 0000000000000000000000000000000000000000..0515ccb8c60433d7cd76a707f09836121021f20e --- /dev/null +++ b/core/src/main/java/hudson/matrix/MatrixRunCheckoutStrategy.java @@ -0,0 +1,20 @@ +package hudson.matrix; + +import hudson.ExtensionPoint; +import hudson.Launcher; +import hudson.model.AbstractDescribableImpl; +import hudson.model.BuildListener; + +import java.io.IOException; + +public abstract class MatrixRunCheckoutStrategy extends + AbstractDescribableImpl implements ExtensionPoint { + + protected abstract boolean preCheckout(MatrixRun build, Launcher launcher, BuildListener listener) throws IOException, InterruptedException; + protected abstract boolean checkout(MatrixRun build, Launcher launcher, BuildListener listener) throws Exception; + + @Override + public MatrixRunCheckoutStrategyDescriptor getDescriptor() { + return (MatrixRunCheckoutStrategyDescriptor)super.getDescriptor(); + } +} diff --git a/core/src/main/java/hudson/matrix/MatrixRunCheckoutStrategyDescriptor.java b/core/src/main/java/hudson/matrix/MatrixRunCheckoutStrategyDescriptor.java new file mode 100644 index 0000000000000000000000000000000000000000..df00f72388826fabb7d2d72f752e6b3f10607a58 --- /dev/null +++ b/core/src/main/java/hudson/matrix/MatrixRunCheckoutStrategyDescriptor.java @@ -0,0 +1,23 @@ +package hudson.matrix; + +import hudson.DescriptorExtensionList; +import hudson.model.Descriptor; +import jenkins.model.Jenkins; + +public abstract class MatrixRunCheckoutStrategyDescriptor extends Descriptor { + + protected MatrixRunCheckoutStrategyDescriptor(Class clazz) { + super(clazz); + } + + protected MatrixRunCheckoutStrategyDescriptor() { + } + + /** + * Returns all the registered {@link MatrixExecutionStrategyDescriptor}s. + */ + public static DescriptorExtensionList all() { + return Jenkins.getInstance().getDescriptorList(MatrixRunCheckoutStrategy.class); + } + +} diff --git a/core/src/main/java/hudson/model/AbstractBuild.java b/core/src/main/java/hudson/model/AbstractBuild.java index 185928ed14fee707735825a79de1f9615f0d98b4..a71101a33d04173b5b94d42ffdc6275145d5891e 100644 --- a/core/src/main/java/hudson/model/AbstractBuild.java +++ b/core/src/main/java/hudson/model/AbstractBuild.java @@ -568,7 +568,7 @@ public abstract class AbstractBuild

,R extends Abs * @throws IOException * @throws InterruptedException */ - private void preCheckout(Launcher launcher, BuildListener listener) throws IOException, InterruptedException{ + protected void preCheckout(Launcher launcher, BuildListener listener) throws IOException, InterruptedException{ if (project instanceof BuildableItemWithBuildWrappers) { BuildableItemWithBuildWrappers biwbw = (BuildableItemWithBuildWrappers) project; for (BuildWrapper bw : biwbw.getBuildWrappersList()) @@ -576,7 +576,7 @@ public abstract class AbstractBuild

,R extends Abs } } - private void checkout(BuildListener listener) throws Exception { + protected void checkout(BuildListener listener) throws Exception { for (int retryCount=project.getScmCheckoutRetryCount(); ; retryCount--) { // for historical reasons, null in the scm field means CVS, so we need to explicitly set this to something // in case check out fails and leaves a broken changelog.xml behind. diff --git a/core/src/main/resources/hudson/matrix/DefaultMatrixRunCheckoutStrategyImpl/config.jelly b/core/src/main/resources/hudson/matrix/DefaultMatrixRunCheckoutStrategyImpl/config.jelly new file mode 100644 index 0000000000000000000000000000000000000000..f672fd0986ad7df372027d591a9281fed0a646a0 --- /dev/null +++ b/core/src/main/resources/hudson/matrix/DefaultMatrixRunCheckoutStrategyImpl/config.jelly @@ -0,0 +1,27 @@ + + + + + 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 07a8c2809c600dcca61763059ce828be39ad1251..9c869fb2dced26f5017e2a42c4d8d9ea6ab1863a 100644 --- a/core/src/main/resources/hudson/matrix/MatrixProject/configure-entries.jelly +++ b/core/src/main/resources/hudson/matrix/MatrixProject/configure-entries.jelly @@ -57,6 +57,18 @@ THE SOFTWARE. + + + + + + + + + + + +