Skip to content
Permalink
Browse files
Merge remote-tracking branch 'origin/JENKINS-31162' into JENKINS-3116…
…1-withUI
  • Loading branch information
recena committed Mar 15, 2016
2 parents c1a0649 + a39a7f8 commit 480e41a356a584262881b99acfd0e3d8d316a12d
@@ -344,15 +344,15 @@ 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("weight", ItemCategoryConfigurator.getWeight(descriptor));
metadata.put("name", descriptor.getDisplayName());
metadata.put("displayName", descriptor.getDisplayName());
metadata.put("description", ItemCategoryConfigurator.getDescription(descriptor));

Category category = categories.getItem(ic.getId());
@@ -361,8 +361,7 @@ public static Categories getCategories(Authentication a, ItemGroup c) {
} else {
List<Map<String, Serializable>> temp = new ArrayList<Map<String, Serializable>>();
temp.add(metadata);
category = new Category(ic.getId(), ic.getDisplayName(), ic.getDescription(), ic.getIconClassName(),
ic.getWeight(), ic.getMinToShow(), temp);
category = new Category(ic.getId(), ic.getDisplayName(), ic.getDescription(), ic.getWeight(), ic.getMinToShow(), temp);
categories.getItems().add(category);
}
}
@@ -22,20 +22,16 @@ public class Category implements Serializable {

private String description;

private String iconClassName;

private int weight;

private int minToShow;

private List<Map<String, Serializable>> items;

public Category(String id, String name, String description, String iconClassName, int weight, int minToShow,
List<Map<String, Serializable>> items) {
public Category(String id, String name, String description, int weight, int minToShow, List<Map<String, Serializable>> items) {
this.id= id;
this.name = name;
this.description = description;
this.iconClassName = iconClassName;
this.weight = weight;
this.minToShow = minToShow;
this.items = items;
@@ -56,11 +52,6 @@ public String getDescription() {
return description;
}

@Exported
public String getIconClassName() {
return iconClassName;
}

@Exported
public int getWeight() {
return weight;
@@ -23,13 +23,6 @@ public abstract class ItemCategory implements ModelObject, ExtensionPoint {
*/
public abstract String getId();

/**
* The icon class specification e.g. 'category-icon-folder', 'category-icon-basicprojects', etc.
*
* @return the icon class specification
*/
public abstract String getIconClassName();

/**
* The description in plain text
*
@@ -62,11 +55,6 @@ public String getId() {
return "category-id-basicprojects";
}

@Override
public String getIconClassName() {
return "category-icon-basicprojects";
}

@Override
public String getDescription() {
return Messages.ItemCategory_BasicProjects_Description();
@@ -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 480e41a

Please sign in to comment.