James Moger
2014-03-18 8f6d5356f3cb7f8e800541fe6d46911bd46c0247
Get the command context with an accessor instead of direct field access
10 files modified
50 ■■■■ changed files
src/main/java/com/gitblit/transport/ssh/commands/BaseCommand.java 18 ●●●● patch | view | raw | blame | history
src/main/java/com/gitblit/transport/ssh/commands/DispatchCommand.java 10 ●●●●● patch | view | raw | blame | history
src/main/java/com/gitblit/transport/ssh/git/BaseGitCommand.java 2 ●●● patch | view | raw | blame | history
src/main/java/com/gitblit/transport/ssh/git/Receive.java 2 ●●● patch | view | raw | blame | history
src/main/java/com/gitblit/transport/ssh/git/Upload.java 2 ●●● patch | view | raw | blame | history
src/main/java/com/gitblit/transport/ssh/gitblit/AddKeyCommand.java 2 ●●● patch | view | raw | blame | history
src/main/java/com/gitblit/transport/ssh/gitblit/BaseKeyCommand.java 2 ●●● patch | view | raw | blame | history
src/main/java/com/gitblit/transport/ssh/gitblit/LsCommand.java 8 ●●●● patch | view | raw | blame | history
src/main/java/com/gitblit/transport/ssh/gitblit/LsUsersCommand.java 2 ●●● patch | view | raw | blame | history
src/main/java/com/gitblit/transport/ssh/gitblit/RemoveKeyCommand.java 2 ●●● patch | view | raw | blame | history
src/main/java/com/gitblit/transport/ssh/commands/BaseCommand.java
@@ -48,9 +48,6 @@
    private static final Logger log = LoggerFactory.getLogger(BaseCommand.class);
    /** Ssh context */
    protected SshCommandContext ctx;
    protected InputStream in;
    protected OutputStream out;
@@ -60,6 +57,9 @@
    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 = "";
@@ -96,10 +96,22 @@
    @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;
src/main/java/com/gitblit/transport/ssh/commands/DispatchCommand.java
@@ -239,14 +239,4 @@
        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);
    }
}
src/main/java/com/gitblit/transport/ssh/git/BaseGitCommand.java
@@ -84,7 +84,7 @@
        }
        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);
        }
src/main/java/com/gitblit/transport/ssh/git/Receive.java
@@ -24,7 +24,7 @@
    @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);
src/main/java/com/gitblit/transport/ssh/git/Upload.java
@@ -24,7 +24,7 @@
    @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);
src/main/java/com/gitblit/transport/ssh/gitblit/AddKeyCommand.java
@@ -41,7 +41,7 @@
    @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);
src/main/java/com/gitblit/transport/ssh/gitblit/BaseKeyCommand.java
@@ -53,6 +53,6 @@
    }
    protected IPublicKeyManager getKeyManager() {
        return ctx.getGitblit().getPublicKeyManager();
        return getContext().getGitblit().getPublicKeyManager();
    }
}
src/main/java/com/gitblit/transport/ssh/gitblit/LsCommand.java
@@ -49,8 +49,8 @@
    }
    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);
@@ -85,8 +85,8 @@
    }
    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);
src/main/java/com/gitblit/transport/ssh/gitblit/LsUsersCommand.java
@@ -35,7 +35,7 @@
    @Override
    public void run() {
        IGitblit gitblit = ctx.getGitblit();
        IGitblit gitblit = getContext().getGitblit();
        List<UserModel> users = gitblit.getAllUsers();
        int displaynameLen = 0;
        int usernameLen = 0;
src/main/java/com/gitblit/transport/ssh/gitblit/RemoveKeyCommand.java
@@ -44,7 +44,7 @@
    @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);