Merge pull request #847 from bstick12/JENKINS-18734

[JENKINS-18734] - Call perform(AbstractBuild build, Launcher launcher, BuildListener listener) if implemented in BuildStep
This commit is contained in:
Oleg Nenashev 2017-02-19 00:17:07 +03:00 committed by GitHub
commit fe4266b7d1
2 changed files with 64 additions and 2 deletions

View File

@ -31,9 +31,12 @@ import hudson.model.Action;
import hudson.model.Project;
import hudson.model.AbstractBuild;
import hudson.model.AbstractProject;
import hudson.util.ReflectionUtils;
import hudson.Launcher;
import hudson.Util;
import java.io.IOException;
import java.lang.reflect.Method;
import java.util.Collection;
import java.util.Collections;
@ -118,8 +121,13 @@ public abstract class BuildStepCompatibilityLayer implements BuildStep {
* Use {@link #perform(AbstractBuild, Launcher, BuildListener)} instead.
*/
@Deprecated
public boolean perform(Build<?,?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException {
throw new UnsupportedOperationException();
public boolean perform(Build<?, ?> build, Launcher launcher, BuildListener listener)
throws InterruptedException, IOException {
if (build instanceof AbstractBuild && Util.isOverridden(BuildStepCompatibilityLayer.class, this.getClass(),
"perform", AbstractBuild.class, Launcher.class, BuildListener.class)) {
return perform((AbstractBuild<?, ?>) build, launcher, listener);
}
throw new AbstractMethodError();
}
/**

View File

@ -0,0 +1,54 @@
package hudson.tasks;
import static org.junit.Assert.assertTrue;
import hudson.Launcher;
import hudson.model.AbstractBuild;
import hudson.model.BuildListener;
import hudson.model.FreeStyleBuild;
import java.io.IOException;
import org.junit.Test;
import org.jvnet.hudson.test.Issue;
import org.mockito.Mockito;
public class BuildStepCompatibilityLayerTest {
@Issue("JENKINS-18734")
@Test(expected = AbstractMethodError.class)
public void testPerformExpectAbstractMethodError() throws InterruptedException, IOException {
FreeStyleBuild mock = Mockito.mock(FreeStyleBuild.class, Mockito.CALLS_REAL_METHODS);
BuildStepCompatibilityLayer bscl = new BuildStepCompatibilityLayer() {
@Override
public BuildStepMonitor getRequiredMonitorService() {
return null;
}
};
bscl.perform(mock, null, null);
}
@Issue("JENKINS-18734")
@Test
public void testPerform() throws InterruptedException, IOException {
FreeStyleBuild mock = Mockito.mock(FreeStyleBuild.class, Mockito.CALLS_REAL_METHODS);
BuildStepCompatibilityLayer bscl = new BuildStepCompatibilityLayer() {
@Override
public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener)
throws InterruptedException, IOException {
return true;
}
@Override
public BuildStepMonitor getRequiredMonitorService() {
return null;
}
};
assertTrue(bscl.perform(mock, null, null));
}
}