Manually bind plugin guice modules in gerrit Guice universe
Short circuit the plugin loading phase from the unit tests by passing
the module names from the manifest file.
This allows us to avoid building and deploying the plugin JAR from
within build tool chain.
To use the simplified plugin bootstrap tests, plugin test class must
be inherited from the LightweightPluginDaemonTest class and must be
annotated with @TestPlugin annotation:
@TestPlugin(
name = "cookbook",
sysModule = "com.googlesource.gerrit.plugins.cookbook.Module",
httpModule = "com.googlesource.gerrit.plugins.cookbook.HttpModule",
sshModule = "com.googlesource.gerrit.plugins.cookbook.SshModule"
)
public class CookbookIT extends LightweightPluginDaemonTest {
@Test
public void revisionTest() throws Exception {
createChange();
RestResponse response =
adminRestSession.post("/changes/1/revisions/1/cookbook~hello-revision");
assertThat(response.getEntityContent())
.contains("Hello admin from change 1, patch set 1!");
}
}
Inspired-By: Dave Borowitz <dborowitz@google.com>
Change-Id: I689bb71413ecfbbf99f72730b0d2617bf526d9dd
This commit is contained in:
committed by
David Ostrovsky
parent
9c6306532b
commit
8df8af2572
@@ -42,9 +42,9 @@ public class ServerPlugin extends Plugin {
|
||||
private final Path dataDir;
|
||||
private final String pluginCanonicalWebUrl;
|
||||
private final ClassLoader classLoader;
|
||||
private Class<? extends Module> sysModule;
|
||||
private Class<? extends Module> sshModule;
|
||||
private Class<? extends Module> httpModule;
|
||||
protected Class<? extends Module> sysModule;
|
||||
protected Class<? extends Module> sshModule;
|
||||
protected Class<? extends Module> httpModule;
|
||||
|
||||
private Injector sysInjector;
|
||||
private Injector sshInjector;
|
||||
@@ -61,13 +61,17 @@ public class ServerPlugin extends Plugin {
|
||||
Path dataDir,
|
||||
ClassLoader classLoader) throws InvalidPluginException {
|
||||
super(name, srcJar, pluginUser, snapshot,
|
||||
Plugin.getApiType(getPluginManifest(scanner)));
|
||||
scanner == null
|
||||
? ApiType.PLUGIN
|
||||
: Plugin.getApiType(getPluginManifest(scanner)));
|
||||
this.pluginCanonicalWebUrl = pluginCanonicalWebUrl;
|
||||
this.scanner = scanner;
|
||||
this.dataDir = dataDir;
|
||||
this.classLoader = classLoader;
|
||||
this.manifest = getPluginManifest(scanner);
|
||||
loadGuiceModules(manifest, classLoader);
|
||||
this.manifest = scanner == null ? null : getPluginManifest(scanner);
|
||||
if (manifest != null) {
|
||||
loadGuiceModules(manifest, classLoader);
|
||||
}
|
||||
}
|
||||
|
||||
private void loadGuiceModules(Manifest manifest, ClassLoader classLoader) throws InvalidPluginException {
|
||||
@@ -92,7 +96,7 @@ public class ServerPlugin extends Plugin {
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static Class<? extends Module> load(String name, ClassLoader pluginLoader)
|
||||
protected static Class<? extends Module> load(String name, ClassLoader pluginLoader)
|
||||
throws ClassNotFoundException {
|
||||
if (Strings.isNullOrEmpty(name)) {
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user