diff --git a/core/src/main/java/hudson/Functions.java b/core/src/main/java/hudson/Functions.java index 790fdc78b88e5f590408ff85e0027adf7d3a330e..37b5962dd80cb6530acfd874903a13e74f62c01e 100644 --- a/core/src/main/java/hudson/Functions.java +++ b/core/src/main/java/hudson/Functions.java @@ -1037,7 +1037,7 @@ public class Functions { * Gets all the {@link PageDecorator}s. */ public static List getPageDecorators() { - return (List)PageDecorator.ALL; + return PageDecorator.all(); } public static DescriptorList getCloudDescriptors() { diff --git a/core/src/main/java/hudson/model/Hudson.java b/core/src/main/java/hudson/model/Hudson.java index 548bbdd4e6d64444fada63f1b9fccd5ac6a04df4..367a6a18f280dcd4216a0ed3fc013febf01cddd8 100644 --- a/core/src/main/java/hudson/model/Hudson.java +++ b/core/src/main/java/hudson/model/Hudson.java @@ -536,7 +536,6 @@ public final class Hudson extends Node implements ItemGroup, Stapl l.onLoaded(); WindowsInstallerLink.registerIfApplicable(); - UsageStatistics.register(); LoadStatistics.register(); NodeProvisioner.launch(); } @@ -2043,7 +2042,7 @@ public final class Hudson extends Node implements ItemGroup, Stapl for( JobPropertyDescriptor d : JobPropertyDescriptor.all() ) result &= configureDescriptor(req,json,d); - for( PageDecorator d : PageDecorator.ALL ) + for( PageDecorator d : PageDecorator.all() ) result &= configureDescriptor(req,json,d); for( JSONObject o : StructuredForm.toList(json,"plugin")) diff --git a/core/src/main/java/hudson/model/PageDecorator.java b/core/src/main/java/hudson/model/PageDecorator.java index 4d7159ee049a6c362464a2c82b671729dfe70d30..fbf5581b9bab9a63e0801cce6fb3e3782c0292d5 100644 --- a/core/src/main/java/hudson/model/PageDecorator.java +++ b/core/src/main/java/hudson/model/PageDecorator.java @@ -25,9 +25,11 @@ package hudson.model; import hudson.ExtensionPoint; import hudson.Plugin; +import hudson.ExtensionListView; +import hudson.DescriptorExtensionList; +import hudson.Extension; import java.util.List; -import java.util.concurrent.CopyOnWriteArrayList; /** * Participates in the rendering of HTML pages for all pages of Hudson. @@ -42,8 +44,8 @@ import java.util.concurrent.CopyOnWriteArrayList; * *

Life-cycle

*

- * Instances of this class is singleton. {@link Plugin}s that contribute this extension point - * should instantiate a new decorator and add it to the {@link #ALL} list in {@link Plugin#start()}. + * {@link Plugin}s that contribute this extension point + * should implement a new decorator and put {@link Extension} on the class. * *

Associated Views

*

global.jelly

@@ -74,15 +76,9 @@ public abstract class PageDecorator extends Descriptor implements super(yourClass); } - /** - * Infers the type of the corresponding {@link Describable} from the outer class. - * This version works when you follow the common convention, where a descriptor - * is written as the static nested class of the describable class. - * - * @since 1.278 - */ - protected PageDecorator() { - } +// this will never work because Descriptor and Describable are the same thing. +// protected PageDecorator() { +// } public final Descriptor getDescriptor() { return this; @@ -98,6 +94,15 @@ public abstract class PageDecorator extends Descriptor implements /** * All the registered instances. + * @deprecated as of 1.286 + * Use {@link #all()} for read access, and use {@link Extension} for registration. */ - public static final List ALL = new CopyOnWriteArrayList(); + public static final List ALL = ExtensionListView.createList(PageDecorator.class); + + /** + * Returns all the registered {@link PageDecorator} descriptors. + */ + public static DescriptorExtensionList all() { + return Hudson.getInstance().getDescriptorList(PageDecorator.class); + } } diff --git a/core/src/main/java/hudson/model/UpdateCenter.java b/core/src/main/java/hudson/model/UpdateCenter.java index c875fef10b3f09f56f0531c13624945c4cc87853..e48f0e79109a5ac86d39a718fdd94283baaa6a6e 100644 --- a/core/src/main/java/hudson/model/UpdateCenter.java +++ b/core/src/main/java/hudson/model/UpdateCenter.java @@ -894,16 +894,13 @@ public class UpdateCenter extends AbstractModelObject { /** * Adds the update center data retriever to HTML. */ + @Extension public static class PageDecoratorImpl extends PageDecorator { public PageDecoratorImpl() { super(PageDecoratorImpl.class); } } - static { - PageDecorator.ALL.add(new PageDecoratorImpl()); - } - /** * Sequence number generator. */ diff --git a/core/src/main/java/hudson/model/UsageStatistics.java b/core/src/main/java/hudson/model/UsageStatistics.java index 4ee755ec0bdb7c17d59b29ba7b4b43e50abf2803..1bf16a3e0e7e56488697df9904915fac8ca6e307 100644 --- a/core/src/main/java/hudson/model/UsageStatistics.java +++ b/core/src/main/java/hudson/model/UsageStatistics.java @@ -26,6 +26,7 @@ package hudson.model; import com.trilead.ssh2.crypto.Base64; import hudson.PluginWrapper; import hudson.Util; +import hudson.Extension; import hudson.node_monitors.ArchitectureMonitor.DescriptorImpl; import static hudson.util.TimeUnit2.DAYS; import net.sf.json.JSONObject; @@ -55,6 +56,7 @@ import java.util.zip.GZIPOutputStream; /** * @author Kohsuke Kawaguchi */ +@Extension public class UsageStatistics extends PageDecorator { private final String keyImage; @@ -81,16 +83,6 @@ public class UsageStatistics extends PageDecorator { load(); } - // register the instance - static { - PageDecorator.ALL.add(new UsageStatistics()); - } - - /** - * No-op, but calling this method makes sure that the static initializer is run. - */ - static void register() {} - /** * Returns true if it's time for us to check for new version. */