Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[JENKINS-31162] @jglick's comment was addressed. A getEffectiveClazzF…
…or() method was added to determine effective clazz of CustomOrganizationFolderDescriptor
  • Loading branch information
recena committed Mar 15, 2016
1 parent 0b0b21d commit c0bf2de
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 5 deletions.
7 changes: 4 additions & 3 deletions core/src/main/java/hudson/model/ItemGroupMixIn.java
Expand Up @@ -344,13 +344,14 @@ public synchronized TopLevelItem createProject( TopLevelItemDescriptor type, Str
*/
public static Categories getCategories(Authentication a, ItemGroup c) {
Categories categories = new Categories();
for (TopLevelItemDescriptor descriptor : Items.all(a, c)) {
for (TopLevelItemDescriptor descriptor : DescriptorVisibilityFilter.apply(c, Items.all(a, c))) {
String effectiveClazz = ItemCategoryConfigurator.getEffectiveClazz(descriptor);
ItemCategory ic = ItemCategoryConfigurator.getCategory(descriptor);
Map<String, Serializable> metadata = new HashMap<String, Serializable>();

// 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("class", effectiveClazz);
metadata.put("iconClassName", "item-icon-" + effectiveClazz.substring(descriptor.clazz.getName().lastIndexOf(".") + 1).toLowerCase());
metadata.put("weight", ItemCategoryConfigurator.getWeight(descriptor));
metadata.put("name", descriptor.getDisplayName());
metadata.put("description", ItemCategoryConfigurator.getDescription(descriptor));
Expand Down
Expand Up @@ -85,7 +85,7 @@ public static Integer getWeight(@Nonnull TopLevelItemDescriptor descriptor) {
protected abstract String getDescriptionFor(@Nonnull TopLevelItemDescriptor descriptor);

/**
* Finds the weight specified by the first configurator.
* Finds the description specified by the first configurator.
* If none can be found a empty string is returned. {@see DefaultConfigurator#getDescriptionFor}.
*
* @param descriptor the item to categorize.
Expand All @@ -103,12 +103,41 @@ public static String getDescription(@Nonnull TopLevelItemDescriptor descriptor)
throw new IllegalStateException("At least, a default value must exist for description field");
}

/**
* Provides the effective clazz for the requested item or null if this configurator doesn't have one.
*
* @param descriptor the item to categorize
*
* @return A string or null
*/
@CheckForNull
protected abstract String getEffectiveClazzFor(@Nonnull TopLevelItemDescriptor descriptor);

/**
* Finds the weight specified by the first configurator.
* If none can be found a empty string with {@code descriptor.clazz.getName();} is returned. {@see DefaultConfigurator#getEffectiveClazzFor}.
*
* @param descriptor the item to categorize.
*
* @return A {@link ItemCategory}
*/
@Nonnull
public static String getEffectiveClazz(@Nonnull TopLevelItemDescriptor descriptor) {
for (ItemCategoryConfigurator m : all()) {
String clazz = m.getEffectiveClazzFor(descriptor);
if (clazz != null) {
return clazz;
}
}
throw new IllegalStateException("At least, a default value must exist for clazz field");
}

public static Collection<ItemCategoryConfigurator> all() {
return ExtensionList.lookup(ItemCategoryConfigurator.class);
}

/**
* Default configurator with the lowest ordinal that simply returns {@link ItemCategory.BasicProjects}.
* Default configurator with the lowest ordinal that simply returns default values.
*/
@Extension(ordinal = Integer.MIN_VALUE)
public static final class DefaultConfigurator extends ItemCategoryConfigurator {
Expand All @@ -131,5 +160,10 @@ public String getDescriptionFor(@Nonnull TopLevelItemDescriptor descriptor) {
return "";
}

@Nonnull
@Override
public String getEffectiveClazzFor(@Nonnull TopLevelItemDescriptor descriptor) {
return descriptor.clazz.getName();
}
}
}

0 comments on commit c0bf2de

Please sign in to comment.