Skip to content
Permalink
Browse files
[JENKINS-36626] - Get full names for queue items when they're availab…
…le (#13)
  • Loading branch information
rjohnst authored and oleg-nenashev committed Oct 1, 2016
1 parent a3b25df commit 6c5a69543a94eab0fb01a1200d6294417eaef367
Showing with 18 additions and 14 deletions.
  1. +18 −14 src/main/java/com/synopsys/arc/jenkinsci/plugins/jobrestrictions/util/QueueHelper.java
@@ -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
@@ -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.