Skip to content
Permalink
Browse files

[FIXED JENKINS-38960] Deprecate getIconFilePathPattern and switch to …

…IconSpec
  • Loading branch information...
stephenc committed Oct 13, 2016
1 parent b62ad15 commit bd834fe831b14a0658594ab6b3a4a68a8f3de808
@@ -25,6 +25,8 @@

import hudson.Extension;
import jenkins.model.Jenkins;
import org.jenkins.ui.icon.Icon;
import org.jenkins.ui.icon.IconSet;
import org.jenkinsci.Symbol;
import jenkins.model.item_category.StandaloneProjectsCategory;
import org.kohsuke.accmod.Restricted;
@@ -97,5 +99,16 @@ public String getIconFilePathPattern() {
return (Jenkins.RESOURCE_PATH + "/images/:size/freestyleproject.png").replaceFirst("^/", "");
}

@Override
public String getIconClassName() {
return "icon-freestyle-project";
}

static {
IconSet.icons.addIcon(new Icon("icon-freestyle-project icon-sm", "16x16/freestyleproject.png", Icon.ICON_SMALL_STYLE));
IconSet.icons.addIcon(new Icon("icon-freestyle-project icon-md", "24x24/freestyleproject.png", Icon.ICON_MEDIUM_STYLE));
IconSet.icons.addIcon(new Icon("icon-freestyle-project icon-lg", "32x32/freestyleproject.png", Icon.ICON_LARGE_STYLE));
IconSet.icons.addIcon(new Icon("icon-freestyle-project icon-xlg", "48x48/freestyleproject.png", Icon.ICON_XLARGE_STYLE));
}
}
}
@@ -30,6 +30,9 @@
import org.apache.commons.jelly.Script;
import org.apache.commons.jelly.XMLOutput;
import org.apache.commons.lang.StringUtils;
import org.jenkins.ui.icon.Icon;
import org.jenkins.ui.icon.IconSet;
import org.jenkins.ui.icon.IconSpec;
import org.kohsuke.stapler.MetaClass;
import org.kohsuke.stapler.Stapler;
import org.kohsuke.stapler.StaplerRequest;
@@ -48,7 +51,7 @@
*
* @author Kohsuke Kawaguchi
*/
public abstract class TopLevelItemDescriptor extends Descriptor<TopLevelItem> {
public abstract class TopLevelItemDescriptor extends Descriptor<TopLevelItem> implements IconSpec {

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

@@ -189,6 +192,7 @@ public String getCategoryId() {
* @return A string or null if it is not defined.
*
* @since 2.0
* @deprecated prefer {@link #getIconClassName()}
*/
@CheckForNull
public String getIconFilePathPattern() {
@@ -203,6 +207,7 @@ public String getIconFilePathPattern() {
* @return A string or null if it is not defined.
*
* @since 2.0
* @deprecated prefer {@link #getIconClassName()}
*/
@CheckForNull
public String getIconFilePath(String size) {
@@ -212,6 +217,36 @@ public String getIconFilePath(String size) {
return null;
}

/**
* Get the Item's Icon class specification e.g. 'icon-notepad'.
* <p/>
* Note: do <strong>NOT</strong> include icon size specifications (such as 'icon-sm').
*
* @return The Icon class specification e.g. 'icon-notepad'.
*/
@Override
public String getIconClassName() {
// Oh the fun of somebody adding a legacy way of referencing images into 2.0 code
String pattern = getIconFilePathPattern();
if (pattern != null) {
// here we go with the dance of the IconSet's
String path = pattern.replace(":size", "24x24"); // we'll strip the icon-md to get the class name
if (path.indexOf('/') == -1) {
// this one is easy... too easy... also will never happen
return IconSet.toNormalizedIconNameClass(path);
}
if (Jenkins.RESOURCE_PATH.length() > 0 && path.startsWith(Jenkins.RESOURCE_PATH)) {
// will to live falling
path = path.substring(Jenkins.RESOURCE_PATH.length());
}
Icon icon = IconSet.icons.getIconByUrl(path);
if (icon != null) {
return icon.getClassSpec().replaceAll("\\s*icon-md\\s*", " ").replaceAll("\\s+", " ");
}
}
return null;
}

/**
* @deprecated since 2007-01-19.
* This is not a valid operation for {@link Item}s.
@@ -1058,6 +1058,7 @@ public Categories doItemCategories(StaplerRequest req, StaplerResponse rsp) thro
metadata.put("displayName", descriptor.getDisplayName());
metadata.put("description", descriptor.getDescription());
metadata.put("iconFilePathPattern", descriptor.getIconFilePathPattern());
metadata.put("iconClassName", descriptor.getIconClassName());

Category category = categories.getItem(ic.getId());
if (category != null) {

0 comments on commit bd834fe

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