提交 2c64b133 编写于 作者: K kohsuke

updated PageDecorator to support auto discovery

git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@15674 71c3de6d-444a-0410-be80-ed276b4c234a
上级 36e49dd6
...@@ -1037,7 +1037,7 @@ public class Functions { ...@@ -1037,7 +1037,7 @@ public class Functions {
* Gets all the {@link PageDecorator}s. * Gets all the {@link PageDecorator}s.
*/ */
public static List<PageDecorator> getPageDecorators() { public static List<PageDecorator> getPageDecorators() {
return (List)PageDecorator.ALL; return PageDecorator.all();
} }
public static DescriptorList<Cloud> getCloudDescriptors() { public static DescriptorList<Cloud> getCloudDescriptors() {
......
...@@ -536,7 +536,6 @@ public final class Hudson extends Node implements ItemGroup<TopLevelItem>, Stapl ...@@ -536,7 +536,6 @@ public final class Hudson extends Node implements ItemGroup<TopLevelItem>, Stapl
l.onLoaded(); l.onLoaded();
WindowsInstallerLink.registerIfApplicable(); WindowsInstallerLink.registerIfApplicable();
UsageStatistics.register();
LoadStatistics.register(); LoadStatistics.register();
NodeProvisioner.launch(); NodeProvisioner.launch();
} }
...@@ -2043,7 +2042,7 @@ public final class Hudson extends Node implements ItemGroup<TopLevelItem>, Stapl ...@@ -2043,7 +2042,7 @@ public final class Hudson extends Node implements ItemGroup<TopLevelItem>, Stapl
for( JobPropertyDescriptor d : JobPropertyDescriptor.all() ) for( JobPropertyDescriptor d : JobPropertyDescriptor.all() )
result &= configureDescriptor(req,json,d); result &= configureDescriptor(req,json,d);
for( PageDecorator d : PageDecorator.ALL ) for( PageDecorator d : PageDecorator.all() )
result &= configureDescriptor(req,json,d); result &= configureDescriptor(req,json,d);
for( JSONObject o : StructuredForm.toList(json,"plugin")) for( JSONObject o : StructuredForm.toList(json,"plugin"))
......
...@@ -25,9 +25,11 @@ package hudson.model; ...@@ -25,9 +25,11 @@ package hudson.model;
import hudson.ExtensionPoint; import hudson.ExtensionPoint;
import hudson.Plugin; import hudson.Plugin;
import hudson.ExtensionListView;
import hudson.DescriptorExtensionList;
import hudson.Extension;
import java.util.List; import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
/** /**
* Participates in the rendering of HTML pages for all pages of Hudson. * Participates in the rendering of HTML pages for all pages of Hudson.
...@@ -42,8 +44,8 @@ import java.util.concurrent.CopyOnWriteArrayList; ...@@ -42,8 +44,8 @@ import java.util.concurrent.CopyOnWriteArrayList;
* *
* <h2>Life-cycle</h2> * <h2>Life-cycle</h2>
* <p> * <p>
* Instances of this class is singleton. {@link Plugin}s that contribute this extension point * {@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()}. * should implement a new decorator and put {@link Extension} on the class.
* *
* <h2>Associated Views</h2> * <h2>Associated Views</h2>
* <h4>global.jelly</h4> * <h4>global.jelly</h4>
...@@ -74,15 +76,9 @@ public abstract class PageDecorator extends Descriptor<PageDecorator> implements ...@@ -74,15 +76,9 @@ public abstract class PageDecorator extends Descriptor<PageDecorator> implements
super(yourClass); super(yourClass);
} }
/** // this will never work because Descriptor and Describable are the same thing.
* Infers the type of the corresponding {@link Describable} from the outer class. // protected PageDecorator() {
* 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() {
}
public final Descriptor<PageDecorator> getDescriptor() { public final Descriptor<PageDecorator> getDescriptor() {
return this; return this;
...@@ -98,6 +94,15 @@ public abstract class PageDecorator extends Descriptor<PageDecorator> implements ...@@ -98,6 +94,15 @@ public abstract class PageDecorator extends Descriptor<PageDecorator> implements
/** /**
* All the registered instances. * 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<PageDecorator> ALL = new CopyOnWriteArrayList<PageDecorator>(); public static final List<PageDecorator> ALL = ExtensionListView.createList(PageDecorator.class);
/**
* Returns all the registered {@link PageDecorator} descriptors.
*/
public static DescriptorExtensionList<PageDecorator,PageDecorator> all() {
return Hudson.getInstance().getDescriptorList(PageDecorator.class);
}
} }
...@@ -894,16 +894,13 @@ public class UpdateCenter extends AbstractModelObject { ...@@ -894,16 +894,13 @@ public class UpdateCenter extends AbstractModelObject {
/** /**
* Adds the update center data retriever to HTML. * Adds the update center data retriever to HTML.
*/ */
@Extension
public static class PageDecoratorImpl extends PageDecorator { public static class PageDecoratorImpl extends PageDecorator {
public PageDecoratorImpl() { public PageDecoratorImpl() {
super(PageDecoratorImpl.class); super(PageDecoratorImpl.class);
} }
} }
static {
PageDecorator.ALL.add(new PageDecoratorImpl());
}
/** /**
* Sequence number generator. * Sequence number generator.
*/ */
......
...@@ -26,6 +26,7 @@ package hudson.model; ...@@ -26,6 +26,7 @@ package hudson.model;
import com.trilead.ssh2.crypto.Base64; import com.trilead.ssh2.crypto.Base64;
import hudson.PluginWrapper; import hudson.PluginWrapper;
import hudson.Util; import hudson.Util;
import hudson.Extension;
import hudson.node_monitors.ArchitectureMonitor.DescriptorImpl; import hudson.node_monitors.ArchitectureMonitor.DescriptorImpl;
import static hudson.util.TimeUnit2.DAYS; import static hudson.util.TimeUnit2.DAYS;
import net.sf.json.JSONObject; import net.sf.json.JSONObject;
...@@ -55,6 +56,7 @@ import java.util.zip.GZIPOutputStream; ...@@ -55,6 +56,7 @@ import java.util.zip.GZIPOutputStream;
/** /**
* @author Kohsuke Kawaguchi * @author Kohsuke Kawaguchi
*/ */
@Extension
public class UsageStatistics extends PageDecorator { public class UsageStatistics extends PageDecorator {
private final String keyImage; private final String keyImage;
...@@ -81,16 +83,6 @@ public class UsageStatistics extends PageDecorator { ...@@ -81,16 +83,6 @@ public class UsageStatistics extends PageDecorator {
load(); 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. * Returns true if it's time for us to check for new version.
*/ */
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册