diff --git a/core/src/main/java/hudson/Functions.java b/core/src/main/java/hudson/Functions.java index bf755d2f9e..bbc1fd3a5d 100644 --- a/core/src/main/java/hudson/Functions.java +++ b/core/src/main/java/hudson/Functions.java @@ -17,6 +17,7 @@ import hudson.model.Project; import hudson.model.Run; import hudson.model.TopLevelItem; import hudson.model.View; +import hudson.model.PageDecorator; import hudson.search.SearchableModelObject; import hudson.security.AccessControlled; import hudson.security.AuthorizationStrategy; @@ -932,5 +933,12 @@ public class Functions { return null; } + /** + * Gets all the {@link PageDecorator}s. + */ + public static List getPageDecorators() { + return (List)PageDecorator.ALL; + } + private static final Pattern SCHEME = Pattern.compile("[a-z]+://.+"); } diff --git a/core/src/main/java/hudson/model/PageDecorator.java b/core/src/main/java/hudson/model/PageDecorator.java new file mode 100644 index 0000000000..0dd02b761a --- /dev/null +++ b/core/src/main/java/hudson/model/PageDecorator.java @@ -0,0 +1,68 @@ +package hudson.model; + +import hudson.ExtensionPoint; +import hudson.Plugin; +import hudson.util.DescriptorList; + +/** + * Participates in the rendering of HTML pages for all pages of Hudson. + * + *

+ * This class provides a few hooks to augument the HTML generation process of Hudson, across + * all the HTML pages that Hudson delivers. + * + *

+ * For example, if you'd like to add a Google Analytics stat to Hudson, then you need to inject + * a small script fragment to all Hudson pages. This extension point provides a means to do that. + * + *

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()}. + * + *

Associated Views

+ *

global.jelly

+ *

+ * If this extension point needs to expose a global configuration, write this jelly page. + * See {@link Descriptor} for more about this. Optional. + * + *

footer.jelly

+ *

+ * This page is added right before the </body> tag. Convenient place for adding tracking beacons, etc. + * + *

header.jelly

+ *

+ * This page is added right before the </head> tag. Convenient place for additional stylesheet, + * <meta> tags, etc. + * + * + * @author Kohsuke Kawaguchi + * @since 1.235 + */ +public abstract class PageDecorator extends Descriptor implements ExtensionPoint, Describable { + /** + * @param yourClass + * pass-in "this.getClass()" (except that the constructor parameters cannot use 'this', + * so you'd have to hard-code the class name. + */ + protected PageDecorator(Class yourClass) { + super(yourClass); + } + + public final Descriptor getDescriptor() { + return this; + } + + /** + * Unless this object has additional web presence, display name is not used at all. + * So default to "". + */ + public String getDisplayName() { + return ""; + } + + /** + * All the registered instances. + */ + public static final DescriptorList ALL = new DescriptorList(); +} diff --git a/core/src/main/java/hudson/model/UpdateCenter.java b/core/src/main/java/hudson/model/UpdateCenter.java index 82d939b56a..8639e3eaa2 100644 --- a/core/src/main/java/hudson/model/UpdateCenter.java +++ b/core/src/main/java/hudson/model/UpdateCenter.java @@ -513,6 +513,19 @@ public class UpdateCenter implements ModelObject { } } + /** + * Adds the update center data retriever to HTML. + */ + 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/resources/hudson/model/UpdateCenter/PageDecoratorImpl/footer.jelly b/core/src/main/resources/hudson/model/UpdateCenter/PageDecoratorImpl/footer.jelly new file mode 100644 index 0000000000..7e70e444ad --- /dev/null +++ b/core/src/main/resources/hudson/model/UpdateCenter/PageDecoratorImpl/footer.jelly @@ -0,0 +1,16 @@ + + + + + + \ No newline at end of file diff --git a/core/src/main/resources/lib/layout/layout.jelly b/core/src/main/resources/lib/layout/layout.jelly index 645f63934e..04ce7f534f 100644 --- a/core/src/main/resources/lib/layout/layout.jelly +++ b/core/src/main/resources/lib/layout/layout.jelly @@ -74,6 +74,9 @@ + + + @@ -176,6 +179,9 @@ + + + \ No newline at end of file