提交 a662c065 编写于 作者: M mindless

Group available plugins by category in PluginManager, using data from wiki.


git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@24292 71c3de6d-444a-0410-be80-ed276b4c234a
上级 d69a5351
......@@ -61,6 +61,7 @@ import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;
import java.util.Vector;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
......@@ -305,6 +306,33 @@ public class UpdateCenter extends AbstractModelObject implements Saveable {
return plugins;
}
/**
* Returns a list of plugins that should be shown in the "available" tab, grouped by category.
* A plugin with multiple categories will appear multiple times in the list.
*/
public PluginEntry[] getCategorizedAvailables() {
TreeSet<PluginEntry> entries = new TreeSet<PluginEntry>();
for (Plugin p : getAvailables()) {
if (p.categories==null || p.categories.length==0)
entries.add(new PluginEntry(p, getCategoryDisplayName(null)));
else
for (String c : p.categories)
entries.add(new PluginEntry(p, getCategoryDisplayName(c)));
}
return entries.toArray(new PluginEntry[entries.size()]);
}
private static String getCategoryDisplayName(String category) {
if (category==null)
return Messages.UpdateCenter_PluginCategory_misc();
try {
return (String)Messages.class.getMethod(
"UpdateCenter_PluginCategory_" + category.replace('-', '_')).invoke(null);
} catch (Exception ex) {
return Messages.UpdateCenter_PluginCategory_unrecognized(category);
}
}
public List<Plugin> getUpdates() {
List<Plugin> plugins = new ArrayList<Plugin>();
......@@ -827,6 +855,18 @@ public class UpdateCenter extends AbstractModelObject implements Saveable {
}
}
public static final class PluginEntry implements Comparable<PluginEntry> {
public Plugin plugin;
public String category;
private PluginEntry(Plugin p, String c) { plugin = p; category = c; }
public int compareTo(PluginEntry o) {
int r = category.compareTo(o.category);
if (r==0) r = plugin.name.compareToIgnoreCase(o.plugin.name);
return r;
}
}
/**
* Adds the update center data retriever to HTML.
*/
......
......@@ -246,14 +246,14 @@ public class UpdateSite {
public List<Plugin> getAvailables() {
List<Plugin> r = new ArrayList<Plugin>();
Data data = getData();
if(data ==null) return Collections.emptyList();
if(data==null) return Collections.emptyList();
for (Plugin p : data.plugins.values()) {
if(p.getInstalled()==null)
r.add(p);
}
return r;
}
/**
* Gets the information about a specific plugin.
*
......@@ -468,6 +468,11 @@ public class UpdateSite {
* Version of Hudson core this plugin was compiled against.
*/
public final String requiredCore;
/**
* Categories for grouping plugins, taken from labels assigned to wiki page.
* Can be null.
*/
public final String[] categories;
@DataBoundConstructor
public Plugin(String sourceId, JSONObject o) {
......@@ -477,6 +482,7 @@ public class UpdateSite {
this.excerpt = get(o,"excerpt");
this.compatibleSinceVersion = get(o,"compatibleSinceVersion");
this.requiredCore = get(o,"requiredCore");
this.categories = o.has("labels") ? (String[])o.getJSONArray("labels").toArray(new String[0]) : null;
}
private String get(JSONObject o, String prop) {
......
......@@ -26,5 +26,5 @@ THE SOFTWARE.
List of available new plugins
-->
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form">
<local:table page="available" list="${app.updateCenter.availables}" xmlns:local="/hudson/PluginManager" />
</j:jelly>
\ No newline at end of file
<local:table page="available" list="${app.updateCenter.categorizedAvailables}" xmlns:local="/hudson/PluginManager" />
</j:jelly>
......@@ -33,20 +33,54 @@ THE SOFTWARE.
<l:layout title="Update Center" permission="${app.ADMINISTER}" norefresh="true">
<st:include page="sidepanel.jelly"/>
<l:main-panel>
<script type="text/javascript">// &lt;![CDATA[
function showhideCategories(hdr,on) {
var table = hdr.parentNode.parentNode.parentNode,
newDisplay = on ? '' : 'none',
nameList = new Array(), name;
for (var i = 1; i &lt; table.rows.length; i++) {
if (on || table.rows[i].cells.length == 1)
table.rows[i].style.display = newDisplay;
else {
// Hide duplicate rows for a plugin when not viewing by-category
name = table.rows[i].cells[1].getAttribute('data');
if (nameList[name] == 1) table.rows[i].style.display = 'none';
nameList[name] = 1;
}
}
}
// ]]&gt;
</script>
<form method="post" action="install">
<j:set var="isUpdates" value="${attrs.page=='updates'}" />
<local:tabBar page="${attrs.page}" xmlns:local="/hudson/PluginManager">
<tr style="border-top: 0px;">
<th width="32" tooltip="${%Check to install the plugin}">${%Install}</th>
<th initialSortDir="down">${%Name}</th>
<th>${%Version}</th>
<j:if test="${attrs.page=='updates'}"><th>${%Installed}</th></j:if>
<th initialSortDir="${isUpdates?null:'down'}" tooltip="${%Check to install the plugin}"
width="32" onclick="showhideCategories(this,1)">${%Install}</th>
<th initialSortDir="${isUpdates?'down':null}"
onclick="showhideCategories(this,0)">${%Name}</th>
<th onclick="showhideCategories(this,0)">${%Version}</th>
<j:if test="${isUpdates}"><th>${%Installed}</th></j:if>
</tr>
<j:choose>
<j:when test="${!empty(list)}">
<j:set var="lastCat" value="" />
<j:forEach var="p" items="${list}">
<j:if test="${!isUpdates}">
<j:set var="thisCat" value="${p.category}" />
<j:set var="p" value="${p.plugin}" />
<j:if test="${thisCat != lastCat}">
<tr>
<td class="pane" colspan="3">${thisCat}</td>
</tr>
</j:if>
<j:set var="lastCat" value="${thisCat}" />
</j:if>
<tr>
<td class="pane" align="center"><input type="checkbox" name="plugin.${p.name}.${p.sourceId}"/></td>
<td class="pane">
<td class="pane" align="center" data="${thisCat}_">
<input type="checkbox" name="plugin.${p.name}.${p.sourceId}"/>
</td>
<td class="pane" data="${h.xmlEscape(p.displayName)}">
<div>
<a href="${p.wiki}"><st:out value="${p.displayName}"/></a>
</div>
......@@ -61,7 +95,7 @@ THE SOFTWARE.
</j:if>
</td>
<td class="pane"><st:out value="${p.version}" /></td>
<j:if test="${attrs.page=='updates'}">
<j:if test="${isUpdates}">
<td>
<j:choose><j:when test="${p.installed.active}">
<st:out value="${p.installed.version}" />
......
......@@ -200,6 +200,26 @@ UpdateCenter.Status.ConnectionFailed=\
<span class=error>Failed to connect to {0}. \
Perhaps you need to <a href="../pluginManager/advanced">configure HTTP proxy?</a></span>
UpdateCenter.init=Initialing update center
UpdateCenter.PluginCategory.builder=Build Tools
UpdateCenter.PluginCategory.buildwrapper=Build Wrappers
UpdateCenter.PluginCategory.cli=Command Line Interface
UpdateCenter.PluginCategory.cluster=Cluster Management and Distributed Build
UpdateCenter.PluginCategory.external=External Site/Tool Integrations
UpdateCenter.PluginCategory.maven=Maven
UpdateCenter.PluginCategory.misc=Miscellaneous
UpdateCenter.PluginCategory.notifier=Build Notifiers
UpdateCenter.PluginCategory.page-decorator=Page Decorators
UpdateCenter.PluginCategory.post-build=Other Post-Build Actions
UpdateCenter.PluginCategory.report=Build Reports
UpdateCenter.PluginCategory.scm=Source Code Management
UpdateCenter.PluginCategory.scm-related=Source Code Management related
UpdateCenter.PluginCategory.slaves=Slave Launchers and Controllers
UpdateCenter.PluginCategory.trigger=Build Triggers
UpdateCenter.PluginCategory.ui=User Interface
UpdateCenter.PluginCategory.upload=Artifact Uploaders
UpdateCenter.PluginCategory.user=Authentication and User Management
UpdateCenter.PluginCategory.must-be-labeled=Uncategorized
UpdateCenter.PluginCategory.unrecognized=Misc ({0})
Permalink.LastBuild=Last build
Permalink.LastStableBuild=Last stable build
......
......@@ -87,6 +87,7 @@ function ts_getInnerText(el) {
// extract data for sorting from a cell
function extractData(x) {
if(x==null) return '';
var data = x.getAttribute("data");
if(data!=null)
return data;
......@@ -219,4 +220,4 @@ function ts_sort_default(a,b) {
if (a==b) return 0;
if (a<b) return -1;
return 1;
}
\ No newline at end of file
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册