Installing SSH plugins from <review_site>/plugins
Plugins whose moduleClass is a subclass of PluginCommandModule will be installed. Others will be skipped for now. Change-Id: Ib90a6b990a6d3c931c58fddaca35d6452175aac5
This commit is contained in:
parent
cf5cd23d07
commit
9051534d1d
@ -50,6 +50,7 @@ import com.google.gerrit.server.schema.SchemaVersionCheck;
|
||||
import com.google.gerrit.server.ssh.NoSshModule;
|
||||
import com.google.gerrit.sshd.SshModule;
|
||||
import com.google.gerrit.sshd.commands.MasterCommandModule;
|
||||
import com.google.gerrit.sshd.commands.MasterPluginsModule;
|
||||
import com.google.gerrit.sshd.commands.SlaveCommandModule;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.Module;
|
||||
@ -242,6 +243,7 @@ public class Daemon extends SiteProgram {
|
||||
modules.add(new SlaveCommandModule());
|
||||
} else {
|
||||
modules.add(new MasterCommandModule());
|
||||
modules.add(cfgInjector.getInstance(MasterPluginsModule.class));
|
||||
}
|
||||
} else {
|
||||
modules.add(new NoSshModule());
|
||||
|
@ -0,0 +1,57 @@
|
||||
// Copyright (C) 2012 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package com.google.gerrit.sshd.commands;
|
||||
|
||||
import com.google.gerrit.common.Plugin;
|
||||
import com.google.gerrit.common.PluginLoader;
|
||||
import com.google.gerrit.sshd.CommandModule;
|
||||
import com.google.inject.Inject;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
public class MasterPluginsModule extends CommandModule {
|
||||
private static final Logger log =
|
||||
LoggerFactory.getLogger(MasterPluginsModule.class);
|
||||
|
||||
private PluginLoader pluginLoader;
|
||||
|
||||
@Inject
|
||||
MasterPluginsModule(PluginLoader loader) {
|
||||
pluginLoader = loader;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
Collection<Plugin> plugins = pluginLoader.getPlugins();
|
||||
for (Plugin p : plugins) {
|
||||
if (PluginCommandModule.class.isAssignableFrom(p.moduleClass)) {
|
||||
@SuppressWarnings("unchecked")
|
||||
Class<PluginCommandModule> c = (Class<PluginCommandModule>) p.moduleClass;
|
||||
try {
|
||||
PluginCommandModule module = c.newInstance();
|
||||
module.initSshModule(p.name);
|
||||
install(module);
|
||||
} catch (InstantiationException e) {
|
||||
log.warn("Initialization of plugin module '" + p.name + "' failed");
|
||||
} catch (IllegalAccessException e) {
|
||||
log.warn("Initialization of plugin module '" + p.name + "' failed");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -43,6 +43,7 @@ import com.google.gerrit.server.schema.SchemaModule;
|
||||
import com.google.gerrit.server.schema.SchemaVersionCheck;
|
||||
import com.google.gerrit.sshd.SshModule;
|
||||
import com.google.gerrit.sshd.commands.MasterCommandModule;
|
||||
import com.google.gerrit.sshd.commands.MasterPluginsModule;
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.CreationException;
|
||||
import com.google.inject.Guice;
|
||||
@ -211,6 +212,7 @@ public class WebAppInitializer extends GuiceServletContextListener {
|
||||
final List<Module> modules = new ArrayList<Module>();
|
||||
modules.add(new SshModule());
|
||||
modules.add(new MasterCommandModule());
|
||||
modules.add(cfgInjector.getInstance(MasterPluginsModule.class));
|
||||
return sysInjector.createChildInjector(modules);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user