提交 45721b0e 编写于 作者: K kohsuke

Remember the current CLICommand that's being executed.

git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@32817 71c3de6d-444a-0410-be80-ed276b4c234a
上级 24408ed6
......@@ -334,4 +334,19 @@ public abstract class CLICommand implements ExtensionPoint, Cloneable {
* which captures the identity of the client given by the transport layer.
*/
public static final ChannelProperty<Authentication> TRANSPORT_AUTHENTICATION = new ChannelProperty<Authentication>(Authentication.class,"transportAuthentication");
private static final ThreadLocal<CLICommand> CURRENT_COMMAND = new ThreadLocal<CLICommand>();
/*package*/ static CLICommand setCurrent(CLICommand cmd) {
CLICommand old = getCurrent();
CURRENT_COMMAND.set(cmd);
return old;
}
/**
* If the calling thread is in the middle of executing a CLI command, return it. Otherwise null.
*/
public static CLICommand getCurrent() {
return CURRENT_COMMAND.get();
}
}
......@@ -63,8 +63,12 @@ public class CliManagerImpl implements CliEntryPoint, Serializable {
String subCmd = args.get(0);
CLICommand cmd = CLICommand.clone(subCmd);
if(cmd!=null) {
// execute the command, do so with the originator of the request as the principal
return cmd.main(args.subList(1,args.size()),locale, stdin, out, err);
final CLICommand old = CLICommand.setCurrent(cmd);
try {
return cmd.main(args.subList(1,args.size()),locale, stdin, out, err);
} finally {
CLICommand.setCurrent(old);
}
}
err.println("No such command: "+subCmd);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册