Skip to content

Commit

Permalink
[JENKINS-28359] Remove support for Legacy Sorter
Browse files Browse the repository at this point in the history
  • Loading branch information
emsa23 committed May 12, 2015
1 parent 032a930 commit f070c3b
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 140 deletions.
3 changes: 3 additions & 0 deletions pom.xml
Expand Up @@ -45,6 +45,9 @@
<groupId>org.jenkins-ci.tools</groupId>
<artifactId>maven-hpi-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<compatibleSinceVersion>3.1</compatibleSinceVersion>
</configuration>
</plugin>
<!-- http://stackoverflow.com/questions/15166781/mvn-releaseprepare-not-committing-changes-to-pom-xml -->
<plugin>
Expand Down
68 changes: 0 additions & 68 deletions src/main/java/hudson/queueSorter/PrioritySorterJobProperty.java

This file was deleted.

Expand Up @@ -25,8 +25,6 @@

import hudson.Extension;
import hudson.model.AbstractProject;
import hudson.model.TopLevelItem;
import hudson.queueSorter.PrioritySorterJobProperty;
import hudson.security.ACL;
import hudson.util.FormValidation;
import hudson.util.ListBoxModel;
Expand Down Expand Up @@ -61,8 +59,6 @@ public class PrioritySorterConfiguration extends GlobalConfiguration {
private final static SorterStrategy DEFAULT_STRATEGY = new AbsoluteStrategy(
MultiBucketStrategy.DEFAULT_PRIORITIES_NUMBER, MultiBucketStrategy.DEFAULT_PRIORITY);

private boolean legacyMode = false;

/**
* @deprecated used in 2.x - replaces with XXX
*/
Expand All @@ -81,11 +77,7 @@ public static void init() {
// Make sure default is good for updating from legacy
prioritySorterConfiguration.strategy = DEFAULT_STRATEGY; // TODO: replace with class ref
prioritySorterConfiguration.allowPriorityOnJobs = false;
// Check for legacy
prioritySorterConfiguration.checkLegacy();
if (!prioritySorterConfiguration.getLegacyMode()) {
prioritySorterConfiguration.load();
}
prioritySorterConfiguration.load();
}

@Override
Expand All @@ -101,22 +93,13 @@ public boolean configure(StaplerRequest req, JSONObject json) throws FormExcepti
}
//
onlyAdminsMayEditPriorityConfiguration = json.getBoolean("onlyAdminsMayEditPriorityConfiguration");
if (getLegacyMode()) {
Boolean advanced = json.getBoolean("advanced");
if (advanced) {
convertFromLegacyToAdvanced();
}
} else {
updatePriorities(prevNumberOfPriorities);
}
//
updatePriorities(prevNumberOfPriorities);
//
save();
return true;
}

private final boolean getLegacyMode() {
return legacyMode;
}

public boolean getOnlyAdminsMayEditPriorityConfiguration() {
return onlyAdminsMayEditPriorityConfiguration;
}
Expand Down Expand Up @@ -167,30 +150,6 @@ public FormValidation doCheckNumberOfPriorities(@QueryParameter String value) {
return FormValidation.ok();
}

private void checkLegacy() {
// Shouldn't really by a permission problem when getting here but
// to be on the safe side
SecurityContext saveCtx = ACL.impersonate(ACL.SYSTEM);
try {
legacyMode = false;

// getAllItems() doesn't return MatrixProject even if actually is a Project
// since it also is a group of items (ItemGroup) in the tree being traversed
List<TopLevelItem> allItems = Jenkins.getInstance().getItems();
for (TopLevelItem item : allItems) {
if (item instanceof AbstractProject) {
AbstractProject<?, ?> project = (AbstractProject<?, ?>) item;
PrioritySorterJobProperty priority = project.getProperty(PrioritySorterJobProperty.class);
if (priority != null) {
legacyMode = true;
}
}
}
} finally {
SecurityContextHolder.setContext(saveCtx);
}
}

private void updatePriorities(int prevNumberOfPriorities) {
// Shouldn't really by a permission problem when getting here but
// to be on the safe side
Expand Down Expand Up @@ -234,30 +193,6 @@ private void updatePriorities(int prevNumberOfPriorities) {
}
}

private void convertFromLegacyToAdvanced() {
// Shouldn't really by a permission problem when getting here but
// to be on the safe side
SecurityContext saveCtx = ACL.impersonate(ACL.SYSTEM);
try {
@SuppressWarnings("rawtypes")
List<AbstractProject> allProjects = Jenkins.getInstance().getAllItems(AbstractProject.class);
for (AbstractProject<?, ?> project : allProjects) {
PrioritySorterJobProperty legacyPriorityProperty = project
.getProperty(PrioritySorterJobProperty.class);
try {
project.removeProperty(PrioritySorterJobProperty.class);
project.save();
} catch (IOException e) {
LOGGER.warning("Failed to remove Legacy Job Priority From " + project.getName());
}
}
// Finally, switch Legacy Mode
legacyMode = false;
} finally {
SecurityContextHolder.setContext(saveCtx);
}
}

static int legacyPriorityToAdvancedPriority(int legacyMinPriority, int legacyMaxPriority, int numberOfPriorities,
int priority) {
int offset = normalizedOffset(legacyMinPriority);
Expand Down

This file was deleted.

0 comments on commit f070c3b

Please sign in to comment.