commit | author | age
|
7613df
|
1 |
// Copyright (C) 2012 The Android Open Source Project |
DO |
2 |
// |
|
3 |
// Licensed under the Apache License, Version 2.0 (the "License"); |
|
4 |
// you may not use this file except in compliance with the License. |
|
5 |
// You may obtain a copy of the License at |
|
6 |
// |
|
7 |
// http://www.apache.org/licenses/LICENSE-2.0 |
|
8 |
// |
|
9 |
// Unless required by applicable law or agreed to in writing, software |
|
10 |
// distributed under the License is distributed on an "AS IS" BASIS, |
|
11 |
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
12 |
// See the License for the specific language governing permissions and |
|
13 |
// limitations under the License. |
|
14 |
|
|
15 |
package com.gitblit.transport.ssh.commands; |
|
16 |
|
|
17 |
import java.io.IOException; |
|
18 |
import java.io.PrintWriter; |
|
19 |
|
|
20 |
import org.apache.sshd.server.Environment; |
617909
|
21 |
import org.slf4j.Logger; |
JM |
22 |
import org.slf4j.LoggerFactory; |
7613df
|
23 |
|
991857
|
24 |
public abstract class SshCommand extends BaseCommand { |
617909
|
25 |
|
JM |
26 |
protected Logger log = LoggerFactory.getLogger(getClass()); |
503a85
|
27 |
protected PrintWriter stdout; |
JM |
28 |
protected PrintWriter stderr; |
7613df
|
29 |
|
503a85
|
30 |
@Override |
JM |
31 |
public void start(Environment env) throws IOException { |
|
32 |
startThread(new CommandRunnable() { |
|
33 |
@Override |
|
34 |
public void run() throws Exception { |
|
35 |
parseCommandLine(); |
|
36 |
stdout = toPrintWriter(out); |
|
37 |
stderr = toPrintWriter(err); |
|
38 |
try { |
|
39 |
SshCommand.this.run(); |
|
40 |
} finally { |
|
41 |
stdout.flush(); |
|
42 |
stderr.flush(); |
|
43 |
} |
|
44 |
} |
|
45 |
}); |
|
46 |
} |
7613df
|
47 |
|
503a85
|
48 |
protected abstract void run() throws UnloggedFailure, Failure, Exception; |
7613df
|
49 |
} |