提交 80abb986 编写于 作者: S Sam Van Oort 提交者: Daniel Beck

Merge PR #1788: Make plugin manager pluggable

Squashed commit of the following:

commit f2c6ad272fe9bd3b93e21001be63694f2b8841ec
Author: Sam Van Oort <samvanoort@gmail.com>
Date:   Thu Aug 20 18:28:09 2015 -0400

    After much discussion, just remove the helper method to let a plugin manager override easily get instance of the PluginManager

commit a96f933d8dcd1bf2f02b216ccf0a6517bb649121
Author: Sam Van Oort <samvanoort@gmail.com>
Date:   Thu Aug 20 16:59:07 2015 -0400

    Add javadocs and restrict access on the PluginManagerStaplerOverride getManager method

commit 7e1facf887ab1b3219b116cac42a785c99b2a635
Author: Sam Van Oort <samvanoort@gmail.com>
Date:   Thu Aug 20 12:50:47 2015 -0400

    Simplify plugin manager test using @TestExtension

commit b9f2841f6d3453a2b9a38ec3d90247ce8020add3
Author: Sam Van Oort <samvanoort@gmail.com>
Date:   Thu Aug 20 10:32:49 2015 -0400

    Modify the Since version for pluginmanager overrides

commit 3af45ce579310f157f4cc3ee128a14a33bd4e480
Author: Sam Van Oort <samvanoort@gmail.com>
Date:   Thu Aug 20 10:28:14 2015 -0400

    Add test for PluginManagerStaplerOverride

commit 786409456590026cb2c4f56f687bae71d05990d8
Author: Sam Van Oort <samvanoort@gmail.com>
Date:   Mon Aug 17 20:59:33 2015 -0400

    Changes from review, mostly comments and rename of class

commit 1c23f086eced9fb46a7c643174a50f71bc64ec37
Author: Sam Van Oort <samvanoort@gmail.com>
Date:   Mon Aug 17 12:58:07 2015 -0400

    Cleanup for PluginManager extensibility/UI overrides

commit e105a13bcf9324c87d896ddc04ae03f905dd0f0a
Author: Sam Van Oort <samvanoort@gmail.com>
Date:   Fri Aug 14 15:23:07 2015 -0400

    Different approach to plugin manager UX pluggability, using Extension and StaplerOverridable

commit 81f21fba08a170a0f11bb88b769d6b8c69e4d1c0
Author: Sam Van Oort <samvanoort@gmail.com>
Date:   Thu Aug 13 21:32:45 2015 -0400

    Initial round of changes to allow  overriding PluginManager

    This includes renaming the setTarget method to setUIProxy and defining an interface to retain APIs
    Fields have not been mapped through yet as that is still in progress
    Also, an AbstractStaplerUIProxy has been defined to delegate Stapler bound calls to the pluginManager

commit eeef666de718ddfca04895108f5015eb13729e5e
Author: Sam Van Oort <samvanoort@gmail.com>
Date:   Wed Aug 5 17:40:50 2015 -0400

    Make plugin manager pluggable
上级 b204bd07
......@@ -71,6 +71,7 @@ import org.kohsuke.stapler.HttpRedirect;
import org.kohsuke.stapler.HttpResponse;
import org.kohsuke.stapler.HttpResponses;
import org.kohsuke.stapler.QueryParameter;
import org.kohsuke.stapler.StaplerOverridable;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse;
import org.kohsuke.stapler.export.Exported;
......@@ -128,7 +129,7 @@ import org.kohsuke.accmod.restrictions.NoExternalUse;
* @author Kohsuke Kawaguchi
*/
@ExportedBean
public abstract class PluginManager extends AbstractModelObject implements OnMaster {
public abstract class PluginManager extends AbstractModelObject implements OnMaster, StaplerOverridable {
/**
* All discovered plugins.
*/
......@@ -215,6 +216,16 @@ public abstract class PluginManager extends AbstractModelObject implements OnMas
return new Api(this);
}
/**
* Find all registered overrides (intended to allow overriding/adding views)
* @return List of extensions
* @since 1.626
*/
@Override
public Collection<PluginManagerStaplerOverride> getOverrides() {
return PluginManagerStaplerOverride.all();
}
/**
* Called immediately after the construction.
* This is a separate method so that code executed from here will see a valid value in
......
package hudson;
import jenkins.model.Jenkins;
import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
/**
* Extension point for selectively overriding parts of the {@link PluginManager} views
* Anything extending this and registered with an @Extension can replace existing views and define new views.
*
* It is also possible to add/modify API calls coming via Stapler, but this requires caution.
*
* In both cases, this is simply done by defining a resource or method that matches the existing one
*
* @author Sam Van Oort
* @since 1.626
*/
public abstract class PluginManagerStaplerOverride implements ExtensionPoint {
/**
* Return all implementations of this extension point
* @return All implementations of this extension point
*/
public static @Nonnull ExtensionList<PluginManagerStaplerOverride> all() {
return ExtensionList.lookup(PluginManagerStaplerOverride.class);
}
}
package hudson.core;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import hudson.PluginManagerStaplerOverride;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.JenkinsRule;
import org.jvnet.hudson.test.TestExtension;
import static org.junit.Assert.*;
/**
* Verify that the PluginManagerStaplerOverride extensions register and allow safely modifying PluginManager views
* @author Sam Van Oort
*/
public class PluginManagerOverrideTest {
@Rule
public JenkinsRule j = new JenkinsRule();
@Test
public void testViewOverrides() throws Exception {
// Verify extension registered correctly and comes back in overrides
assertEquals(1,PluginManagerStaplerOverride.all().size());
assertTrue(PluginManagerStaplerOverride.all().get(0) instanceof BasicPluginManagerOverride);
// Verify we can load untouched resources
JenkinsRule.WebClient client = j.createWebClient();
assertEquals(200, client.goTo("self/pluginManager/available").getWebResponse().getStatusCode());
// Verify new view loads
HtmlPage p = j.createWebClient().goTo("self/pluginManager/newview");
assertEquals("LoremIpsum", p.getElementById("dummyElement").getTextContent());
}
/** Micro-implementation simply to allow adding a view resource */
@TestExtension("testViewOverrides")
public static class BasicPluginManagerOverride extends PluginManagerStaplerOverride {
}
}
<!-- Trivial dummy view with a dummy element to demonstrate adding view -->
<?jelly escape-by-default='true'?>
<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">
<st:contentType value="text/html;charset=UTF-8" />
<div style="margin-top:1em" id="dummyElement">LoremIpsum</div>
</j:jelly>
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册