James Moger
2014-03-17 261ddf0fcf9a55fbb5b4e7c6c2cdb4c2f8c860fe
commit | author | age
9d44ad 1 /*
JM 2  * Copyright 2014 gitblit.com.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package com.gitblit.transport.ssh.git;
17
18 import com.gitblit.git.GitblitReceivePackFactory;
19 import com.gitblit.git.GitblitUploadPackFactory;
20 import com.gitblit.git.RepositoryResolver;
21 import com.gitblit.manager.IGitblit;
22 import com.gitblit.models.UserModel;
23 import com.gitblit.transport.ssh.SshDaemonClient;
24 import com.gitblit.transport.ssh.commands.BaseCommand;
261ddf 25 import com.gitblit.transport.ssh.commands.CommandMetaData;
9d44ad 26 import com.gitblit.transport.ssh.commands.DispatchCommand;
261ddf 27 import com.gitblit.transport.ssh.commands.SshCommandContext;
9d44ad 28
JM 29 @CommandMetaData(name = "git", description="Dispatcher for git receive and upload commands", hidden = true)
261ddf 30 public class GitDispatcher extends DispatchCommand {
9d44ad 31
JM 32     protected RepositoryResolver<SshDaemonClient> repositoryResolver;
33     protected GitblitUploadPackFactory<SshDaemonClient> uploadPackFactory;
34     protected GitblitReceivePackFactory<SshDaemonClient> receivePackFactory;
35
36     @Override
37     public void setContext(SshCommandContext context) {
38         super.setContext(context);
39
40         IGitblit gitblit = context.getGitblit();
41         repositoryResolver = new RepositoryResolver<SshDaemonClient>(gitblit);
42         uploadPackFactory = new GitblitUploadPackFactory<SshDaemonClient>(gitblit);
43         receivePackFactory = new GitblitReceivePackFactory<SshDaemonClient>(gitblit);
44     }
45
46     @Override
47     protected void registerCommands(UserModel user) {
48         registerCommand(user, Upload.class);
49         registerCommand(user, Receive.class);
50     }
51
52     @Override
53     protected void provideStateTo(final BaseCommand cmd) {
54         super.provideStateTo(cmd);
55
56         BaseGitCommand a = (BaseGitCommand) cmd;
57         a.setRepositoryResolver(repositoryResolver);
58         a.setUploadPackFactory(uploadPackFactory);
59         a.setReceivePackFactory(receivePackFactory);
60     }
61 }