public int main(List<String> args, Locale locale, InputStream stdin, OutputStream stdout, OutputStream stderr) { // remoting sets the context classloader to the RemoteClassLoader, // which slows down the classloading. we don't load anything from CLI, // so counter that effect. Thread.currentThread().setContextClassLoader(getClass().getClassLoader()); PrintStream out = new PrintStream(stdout); PrintStream err = new PrintStream(stderr); String subCmd = args.get(0); CLICommand cmd = CLICommand.clone(subCmd); if(cmd!=null) { cmd.channel = Channel.current(); final CLICommand old = CLICommand.setCurrent(cmd); try { transportAuth = Channel.currentOrFail().getProperty(CLICommand.TRANSPORT_AUTHENTICATION); cmd.setTransportAuth(transportAuth); return cmd.main(args.subList(1,args.size()),locale, stdin, out, err); } finally { CLICommand.setCurrent(old); } } err.println("No such command: "+subCmd); new HelpCommand().main(Collections.emptyList(), locale, stdin, out, err); return -1; }
/** * Obtains a copy of the command for invocation. */ public static CLICommand clone(String name) { for (CLICommand cmd : all()) if(name.equals(cmd.getName())) return cmd.createClone(); return null; }
this.stderr = stderr; this.locale = locale; registerOptionHandlers(); CmdLineParser p = getCmdLineParser(); sc.setAuthentication(getTransportAuthentication()); new ClassParser().parse(authenticator,p); auth = authenticator.authenticate(); if (auth==Jenkins.ANONYMOUS) auth = loadStoredAuthentication(); new Object[] {getName(), args.size(), auth.getName()}); int res = run(); LOGGER.log(Level.FINE, "Executed CLI command {0}, with {1} arguments, as user {2}, return code {3}", new Object[] {getName(), args.size(), auth.getName(), res}); return res; } catch (CmdLineException e) { LOGGER.log(Level.FINE, String.format("Failed call to CLI command %s, with %d arguments, as user %s.", getName(), args.size(), auth != null ? auth.getName() : "<unknown>"), e); stderr.println(""); stderr.println("ERROR: " + e.getMessage()); printUsage(stderr, p); return 2; } catch (IllegalStateException e) { LOGGER.log(Level.FINE, String.format("Failed call to CLI command %s, with %d arguments, as user %s.", getName(), args.size(), auth != null ? auth.getName() : "<unknown>"), e); stderr.println(""); stderr.println("ERROR: " + e.getMessage());
private int showAllCommands() { Map<String,CLICommand> commands = new TreeMap<>(); for (CLICommand c : CLICommand.all()) commands.put(c.getName(),c); for (CLICommand c : commands.values()) { stderr.println(" "+c.getName()); stderr.println(" "+c.getShortDescription()); } return 0; }
protected void printUsage(PrintStream stderr, CmdLineParser p) { stderr.print("java -jar jenkins-cli.jar " + getName()); p.printSingleLineUsage(stderr); stderr.println(); printUsageSummary(stderr); p.printUsage(stderr); }
this.locale = locale; this.channel = Channel.current(); registerOptionHandlers(); CmdLineParser p = new CmdLineParser(this); parseArguments(p, args, false); Authentication auth = authenticator.authenticate(); if (auth == Hudson.ANONYMOUS) { auth = loadStoredAuthentication(); parseArguments(p, args, true); if (!(this instanceof LoginCommand || this instanceof HelpCommand)) { Hudson.getInstance().checkPermission(Hudson.READ); return run(); } catch (CmdLineException e) { stderr.println(e.getMessage()); printUsage(stderr, p); return -1; } catch (AbortException e) {
public int main(List<String> args, Locale locale, InputStream stdin, OutputStream stdout, OutputStream stderr) { // remoting sets the context classloader to the RemoteClassLoader, // which slows down the classloading. we don't load anything from CLI, // so counter that effect. Thread.currentThread().setContextClassLoader(getClass().getClassLoader()); PrintStream out = new PrintStream(stdout); PrintStream err = new PrintStream(stderr); String subCmd = args.get(0); CLICommand cmd = CLICommand.clone(subCmd); if(cmd!=null) { 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); new HelpCommand().main(Collections.<String>emptyList(), locale, stdin, out, err); return -1; }
public boolean hasCommand(String name) { return CLICommand.clone(name)!=null; }
private int showCommandDetails() throws Exception { CLICommand command = CLICommand.clone(this.command); if (command == null) { showAllCommands(); throw new AbortException(String.format("No such command %s. Available commands are above. ", this.command)); } command.printUsage(stderr, command.getCmdLineParser()); return 0; } }
/** * Get long description as a string. */ @Restricted(NoExternalUse.class) public final String getLongDescription() { ByteArrayOutputStream out = new ByteArrayOutputStream(); PrintStream ps = new PrintStream(out); printUsageSummary(ps); ps.close(); return out.toString(); }
public Authentication authenticate() { return command.getTransportAuthentication(); } };
public int superMain(List<String> args, Locale locale, InputStream stdin, PrintStream stdout, PrintStream stderr) { return super.main(args, locale, stdin, stdout, stderr); }
public Authentication authenticate() throws AuthenticationException, IOException, InterruptedException { if (userName==null) return command.getTransportAuthentication(); // no authentication parameter. fallback to the transport if (passwordFile!=null) try { password = new FilePath(command.checkChannel(), passwordFile).readToString().trim(); } catch (IOException e) { throw new BadCredentialsException("Failed to read "+passwordFile,e); } if (password==null) password = command.checkChannel().call(new InteractivelyAskForPassword()); if (password==null) throw new BadCredentialsException("No password specified"); UserDetails d = doAuthenticate(userName, password); return new UsernamePasswordAuthenticationToken(d, password, d.getAuthorities()); } };
public Authentication superLoadStoredAuthentication() throws InterruptedException { return super.loadStoredAuthentication(); }
public void superRegisterOptionHandlers() { super.registerOptionHandlers(); }
public void superPrintUsage(PrintStream stderr, CmdLineParser p) { super.printUsage(stderr, p); }
public CLICommand superCreateClone() { return super.createClone(); }
public static ArrayList<CLICommand> getCLICommands() { ArrayList<CLICommand> all = new ArrayList<CLICommand>(CLICommand.all()); Collections.sort(all, new Comparator<CLICommand>() { public int compare(CLICommand cliCommand, CLICommand cliCommand1) { return cliCommand.getName().compareTo(cliCommand1.getName()); } }); return all; }
this.locale = locale; this.channel = Channel.current(); registerOptionHandlers(); CmdLineParser p = new CmdLineParser(this); Authentication auth = authenticator.authenticate(); if (auth==Hudson.ANONYMOUS) auth = loadStoredAuthentication(); return run(); } catch (CmdLineException e) { stderr.println(e.getMessage()); printUsage(stderr, p); return -1; } catch (AbortException e) {