Skip to content
Permalink
Browse files

Added PrioritySorterPLugin and moved initialization

All initialization is now done from the PrioritySorterPlugin
this includes legacy check and initial queue sorting.
  • Loading branch information...
emsa23 committed Dec 7, 2013
1 parent 260b02f commit a2447a7e371869cb4ada8ed76a7114b3eb165ee8
@@ -23,9 +23,7 @@
*/
package jenkins.advancedqueue;

import static hudson.init.InitMilestone.JOB_LOADED;
import hudson.Extension;
import hudson.init.Initializer;
import hudson.model.AbstractProject;
import hudson.model.TopLevelItem;
import hudson.queueSorter.PrioritySorterJobProperty;
@@ -73,7 +71,6 @@
public PrioritySorterConfiguration() {
}

@Initializer(after = JOB_LOADED)
public static void init() {
PrioritySorterConfiguration prioritySorterConfiguration = PrioritySorterConfiguration.get();
// Make sure default is good for updating from legacy
@@ -0,0 +1,58 @@
/*
* The MIT License
*
* Copyright 2013 Magnus Sandberg, Oleg Nenashev
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package jenkins.advancedqueue;

import static hudson.init.InitMilestone.JOB_LOADED;
import hudson.Plugin;
import hudson.init.Initializer;

import java.util.logging.Logger;

import jenkins.advancedqueue.sorter.AdvancedQueueSorter;

/**
* Plugin is the staring point of the Priority Sorter Plugin.
*
* Used to make sure that the data is initialized at startup.
*
* @author Magnus Sandberg
* @since 2.3
*/
public class PrioritySorterPlugin extends Plugin {

private final static Logger LOGGER = Logger.getLogger(PrioritySorterPlugin.class.getName());

@Initializer(after = JOB_LOADED)
public static void init() {
// Check for Legacy Mode and init the Configuration
LOGGER.info("Configuring the Priority Sorter ...");
PrioritySorterConfiguration.init();
// If Legacy Mode - init the Queue and sort the loaded Queue items
if (PrioritySorterConfiguration.get().getLegacyMode()) {
LOGGER.info("Sorting existing Queue ...");
AdvancedQueueSorter.init();
}
}

}
@@ -46,7 +46,9 @@
public class AdvancedQueueSorter extends QueueSorter {

public AdvancedQueueSorter() {
super();
}

static public void init() {
List<BuildableItem> items = Queue.getInstance().getBuildableItems();
// Sort the queue in the order the items entered the queue
// so that onNewItem() happens in the correct order below
@@ -55,8 +57,9 @@ public int compare(BuildableItem o1, BuildableItem o2) {
return (int) (o1.getInQueueSince() - o2.getInQueueSince());
}
});
AdvancedQueueSorter advancedQueueSorter = AdvancedQueueSorter.get();
for (BuildableItem item : items) {
onNewItem(item);
advancedQueueSorter.onNewItem(item);
}
}

0 comments on commit a2447a7

Please sign in to comment.
You can’t perform that action at this time.