Skip to content

Commit

Permalink
Merge pull request #847 from bstick12/JENKINS-18734
Browse files Browse the repository at this point in the history
[JENKINS-18734] - Call perform(AbstractBuild build, Launcher launcher, BuildListener listener) if implemented in BuildStep
  • Loading branch information
oleg-nenashev committed Feb 18, 2017
2 parents 37d2e6a + 01fe717 commit fe4266b
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 2 deletions.
12 changes: 10 additions & 2 deletions core/src/main/java/hudson/tasks/BuildStepCompatibilityLayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,12 @@
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;

Expand Down Expand Up @@ -118,8 +121,13 @@ public boolean prebuild(Build<?,?> build, BuildListener listener) {
* 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();
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -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));

}

}

0 comments on commit fe4266b

Please sign in to comment.