Skip to content

Commit

Permalink
[JENKINS-36626] - Get full names for queue items when they're availab…
Browse files Browse the repository at this point in the history
…le (#13)
  • Loading branch information
rjohnst authored and oleg-nenashev committed Oct 1, 2016
1 parent a3b25df commit 6c5a695
Showing 1 changed file with 18 additions and 14 deletions.
Expand Up @@ -23,14 +23,14 @@
*/
package com.synopsys.arc.jenkinsci.plugins.jobrestrictions.util;

import javax.annotation.Nonnull;

import hudson.model.Item;
import hudson.model.Job;
import hudson.model.Queue;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.NoExternalUse;

import javax.annotation.Nonnull;

/**
* Provides additional for Queue objects.
* @author Oleg Nenashev
Expand All @@ -48,22 +48,26 @@ public class QueueHelper {
@Deprecated
public static String getFullName(@Nonnull Queue.BuildableItem item) {
Queue.Task current = item.task;
String res = current.getName();
//Fetching the full path of the item
if (current instanceof Item) {
Item stub = (Item)current;
return stub.getFullName();
}

// Default approach via interface
while (true) {
String res = getItemName(current);

// this is only executed if we didn't call Item.getFullName() in getItemName
while (!(current instanceof Item)) {
Queue.Task parent = current.getOwnerTask();
if (parent == current || parent == null) {
break;
}
res = parent.getName() + "/" + res;
}
res = getItemName(parent) + "/" + res;
current = parent;
}
}
return res;
}

private static String getItemName(Queue.Task task) {
if (task instanceof Item) {
Item stub = (Item)task;
return stub.getFullName();
} else {
return task.getName();
}
}
}

0 comments on commit 6c5a695

Please sign in to comment.