* Setup this dispatcher. Commands and nested dispatchers are normally
* registered within this method.
*
- * @param user
* @since 1.5.0
*/
- protected abstract void setup(UserModel user);
+ protected abstract void setup();
/**
* Register a command or a dispatcher by it's class.
*
- * @param user
* @param clazz
*/
@SuppressWarnings("unchecked")
- protected final void register(UserModel user, Class<? extends BaseCommand> clazz) {
+ protected final void register(Class<? extends BaseCommand> clazz) {
if (DispatchCommand.class.isAssignableFrom(clazz)) {
- registerDispatcher(user, (Class<? extends DispatchCommand>) clazz);
+ registerDispatcher((Class<? extends DispatchCommand>) clazz);
return;
}
- registerCommand(user, clazz);
+ registerCommand(clazz);
}
/**
* Register a command or a dispatcher instance.
*
- * @param user
* @param cmd
*/
- protected final void register(UserModel user, BaseCommand cmd) {
+ protected final void register(BaseCommand cmd) {
if (cmd instanceof DispatchCommand) {
- registerDispatcher(user, (DispatchCommand) cmd);
+ registerDispatcher((DispatchCommand) cmd);
return;
}
- registerCommand(user, cmd);
+ registerCommand(cmd);
}
- private void registerDispatcher(UserModel user, Class<? extends DispatchCommand> clazz) {
+ private void registerDispatcher(Class<? extends DispatchCommand> clazz) {
try {
DispatchCommand dispatcher = clazz.newInstance();
- registerDispatcher(user, dispatcher);
+ registerDispatcher(dispatcher);
} catch (Exception e) {
log.error("failed to instantiate {}", clazz.getName());
}
}
- private void registerDispatcher(UserModel user, DispatchCommand dispatcher) {
+ private void registerDispatcher(DispatchCommand dispatcher) {
Class<? extends DispatchCommand> dispatcherClass = dispatcher.getClass();
if (!dispatcherClass.isAnnotationPresent(CommandMetaData.class)) {
throw new RuntimeException(MessageFormat.format("{0} must be annotated with {1}!", dispatcher.getName(),
CommandMetaData.class.getName()));
}
+ UserModel user = getContext().getClient().getUser();
CommandMetaData meta = dispatcherClass.getAnnotation(CommandMetaData.class);
if (meta.admin() && !user.canAdmin()) {
log.debug(MessageFormat.format("excluding admin dispatcher {0} for {1}",
}
try {
- dispatcher.setup(user);
+ dispatcher.setContext(getContext());
+ dispatcher.setup();
if (dispatcher.commands.isEmpty() && dispatcher.dispatchers.isEmpty()) {
log.debug(MessageFormat.format("excluding empty dispatcher {0} for {1}",
meta.name(), user.username));
/**
* Registers a command as long as the user is permitted to execute it.
*
- * @param user
* @param clazz
*/
- private void registerCommand(UserModel user, Class<? extends BaseCommand> clazz) {
+ private void registerCommand(Class<? extends BaseCommand> clazz) {
if (!clazz.isAnnotationPresent(CommandMetaData.class)) {
throw new RuntimeException(MessageFormat.format("{0} must be annotated with {1}!", clazz.getName(),
CommandMetaData.class.getName()));
}
+
+ UserModel user = getContext().getClient().getUser();
CommandMetaData meta = clazz.getAnnotation(CommandMetaData.class);
if (meta.admin() && !user.canAdmin()) {
log.debug(MessageFormat.format("excluding admin command {0} for {1}", meta.name(), user.username));
/**
* Registers a command as long as the user is permitted to execute it.
*
- * @param user
* @param cmd
*/
- private void registerCommand(UserModel user, BaseCommand cmd) {
+ private void registerCommand(BaseCommand cmd) {
if (!cmd.getClass().isAnnotationPresent(CommandMetaData.class)) {
throw new RuntimeException(MessageFormat.format("{0} must be annotated with {1}!", cmd.getName(),
CommandMetaData.class.getName()));
}
+
+ UserModel user = getContext().getClient().getUser();
CommandMetaData meta = cmd.getClass().getAnnotation(CommandMetaData.class);
if (meta.admin() && !user.canAdmin()) {
log.debug(MessageFormat.format("excluding admin command {0} for {1}", meta.name(), user.username));
import com.gitblit.models.PluginRegistry.InstallState;
import com.gitblit.models.PluginRegistry.PluginRegistration;
import com.gitblit.models.PluginRegistry.PluginRelease;
-import com.gitblit.models.UserModel;
import com.gitblit.utils.FlipTable;
import com.gitblit.utils.FlipTable.Borders;
import com.gitblit.utils.StringUtils;
public class PluginDispatcher extends DispatchCommand {
@Override
- protected void setup(UserModel user) {
- register(user, ListPlugins.class);
- register(user, StartPlugin.class);
- register(user, StopPlugin.class);
- register(user, EnablePlugin.class);
- register(user, DisablePlugin.class);
- register(user, ShowPlugin.class);
- register(user, RefreshPlugins.class);
- register(user, AvailablePlugins.class);
- register(user, InstallPlugin.class);
- register(user, UpgradePlugin.class);
- register(user, UninstallPlugin.class);
+ protected void setup() {
+ register(ListPlugins.class);
+ register(StartPlugin.class);
+ register(StopPlugin.class);
+ register(EnablePlugin.class);
+ register(DisablePlugin.class);
+ register(ShowPlugin.class);
+ register(RefreshPlugins.class);
+ register(AvailablePlugins.class);
+ register(InstallPlugin.class);
+ register(UpgradePlugin.class);
+ register(UninstallPlugin.class);
}
@CommandMetaData(name = "list", aliases = { "ls" }, description = "List plugins")
import ro.fortsoft.pf4j.PluginWrapper;
import com.gitblit.manager.IGitblit;
-import com.gitblit.models.UserModel;
import com.gitblit.transport.ssh.SshDaemonClient;
import com.gitblit.transport.ssh.git.GitDispatcher;
import com.gitblit.transport.ssh.keys.KeysDispatcher;
super();
setContext(new SshCommandContext(gitblit, client, cmdLine));
- UserModel user = client.getUser();
- register(user, VersionCommand.class);
- register(user, GitDispatcher.class);
- register(user, KeysDispatcher.class);
- register(user, PluginDispatcher.class);
+ register(VersionCommand.class);
+ register(GitDispatcher.class);
+ register(KeysDispatcher.class);
+ register(PluginDispatcher.class);
List<DispatchCommand> exts = gitblit.getExtensions(DispatchCommand.class);
for (DispatchCommand ext : exts) {
String plugin = wrapper.getDescriptor().getPluginId();
CommandMetaData meta = extClass.getAnnotation(CommandMetaData.class);
log.debug("Dispatcher {} is loaded from plugin {}", meta.name(), plugin);
- register(user, ext);
+ register(ext);
}
}
@Override
- protected final void setup(UserModel user) {
+ protected final void setup() {
}
}
\ No newline at end of file
import com.gitblit.git.GitblitUploadPackFactory;
import com.gitblit.git.RepositoryResolver;
import com.gitblit.manager.IGitblit;
-import com.gitblit.models.UserModel;
import com.gitblit.transport.ssh.SshDaemonClient;
import com.gitblit.transport.ssh.commands.BaseCommand;
import com.gitblit.transport.ssh.commands.CommandMetaData;
}
@Override
- protected void setup(UserModel user) {
- register(user, Upload.class);
- register(user, Receive.class);
- register(user, GarbageCollectionCommand.class);
+ protected void setup() {
+ register(Upload.class);
+ register(Receive.class);
+ register(GarbageCollectionCommand.class);
}
@Override
import org.slf4j.LoggerFactory;
import com.gitblit.Constants.AccessPermission;
-import com.gitblit.models.UserModel;
import com.gitblit.transport.ssh.IPublicKeyManager;
import com.gitblit.transport.ssh.SshKey;
import com.gitblit.transport.ssh.commands.CommandMetaData;
public class KeysDispatcher extends DispatchCommand {
@Override
- protected void setup(UserModel user) {
- register(user, AddKey.class);
- register(user, RemoveKey.class);
- register(user, ListKeys.class);
- register(user, WhichKey.class);
- register(user, CommentKey.class);
- register(user, PermissionKey.class);
+ protected void setup() {
+ register(AddKey.class);
+ register(RemoveKey.class);
+ register(ListKeys.class);
+ register(WhichKey.class);
+ register(CommentKey.class);
+ register(PermissionKey.class);
}
@CommandMetaData(name = "add", description = "Add an SSH public key to your account")
public class MyDispatcher extends DispatchCommand {
@Override
- protected void setup(UserModel user) {
+ protected void setup() {
// commands in this dispatcher
- register(user, CommandA.class);
- register(user, CommandB.class);
+ register(CommandA.class);
+ register(CommandB.class);
// nested dispatchers
- register(user, SubDispatcher1.class);
- register(user, SubDispatcher2.class);
+ register(SubDispatcher1.class);
+ register(SubDispatcher2.class);
}
@CommandMetaData(name = "commanda", aliases = { "ca" }, description = "description of command a")