Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[JENKINS-31162] New fields were added to the JSON file
  • Loading branch information
Manuel Recena committed Mar 11, 2016
1 parent 09a58b1 commit f3b92f8
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 7 deletions.
16 changes: 12 additions & 4 deletions core/src/main/java/hudson/model/ItemGroupMixIn.java
Expand Up @@ -50,6 +50,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
Expand Down Expand Up @@ -348,15 +349,22 @@ public static Categories getCategories(Authentication a, ItemGroup c) {
boolean found = false;
while (i < categories.getItems().size() && !found) {
if (categories.getItems().get(i).getId() == ic.getId()) {
categories.getItems().get(i).getItems().add(descriptor.clazz.getName());
Map<String, String> metadata = new HashMap<String, String>();
metadata.put("class", descriptor.clazz.getName());
metadata.put("iconClassName", "item-icon-" + descriptor.clazz.getName().substring(descriptor.clazz.getName().lastIndexOf(".") + 1).toLowerCase());
categories.getItems().get(i).getItems().add(metadata);
found = true;
}
i++;
}
if (!found) {
List<String> descriptors = new ArrayList<String>();
descriptors.add(descriptor.clazz.getName());
categories.getItems().add(new Category(ic.getId(), ic.getDisplayName(), ic.getDescription(), ic.getIconClassName(), descriptors));
Map<String, String> metadata = new HashMap<String, String>();
metadata.put("class", descriptor.clazz.getName());
metadata.put("iconClassName", "item-icon-" + descriptor.clazz.getName().substring(descriptor.clazz.getName().lastIndexOf(".") + 1).toLowerCase());
List<Map<String, String>> temp = new ArrayList<Map<String, String>>();
temp.add(metadata);
categories.getItems().add(new Category(ic.getId(), ic.getDisplayName(), ic.getDescription(),
ic.getIconClassName(), ic.getWeight(), temp));
}
}
return categories;
Expand Down
15 changes: 12 additions & 3 deletions core/src/main/java/jenkins/model/ItemCategory/Category.java
Expand Up @@ -6,6 +6,7 @@

import java.io.Serializable;
import java.util.List;
import java.util.Map;

/**
* Represents an {$link ItemCategory} and its {@link TopLevelItem}s.
Expand All @@ -21,13 +22,16 @@ public class Category implements Serializable {

private String iconClassName;

private List<String> items;
private int weight;

public Category(String id, String name, String description, String iconClassName, List<String> items) {
private List<Map<String, String>> items;

public Category(String id, String name, String description, String iconClassName, int weight, List<Map<String, String>> items) {
this.id= id;
this.name = name;
this.description = description;
this.iconClassName = iconClassName;
this.weight = weight;
this.items = items;
}

Expand All @@ -52,7 +56,12 @@ public String getIconClassName() {
}

@Exported
public List<String> getItems() {
public int getWeight() {
return weight;
}

@Exported
public List<Map<String, String>> getItems() {
return items;
}

Expand Down
13 changes: 13 additions & 0 deletions core/src/main/java/jenkins/model/ItemCategory/ItemCategory.java
Expand Up @@ -31,6 +31,13 @@ public abstract class ItemCategory implements ModelObject, ExtensionPoint {
*/
public abstract String getDescription();

/**
* Helpful to set the order.
*
* @return the weight
*/
public abstract int getWeight();

/**
* The default category, if an item doesn't belong anywhere else, this is where it goes by default.
*/
Expand All @@ -56,6 +63,12 @@ public String getDescription() {
public String getDisplayName() {
return Messages.ItemCategory_Default_DisplayName();
}

@Override
public int getWeight() {
return Integer.MIN_VALUE;
}

}

}

0 comments on commit f3b92f8

Please sign in to comment.