Revise dispatchers and move command classes
5 files renamed
1 files added
14 files modified
| | |
| | | import com.gitblit.IStoredSettings; |
| | | import com.gitblit.Keys; |
| | | import com.gitblit.manager.IGitblit; |
| | | import com.gitblit.transport.ssh.commands.SshCommandFactory; |
| | | import com.gitblit.utils.IdGenerator; |
| | | import com.gitblit.utils.StringUtils; |
| | | |
| | |
| | | import com.gitblit.Keys; |
| | | import com.gitblit.models.UserModel; |
| | | import com.gitblit.transport.ssh.commands.DispatchCommand; |
| | | import com.gitblit.transport.ssh.commands.SshCommandFactory; |
| | | import com.gitblit.utils.StringUtils; |
| | | |
| | | /** |
| | |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | |
| | | import com.gitblit.transport.ssh.SshCommandContext; |
| | | import com.gitblit.utils.IdGenerator; |
| | | import com.gitblit.utils.WorkQueue; |
| | | import com.gitblit.utils.WorkQueue.CancelableRunnable; |
File was renamed from src/main/java/com/gitblit/transport/ssh/CommandMetaData.java |
| | |
| | | //See the License for the specific language governing permissions and |
| | | //limitations under the License. |
| | | |
| | | package com.gitblit.transport.ssh; |
| | | package com.gitblit.transport.ssh.commands; |
| | | |
| | | import static java.lang.annotation.RetentionPolicy.RUNTIME; |
| | | |
| | |
| | | import org.slf4j.LoggerFactory; |
| | | |
| | | import com.gitblit.models.UserModel; |
| | | import com.gitblit.transport.ssh.CommandMetaData; |
| | | import com.gitblit.utils.StringUtils; |
| | | import com.gitblit.utils.cli.SubcommandHandler; |
| | | import com.google.common.base.Charsets; |
| | |
| | | @Argument(index = 1, multiValued = true, metaVar = "ARG") |
| | | private List<String> args = new ArrayList<String>(); |
| | | |
| | | private Set<Class<? extends BaseCommand>> commands; |
| | | private final Set<Class<? extends BaseCommand>> commands; |
| | | private Map<String, Class<? extends BaseCommand>> map; |
| | | private Map<String, BaseCommand> dispatchers; |
| | | |
| | | public DispatchCommand() { |
| | | protected DispatchCommand() { |
| | | commands = new HashSet<Class<? extends BaseCommand>>(); |
| | | } |
| | | |
| | | public void registerDispatcher(UserModel user, Class<? extends DispatchCommand> cmd) { |
| | | protected void registerDispatcher(UserModel user, Class<? extends DispatchCommand> cmd) { |
| | | if (!cmd.isAnnotationPresent(CommandMetaData.class)) { |
| | | throw new RuntimeException(MessageFormat.format("{0} must be annotated with {1}!", cmd.getName(), |
| | | CommandMetaData.class.getName())); |
| | |
| | | } |
| | | } |
| | | |
| | | protected void registerCommands(UserModel user) { |
| | | } |
| | | protected abstract void registerCommands(UserModel user); |
| | | |
| | | |
| | | /** |
| | |
| | | * @param user |
| | | * @param cmd |
| | | */ |
| | | public void registerCommand(UserModel user, Class<? extends BaseCommand> cmd) { |
| | | protected void registerCommand(UserModel user, Class<? extends BaseCommand> cmd) { |
| | | if (!cmd.isAnnotationPresent(CommandMetaData.class)) { |
| | | throw new RuntimeException(MessageFormat.format("{0} must be annotated with {1}!", cmd.getName(), |
| | | CommandMetaData.class.getName())); |
New file |
| | |
| | | /* |
| | | * Copyright 2014 gitblit.com. |
| | | * |
| | | * 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.gitblit.transport.ssh.commands; |
| | | |
| | | 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.gitblit.GitblitDispatcher; |
| | | |
| | | /** |
| | | * The root dispatcher is the dispatch command that handles registering all |
| | | * other commands. |
| | | * |
| | | */ |
| | | public class RootDispatcher extends DispatchCommand { |
| | | |
| | | public RootDispatcher(IGitblit gitblit, SshDaemonClient client, String cmdLine) { |
| | | super(); |
| | | setContext(new SshCommandContext(gitblit, client, cmdLine)); |
| | | |
| | | final UserModel user = client.getUser(); |
| | | registerDispatcher(user, GitblitDispatcher.class); |
| | | registerDispatcher(user, GitDispatcher.class); |
| | | |
| | | // TODO register plugin dispatchers here |
| | | } |
| | | |
| | | @Override |
| | | protected final void registerCommands(UserModel user) { |
| | | } |
| | | |
| | | @Override |
| | | protected final void registerCommand(UserModel user, Class<? extends BaseCommand> cmd) { |
| | | throw new RuntimeException("The root dispatcher does not accept commands, only dispatchers!"); |
| | | } |
| | | } |
File was renamed from src/main/java/com/gitblit/transport/ssh/SshCommandContext.java |
| | |
| | | * See the License for the specific language governing permissions and |
| | | * limitations under the License. |
| | | */ |
| | | package com.gitblit.transport.ssh; |
| | | package com.gitblit.transport.ssh.commands; |
| | | |
| | | import com.gitblit.manager.IGitblit; |
| | | import com.gitblit.transport.ssh.SshDaemonClient; |
| | | |
| | | public class SshCommandContext { |
| | | |
File was renamed from src/main/java/com/gitblit/transport/ssh/SshCommandFactory.java |
| | |
| | | * See the License for the specific language governing permissions and |
| | | * limitations under the License. |
| | | */ |
| | | package com.gitblit.transport.ssh; |
| | | package com.gitblit.transport.ssh.commands; |
| | | |
| | | import java.io.IOException; |
| | | import java.io.InputStream; |
| | |
| | | import org.slf4j.LoggerFactory; |
| | | |
| | | import com.gitblit.manager.IGitblit; |
| | | import com.gitblit.models.UserModel; |
| | | import com.gitblit.transport.ssh.commands.DispatchCommand; |
| | | import com.gitblit.transport.ssh.git.GitDispatchCommand; |
| | | import com.gitblit.transport.ssh.gitblit.GitblitDispatchCommand; |
| | | import com.gitblit.transport.ssh.SshDaemonClient; |
| | | import com.gitblit.utils.IdGenerator; |
| | | import com.gitblit.utils.WorkQueue; |
| | | import com.google.common.util.concurrent.Atomics; |
| | |
| | | startExecutor = workQueue.createQueue(threads, "SshCommandStart"); |
| | | } |
| | | |
| | | /** |
| | | * Creates the root dispatcher command which builds up the available commands. |
| | | * |
| | | * @param the client |
| | | * @param the command line |
| | | * @return the root dispatcher command |
| | | */ |
| | | protected DispatchCommand createRootDispatcher(SshDaemonClient client, String cmdLine) { |
| | | final UserModel user = client.getUser(); |
| | | |
| | | DispatchCommand root = new DispatchCommand() { |
| | | }; |
| | | root.setContext(new SshCommandContext(gitblit, client, cmdLine)); |
| | | |
| | | // TODO convert these dispatchers to plugin extension points |
| | | root.registerDispatcher(user, GitblitDispatchCommand.class); |
| | | root.registerDispatcher(user, GitDispatchCommand.class); |
| | | |
| | | return root; |
| | | public RootDispatcher createRootDispatcher(SshDaemonClient client, String commandLine) { |
| | | return new RootDispatcher(gitblit, client, commandLine); |
| | | } |
| | | |
| | | @Override |
File was renamed from src/main/java/com/gitblit/transport/ssh/git/GitDispatchCommand.java |
| | |
| | | import com.gitblit.git.RepositoryResolver; |
| | | import com.gitblit.manager.IGitblit; |
| | | import com.gitblit.models.UserModel; |
| | | import com.gitblit.transport.ssh.CommandMetaData; |
| | | import com.gitblit.transport.ssh.SshCommandContext; |
| | | import com.gitblit.transport.ssh.SshDaemonClient; |
| | | import com.gitblit.transport.ssh.commands.BaseCommand; |
| | | import com.gitblit.transport.ssh.commands.CommandMetaData; |
| | | import com.gitblit.transport.ssh.commands.DispatchCommand; |
| | | import com.gitblit.transport.ssh.commands.SshCommandContext; |
| | | |
| | | @CommandMetaData(name = "git", description="Dispatcher for git receive and upload commands", hidden = true) |
| | | public class GitDispatchCommand extends DispatchCommand { |
| | | public class GitDispatcher extends DispatchCommand { |
| | | |
| | | protected RepositoryResolver<SshDaemonClient> repositoryResolver; |
| | | protected GitblitUploadPackFactory<SshDaemonClient> uploadPackFactory; |
| | |
| | | |
| | | import org.eclipse.jgit.transport.ReceivePack; |
| | | |
| | | import com.gitblit.transport.ssh.CommandMetaData; |
| | | import com.gitblit.transport.ssh.commands.CommandMetaData; |
| | | |
| | | @CommandMetaData(name = "git-receive-pack", description = "Receives pushes from a client") |
| | | public class Receive extends BaseGitCommand { |
| | |
| | | |
| | | import org.eclipse.jgit.transport.UploadPack; |
| | | |
| | | import com.gitblit.transport.ssh.CommandMetaData; |
| | | import com.gitblit.transport.ssh.commands.CommandMetaData; |
| | | |
| | | @CommandMetaData(name = "git-upload-pack", description = "Sends packs to a client for clone and fetch") |
| | | public class Upload extends BaseGitCommand { |
| | |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | |
| | | import com.gitblit.transport.ssh.CommandMetaData; |
| | | import com.gitblit.transport.ssh.commands.CommandMetaData; |
| | | |
| | | /** |
| | | * Add a key to the current user's authorized keys list. |
| | |
| | | |
| | | import org.kohsuke.args4j.Option; |
| | | |
| | | import com.gitblit.transport.ssh.CommandMetaData; |
| | | import com.gitblit.transport.ssh.commands.CommandMetaData; |
| | | import com.gitblit.transport.ssh.commands.SshCommand; |
| | | |
| | | @CommandMetaData(name = "create-repository", description = "Create new GIT repository", admin = true, hidden = true) |
File was renamed from src/main/java/com/gitblit/transport/ssh/gitblit/GitblitDispatchCommand.java |
| | |
| | | package com.gitblit.transport.ssh.gitblit; |
| | | |
| | | import com.gitblit.models.UserModel; |
| | | import com.gitblit.transport.ssh.CommandMetaData; |
| | | import com.gitblit.transport.ssh.commands.CommandMetaData; |
| | | import com.gitblit.transport.ssh.commands.DispatchCommand; |
| | | |
| | | @CommandMetaData(name = "gitblit", description = "Gitblit server commands") |
| | | public class GitblitDispatchCommand extends DispatchCommand { |
| | | public class GitblitDispatcher extends DispatchCommand { |
| | | |
| | | @Override |
| | | protected void registerCommands(UserModel user) { |
| | |
| | | import com.gitblit.models.ProjectModel; |
| | | import com.gitblit.models.RepositoryModel; |
| | | import com.gitblit.models.UserModel; |
| | | import com.gitblit.transport.ssh.CommandMetaData; |
| | | import com.gitblit.transport.ssh.commands.CommandMetaData; |
| | | import com.gitblit.transport.ssh.commands.SshCommand; |
| | | |
| | | @CommandMetaData(name = "ls", description = "List repositories or projects") |
| | |
| | | |
| | | import com.gitblit.manager.IGitblit; |
| | | import com.gitblit.models.UserModel; |
| | | import com.gitblit.transport.ssh.CommandMetaData; |
| | | import com.gitblit.transport.ssh.commands.CommandMetaData; |
| | | import com.gitblit.transport.ssh.commands.SshCommand; |
| | | |
| | | @CommandMetaData(name = "ls-users", description = "List users", admin = true) |
| | |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | |
| | | import com.gitblit.transport.ssh.CommandMetaData; |
| | | import com.gitblit.transport.ssh.commands.CommandMetaData; |
| | | |
| | | |
| | | /** |
| | |
| | | import com.gitblit.models.TicketModel.Patchset; |
| | | import com.gitblit.models.TicketModel.Score; |
| | | import com.gitblit.models.UserModel; |
| | | import com.gitblit.transport.ssh.CommandMetaData; |
| | | import com.gitblit.transport.ssh.commands.CommandMetaData; |
| | | import com.gitblit.transport.ssh.commands.SshCommand; |
| | | import com.gitblit.wicket.GitBlitWebSession; |
| | | |
| | |
| | | import org.kohsuke.args4j.Argument; |
| | | import org.kohsuke.args4j.Option; |
| | | |
| | | import com.gitblit.transport.ssh.CommandMetaData; |
| | | import com.gitblit.transport.ssh.commands.CommandMetaData; |
| | | |
| | | /** Set a user's account settings. **/ |
| | | @CommandMetaData(name = "set-account", description = "Change an account's settings", admin = true) |
| | |
| | | package com.gitblit.transport.ssh.gitblit; |
| | | |
| | | import com.gitblit.Constants; |
| | | import com.gitblit.transport.ssh.CommandMetaData; |
| | | import com.gitblit.transport.ssh.commands.CommandMetaData; |
| | | import com.gitblit.transport.ssh.commands.SshCommand; |
| | | |
| | | @CommandMetaData(name="version", description = "Display the Gitblit version") |