Skip to content
Permalink
Browse files
Merge branch 'JENKINS-31162' into JENKINS-31161-withUI
  • Loading branch information
recena committed Mar 15, 2016
2 parents 1da906f + d204d57 commit 2d0219f739030a45f7fce645b4e4e02ac7536574
Showing with 44 additions and 4 deletions.
  1. +9 −3 core/src/main/java/hudson/model/ItemGroupMixIn.java
  2. +35 −1 core/src/main/java/jenkins/model/item_category/ItemCategoryConfigurator.java
@@ -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));
@@ -366,6 +367,11 @@ public static Categories getCategories(Authentication a, ItemGroup c) {
categories.getItems().add(category);
}
}
if (Jenkins.getInstance().getAllItems().size() > 0) {
Category copy = new Category("category-id-copy", "Copy existing Item", "", "category-icon-copy",
ItemCategory.MIN_WEIGHT, ItemCategory.MIN_TOSHOW, new ArrayList<Map<String, Serializable>>());
categories.getItems().add(copy);
}
return categories;
}

@@ -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 {
@@ -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 2d0219f

Please sign in to comment.