| | |
| | | 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; |
| | |
| | | |
| | | private static final Logger log = LoggerFactory.getLogger(BaseCommand.class); |
| | | |
| | | /** Ssh context */ |
| | | protected SshCommandContext ctx; |
| | | private static final int PRIVATE_STATUS = 1 << 30; |
| | | |
| | | public final static int STATUS_CANCEL = PRIVATE_STATUS | 1; |
| | | |
| | | public final static int STATUS_NOT_FOUND = PRIVATE_STATUS | 2; |
| | | |
| | | public final static int STATUS_NOT_ADMIN = PRIVATE_STATUS | 3; |
| | | |
| | | protected InputStream in; |
| | | |
| | |
| | | protected ExitCallback exit; |
| | | |
| | | protected ServerSession session; |
| | | |
| | | /** Ssh command context */ |
| | | private SshCommandContext ctx; |
| | | |
| | | /** Text of the command line which lead up to invoking this instance. */ |
| | | private String commandName = ""; |
| | |
| | | |
| | | @Override |
| | | public void destroy() { |
| | | log.debug("destroying " + getClass().getName()); |
| | | session = null; |
| | | ctx = null; |
| | | } |
| | | |
| | | protected static PrintWriter toPrintWriter(final OutputStream o) { |
| | |
| | | @Override |
| | | public abstract void start(Environment env) throws IOException; |
| | | |
| | | protected void provideStateTo(final BaseCommand cmd) { |
| | | cmd.setContext(ctx); |
| | | cmd.setInputStream(in); |
| | | cmd.setOutputStream(out); |
| | | cmd.setErrorStream(err); |
| | | cmd.setExitCallback(exit); |
| | | } |
| | | |
| | | public void setContext(SshCommandContext ctx) { |
| | | this.ctx = ctx; |
| | | } |
| | | |
| | | public SshCommandContext getContext() { |
| | | return ctx; |
| | | } |
| | | |
| | | @Override |
| | |
| | | @Override |
| | | public void setExitCallback(final ExitCallback callback) { |
| | | this.exit = callback; |
| | | } |
| | | |
| | | protected void provideBaseStateTo(final Command cmd) { |
| | | if (cmd instanceof BaseCommand) { |
| | | ((BaseCommand) cmd).setContext(ctx); |
| | | } |
| | | cmd.setInputStream(in); |
| | | cmd.setOutputStream(out); |
| | | cmd.setErrorStream(err); |
| | | cmd.setExitCallback(exit); |
| | | } |
| | | |
| | | protected String getName() { |
| | |
| | | return new CmdLineParser(options); |
| | | } |
| | | |
| | | protected String usage() { |
| | | public String usage() { |
| | | return ""; |
| | | } |
| | | |