private static final Logger log = LoggerFactory.getLogger(BaseCommand.class);
- /** Ssh context */
- protected SshCommandContext ctx;
-
protected InputStream in;
protected OutputStream out;
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 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
public void setInputStream(final InputStream in) {
this.in = in;
usage.append("\n");
return usage.toString();
}
-
- protected void provideStateTo(final BaseCommand cmd) {
- if (cmd instanceof BaseCommand) {
- cmd.setContext(ctx);
- }
- cmd.setInputStream(in);
- cmd.setOutputStream(out);
- cmd.setErrorStream(err);
- cmd.setExitCallback(exit);
- }
}
}
repository = repository.substring(1);
try {
- return repositoryResolver.open(ctx.getClient(), repository);
+ return repositoryResolver.open(getContext().getClient(), repository);
} catch (Exception e) {
throw new Failure(1, "fatal: '" + repository + "': not a git archive", e);
}
@Override
protected void runImpl() throws Failure {
try {
- ReceivePack rp = receivePackFactory.create(ctx.getClient(), repo);
+ ReceivePack rp = receivePackFactory.create(getContext().getClient(), repo);
rp.receive(in, out, null);
} catch (Exception e) {
throw new Failure(1, "fatal: Cannot receive pack: ", e);
@Override
protected void runImpl() throws Failure {
try {
- UploadPack up = uploadPackFactory.create(ctx.getClient(), repo);
+ UploadPack up = uploadPackFactory.create(getContext().getClient(), repo);
up.upload(in, out, null);
} catch (Exception e) {
throw new Failure(1, "fatal: Cannot upload pack: ", e);
@Override
public void run() throws IOException, UnloggedFailure {
- String username = ctx.getClient().getUsername();
+ String username = getContext().getClient().getUsername();
List<String> keys = readKeys(addKeys);
for (String key : keys) {
getKeyManager().addKey(username, key);
}
protected IPublicKeyManager getKeyManager() {
- return ctx.getGitblit().getPublicKeyManager();
+ return getContext().getGitblit().getPublicKeyManager();
}
}
}
protected void listProjects() {
- IGitblit gitblit = ctx.getGitblit();
- UserModel user = ctx.getClient().getUser();
+ IGitblit gitblit = getContext().getGitblit();
+ UserModel user = getContext().getClient().getUser();
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
List<ProjectModel> projects = gitblit.getProjectModels(user, false);
}
protected void listRepositories() {
- IGitblit gitblit = ctx.getGitblit();
- UserModel user = ctx.getClient().getUser();
+ IGitblit gitblit = getContext().getGitblit();
+ UserModel user = getContext().getClient().getUser();
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
List<RepositoryModel> repositories = gitblit.getRepositoryModels(user);
@Override
public void run() {
- IGitblit gitblit = ctx.getGitblit();
+ IGitblit gitblit = getContext().getGitblit();
List<UserModel> users = gitblit.getAllUsers();
int displaynameLen = 0;
int usernameLen = 0;
@Override
public void run() throws IOException, UnloggedFailure {
- String username = ctx.getClient().getUsername();
+ String username = getContext().getClient().getUsername();
List<String> keys = readKeys(removeKeys);
if (keys.contains(ALL)) {
getKeyManager().removeAllKeys(username);