Skip to content

Commit

Permalink
Fixed NPE when concurrent execution is involved.
Browse files Browse the repository at this point in the history
Improved the progress report message.
  • Loading branch information
kohsuke committed Feb 18, 2011
1 parent 58de047 commit ed07f4d
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 8 deletions.
1 change: 1 addition & 0 deletions pom.xml
Expand Up @@ -29,6 +29,7 @@
<groupId>org.jvnet.hudson.plugins</groupId>
<artifactId>subversion</artifactId>
<version>1.4</version>
<optional>true</optional>
</dependency>
</dependencies>

Expand Down
Expand Up @@ -3,8 +3,11 @@
import hudson.Extension;
import hudson.Launcher;
import hudson.model.AbstractBuild;
import hudson.model.AbstractProject;
import hudson.model.Action;
import hudson.model.BuildListener;
import hudson.model.Result;
import hudson.model.Cause.UpstreamCause;
import hudson.model.Run;
import org.kohsuke.stapler.DataBoundConstructor;

import java.io.IOException;
Expand Down Expand Up @@ -41,6 +44,21 @@ public List<Future<AbstractBuild>> perform(AbstractBuild<?, ?> build, Launcher l
return r;
}

@Override
protected Future schedule(AbstractBuild<?, ?> build, AbstractProject project, List<Action> list) throws InterruptedException, IOException {
if (block!=null) {
while (true) {
// if we fail to add the item to the queue, wait and retry.
// it also means we have to force quiet period = 0, or else it'll never leave the queue
Future f = project.scheduleBuild2(0, new UpstreamCause((Run) build), list.toArray(new Action[list.size()]));
if (f!=null) return f;
Thread.sleep(1000);
}
} else {
return super.schedule(build,project,list);
}
}

@Extension
public static class DescriptorImpl extends BuildTriggerConfig.DescriptorImpl {
}
Expand Down
Expand Up @@ -140,9 +140,7 @@ public List<Future<AbstractBuild>> perform(AbstractBuild<?, ?> build, Launcher l
for (AbstractProject project : getProjectList()) {
List<Action> list = getBuildActions(actions, project);

futures.add(project.scheduleBuild2(project.getQuietPeriod(),
new UpstreamCause((Run) build),
list.toArray(new Action[list.size()])));
futures.add(schedule(build, project, list));
}
return futures;
}
Expand All @@ -152,7 +150,13 @@ public List<Future<AbstractBuild>> perform(AbstractBuild<?, ?> build, Launcher l
return Collections.emptyList();
}

public boolean onJobRenamed(String oldName, String newName) {
protected Future schedule(AbstractBuild<?, ?> build, AbstractProject project, List<Action> list) throws InterruptedException, IOException {
return project.scheduleBuild2(project.getQuietPeriod(),
new UpstreamCause((Run) build),
list.toArray(new Action[list.size()]));
}

public boolean onJobRenamed(String oldName, String newName) {
boolean changed = false;
String[] list = projects.split(",");
for (int i = 0; i < list.length; i++) {
Expand Down
@@ -1,5 +1,6 @@
package hudson.plugins.parameterizedtrigger;

import hudson.AbortException;
import hudson.Extension;
import hudson.Launcher;
import hudson.Util;
Expand All @@ -19,6 +20,7 @@
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.concurrent.CancellationException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;

Expand Down Expand Up @@ -58,10 +60,18 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher,
}
try {
for (Entry<BlockableBuildTriggerConfig, List<Future<AbstractBuild>>> e : futures.entrySet()) {
int n=0;
AbstractProject p = e.getKey().getProjectList().get(n);
for (Future<AbstractBuild> f : e.getValue()) {
AbstractBuild b = f.get();
listener.getLogger().println(b.getFullDisplayName()+" completed. result was "+b.getResult());
build.setResult(e.getKey().getBlock().mapResult(b.getResult()));
try {
listener.getLogger().println("Waiting for the completion of "+p.getFullDisplayName());
AbstractBuild b = f.get();
listener.getLogger().println(b.getFullDisplayName()+" completed. result was "+b.getResult());
build.setResult(e.getKey().getBlock().mapResult(b.getResult()));
} catch (CancellationException x) {
throw new AbortException(p.getFullDisplayName() +" aborted.");
}
n++;
}
}
} catch (ExecutionException e) {
Expand Down

0 comments on commit ed07f4d

Please sign in to comment.