Skip to content

Commit

Permalink
Merge pull request #10 from ikedam/feature/JENKINS-27233_NonMatrixPro…
Browse files Browse the repository at this point in the history
…jects

[JENKINS-27233] Fixed exceptions in rebuild pages with non-matrix projects
  • Loading branch information
ikedam committed Jul 11, 2015
2 parents 3a20793 + 5f1e026 commit e7540f7
Show file tree
Hide file tree
Showing 6 changed files with 120 additions and 9 deletions.
Expand Up @@ -13,13 +13,21 @@ f = namespace("lib/form")
nsProject = namespace("/hudson/plugins/matrix_configuration_parameter/taglib")


def paramDef = it;
String nameIt = it.getName();
MatrixProject project = request.findAncestorObject(MatrixProject.class);
if (project == null) //in case project is not a Matrix Project
if (project == null) {
//in case project is not a Matrix Project
f.entry(title: nameIt, description: it.getDescription()) {
div(name: "parameter") {
input(type: "hidden", name: "name", value: nameIt)
text(_("Not applicable. Applicable only to multi-configuration projects."))
}//div
}
return;
}

AxisList axes = project.getAxes();
def paramDef = it;
String nameIt = it.getName();
Layouter layouter = new Layouter<Combination>(axes) {
protected Combination getT(Combination c) {
return c;
Expand Down
Expand Up @@ -16,12 +16,21 @@ f = namespace("lib/form")
nsProject = namespace("/hudson/plugins/matrix_configuration_parameter/taglib")


def valueIt = it;

MatrixProject project = request.findAncestorObject(MatrixProject.class);
AxisList axes = project.getAxes();
MatrixBuild build = request.findAncestorObject(MatrixBuild.class);
if (build == null) //in case you are looking at a specific run, MatrixRun Ancestor will replace the MatrixBuild
if (project == null || build == null) {
//in case you are looking at a specific run, MatrixRun Ancestor will replace the MatrixBuild
f.entry(title: valueIt.getName(), description: it.getDescription()) {
// In the case the parameter is not defined in this project,
// sending parameters cause rebuild-plugin throws exception.
// Acts as if I'm not here.
text(_("Not applicable. Applicable only to multi-configuration projects."))
}
return;
def valueIt = it;
}
AxisList axes = project.getAxes();
Layouter layouter = new Layouter<Combination>(axes) {
protected Combination getT(Combination c) {
return c;
Expand Down
Expand Up @@ -15,12 +15,20 @@ st = namespace("jelly:stapler")
f = namespace("lib/form")
nsProject = namespace("/hudson/plugins/matrix_configuration_parameter/taglib")

MatrixCombinationsParameterValue valueIt = it;
MatrixProject project = request.findAncestorObject(MatrixProject.class);
AxisList axes = project.getAxes();
MatrixBuild build = request.findAncestorObject(MatrixBuild.class);
if (build == null) //in case you are looking at a specific run, MatrixRun Ancestor will replace the MatrixBuild
if (project == null || build == null) {
//in case you are looking at a specific run, MatrixRun Ancestor will replace the MatrixBuild
f.entry(title: valueIt.getName(), description: it.getDescription()) {
div(name: "parameter") {
input(type: "hidden", name: "name", value: valueIt.getName())
text(_("Not applicable. Applicable only to multi-configuration projects."))
}//div
}
return;
MatrixCombinationsParameterValue valueIt = it;
}
AxisList axes = project.getAxes();
Layouter layouter = new Layouter<Combination>(axes) {
protected Combination getT(Combination c) {
return c;
Expand Down
Expand Up @@ -30,6 +30,8 @@
import hudson.matrix.MatrixBuild;
import hudson.matrix.MatrixProject;
import hudson.matrix.TextAxis;
import hudson.model.FreeStyleBuild;
import hudson.model.FreeStyleProject;
import hudson.model.ParametersDefinitionProperty;
import hudson.model.queue.QueueTaskFuture;
import hudson.model.Result;
Expand Down Expand Up @@ -442,4 +444,26 @@ public void testBuildPageForBuilding() throws Exception {

f.cancel(true);
}

@Test
public void testAppliedForNonMatrixProject() throws Exception {
FreeStyleProject p = j.createFreeStyleProject();
p.addProperty(new ParametersDefinitionProperty(
new MatrixCombinationsParameterDefinition("combinations", "", "")
));

{
WebClient wc = j.createAllow405WebClient();
HtmlPage page = wc.getPage(p, "build");
j.submit(page.getFormByName("parameters"));

j.waitUntilNoActivity();
FreeStyleBuild b = p.getLastBuild();
assertNotNull(b);
j.assertBuildStatusSuccess(b);
}

// default trigger
j.assertBuildStatusSuccess(p.scheduleBuild2(0));
}
}
Expand Up @@ -25,14 +25,22 @@
package hudson.plugins.matrix_configuration_parameter;

import static org.junit.Assert.*;

import java.util.Arrays;

import hudson.matrix.AxisList;
import hudson.matrix.MatrixBuild;
import hudson.matrix.MatrixProject;
import hudson.matrix.TextAxis;
import hudson.model.Cause;
import hudson.model.FreeStyleBuild;
import hudson.model.FreeStyleProject;
import hudson.model.ParametersAction;
import hudson.model.ParametersDefinitionProperty;

import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.Bug;
import org.jvnet.hudson.test.JenkinsRule;
import org.jvnet.hudson.test.JenkinsRule.WebClient;

Expand Down Expand Up @@ -92,4 +100,23 @@ public void testParametersPageWithDoubleAxis() throws Exception{
assertTrue(((HtmlCheckBoxInput)page.getElementById("checkboxcombinations-axis1-value1-2-axis2-value2-1")).isChecked());
assertTrue(((HtmlCheckBoxInput)page.getElementById("checkboxcombinations-axis1-value1-2-axis2-value2-2")).isChecked());
}

@Bug(27233)
@Test
public void testNonMatrixBuild() throws Exception {
FreeStyleProject p = j.createFreeStyleProject();

@SuppressWarnings("deprecation")
Cause cause = new Cause.UserCause();
FreeStyleBuild b = p.scheduleBuild2(0, cause, Arrays.asList(
new ParametersAction(new MatrixCombinationsParameterValue(
"combinations",
new Boolean[]{ true, false, true },
new String[]{ "axis1=value1", "axis1=value2", "axis1=value3" }
))
)).get();

WebClient wc = j.createWebClient();
wc.getPage(b, "parameters");
}
}
Expand Up @@ -34,11 +34,15 @@
import hudson.matrix.MatrixProject;
import hudson.matrix.TextAxis;
import hudson.model.Cause;
import hudson.model.FreeStyleBuild;
import hudson.model.FreeStyleProject;
import hudson.model.ParametersAction;
import hudson.model.ParametersDefinitionProperty;
import hudson.model.StringParameterValue;

import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.Bug;
import org.jvnet.hudson.test.JenkinsRule;
import org.jvnet.hudson.test.JenkinsRule.WebClient;

Expand Down Expand Up @@ -141,4 +145,35 @@ public void testRebuildTwoAxes() throws Exception {
assertNull(b1.getExactRun(new Combination(p.getAxes(), "value1-1", "value2-2")));
assertNotNull(b1.getExactRun(new Combination(p.getAxes(), "value1-2", "value2-2")));
}

@Bug(27233)
@Test
public void testAppliedForNonMatrixProjectRebuild() throws Exception {
FreeStyleProject p = j.createFreeStyleProject();

@SuppressWarnings("deprecation")
Cause cause = new Cause.UserCause();
FreeStyleBuild b1 = p.scheduleBuild2(0, cause, Arrays.asList(
new ParametersAction(
new MatrixCombinationsParameterValue(
"combinations",
new Boolean[]{ true, false, true },
new String[]{ "axis1=value1", "axis1=value2", "axis1=value3" }
)
// rebuild-plugin causes exception
// when requesting a rebuild with no parameters.
, new StringParameterValue("dummy", "")
)
)).get();

WebClient wc = j.createWebClient();
HtmlPage page = wc.getPage(b1, "rebuild");
HtmlForm form = page.getFormByName("config");
j.submit(form);

j.waitUntilNoActivity();

FreeStyleBuild b2 = p.getLastBuild();
assertNotEquals(b1.getNumber(), b2.getNumber());
}
}

0 comments on commit e7540f7

Please sign in to comment.