Remove iteration in RunContainerImpl.get

Looking for the job when it already has it
This commit is contained in:
tfennelly 2016-05-24 22:17:08 +01:00
parent da815db21a
commit 1f45e58eaa
1 changed files with 17 additions and 26 deletions

View File

@ -6,10 +6,9 @@ import io.jenkins.blueocean.commons.ServiceException;
import io.jenkins.blueocean.rest.model.BluePipeline;
import io.jenkins.blueocean.rest.model.BlueRun;
import io.jenkins.blueocean.rest.model.BlueRunContainer;
import jenkins.model.Jenkins;
import javax.annotation.Nonnull;
import java.util.Iterator;
import java.util.List;
/**
* @author Vivek Pandey
@ -19,7 +18,7 @@ public class RunContainerImpl extends BlueRunContainer {
private final Job job;
private final BluePipeline pipeline;
public RunContainerImpl(BluePipeline pipeline, Job job) {
public RunContainerImpl(@Nonnull BluePipeline pipeline, @Nonnull Job job) {
this.job = job;
this.pipeline = pipeline;
}
@ -27,33 +26,25 @@ public class RunContainerImpl extends BlueRunContainer {
@Override
public BlueRun get(String name) {
List<Job> projects = Jenkins.getActiveInstance().getAllItems(Job.class);
for (Job p : projects) {
if (!p.getFullName().equals(job.getFullName())) {
continue;
}
RunList<? extends hudson.model.Run> runList = p.getBuilds();
RunList<? extends hudson.model.Run> runList = job.getBuilds();
hudson.model.Run run = null;
if (name != null) {
for (hudson.model.Run r : runList) {
if (r.getId().equals(name)) {
run = r;
break;
}
hudson.model.Run run = null;
if (name != null) {
for (hudson.model.Run r : runList) {
if (r.getId().equals(name)) {
run = r;
break;
}
if (run == null) {
throw new ServiceException.NotFoundException(
String.format("Run %s not found in organization %s and pipeline %s",
name, pipeline.getOrganization(), job.getName()));
}
} else {
run = runList.getLastBuild();
}
return AbstractRunImpl.getBlueRun(run);
if (run == null) {
throw new ServiceException.NotFoundException(
String.format("Run %s not found in organization %s and pipeline %s",
name, pipeline.getOrganization(), job.getName()));
}
} else {
run = runList.getLastBuild();
}
throw new ServiceException.NotFoundException(String.format("Run id %s not found for organization %s, pipeline: %s",
name, pipeline.getOrganization(), job.getName()));
return AbstractRunImpl.getBlueRun(run);
}
@Override