From 2356791978db17c19e767de7195ec07cb648b7a0 Mon Sep 17 00:00:00 2001 From: recena Date: Mon, 14 Mar 2016 13:56:08 +0100 Subject: [PATCH] [JENKINS-31162] A new description field has been added for Items --- .../java/hudson/model/ItemGroupMixIn.java | 2 + .../ItemCategoryConfigurator.java | 45 ++++++++++++++++--- 2 files changed, 42 insertions(+), 5 deletions(-) diff --git a/core/src/main/java/hudson/model/ItemGroupMixIn.java b/core/src/main/java/hudson/model/ItemGroupMixIn.java index 417b9dac19..96913f748b 100644 --- a/core/src/main/java/hudson/model/ItemGroupMixIn.java +++ b/core/src/main/java/hudson/model/ItemGroupMixIn.java @@ -348,10 +348,12 @@ public abstract class ItemGroupMixIn { ItemCategory ic = ItemCategoryConfigurator.getCategory(descriptor); Map metadata = new HashMap(); + // Information about Item. metadata.put("class", descriptor.clazz.getName()); metadata.put("iconClassName", "item-icon-" + descriptor.clazz.getName().substring(descriptor.clazz.getName().lastIndexOf(".") + 1).toLowerCase()); metadata.put("weight", ItemCategoryConfigurator.getWeight(descriptor)); metadata.put("name", descriptor.getDisplayName()); + metadata.put("description", ItemCategoryConfigurator.getDescription(descriptor)); Category category = categories.getItem(ic.getId()); if (category != null) { diff --git a/core/src/main/java/jenkins/model/item_category/ItemCategoryConfigurator.java b/core/src/main/java/jenkins/model/item_category/ItemCategoryConfigurator.java index 62840566e9..925aac349f 100644 --- a/core/src/main/java/jenkins/model/item_category/ItemCategoryConfigurator.java +++ b/core/src/main/java/jenkins/model/item_category/ItemCategoryConfigurator.java @@ -56,12 +56,12 @@ public abstract class ItemCategoryConfigurator implements ExtensionPoint { protected abstract Integer getWeightFor(@Nonnull TopLevelItemDescriptor descriptor); /** - * Finds the category specified by the first mapper. - * If none can be found {@link ItemCategory.Default} is returned. + * Finds the weight specified by the first configurator. + * If none can be found {@link Integer#MIN_VALUE} is returned. {@see DefaultConfigurator#getWeightFor}. * * @param descriptor the item to categorize. * - * @return the category + * @return the weight */ @Nonnull public static Integer getWeight(@Nonnull TopLevelItemDescriptor descriptor) { @@ -71,7 +71,36 @@ public abstract class ItemCategoryConfigurator implements ExtensionPoint { return weight; } } - throw new IllegalStateException("At least, must exist the category: " + ItemCategory.Default.class); + throw new IllegalStateException("At least, a default value must exist"); + } + + /** + * Provides the description for the requested item or null if this configurator doesn't have one. + * + * @param descriptor the item to categorize + * + * @return A {@link ItemCategory} or null + */ + @CheckForNull + protected abstract String getDescriptionFor(@Nonnull TopLevelItemDescriptor descriptor); + + /** + * Finds the weight specified by the first configurator. + * If none can be found a empty string is returned. {@see DefaultConfigurator#getDescriptionFor}. + * + * @param descriptor the item to categorize. + * + * @return A {@link ItemCategory} + */ + @Nonnull + public static String getDescription(@Nonnull TopLevelItemDescriptor descriptor) { + for (ItemCategoryConfigurator m : all()) { + String description = m.getDescriptionFor(descriptor); + if (description != null) { + return description; + } + } + throw new IllegalStateException("At least, a default value must exist"); } public static Collection all() { @@ -79,7 +108,7 @@ public abstract class ItemCategoryConfigurator implements ExtensionPoint { } /** - * Mapper implementation with the lowest ordinal that simply returns {@link ItemCategory.Default}. + * Default configurator with the lowest ordinal that simply returns {@link ItemCategory.Default}. */ @Extension(ordinal = Integer.MIN_VALUE) public static final class DefaultConfigurator extends ItemCategoryConfigurator { @@ -96,5 +125,11 @@ public abstract class ItemCategoryConfigurator implements ExtensionPoint { return Integer.MIN_VALUE; } + @Nonnull + @Override + public String getDescriptionFor(@Nonnull TopLevelItemDescriptor descriptor) { + return ""; + } + } }