package jenkins.advancedqueue;


import hudson.Plugin;
import hudson.model.Job;
import hudson.model.Queue;
import jenkins.advancedqueue.sorter.ItemInfo;
import jenkins.advancedqueue.sorter.QueueItemCache;
import jenkins.model.Jenkins;
import org.jenkinsci.plugins.workflow.support.steps.ExecutorStepExecution;

class PriorityConfigurationPlaceholderTaskHelper {

    boolean isPlaceholderTask(Queue.Task task) {
        return isPlaceholderTaskUsed() && task instanceof  ExecutorStepExecution.PlaceholderTask;
    }

    PriorityConfigurationCallback getPriority(ExecutorStepExecution.PlaceholderTask task, PriorityConfigurationCallback priorityCallback) {
        Job<?, ?> job = (Job<?, ?>) task.getOwnerTask();
        ItemInfo itemInfo = QueueItemCache.get().getItem(job.getName());
        itemInfo.getPriority();
        priorityCallback.setPrioritySelection(itemInfo.getPriority());
        return priorityCallback;
    }

    static boolean isPlaceholderTaskUsed() {
        Plugin plugin = Jenkins.getInstance().getPlugin("workflow-durable-task-step");
        return plugin != null && plugin.getWrapper().isActive();
    }

}

@@ -25,17 +25,16 @@
 queue;%0A%0A
-%0A
 import h
@@ -355,20 +355,17 @@
 lper %7B%0A%0A
-    
+%09
 boolean 
@@ -401,24 +401,18 @@
 task) %7B%0A
-        
+%09%09
 return i
@@ -453,17 +453,16 @@
 tanceof 
- 
 Executor
@@ -492,27 +492,21 @@
 erTask;%0A
-    %7D%0A%0A    
+%09%7D%0A%0A%09
 Priority
@@ -582,17 +582,20 @@
 sk task,
- 
+%0A%09%09%09
 Priority
@@ -636,24 +636,18 @@
 back) %7B%0A
-        
+%09%09
 Job%3C?, ?
@@ -687,24 +687,18 @@
 Task();%0A
-        
+%09%09
 ItemInfo
@@ -754,24 +754,124 @@
 ame());%0A
-        
+%0A%09%09// Can be null if job didn't run yet%0A%0A%09%09if (itemInfo != null) %7B%0A%09%09%09priorityCallback.setPrioritySelection(
 itemInfo
@@ -884,26 +884,33 @@
 iority()
+)
 ;%0A
-        
+%09%09%7D else %7B%0A%09%09%09
 priority
@@ -935,35 +935,81 @@
 tySelection(
-itemInfo.ge
+PrioritySorterConfiguration.get().getStrategy().getDefaul
 tPriority())
@@ -1010,24 +1010,23 @@
 ity());%0A
-        
+%09%09%7D%0A%0A%09%09
 return p
@@ -1046,19 +1046,13 @@
 ck;%0A
-    %7D%0A%0A    
+%09%7D%0A%0A%09
 stat
@@ -1088,24 +1088,18 @@
 sed() %7B%0A
-        
+%09%09
 Plugin p
@@ -1173,16 +1173,10 @@
 %22);%0A
-        
+%09%09
 retu
@@ -1232,12 +1232,9 @@
 ();%0A
-    
+%09
 %7D%0A%0A%7D

Fix upstream job priority retrieval