Skip to content
Permalink
Browse files

Merge pull request #31 from ikedam/feature/JENKINS-34900_FixNPEforMav…

…enModule

[JENKINS-34900] Fix NPE when triggering single Maven module.
  • Loading branch information
ikedam committed Jun 4, 2016
2 parents 27f461a + cbd89e5 commit ce036de06b64d734d89ed5a4cbc6d099e63be8a6
@@ -91,7 +91,13 @@ public void onCompleted(AbstractBuild<?, ?> build, @Nonnull TaskListener listene
public Environment setUpEnvironment(@SuppressWarnings("rawtypes") AbstractBuild build, Launcher launcher, BuildListener listener)
throws IOException, InterruptedException, RunnerAbortedException
{
final NaginatorAction action = build.getRootBuild().getAction(NaginatorAction.class);
AbstractBuild<?, ?> rootBuild = build.getRootBuild();
if (rootBuild == null) {
// getRootBuild() should not be null,
// but some builds irregularly returns null.
rootBuild = build;
}
final NaginatorAction action = rootBuild.getAction(NaginatorAction.class);
if (action == null) {
return null;
}
@@ -7,8 +7,10 @@
import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;

import org.apache.commons.lang.StringUtils;
import org.jvnet.hudson.test.Bug;
import org.jvnet.hudson.test.HudsonTestCase;
import org.jvnet.hudson.test.SingleFileSCM;
import org.jvnet.hudson.test.FailureBuilder;
import org.jvnet.hudson.test.SleepBuilder;

@@ -22,6 +24,7 @@
import hudson.matrix.AxisList;
import hudson.matrix.Combination;
import hudson.matrix.MatrixProject;
import hudson.maven.MavenModuleSet;
import hudson.model.AbstractBuild;
import hudson.model.AbstractProject;
import hudson.model.BuildListener;
@@ -383,4 +386,29 @@ public void testVariableForMatrixBuild() throws Exception {
assertEquals("2", maxCountRecorder.getRecordedValue(p.getBuildByNumber(3).getExactRun(new Combination(axisList, "value2"))));
assertEquals("2", buildNumberRecorder.getRecordedValue(p.getBuildByNumber(3).getExactRun(new Combination(axisList, "value2"))));
}

@Bug(34900)
public void testMavenModuleSetWithoutNaginator() throws Exception {
final String SIMPLE_POM = StringUtils.join(new String[]{
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>",
"<project xmlns=\"http://maven.apache.org/POM/4.0.0\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd\">",
" <modelVersion>4.0.0</modelVersion>",
" <groupId>com.exmaple</groupId>",
" <artifactId>test</artifactId>",
" <version>1.0</version>",
" <packaging>jar</packaging>",
"</project>"
}, "\n");

configureDefaultMaven();
MavenModuleSet p = createMavenProject();
p.setScm(new SingleFileSCM("pom.xml", SIMPLE_POM));
p.setGoals("clean");

// Run once to have the project read the module structure.
assertBuildStatusSuccess(p.scheduleBuild2(0));

// This results MavenModuleBuild#getRootBuild() to be `null`.
assertBuildStatusSuccess(p.getRootModule().scheduleBuild2(0));
}
}

0 comments on commit ce036de

Please sign in to comment.
You can’t perform that action at this time.