Skip to content
Permalink
Browse files
[JENKINS-8929] follow up changes
- AbstractProject.getBuildingUpstream/getBuildingDownstream()
  should be symmetric.
- It's unlikely for us to add another category of items,
  so reverted getUnblockedItems() implementation to the older one
  that was more efficient.
- ItemList was meant to be internal, so keep it as such,
  at least for now.
  • Loading branch information
kohsuke committed Apr 7, 2011
1 parent 34d28db commit 1eff6776e81756b5f15c0b599210e433d366f11d
Showing with 31 additions and 16 deletions.
  1. +8 −11 core/src/main/java/hudson/model/AbstractProject.java
  2. +23 −5 core/src/main/java/hudson/model/Queue.java
@@ -43,7 +43,6 @@
import hudson.model.Descriptor.FormException;
import hudson.model.Fingerprint.RangeSet;
import hudson.model.Queue.Executable;
import hudson.model.Queue.ItemList;
import hudson.model.Queue.Task;
import hudson.model.queue.SubTask;
import hudson.model.Queue.WaitingItem;
@@ -1071,12 +1070,10 @@ public CauseOfBlockage getCauseOfBlockage() {
* the given project (provided that all builds went smoothly.)
*/
protected AbstractProject getBuildingDownstream() {
DependencyGraph graph = Hudson.getInstance().getDependencyGraph();
Set<AbstractProject> tups = graph.getTransitiveDownstream(this);
Queue queue = Hudson.getInstance().getQueue();
ItemList<Queue.Item> unblockedItems = queue.getUnblockedItems();
for (AbstractProject tup : tups) {
if(tup.isBuilding() || unblockedItems.containsKey(tup))
Set<Task> unblockedTasks = Hudson.getInstance().getQueue().getUnblockedTasks();

for (AbstractProject tup : Hudson.getInstance().getDependencyGraph().getTransitiveDownstream(this)) {
if (tup!=this && (tup.isBuilding() || unblockedTasks.contains(tup)))
return tup;
}
return null;
@@ -1090,10 +1087,10 @@ protected AbstractProject getBuildingDownstream() {
* the given project (provided that all builds went smoothly.)
*/
protected AbstractProject getBuildingUpstream() {
DependencyGraph graph = Hudson.getInstance().getDependencyGraph();
Set<AbstractProject> tups = graph.getTransitiveUpstream(this);
for (AbstractProject tup : tups) {
if(tup.isBuilding() || tup.isInQueue())
Set<Task> unblockedTasks = Hudson.getInstance().getQueue().getUnblockedTasks();

for (AbstractProject tup : Hudson.getInstance().getDependencyGraph().getTransitiveUpstream(this)) {
if (tup!=this && (tup.isBuilding() || unblockedTasks.contains(tup)))
return tup;
}
return null;
@@ -76,6 +76,7 @@
import java.util.Collections;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
@@ -636,14 +637,31 @@ private void _getBuildableItems(Computer c, ItemList<BuildableItem> col, List<Bu

/**
* Gets all items that are in the queue but not blocked
*
* @since 1.402
*/
synchronized ItemList<Item> getUnblockedItems() {
ItemList<Item> queuedNotBlocked = new ItemList<Item>();
queuedNotBlocked.addAll(Arrays.asList(getItems()));
queuedNotBlocked.removeAll(blockedProjects);
public synchronized List<Item> getUnblockedItems() {
List<Item> queuedNotBlocked = new ArrayList<Item>();
queuedNotBlocked.addAll(waitingList);
queuedNotBlocked.addAll(buildables);
queuedNotBlocked.addAll(pendings);
// but not 'blockedProjects'
return queuedNotBlocked;
}

/**
* Works just like {@link #getUnblockedItems()} but return tasks.
*
* @since 1.402
*/
public synchronized Set<Task> getUnblockedTasks() {
List<Item> items = getUnblockedItems();
Set<Task> unblockedTasks = new HashSet<Task>(items.size());
for (Queue.Item t : items)
unblockedTasks.add(t.task);
return unblockedTasks;
}

/**
* Is the given task currently pending execution?
*/
@@ -1568,7 +1586,7 @@ protected void doRun() {
/**
* {@link ArrayList} of {@link Item} with more convenience methods.
*/
static class ItemList<T extends Item> extends ArrayList<T> {
private static class ItemList<T extends Item> extends ArrayList<T> {
public T get(Task task) {
for (T item: this) {
if (item.task == task) {

0 comments on commit 1eff677

Please sign in to comment.