提交 831a6e8b 编写于 作者: K kohsuke

allow all Descriptors with global.jelly to participate in the global configuration UI.

git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@33837 71c3de6d-444a-0410-be80-ed276b4c234a
上级 1cc19f0e
......@@ -28,6 +28,7 @@ import hudson.console.ConsoleAnnotationDescriptor;
import hudson.console.ConsoleAnnotatorFactory;
import hudson.model.AbstractProject;
import hudson.model.Action;
import hudson.model.Describable;
import hudson.model.Descriptor;
import hudson.model.Hudson;
import hudson.model.Item;
......@@ -680,6 +681,25 @@ public class Functions {
return result;
}
/**
* Gets all the descriptors sorted by their inheritance tree of {@link Describable}
* so that descriptors of similar types come nearby.
*/
public static Collection<Descriptor> getSortedDescriptorsForGlobalConfig() {
Map<String,Descriptor> r = new TreeMap<String, Descriptor>();
for (Descriptor<?> d : Hudson.getInstance().getExtensionList(Descriptor.class)) {
if (d.getGlobalConfigPage()==null) continue;
r.put(buildSuperclassHierarchy(d.clazz, new StringBuilder()).toString(),d);
}
return r.values();
}
private static StringBuilder buildSuperclassHierarchy(Class c, StringBuilder buf) {
Class sc = c.getSuperclass();
if (sc!=null) buildSuperclassHierarchy(sc,buf).append(':');
return buf.append(c.getName());
}
/**
* Computes the path to the icon of the given action
* from the context path.
......
......@@ -582,22 +582,26 @@ public abstract class Descriptor<T extends Describable<T>> implements Saveable {
}
public String getGlobalConfigPage() {
return getViewPage(clazz, "global.jelly");
return getViewPage(clazz, "global.jelly",null);
}
protected final String getViewPage(Class<?> clazz, String pageName) {
private String getViewPage(Class<?> clazz, String pageName, String defaultValue) {
while(clazz!=Object.class) {
String name = clazz.getName().replace('.', '/').replace('$', '/') + "/" + pageName;
if(clazz.getClassLoader().getResource(name)!=null)
return '/'+name;
clazz = clazz.getSuperclass();
}
return defaultValue;
}
protected final String getViewPage(Class<?> clazz, String pageName) {
// We didn't find the configuration page.
// Either this is non-fatal, in which case it doesn't matter what string we return so long as
// it doesn't exist.
// Or this error is fatal, in which case we want the developer to see what page he's missing.
// so we put the page name.
return pageName;
return getViewPage(clazz,pageName,pageName);
}
......
......@@ -2388,35 +2388,7 @@ public final class Hudson extends Node implements ItemGroup<TopLevelItem>, Stapl
jdks.addAll(req.bindJSONToList(JDK.class,json.get("jdks")));
boolean result = true;
for( Descriptor<Builder> d : Builder.all() )
result &= configureDescriptor(req,json,d);
for( Descriptor<Publisher> d : Publisher.all() )
result &= configureDescriptor(req,json,d);
for( Descriptor<BuildWrapper> d : BuildWrapper.all() )
result &= configureDescriptor(req,json,d);
for( SCMDescriptor scmd : SCM.all() )
result &= configureDescriptor(req,json,scmd);
for( TriggerDescriptor d : Trigger.all() )
result &= configureDescriptor(req,json,d);
for( JobPropertyDescriptor d : JobPropertyDescriptor.all() )
result &= configureDescriptor(req,json,d);
for( PageDecorator d : PageDecorator.all() )
result &= configureDescriptor(req,json,d);
for( Descriptor<CrumbIssuer> d : CrumbIssuer.all() )
result &= configureDescriptor(req,json, d);
for( ToolDescriptor d : ToolInstallation.all() )
result &= configureDescriptor(req,json,d);
for( TopLevelItemDescriptor d : TopLevelItemDescriptor.all() )
for( Descriptor<?> d : Functions.getSortedDescriptorsForGlobalConfig() )
result &= configureDescriptor(req,json,d);
for( JSONObject o : StructuredForm.toList(json,"plugin"))
......
......@@ -29,7 +29,7 @@ THE SOFTWARE.
<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">
<l:layout norefresh="true" permission="${it.ADMINISTER}">
<st:include page="sidepanel.jelly" />
<l:main-panel xmlns:local="local">
<l:main-panel>
<div class="behavior-loading">${%LOADING}</div>
<f:form method="post" name="config" action="configSubmit">
<j:set var="instance" value="${it}" />
......@@ -139,29 +139,13 @@ THE SOFTWARE.
</j:if>
</j:forEach>
<d:taglib uri="local">
<!-- display global config pages for the given descriptors -->
<d:tag name="globalConfig">
<j:invokeStatic var="descriptors" className="${className}" method="all" />
<j:forEach var="idx" begin="0" end="${size(descriptors)-1}">
<j:set var="descriptor" value="${descriptors[idx]}" />
<j:set var="instance" value="${descriptor}" /><!-- this makes the <f:textbox field=.../> work -->
<f:rowSet name="${descriptor.jsonSafeClassName}">
<st:include page="${descriptor.globalConfigPage}" from="${descriptor}" optional="true"/>
</f:rowSet>
</j:forEach>
</d:tag>
</d:taglib>
<local:globalConfig className="hudson.tools.ToolInstallation" />
<local:globalConfig className="hudson.triggers.Trigger" />
<local:globalConfig className="hudson.tasks.BuildWrapper" />
<local:globalConfig className="hudson.tasks.Builder" />
<local:globalConfig className="hudson.scm.SCM" />
<local:globalConfig className="hudson.tasks.Publisher" />
<local:globalConfig className="hudson.model.JobPropertyDescriptor" />
<local:globalConfig className="hudson.model.PageDecorator" />
<local:globalConfig className="hudson.model.TopLevelItemDescriptor" />
<!-- global configuration from everyone -->
<j:forEach var="descriptor" items="${h.getSortedDescriptorsForGlobalConfig()}">
<j:set var="instance" value="${descriptor}" /><!-- this makes the <f:textbox field=.../> work -->
<f:rowSet name="${descriptor.jsonSafeClassName}">
<st:include page="${descriptor.globalConfigPage}" from="${descriptor}" />
</f:rowSet>
</j:forEach>
<j:if test="${!empty(h.getCloudDescriptors())}">
<f:section title="${%Cloud}">
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册