From 831a6e8b1157fb064ab4a90068129c1840ff47ec Mon Sep 17 00:00:00 2001 From: kohsuke Date: Sat, 14 Aug 2010 07:58:33 +0000 Subject: [PATCH] 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 --- core/src/main/java/hudson/Functions.java | 20 ++++++++++++ .../main/java/hudson/model/Descriptor.java | 10 ++++-- core/src/main/java/hudson/model/Hudson.java | 30 +---------------- .../hudson/model/Hudson/configure.jelly | 32 +++++-------------- 4 files changed, 36 insertions(+), 56 deletions(-) diff --git a/core/src/main/java/hudson/Functions.java b/core/src/main/java/hudson/Functions.java index 0d804297b1..87edf95188 100644 --- a/core/src/main/java/hudson/Functions.java +++ b/core/src/main/java/hudson/Functions.java @@ -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 getSortedDescriptorsForGlobalConfig() { + Map r = new TreeMap(); + 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. diff --git a/core/src/main/java/hudson/model/Descriptor.java b/core/src/main/java/hudson/model/Descriptor.java index 02280fa93b..482522abb4 100644 --- a/core/src/main/java/hudson/model/Descriptor.java +++ b/core/src/main/java/hudson/model/Descriptor.java @@ -582,22 +582,26 @@ public abstract class Descriptor> 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); } diff --git a/core/src/main/java/hudson/model/Hudson.java b/core/src/main/java/hudson/model/Hudson.java index 5217a135de..06a28981a7 100644 --- a/core/src/main/java/hudson/model/Hudson.java +++ b/core/src/main/java/hudson/model/Hudson.java @@ -2388,35 +2388,7 @@ public final class Hudson extends Node implements ItemGroup, Stapl jdks.addAll(req.bindJSONToList(JDK.class,json.get("jdks"))); boolean result = true; - - for( Descriptor d : Builder.all() ) - result &= configureDescriptor(req,json,d); - - for( Descriptor d : Publisher.all() ) - result &= configureDescriptor(req,json,d); - - for( Descriptor 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 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")) diff --git a/core/src/main/resources/hudson/model/Hudson/configure.jelly b/core/src/main/resources/hudson/model/Hudson/configure.jelly index fc6ac9c49f..36e9c7fa25 100644 --- a/core/src/main/resources/hudson/model/Hudson/configure.jelly +++ b/core/src/main/resources/hudson/model/Hudson/configure.jelly @@ -29,7 +29,7 @@ THE SOFTWARE. - +
${%LOADING}
@@ -139,29 +139,13 @@ THE SOFTWARE. - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + -- GitLab