Skip to content
Permalink
Browse files

Merge pull request #3000 from liketic/JENKINS-46161

[Fix JENKINS-46161] Make ReverseBuildTrigger#getUpstreamProjects null…
  • Loading branch information...
oleg-nenashev committed Sep 15, 2017
2 parents e8b2f5a + bde6413 commit 2ae37219fe635d1a93d1bb9a6ad5d79cc4072489
@@ -76,6 +76,7 @@
import org.kohsuke.stapler.DataBoundSetter;
import org.kohsuke.stapler.QueryParameter;

import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;

/**
@@ -91,6 +92,7 @@

private static final Logger LOGGER = Logger.getLogger(ReverseBuildTrigger.class.getName());

@CheckForNull
private String upstreamProjects;
private Result threshold = Result.SUCCESS;

@@ -109,8 +111,13 @@ public ReverseBuildTrigger(String upstreamProjects) {
this.upstreamProjects = upstreamProjects;
}

/**
* Gets the upstream projects.
*
* @return Upstream projects or empty("") if upstream projects is null.
*/
public String getUpstreamProjects() {
return upstreamProjects;
return Util.fixNull(upstreamProjects);
}

public Result getThreshold() {
@@ -170,7 +177,7 @@ private boolean shouldTrigger(Run upstreamBuild, TaskListener listener) {
}

@Override public void buildDependencyGraph(final AbstractProject downstream, DependencyGraph graph) {
for (AbstractProject upstream : Items.fromNameList(downstream.getParent(), Util.fixNull(upstreamProjects), AbstractProject.class)) {
for (AbstractProject upstream : Items.fromNameList(downstream.getParent(), getUpstreamProjects(), AbstractProject.class)) {
graph.addDependency(new DependencyGraph.Dependency(upstream, downstream) {
@Override public boolean shouldTriggerBuild(AbstractBuild upstreamBuild, TaskListener listener, List<Action> actions) {
return shouldTrigger(upstreamBuild, listener);
@@ -253,7 +260,7 @@ synchronized void invalidateCache() {
continue;
}
List<Job> upstreams =
Items.fromNameList(downstream.getParent(), Util.fixNull(trigger.upstreamProjects), Job.class);
Items.fromNameList(downstream.getParent(), trigger.getUpstreamProjects(), Job.class);
LOGGER.log(Level.FINE, "from {0} see upstreams {1}", new Object[]{downstream, upstreams});
for (Job upstream : upstreams) {
if (upstream instanceof AbstractProject && downstream instanceof AbstractProject) {
@@ -311,7 +318,7 @@ public void onLocationChanged(Item item, final String oldFullName, final String
if (t != null) {
String revised =
Items.computeRelativeNamesAfterRenaming(oldFullName, newFullName,
Util.fixNull(t.upstreamProjects), p.getParent());
t.getUpstreamProjects(), p.getParent());
if (!revised.equals(t.upstreamProjects)) {
t.upstreamProjects = revised;
try {
@@ -224,4 +224,20 @@ public void nullUpstreamProjectsNoNPE() throws Exception {
// ReverseBuildTrigger.RunListenerImpl, so an additional test may be needed downstream.
trigger.buildDependencyGraph(downstreamJob1, Jenkins.getInstance().getDependencyGraph());
}

@Issue("JENKINS-46161")
@Test
public void testGetUpstreamProjectsShouldNullSafe() throws Exception {
ReverseBuildTrigger trigger1 = new ReverseBuildTrigger(null);
String upstream1 = trigger1.getUpstreamProjects();
assertEquals("", upstream1);

ReverseBuildTrigger trigger2 = new ReverseBuildTrigger("upstream");
String upstream2 = trigger2.getUpstreamProjects();
assertEquals("upstream", upstream2);

ReverseBuildTrigger trigger3 = new ReverseBuildTrigger("");
String upstream3 = trigger3.getUpstreamProjects();
assertEquals("", upstream3);
}
}

0 comments on commit 2ae3721

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