aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenrik Lynggaard Hansen2012-07-10 15:02:45 (EDT)
committerHenrik Lynggaard Hansen2012-07-10 15:02:45 (EDT)
commit9534db34f1a0e3a33b27f3f96827b1bc12f68348 (patch)
tree4e7171d4a04d21b3376fb91951dd3bfbab8d03fc
parent6b2a021db07f935226235132973fb64223c07d91 (diff)
downloadorg.eclipse.hudson.core-9534db34f1a0e3a33b27f3f96827b1bc12f68348.zip
org.eclipse.hudson.core-9534db34f1a0e3a33b27f3f96827b1bc12f68348.tar.gz
org.eclipse.hudson.core-9534db34f1a0e3a33b27f3f96827b1bc12f68348.tar.bz2
Reformatting of hudson.cli packagerefs/changes/94/6694/1
As per our meeting, we could reformat on per package so here is hudson.cli Change-Id: I081f3493fa6dab93c28d277c3913e178b29caa97 Signed-off-by: Henrik Lynggaard Hansen <henrik@hlyh.dk>
-rw-r--r--hudson-core/src/main/java/hudson/cli/AbstractBuildRangeCommand.java14
-rw-r--r--hudson-core/src/main/java/hudson/cli/BuildCommand.java51
-rw-r--r--hudson-core/src/main/java/hudson/cli/CLICommand.java224
-rw-r--r--hudson-core/src/main/java/hudson/cli/CliManagerImpl.java25
-rw-r--r--hudson-core/src/main/java/hudson/cli/ClientAuthenticationCache.java30
-rw-r--r--hudson-core/src/main/java/hudson/cli/CloneableCLICommand.java9
-rw-r--r--hudson-core/src/main/java/hudson/cli/CommandDuringBuild.java46
-rw-r--r--hudson-core/src/main/java/hudson/cli/CopyJobCommand.java28
-rw-r--r--hudson-core/src/main/java/hudson/cli/CreateJobCommand.java20
-rw-r--r--hudson-core/src/main/java/hudson/cli/DeleteBuildsCommand.java16
-rw-r--r--hudson-core/src/main/java/hudson/cli/HelpCommand.java20
-rw-r--r--hudson-core/src/main/java/hudson/cli/InstallPluginCommand.java48
-rw-r--r--hudson-core/src/main/java/hudson/cli/InstallToolCommand.java52
-rw-r--r--hudson-core/src/main/java/hudson/cli/ListChangesCommand.java72
-rw-r--r--hudson-core/src/main/java/hudson/cli/LoginCommand.java17
-rw-r--r--hudson-core/src/main/java/hudson/cli/LogoutCommand.java3
-rw-r--r--hudson-core/src/main/java/hudson/cli/MailCommand.java11
-rw-r--r--hudson-core/src/main/java/hudson/cli/SetBuildDescriptionCommand.java30
-rw-r--r--hudson-core/src/main/java/hudson/cli/SetBuildResultCommand.java14
-rw-r--r--hudson-core/src/main/java/hudson/cli/UpdateJobCommand.java17
-rw-r--r--hudson-core/src/main/java/hudson/cli/VersionCommand.java7
-rw-r--r--hudson-core/src/main/java/hudson/cli/package-info.java6
22 files changed, 393 insertions, 367 deletions
diff --git a/hudson-core/src/main/java/hudson/cli/AbstractBuildRangeCommand.java b/hudson-core/src/main/java/hudson/cli/AbstractBuildRangeCommand.java
index 1fc015a..5352e17 100644
--- a/hudson-core/src/main/java/hudson/cli/AbstractBuildRangeCommand.java
+++ b/hudson-core/src/main/java/hudson/cli/AbstractBuildRangeCommand.java
@@ -8,7 +8,7 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- *
+ *
*
*******************************************************************************/
@@ -28,17 +28,17 @@ import java.util.List;
* @author Kohsuke Kawaguchi
*/
public abstract class AbstractBuildRangeCommand extends CLICommand {
- @Argument(metaVar="JOB",usage="Name of the job to build",required=true,index=0)
- public AbstractProject<?,?> job;
- @Argument(metaVar="RANGE",usage="Range of the build records to delete. 'N-M', 'N,M', or 'N'",required=true,index=1)
+ @Argument(metaVar = "JOB", usage = "Name of the job to build", required = true, index = 0)
+ public AbstractProject<?, ?> job;
+ @Argument(metaVar = "RANGE", usage = "Range of the build records to delete. 'N-M', 'N,M', or 'N'", required = true, index = 1)
public String range;
protected int run() throws Exception {
- RangeSet rs = RangeSet.fromString(range,false);
+ RangeSet rs = RangeSet.fromString(range, false);
- return act((List)job.getBuilds(rs));
+ return act((List) job.getBuilds(rs));
}
- protected abstract int act(List<AbstractBuild<?,?>> builds) throws IOException;
+ protected abstract int act(List<AbstractBuild<?, ?>> builds) throws IOException;
}
diff --git a/hudson-core/src/main/java/hudson/cli/BuildCommand.java b/hudson-core/src/main/java/hudson/cli/BuildCommand.java
index e9fcdd6..1e75f6e 100644
--- a/hudson-core/src/main/java/hudson/cli/BuildCommand.java
+++ b/hudson-core/src/main/java/hudson/cli/BuildCommand.java
@@ -7,10 +7,10 @@
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
- * Contributors:
+ * Contributors:
+ *
+ *
*
- *
- *
*
*******************************************************************************/
@@ -45,19 +45,17 @@ import java.io.PrintStream;
*/
@Extension
public class BuildCommand extends CLICommand {
+
@Override
public String getShortDescription() {
return "Builds a job, and optionally waits until its completion.";
}
-
- @Argument(metaVar="JOB",usage="Name of the job to build",required=true)
- public AbstractProject<?,?> job;
-
- @Option(name="-s",usage="Wait until the completion/abortion of the command")
+ @Argument(metaVar = "JOB", usage = "Name of the job to build", required = true)
+ public AbstractProject<?, ?> job;
+ @Option(name = "-s", usage = "Wait until the completion/abortion of the command")
public boolean sync = false;
-
- @Option(name="-p",usage="Specify the build parameters in the key=value format.")
- public Map<String,String> parameters = new HashMap<String, String>();
+ @Option(name = "-p", usage = "Specify the build parameters in the key=value format.")
+ public Map<String, String> parameters = new HashMap<String, String>();
protected int run() throws Exception {
job.checkPermission(Item.BUILD);
@@ -65,18 +63,20 @@ public class BuildCommand extends CLICommand {
ParametersAction a = null;
if (!parameters.isEmpty()) {
ParametersDefinitionProperty pdp = job.getProperty(ParametersDefinitionProperty.class);
- if (pdp==null)
- throw new AbortException(job.getFullDisplayName()+" is not parameterized but the -p option was specified");
+ if (pdp == null) {
+ throw new AbortException(job.getFullDisplayName() + " is not parameterized but the -p option was specified");
+ }
- List<ParameterValue> values = new ArrayList<ParameterValue>();
+ List<ParameterValue> values = new ArrayList<ParameterValue>();
for (Entry<String, String> e : parameters.entrySet()) {
String name = e.getKey();
ParameterDefinition pd = pdp.getParameterDefinition(name);
- if (pd==null)
+ if (pd == null) {
throw new AbortException(String.format("\'%s\' is not a valid parameter. Did you mean %s?",
name, EditDistance.findNearest(name, pdp.getParameterDefinitionNames())));
- values.add(pd.createValue(this,e.getValue()));
+ }
+ values.add(pd.createValue(this, e.getValue()));
}
for (ParameterDefinition pd : pdp.getParameterDefinitions()) {
if (parameters.get(pd.getName()) == null) {
@@ -87,26 +87,28 @@ public class BuildCommand extends CLICommand {
}
Future<? extends AbstractBuild> f = job.scheduleBuild2(0, new CLICause(), a);
- if (!sync) return 0;
+ if (!sync) {
+ return 0;
+ }
AbstractBuild b = f.get(); // wait for the completion
- stdout.println("Completed "+b.getFullDisplayName()+" : "+b.getResult());
+ stdout.println("Completed " + b.getFullDisplayName() + " : " + b.getResult());
return b.getResult().ordinal;
}
@Override
protected void printUsageSummary(PrintStream stderr) {
stderr.println(
- "Starts a build, and optionally waits for a completion.\n" +
- "Aside from general scripting use, this command can be\n" +
- "used to invoke another job from within a build of one job.\n" +
- "With the -s option, this command changes the exit code based on\n" +
- "the outcome of the build (exit code 0 indicates a success.)\n"
- );
+ "Starts a build, and optionally waits for a completion.\n"
+ + "Aside from general scripting use, this command can be\n"
+ + "used to invoke another job from within a build of one job.\n"
+ + "With the -s option, this command changes the exit code based on\n"
+ + "the outcome of the build (exit code 0 indicates a success.)\n");
}
// TODO: CLI can authenticate as different users, so should record which user here..
public static class CLICause extends Cause {
+
public String getShortDescription() {
return "Started by command line";
}
@@ -122,4 +124,3 @@ public class BuildCommand extends CLICommand {
}
}
}
-
diff --git a/hudson-core/src/main/java/hudson/cli/CLICommand.java b/hudson-core/src/main/java/hudson/cli/CLICommand.java
index da51e3d..028b405 100644
--- a/hudson-core/src/main/java/hudson/cli/CLICommand.java
+++ b/hudson-core/src/main/java/hudson/cli/CLICommand.java
@@ -7,10 +7,10 @@
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
- * Contributors:
+ * Contributors:
*
* Kohsuke Kawaguchi, Winston Prakash
- *
+ *
*******************************************************************************/
package hudson.cli;
@@ -51,36 +51,34 @@ import org.eclipse.hudson.security.HudsonSecurityEntitiesHolder;
/**
* Base class for Hudson CLI.
*
- * <h2>How does a CLI command work</h2>
- * <p>
- * The users starts {@linkplain CLI the "CLI agent"} on a remote system, by specifying arguments, like
- * <tt>"java -jar hudson-cli.jar command arg1 arg2 arg3"</tt>. The CLI agent creates
- * a remoting channel with the server, and it sends the entire arguments to the server, along with
- * the remoted stdin/out/err.
+ * <h2>How does a CLI command work</h2> <p> The users starts
+ * {@linkplain CLI the "CLI agent"} on a remote system, by specifying arguments,
+ * like <tt>"java -jar hudson-cli.jar command arg1 arg2 arg3"</tt>. The CLI
+ * agent creates a remoting channel with the server, and it sends the entire
+ * arguments to the server, along with the remoted stdin/out/err.
*
- * <p>
- * The Hudson master then picks the right {@link CLICommand} to execute, clone it, and
- * calls {@link #main(List, Locale, InputStream, PrintStream, PrintStream)} method.
+ * <p> The Hudson master then picks the right {@link CLICommand} to execute,
+ * clone it, and calls
+ * {@link #main(List, Locale, InputStream, PrintStream, PrintStream)} method.
*
- * <h2>Note for CLI command implementor</h2>
- * Start with <a href="http://wiki.hudson-ci.org/display/HUDSON/Writing+CLI+commands">this document</a>
- * to get the general idea of CLI.
+ * <h2>Note for CLI command implementor</h2> Start with <a
+ * href="http://wiki.hudson-ci.org/display/HUDSON/Writing+CLI+commands">this
+ * document</a> to get the general idea of CLI.
*
- * <ul>
- * <li>
- * Put {@link Extension} on your implementation to have it discovered by Hudson.
+ * <ul> <li> Put {@link Extension} on your implementation to have it discovered
+ * by Hudson.
*
- * <li>
- * Use <a href="http://java.net/projects/args4j/">args4j</a> annotation on your implementation to define
- * options and arguments (however, if you don't like that, you could override
- * the {@link #main(List, Locale, InputStream, PrintStream, PrintStream)} method directly.
+ * <li> Use <a href="http://java.net/projects/args4j/">args4j</a> annotation on
+ * your implementation to define options and arguments (however, if you don't
+ * like that, you could override the
+ * {@link #main(List, Locale, InputStream, PrintStream, PrintStream)} method
+ * directly.
*
- * <li>
- * stdin, stdout, stderr are remoted, so proper buffering is necessary for good user experience.
+ * <li> stdin, stdout, stderr are remoted, so proper buffering is necessary for
+ * good user experience.
*
- * <li>
- * Send {@link Callable} to a CLI agent by using {@link #channel} to get local interaction,
- * such as uploading a file, asking for a password, etc.
+ * <li> Send {@link Callable} to a CLI agent by using {@link #channel} to get
+ * local interaction, such as uploading a file, asking for a password, etc.
*
* </ul>
*
@@ -90,63 +88,58 @@ import org.eclipse.hudson.security.HudsonSecurityEntitiesHolder;
*/
@LegacyInstancesAreScopedToHudson
public abstract class CLICommand implements ExtensionPoint, Cloneable {
+
/**
- * Connected to stdout and stderr of the CLI agent that initiated the session.
- * IOW, if you write to these streams, the person who launched the CLI command
- * will see the messages in his terminal.
+ * Connected to stdout and stderr of the CLI agent that initiated the
+ * session. IOW, if you write to these streams, the person who launched the
+ * CLI command will see the messages in his terminal.
*
- * <p>
- * (In contrast, calling {@code System.out.println(...)} would print out
+ * <p> (In contrast, calling {@code System.out.println(...)} would print out
* the message to the server log file, which is probably not what you want.
*/
- public transient PrintStream stdout,stderr;
-
+ public transient PrintStream stdout, stderr;
/**
* Connected to stdin of the CLI agent.
*
- * <p>
- * This input stream is buffered to hide the latency in the remoting.
+ * <p> This input stream is buffered to hide the latency in the remoting.
*/
public transient InputStream stdin;
-
/**
- * {@link Channel} that represents the CLI JVM. You can use this to
- * execute {@link Callable} on the CLI JVM, among other things.
+ * {@link Channel} that represents the CLI JVM. You can use this to execute
+ * {@link Callable} on the CLI JVM, among other things.
*/
public transient Channel channel;
-
/**
- * The locale of the client. Messages should be formatted with this resource.
+ * The locale of the client. Messages should be formatted with this
+ * resource.
*/
public transient Locale locale;
-
/**
* Gets the command name.
*
- * <p>
- * For example, if the CLI is invoked as <tt>java -jar cli.jar foo arg1 arg2 arg4</tt>,
- * on the server side {@link CLICommand} that returns "foo" from {@link #getName()}
- * will be invoked.
+ * <p> For example, if the CLI is invoked as <tt>java -jar cli.jar foo arg1
+ * arg2 arg4</tt>, on the server side {@link CLICommand} that returns "foo"
+ * from {@link #getName()} will be invoked.
*
- * <p>
- * By default, this method creates "foo-bar-zot" from "FooBarZotCommand".
+ * <p> By default, this method creates "foo-bar-zot" from
+ * "FooBarZotCommand".
*/
public String getName() {
String name = getClass().getName();
- name = name.substring(name.lastIndexOf('.')+1); // short name
- name = name.substring(name.lastIndexOf('$')+1);
- if(name.endsWith("Command"))
- name = name.substring(0,name.length()-7); // trim off the command
-
+ name = name.substring(name.lastIndexOf('.') + 1); // short name
+ name = name.substring(name.lastIndexOf('$') + 1);
+ if (name.endsWith("Command")) {
+ name = name.substring(0, name.length() - 7); // trim off the command
+ }
// convert "FooBarZot" into "foo-bar-zot"
// Locale is fixed so that "CreateInstance" always become "create-instance" no matter where this is run.
- return name.replaceAll("([a-z0-9])([A-Z])","$1-$2").toLowerCase(Locale.ENGLISH);
+ return name.replaceAll("([a-z0-9])([A-Z])", "$1-$2").toLowerCase(Locale.ENGLISH);
}
/**
- * Gets the quick summary of what this command does.
- * Used by the help command to generate the list of commands.
+ * Gets the quick summary of what this command does. Used by the help
+ * command to generate the list of commands.
*/
public abstract String getShortDescription();
@@ -164,16 +157,18 @@ public abstract class CLICommand implements ExtensionPoint, Cloneable {
Authentication old = sc.getAuthentication();
CliAuthenticator authenticator = HudsonSecurityEntitiesHolder.getHudsonSecurityManager().getSecurityRealm().createCliAuthenticator(this);
- new ClassParser().parse(authenticator,p);
+ new ClassParser().parse(authenticator, p);
try {
p.parseArgument(args.toArray(new String[args.size()]));
Authentication auth = authenticator.authenticate();
- if (auth==Hudson.ANONYMOUS)
+ if (auth == Hudson.ANONYMOUS) {
auth = loadStoredAuthentication();
+ }
sc.setAuthentication(auth); // run the CLI with the right credential
- if (!(this instanceof LoginCommand || this instanceof HelpCommand))
+ if (!(this instanceof LoginCommand || this instanceof HelpCommand)) {
Hudson.getInstance().checkPermission(Hudson.READ);
+ }
return run();
} catch (CmdLineException e) {
stderr.println(e.getMessage());
@@ -192,7 +187,8 @@ public abstract class CLICommand implements ExtensionPoint, Cloneable {
}
/**
- * Loads the persisted authentication information from {@link ClientAuthenticationCache}.
+ * Loads the persisted authentication information from
+ * {@link ClientAuthenticationCache}.
*/
protected Authentication loadStoredAuthentication() throws InterruptedException {
try {
@@ -205,84 +201,88 @@ public abstract class CLICommand implements ExtensionPoint, Cloneable {
}
/**
- * Determines if the user authentication is attempted through CLI before running this command.
+ * Determines if the user authentication is attempted through CLI before
+ * running this command.
*
- * <p>
- * If your command doesn't require any authentication whatsoever, and if you don't even want to let the user
- * authenticate, then override this method to always return false &mdash; doing so will result in all the commands
- * running as anonymous user credential.
+ * <p> If your command doesn't require any authentication whatsoever, and if
+ * you don't even want to let the user authenticate, then override this
+ * method to always return false &mdash; doing so will result in all the
+ * commands running as anonymous user credential.
*
- * <p>
- * Note that even if this method returns true, the user can still skip aut
+ * <p> Note that even if this method returns true, the user can still skip
+ * aut
*
- * @param auth
- * Always non-null.
- * If the underlying transport had already performed authentication, this object is something other than
- * {@link Hudson#ANONYMOUS}.
+ * @param auth Always non-null. If the underlying transport had already
+ * performed authentication, this object is something other than
+ * {@link Hudson#ANONYMOUS}.
*/
protected boolean shouldPerformAuthentication(Authentication auth) {
- return auth==Hudson.ANONYMOUS;
+ return auth == Hudson.ANONYMOUS;
}
/**
- * Returns the identity of the client as determined at the CLI transport level.
+ * Returns the identity of the client as determined at the CLI transport
+ * level.
*
- * <p>
- * When the CLI connection to the server is tunneled over HTTP, that HTTP connection
- * can authenticate the client, just like any other HTTP connections to the server
- * can authenticate the client. This method returns that information, if one is available.
- * By generalizing it, this method returns the identity obtained at the transport-level authentication.
+ * <p> When the CLI connection to the server is tunneled over HTTP, that
+ * HTTP connection can authenticate the client, just like any other HTTP
+ * connections to the server can authenticate the client. This method
+ * returns that information, if one is available. By generalizing it, this
+ * method returns the identity obtained at the transport-level
+ * authentication.
*
- * <p>
- * For example, imagine if the current {@link SecurityRealm} is doing Kerberos authentication,
- * then this method can return a valid identity of the client.
+ * <p> For example, imagine if the current {@link SecurityRealm} is doing
+ * Kerberos authentication, then this method can return a valid identity of
+ * the client.
*
- * <p>
- * If the transport doesn't do authentication, this method returns {@link Hudson#ANONYMOUS}.
+ * <p> If the transport doesn't do authentication, this method returns
+ * {@link Hudson#ANONYMOUS}.
*/
public Authentication getTransportAuthentication() {
Authentication a = channel.getProperty(TRANSPORT_AUTHENTICATION);
- if (a==null) a = Hudson.ANONYMOUS;
+ if (a == null) {
+ a = Hudson.ANONYMOUS;
+ }
return a;
}
/**
* Executes the command, and return the exit code.
*
- * @return
- * 0 to indicate a success, otherwise an error code.
- * @throws AbortException
- * If the processing should be aborted. Hudson will report the error message
- * without stack trace, and then exits this command.
- * @throws Exception
- * All the other exceptions cause the stack trace to be dumped, and then
- * the command exits with an error code.
+ * @return 0 to indicate a success, otherwise an error code.
+ * @throws AbortException If the processing should be aborted. Hudson will
+ * report the error message without stack trace, and then exits this
+ * command.
+ * @throws Exception All the other exceptions cause the stack trace to be
+ * dumped, and then the command exits with an error code.
*/
protected abstract int run() throws Exception;
protected void printUsage(PrintStream stderr, CmdLineParser p) {
- stderr.println("java -jar hudson-cli.jar "+getName()+" args...");
+ stderr.println("java -jar hudson-cli.jar " + getName() + " args...");
printUsageSummary(stderr);
p.printUsage(stderr);
}
/**
- * Called while producing usage. This is a good method to override
- * to render the general description of the command that goes beyond
- * a single-line summary.
+ * Called while producing usage. This is a good method to override to render
+ * the general description of the command that goes beyond a single-line
+ * summary.
*/
protected void printUsageSummary(PrintStream stderr) {
stderr.println(getShortDescription());
}
/**
- * Convenience method for subtypes to obtain the system property of the client.
+ * Convenience method for subtypes to obtain the system property of the
+ * client.
*/
protected String getClientSystemProperty(String name) throws IOException, InterruptedException {
return channel.call(new GetSystemProperty(name));
}
private static final class GetSystemProperty implements Callable<String, IOException> {
+
private final String name;
private GetSystemProperty(String name) {
@@ -292,18 +292,19 @@ public abstract class CLICommand implements ExtensionPoint, Cloneable {
public String call() throws IOException {
return System.getProperty(name);
}
-
private static final long serialVersionUID = 1L;
}
/**
- * Convenience method for subtypes to obtain environment variables of the client.
+ * Convenience method for subtypes to obtain environment variables of the
+ * client.
*/
protected String getClientEnvironmentVariable(String name) throws IOException, InterruptedException {
return channel.call(new GetEnvironmentVariable(name));
}
private static final class GetEnvironmentVariable implements Callable<String, IOException> {
+
private final String name;
private GetEnvironmentVariable(String name) {
@@ -313,7 +314,6 @@ public abstract class CLICommand implements ExtensionPoint, Cloneable {
public String call() throws IOException {
return System.getenv(name);
}
-
private static final long serialVersionUID = 1L;
}
@@ -331,13 +331,14 @@ public abstract class CLICommand implements ExtensionPoint, Cloneable {
}
/**
- * Auto-discovers {@link OptionHandler}s and add them to the given command line parser.
+ * Auto-discovers {@link OptionHandler}s and add them to the given command
+ * line parser.
*/
protected void registerOptionHandlers() {
try {
- for (Class c : Index.list(OptionHandlerExtension.class,Hudson.getInstance().pluginManager.uberClassLoader,Class.class)) {
+ for (Class c : Index.list(OptionHandlerExtension.class, Hudson.getInstance().pluginManager.uberClassLoader, Class.class)) {
Type t = Types.getBaseClass(c, OptionHandler.class);
- CmdLineParser.registerHandler(Types.erasure(Types.getTypeArgument(t,0)), c);
+ CmdLineParser.registerHandler(Types.erasure(Types.getTypeArgument(t, 0)), c);
}
} catch (IOException e) {
throw new Error(e);
@@ -355,20 +356,20 @@ public abstract class CLICommand implements ExtensionPoint, Cloneable {
* Obtains a copy of the command for invocation.
*/
public static CLICommand clone(String name) {
- for (CLICommand cmd : all())
- if(name.equals(cmd.getName()))
+ for (CLICommand cmd : all()) {
+ if (name.equals(cmd.getName())) {
return cmd.createClone();
+ }
+ }
return null;
}
-
private static final Logger LOGGER = Logger.getLogger(CLICommand.class.getName());
-
/**
- * Key for {@link Channel#getProperty(Object)} that links to the {@link Authentication} object
- * which captures the identity of the client given by the transport layer.
+ * Key for {@link Channel#getProperty(Object)} that links to the
+ * {@link Authentication} object 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");
-
+ 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) {
@@ -378,7 +379,8 @@ public abstract class CLICommand implements ExtensionPoint, Cloneable {
}
/**
- * If the calling thread is in the middle of executing a CLI command, return it. Otherwise null.
+ * 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();
diff --git a/hudson-core/src/main/java/hudson/cli/CliManagerImpl.java b/hudson-core/src/main/java/hudson/cli/CliManagerImpl.java
index 88ee1bc..e886a16 100644
--- a/hudson-core/src/main/java/hudson/cli/CliManagerImpl.java
+++ b/hudson-core/src/main/java/hudson/cli/CliManagerImpl.java
@@ -7,10 +7,10 @@
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
- * Contributors:
+ * Contributors:
+ *
+ *
*
- *
- *
*
*******************************************************************************/
@@ -41,6 +41,7 @@ import java.io.Serializable;
* @author Kohsuke Kawaguchi
*/
public class CliManagerImpl implements CliEntryPoint, Serializable {
+
public CliManagerImpl() {
}
@@ -55,22 +56,22 @@ public class CliManagerImpl implements CliEntryPoint, Serializable {
String subCmd = args.get(0);
CLICommand cmd = CLICommand.clone(subCmd);
- if(cmd!=null) {
+ if (cmd != null) {
final CLICommand old = CLICommand.setCurrent(cmd);
try {
- return cmd.main(args.subList(1,args.size()),locale, stdin, out, err);
+ return cmd.main(args.subList(1, args.size()), locale, stdin, out, err);
} finally {
CLICommand.setCurrent(old);
}
}
- err.println("No such command: "+subCmd);
+ 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;
+ return CLICommand.clone(name) != null;
}
public int protocolVersion() {
@@ -78,7 +79,7 @@ public class CliManagerImpl implements CliEntryPoint, Serializable {
}
private Object writeReplace() {
- return Channel.current().export(CliEntryPoint.class,this);
+ return Channel.current().export(CliEntryPoint.class, this);
}
static {
@@ -87,14 +88,14 @@ public class CliManagerImpl implements CliEntryPoint, Serializable {
cls.put(Hudson.getInstance().getPluginManager().uberClassLoader);
ResourceNameIterator servicesIter =
- new DiscoverServiceNames(cls).findResourceNames(OptionHandler.class.getName());
+ new DiscoverServiceNames(cls).findResourceNames(OptionHandler.class.getName());
final ResourceClassIterator itr =
- new DiscoverClasses(cls).findResourceClasses(servicesIter);
+ new DiscoverClasses(cls).findResourceClasses(servicesIter);
- while(itr.hasNext()) {
+ while (itr.hasNext()) {
Class h = itr.nextResourceClass().loadClass();
Class c = Types.erasure(Types.getTypeArgument(Types.getBaseClass(h, OptionHandler.class), 0));
- CmdLineParser.registerHandler(c,h);
+ CmdLineParser.registerHandler(c, h);
}
}
}
diff --git a/hudson-core/src/main/java/hudson/cli/ClientAuthenticationCache.java b/hudson-core/src/main/java/hudson/cli/ClientAuthenticationCache.java
index d1fb11e..1ed54f0 100644
--- a/hudson-core/src/main/java/hudson/cli/ClientAuthenticationCache.java
+++ b/hudson-core/src/main/java/hudson/cli/ClientAuthenticationCache.java
@@ -7,10 +7,10 @@
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
- * Contributors:
+ * Contributors:
*
* Kohsuke Kawaguchi, Winston Prakash
- *
+ *
*
*******************************************************************************/
@@ -43,26 +43,25 @@ import org.eclipse.hudson.security.HudsonSecurityEntitiesHolder;
/**
* Represents the authentication credential store of the CLI client.
*
- * <p>
- * This object encapsulates a remote manipulation of the credential store.
+ * <p> This object encapsulates a remote manipulation of the credential store.
* We store encrypted user names.
*
* @author Kohsuke Kawaguchi
* @since 1.351
*/
public class ClientAuthenticationCache implements Serializable {
+
/**
* Where the store should be placed.
*/
private final FilePath store;
-
/**
* Loaded contents of the store.
*/
private final Properties props = new Properties();
public ClientAuthenticationCache(Channel channel) throws IOException, InterruptedException {
- store = (channel==null ? MasterComputer.localChannel : channel).call(new Callable<FilePath, IOException>() {
+ store = (channel == null ? MasterComputer.localChannel : channel).call(new Callable<FilePath, IOException>() {
public FilePath call() throws IOException {
File home = new File(System.getProperty("user.home"));
return new FilePath(new File(home, ".hudson/cli-credentials"));
@@ -76,11 +75,14 @@ public class ClientAuthenticationCache implements Serializable {
/**
* Gets the persisted authentication for this Hudson.
*
- * @return {@link Hudson#ANONYMOUS} if no such credential is found, or if the stored credential is invalid.
+ * @return {@link Hudson#ANONYMOUS} if no such credential is found, or if
+ * the stored credential is invalid.
*/
public Authentication get() {
Secret userName = Secret.decrypt(props.getProperty(getPropertyKey()));
- if (userName==null) return Hudson.ANONYMOUS; // failed to decrypt
+ if (userName == null) {
+ return Hudson.ANONYMOUS; // failed to decrypt
+ }
try {
UserDetails u = HudsonSecurityEntitiesHolder.getHudsonSecurityManager().getSecurityRealm().loadUserByUsername(userName.toString());
return new UsernamePasswordAuthenticationToken(u.getUsername(), u.getPassword(), u.getAuthorities());
@@ -92,11 +94,14 @@ public class ClientAuthenticationCache implements Serializable {
}
/**
- * Computes the key that identifies this Hudson among other Hudsons that the user has a credential for.
+ * Computes the key that identifies this Hudson among other Hudsons that the
+ * user has a credential for.
*/
private String getPropertyKey() {
String url = Hudson.getInstance().getRootUrl();
- if (url!=null) return url;
+ if (url != null) {
+ return url;
+ }
return Secret.fromString("key").toString();
}
@@ -118,8 +123,9 @@ public class ClientAuthenticationCache implements Serializable {
* Removes the persisted credential, if there's one.
*/
public void remove() throws IOException, InterruptedException {
- if (props.remove(getPropertyKey())!=null)
+ if (props.remove(getPropertyKey()) != null) {
save();
+ }
}
private void save() throws IOException, InterruptedException {
@@ -129,7 +135,7 @@ public class ClientAuthenticationCache implements Serializable {
OutputStream os = new FileOutputStream(f);
try {
- props.store(os,"Credential store");
+ props.store(os, "Credential store");
} finally {
os.close();
}
diff --git a/hudson-core/src/main/java/hudson/cli/CloneableCLICommand.java b/hudson-core/src/main/java/hudson/cli/CloneableCLICommand.java
index feb9d44..00a7a77 100644
--- a/hudson-core/src/main/java/hudson/cli/CloneableCLICommand.java
+++ b/hudson-core/src/main/java/hudson/cli/CloneableCLICommand.java
@@ -7,10 +7,10 @@
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
- * Contributors:
+ * Contributors:
+ *
+ *
*
- *
- *
*
*******************************************************************************/
@@ -24,10 +24,11 @@ package hudson.cli;
* @author Kohsuke Kawaguchi
*/
public abstract class CloneableCLICommand extends CLICommand implements Cloneable {
+
@Override
protected CLICommand createClone() {
try {
- return (CLICommand)clone();
+ return (CLICommand) clone();
} catch (CloneNotSupportedException e) {
throw new AssertionError(e);
}
diff --git a/hudson-core/src/main/java/hudson/cli/CommandDuringBuild.java b/hudson-core/src/main/java/hudson/cli/CommandDuringBuild.java
index 22985b3..7f7b5da 100644
--- a/hudson-core/src/main/java/hudson/cli/CommandDuringBuild.java
+++ b/hudson-core/src/main/java/hudson/cli/CommandDuringBuild.java
@@ -7,10 +7,10 @@
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
- * Contributors:
+ * Contributors:
+ *
+ *
*
- *
- *
*
*******************************************************************************/
@@ -30,45 +30,55 @@ import java.io.IOException;
* @author Kohsuke Kawaguchi
*/
public abstract class CommandDuringBuild extends CLICommand {
+
/**
- * This method makes sense only when called from within the build kicked by Hudson.
- * We use the environment variables that Hudson sets to determine the build that is being run.
+ * This method makes sense only when called from within the build kicked by
+ * Hudson. We use the environment variables that Hudson sets to determine
+ * the build that is being run.
*/
protected Run getCurrentlyBuilding() throws CmdLineException {
try {
CLICommand c = CLICommand.getCurrent();
- if (c==null) throw new IllegalStateException("Not executing a CLI command");
+ if (c == null) {
+ throw new IllegalStateException("Not executing a CLI command");
+ }
String[] envs = c.channel.call(new GetCharacteristicEnvironmentVariables());
- if (envs[0]==null || envs[1]==null)
+ if (envs[0] == null || envs[1] == null) {
throw new CmdLineException("This CLI command works only when invoked from inside a build");
+ }
- Job j = Hudson.getInstance().getItemByFullName(envs[0],Job.class);
- if (j==null) throw new CmdLineException("No such job: "+envs[0]);
+ Job j = Hudson.getInstance().getItemByFullName(envs[0], Job.class);
+ if (j == null) {
+ throw new CmdLineException("No such job: " + envs[0]);
+ }
try {
Run r = j.getBuildByNumber(Integer.parseInt(envs[1]));
- if (r==null) throw new CmdLineException("No such build #"+envs[1]+" in "+envs[0]);
+ if (r == null) {
+ throw new CmdLineException("No such build #" + envs[1] + " in " + envs[0]);
+ }
return r;
} catch (NumberFormatException e) {
- throw new CmdLineException("Invalid build number: "+envs[1]);
+ throw new CmdLineException("Invalid build number: " + envs[1]);
}
} catch (IOException e) {
- throw new CmdLineException("Failed to identify the build being executed",e);
+ throw new CmdLineException("Failed to identify the build being executed", e);
} catch (InterruptedException e) {
- throw new CmdLineException("Failed to identify the build being executed",e);
+ throw new CmdLineException("Failed to identify the build being executed", e);
}
}
/**
* Gets the environment variables that points to the build being executed.
*/
- private static final class GetCharacteristicEnvironmentVariables implements Callable<String[],IOException> {
+ private static final class GetCharacteristicEnvironmentVariables implements Callable<String[], IOException> {
+
public String[] call() throws IOException {
- return new String[] {
- System.getenv("JOB_NAME"),
- System.getenv("BUILD_NUMBER")
- };
+ return new String[]{
+ System.getenv("JOB_NAME"),
+ System.getenv("BUILD_NUMBER")
+ };
}
}
}
diff --git a/hudson-core/src/main/java/hudson/cli/CopyJobCommand.java b/hudson-core/src/main/java/hudson/cli/CopyJobCommand.java
index 0c2c704..2a5458c 100644
--- a/hudson-core/src/main/java/hudson/cli/CopyJobCommand.java
+++ b/hudson-core/src/main/java/hudson/cli/CopyJobCommand.java
@@ -7,10 +7,10 @@
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
- * Contributors:
+ * Contributors:
+ *
+ *
*
- *
- *
*
*******************************************************************************/
@@ -24,25 +24,22 @@ import hudson.model.Item;
import org.kohsuke.args4j.Argument;
import org.kohsuke.args4j.Option;
-
/**
* Copies a job from CLI.
- *
+ *
* @author Kohsuke Kawaguchi
*/
@Extension
public class CopyJobCommand extends CLICommand {
+
@Override
public String getShortDescription() {
return "Copies a job";
}
-
- @Argument(metaVar="SRC",usage="Name of the job to copy",required=true)
+ @Argument(metaVar = "SRC", usage = "Name of the job to copy", required = true)
public TopLevelItem src;
-
- @Argument(metaVar="DST",usage="Name of the new job to be created.",index=1,required=true)
+ @Argument(metaVar = "DST", usage = "Name of the new job to be created.", index = 1, required = true)
public String dst;
-
@Option(name = "-fs", aliases = {"--force-save"}, usage = "Force saving the destination job in order to enable build functionality.")
public boolean forceSave;
@@ -50,17 +47,16 @@ public class CopyJobCommand extends CLICommand {
Hudson h = Hudson.getInstance();
h.checkPermission(Item.CREATE);
- if (h.getItem(dst)!=null) {
- stderr.println("Job '"+dst+"' already exists");
+ if (h.getItem(dst) != null) {
+ stderr.println("Job '" + dst + "' already exists");
return -1;
}
-
- h.copy(src,dst);
- Job newJob = (Job)Hudson.getInstance().getItem(dst);
+
+ h.copy(src, dst);
+ Job newJob = (Job) Hudson.getInstance().getItem(dst);
if (forceSave && null != newJob) {
newJob.save();
}
return 0;
}
}
-
diff --git a/hudson-core/src/main/java/hudson/cli/CreateJobCommand.java b/hudson-core/src/main/java/hudson/cli/CreateJobCommand.java
index 572cda0..5d35c2d 100644
--- a/hudson-core/src/main/java/hudson/cli/CreateJobCommand.java
+++ b/hudson-core/src/main/java/hudson/cli/CreateJobCommand.java
@@ -7,10 +7,10 @@
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
- * Contributors:
+ * Contributors:
+ *
+ *
*
- *
- *
*
*******************************************************************************/
@@ -23,31 +23,29 @@ import org.kohsuke.args4j.Argument;
/**
* Creates a new job by reading stdin as a configuration XML file.
- *
+ *
* @author Kohsuke Kawaguchi
*/
@Extension
public class CreateJobCommand extends CLICommand {
+
@Override
public String getShortDescription() {
return "Creates a new job by reading stdin as a configuration XML file";
}
-
- @Argument(metaVar="NAME",usage="Name of the job to create")
+ @Argument(metaVar = "NAME", usage = "Name of the job to create")
public String name;
protected int run() throws Exception {
Hudson h = Hudson.getInstance();
h.checkPermission(Item.CREATE);
- if (h.getItem(name)!=null) {
- stderr.println("Job '"+name+"' already exists");
+ if (h.getItem(name) != null) {
+ stderr.println("Job '" + name + "' already exists");
return -1;
}
- h.createProjectFromXML(name,stdin);
+ h.createProjectFromXML(name, stdin);
return 0;
}
}
-
-
diff --git a/hudson-core/src/main/java/hudson/cli/DeleteBuildsCommand.java b/hudson-core/src/main/java/hudson/cli/DeleteBuildsCommand.java
index f373a09..d36217c 100644
--- a/hudson-core/src/main/java/hudson/cli/DeleteBuildsCommand.java
+++ b/hudson-core/src/main/java/hudson/cli/DeleteBuildsCommand.java
@@ -7,10 +7,10 @@
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
- * Contributors:
+ * Contributors:
+ *
+ *
*
- *
- *
*
*******************************************************************************/
@@ -31,6 +31,7 @@ import java.util.List;
*/
@Extension
public class DeleteBuildsCommand extends AbstractBuildRangeCommand {
+
@Override
public String getShortDescription() {
return "Deletes build record(s)";
@@ -39,20 +40,19 @@ public class DeleteBuildsCommand extends AbstractBuildRangeCommand {
@Override
protected void printUsageSummary(PrintStream stderr) {
stderr.println(
- "Delete build records of a specified job, possibly in a bulk. "
- );
+ "Delete build records of a specified job, possibly in a bulk. ");
}
@Override
protected int act(List<AbstractBuild<?, ?>> builds) throws IOException {
job.checkPermission(Run.DELETE);
- for (AbstractBuild build : builds)
+ for (AbstractBuild build : builds) {
build.delete();
+ }
- stdout.println("Deleted "+builds.size()+" builds");
+ stdout.println("Deleted " + builds.size() + " builds");
return 0;
}
-
}
diff --git a/hudson-core/src/main/java/hudson/cli/HelpCommand.java b/hudson-core/src/main/java/hudson/cli/HelpCommand.java
index 997d461..806d7c2 100644
--- a/hudson-core/src/main/java/hudson/cli/HelpCommand.java
+++ b/hudson-core/src/main/java/hudson/cli/HelpCommand.java
@@ -7,10 +7,10 @@
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
- * Contributors:
+ * Contributors:
+ *
+ *
*
- *
- *
*
*******************************************************************************/
@@ -29,6 +29,7 @@ import java.util.TreeMap;
*/
@Extension
public class HelpCommand extends CLICommand {
+
@Override
public String getShortDescription() {
return "Lists all the available commands";
@@ -41,15 +42,16 @@ public class HelpCommand extends CLICommand {
return 0;
}
- Map<String,CLICommand> commands = new TreeMap<String,CLICommand>();
- for (CLICommand c : CLICommand.all())
- commands.put(c.getName(),c);
+ Map<String, CLICommand> commands = new TreeMap<String, CLICommand>();
+ for (CLICommand c : CLICommand.all()) {
+ commands.put(c.getName(), c);
+ }
for (CLICommand c : commands.values()) {
- stderr.println(" "+c.getName());
- stderr.println(" "+c.getShortDescription());
+ stderr.println(" " + c.getName());
+ stderr.println(" " + c.getShortDescription());
}
-
+
return 0;
}
}
diff --git a/hudson-core/src/main/java/hudson/cli/InstallPluginCommand.java b/hudson-core/src/main/java/hudson/cli/InstallPluginCommand.java
index 9470de6..0f300f3 100644
--- a/hudson-core/src/main/java/hudson/cli/InstallPluginCommand.java
+++ b/hudson-core/src/main/java/hudson/cli/InstallPluginCommand.java
@@ -7,10 +7,10 @@
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
- * Contributors:
+ * Contributors:
+ *
+ *
*
- *
- *
*
*******************************************************************************/
@@ -35,26 +35,24 @@ import java.util.Set;
/**
* Installs a plugin either from a file, an URL, or from update center.
- *
+ *
* @author Kohsuke Kawaguchi
* @since 1.331
*/
@Extension
public class InstallPluginCommand extends CLICommand {
+
public String getShortDescription() {
return "Installs a plugin either from a file, an URL, or from update center";
}
-
- @Argument(metaVar="SOURCE",required=true,usage="If this points to a local file, that file will be installed. " +
- "If this is an URL, Hudson downloads the URL and installs that as a plugin." +
- "Otherwise the name is assumed to be the short name of the plugin in the existing update center (like \"findbugs\")," +
- "and the plugin will be installed from the update center")
+ @Argument(metaVar = "SOURCE", required = true, usage = "If this points to a local file, that file will be installed. "
+ + "If this is an URL, Hudson downloads the URL and installs that as a plugin."
+ + "Otherwise the name is assumed to be the short name of the plugin in the existing update center (like \"findbugs\"),"
+ + "and the plugin will be installed from the update center")
public List<String> sources = new ArrayList<String>();
-
- @Option(name="-name",usage="If specified, the plugin will be installed as this short name (whereas normally the name is inferred from the source name automatically.)")
+ @Option(name = "-name", usage = "If specified, the plugin will be installed as this short name (whereas normally the name is inferred from the source name automatically.)")
public String name;
-
- @Option(name="-restart",usage="Restart Hudson upon successful installation")
+ @Option(name = "-restart", usage = "Restart Hudson upon successful installation")
public boolean restart;
protected int run() throws Exception {
@@ -66,8 +64,9 @@ public class InstallPluginCommand extends CLICommand {
FilePath f = new FilePath(channel, source);
if (f.exists()) {
stdout.println(Messages.InstallPluginCommand_InstallingPluginFromLocalFile(f));
- if (name==null)
+ if (name == null) {
name = f.getBaseName();
+ }
f.copyTo(getTargetFile());
continue;
}
@@ -76,12 +75,14 @@ public class InstallPluginCommand extends CLICommand {
try {
URL u = new URL(source);
stdout.println(Messages.InstallPluginCommand_InstallingPluginFromUrl(u));
- if (name==null) {
+ if (name == null) {
name = u.getPath();
- name = name.substring(name.indexOf('/')+1);
- name = name.substring(name.indexOf('\\')+1);
+ name = name.substring(name.indexOf('/') + 1);
+ name = name.substring(name.indexOf('\\') + 1);
int idx = name.lastIndexOf('.');
- if (idx>0) name = name.substring(0,idx);
+ if (idx > 0) {
+ name = name.substring(0, idx);
+ }
}
getTargetFile().copyFrom(u);
continue;
@@ -91,7 +92,7 @@ public class InstallPluginCommand extends CLICommand {
// is this a plugin the update center?
UpdateSite.Plugin p = h.getUpdateCenter().getPlugin(source);
- if (p!=null) {
+ if (p != null) {
stdout.println(Messages.InstallPluginCommand_InstallingFromUpdateCenter(source));
p.deploy().get();
continue;
@@ -107,25 +108,26 @@ public class InstallPluginCommand extends CLICommand {
Set<String> candidates = new HashSet<String>();
for (UpdateSite s : h.getUpdateCenter().getSites()) {
Data dt = s.getData();
- if (dt==null) {
+ if (dt == null) {
stdout.println(Messages.InstallPluginCommand_NoUpdateDataRetrieved(s.getUrl()));
} else {
candidates.addAll(dt.plugins.keySet());
}
}
- stdout.println(Messages.InstallPluginCommand_DidYouMean(source,EditDistance.findNearest(source,candidates)));
+ stdout.println(Messages.InstallPluginCommand_DidYouMean(source, EditDistance.findNearest(source, candidates)));
}
}
return 1;
}
- if (restart)
+ if (restart) {
h.restart();
+ }
return 0; // all success
}
private FilePath getTargetFile() {
- return new FilePath(new File(Hudson.getInstance().getPluginManager().rootDir,name+".hpi"));
+ return new FilePath(new File(Hudson.getInstance().getPluginManager().rootDir, name + ".hpi"));
}
}
diff --git a/hudson-core/src/main/java/hudson/cli/InstallToolCommand.java b/hudson-core/src/main/java/hudson/cli/InstallToolCommand.java
index cbe47f6..b56cf1e 100644
--- a/hudson-core/src/main/java/hudson/cli/InstallToolCommand.java
+++ b/hudson-core/src/main/java/hudson/cli/InstallToolCommand.java
@@ -7,10 +7,10 @@
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
- * Contributors:
+ * Contributors:
+ *
+ *
*
- *
- *
*
*******************************************************************************/
@@ -46,10 +46,10 @@ import org.kohsuke.args4j.Argument;
*/
@Extension
public class InstallToolCommand extends CLICommand {
- @Argument(index=0,metaVar="KIND",usage="The type of the tool to install, such as 'Ant'")
- public String toolType;
- @Argument(index=1,metaVar="NAME",usage="The name of the tool to install, as you've entered in the Hudson system configuration")
+ @Argument(index = 0, metaVar = "KIND", usage = "The type of the tool to install, such as 'Ant'")
+ public String toolType;
+ @Argument(index = 1, metaVar = "NAME", usage = "The name of the tool to install, as you've entered in the Hudson system configuration")
public String toolName;
public String getShortDescription() {
@@ -63,12 +63,14 @@ public class InstallToolCommand extends CLICommand {
// where is this build running?
BuildIDs id = channel.call(new BuildIDs());
- if (!id.isComplete())
+ if (!id.isComplete()) {
throw new AbortException("This command can be only invoked from a build executing inside Hudson");
+ }
AbstractProject p = Hudson.getInstance().getItemByFullName(id.job, AbstractProject.class);
- if (p==null)
- throw new AbortException("No such job found: "+id.job);
+ if (p == null) {
+ throw new AbortException("No such job found: " + id.job);
+ }
p.checkPermission(Item.CONFIGURE);
List<String> toolTypes = new ArrayList<String>();
@@ -78,8 +80,9 @@ public class InstallToolCommand extends CLICommand {
List<String> toolNames = new ArrayList<String>();
for (ToolInstallation t : d.getInstallations()) {
toolNames.add(t.getName());
- if (t.getName().equals(toolName))
+ if (t.getName().equals(toolName)) {
return install(t, id, p);
+ }
}
// didn't find the right tool name
@@ -95,10 +98,11 @@ public class InstallToolCommand extends CLICommand {
}
private int error(List<String> candidates, String given, String noun) throws AbortException {
- if (given ==null)
- throw new AbortException("No tool "+ noun +" was specified. Valid values are "+candidates.toString());
- else
- throw new AbortException("Unrecognized tool "+noun+". Perhaps you meant '"+ EditDistance.findNearest(given,candidates)+"'?");
+ if (given == null) {
+ throw new AbortException("No tool " + noun + " was specified. Valid values are " + candidates.toString());
+ } else {
+ throw new AbortException("Unrecognized tool " + noun + ". Perhaps you meant '" + EditDistance.findNearest(given, candidates) + "'?");
+ }
}
/**
@@ -107,29 +111,32 @@ public class InstallToolCommand extends CLICommand {
private int install(ToolInstallation t, BuildIDs id, AbstractProject p) throws IOException, InterruptedException {
Run b = p.getBuildByNumber(Integer.parseInt(id.number));
- if (b==null)
- throw new AbortException("No such build: "+id.number);
+ if (b == null) {
+ throw new AbortException("No such build: " + id.number);
+ }
Executor exec = b.getExecutor();
- if (exec==null)
- throw new AbortException(b.getFullDisplayName()+" is not building");
+ if (exec == null) {
+ throw new AbortException(b.getFullDisplayName() + " is not building");
+ }
Node node = exec.getOwner().getNode();
if (t instanceof NodeSpecific) {
NodeSpecific n = (NodeSpecific) t;
- t = (ToolInstallation)n.forNode(node,new StreamTaskListener(stderr));
+ t = (ToolInstallation) n.forNode(node, new StreamTaskListener(stderr));
}
if (t instanceof EnvironmentSpecific) {
EnvironmentSpecific e = (EnvironmentSpecific) t;
- t = (ToolInstallation)e.forEnvironment(EnvVars.getRemote(channel));
+ t = (ToolInstallation) e.forEnvironment(EnvVars.getRemote(channel));
}
stdout.println(t.getHome());
return 0;
}
private static final class BuildIDs implements Callable<BuildIDs, IOException> {
- String job,number,id;
+
+ String job, number, id;
public BuildIDs call() throws IOException {
job = System.getenv("JOB_NAME");
@@ -139,9 +146,8 @@ public class InstallToolCommand extends CLICommand {
}
boolean isComplete() {
- return job!=null && number!=null && id!=null;
+ return job != null && number != null && id != null;
}
-
private static final long serialVersionUID = 1L;
}
}
diff --git a/hudson-core/src/main/java/hudson/cli/ListChangesCommand.java b/hudson-core/src/main/java/hudson/cli/ListChangesCommand.java
index 55fac05..c95a5da 100644
--- a/hudson-core/src/main/java/hudson/cli/ListChangesCommand.java
+++ b/hudson-core/src/main/java/hudson/cli/ListChangesCommand.java
@@ -8,7 +8,7 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- *
+ *
*
*******************************************************************************/
@@ -35,6 +35,7 @@ import java.util.List;
*/
@Extension
public class ListChangesCommand extends AbstractBuildRangeCommand {
+
@Override
public String getShortDescription() {
return "Dumps the changelog for the specified build(s)";
@@ -44,12 +45,11 @@ public class ListChangesCommand extends AbstractBuildRangeCommand {
// protected void printUsageSummary(PrintStream stderr) {
// TODO
// }
-
enum Format {
+
XML, CSV, PLAIN
}
-
- @Option(name="-format",usage="Controls how the output from this command is printed.")
+ @Option(name = "-format", usage = "Controls how the output from this command is printed.")
public Format format = Format.PLAIN;
@Override
@@ -57,42 +57,42 @@ public class ListChangesCommand extends AbstractBuildRangeCommand {
// Loading job for this CLI command requires Item.READ permission.
// No other permission check needed.
switch (format) {
- case XML:
- PrintWriter w = new PrintWriter(stdout);
- w.println("<changes>");
- for (AbstractBuild build : builds) {
- w.println("<build number='"+build.getNumber()+"'>");
- ChangeLogSet<?> cs = build.getChangeSet();
- Model p = new ModelBuilder().get(cs.getClass());
- p.writeTo(cs,Flavor.XML.createDataWriter(cs,w));
- w.println("</build>");
- }
- w.println("</changes>");
- w.flush();
- break;
- case CSV:
- for (AbstractBuild build : builds) {
- ChangeLogSet<?> cs = build.getChangeSet();
- for (Entry e : cs) {
- stdout.printf("%s,%s\n",
- QuotedStringTokenizer.quote(e.getAuthor().getId()),
- QuotedStringTokenizer.quote(e.getMsg()));
+ case XML:
+ PrintWriter w = new PrintWriter(stdout);
+ w.println("<changes>");
+ for (AbstractBuild build : builds) {
+ w.println("<build number='" + build.getNumber() + "'>");
+ ChangeLogSet<?> cs = build.getChangeSet();
+ Model p = new ModelBuilder().get(cs.getClass());
+ p.writeTo(cs, Flavor.XML.createDataWriter(cs, w));
+ w.println("</build>");
+ }
+ w.println("</changes>");
+ w.flush();
+ break;
+ case CSV:
+ for (AbstractBuild build : builds) {
+ ChangeLogSet<?> cs = build.getChangeSet();
+ for (Entry e : cs) {
+ stdout.printf("%s,%s\n",
+ QuotedStringTokenizer.quote(e.getAuthor().getId()),
+ QuotedStringTokenizer.quote(e.getMsg()));
+ }
}
- }
- break;
- case PLAIN:
- for (AbstractBuild build : builds) {
- ChangeLogSet<?> cs = build.getChangeSet();
- for (Entry e : cs) {
- stdout.printf("%s\t%s\n",e.getAuthor(),e.getMsg());
- for (String p : e.getAffectedPaths())
- stdout.println(" "+p);
+ break;
+ case PLAIN:
+ for (AbstractBuild build : builds) {
+ ChangeLogSet<?> cs = build.getChangeSet();
+ for (Entry e : cs) {
+ stdout.printf("%s\t%s\n", e.getAuthor(), e.getMsg());
+ for (String p : e.getAffectedPaths()) {
+ stdout.println(" " + p);
+ }
+ }
}
- }
- break;
+ break;
}
return 0;
}
-
}
diff --git a/hudson-core/src/main/java/hudson/cli/LoginCommand.java b/hudson-core/src/main/java/hudson/cli/LoginCommand.java
index f64b6c9..c17784f 100644
--- a/hudson-core/src/main/java/hudson/cli/LoginCommand.java
+++ b/hudson-core/src/main/java/hudson/cli/LoginCommand.java
@@ -8,9 +8,9 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- *
+ *
* Kohsuke Kawaguchi, Winston Prakash
- *
+ *
*******************************************************************************/
package hudson.cli;
@@ -22,21 +22,23 @@ import org.springframework.security.Authentication;
import org.kohsuke.args4j.CmdLineException;
/**
- * Saves the current credential to allow future commands to run without explicit credential information.
+ * Saves the current credential to allow future commands to run without explicit
+ * credential information.
*
* @author Kohsuke Kawaguchi
* @since 1.351
*/
@Extension
public class LoginCommand extends CLICommand {
+
@Override
public String getShortDescription() {
return "Saves the current credential to allow future commands to run without explicit credential information";
}
/**
- * If we use the stored authentication for the login command, login becomes no-op, which is clearly not what
- * the user has intended.
+ * If we use the stored authentication for the login command, login becomes
+ * no-op, which is clearly not what the user has intended.
*/
@Override
protected Authentication loadStoredAuthentication() throws InterruptedException {
@@ -46,13 +48,12 @@ public class LoginCommand extends CLICommand {
@Override
protected int run() throws Exception {
Authentication a = Hudson.getAuthentication();
- if (a==HudsonSecurityManager.ANONYMOUS)
+ if (a == HudsonSecurityManager.ANONYMOUS) {
throw new CmdLineException("No credentials specified."); // this causes CLI to show the command line options.
-
+ }
ClientAuthenticationCache store = new ClientAuthenticationCache(channel);
store.set(a);
return 0;
}
-
}
diff --git a/hudson-core/src/main/java/hudson/cli/LogoutCommand.java b/hudson-core/src/main/java/hudson/cli/LogoutCommand.java
index ae5fb41..d6ccf25 100644
--- a/hudson-core/src/main/java/hudson/cli/LogoutCommand.java
+++ b/hudson-core/src/main/java/hudson/cli/LogoutCommand.java
@@ -8,7 +8,7 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- *
+ *
*
*******************************************************************************/
@@ -24,6 +24,7 @@ import hudson.Extension;
*/
@Extension
public class LogoutCommand extends CLICommand {
+
@Override
public String getShortDescription() {
return "Deletes the credential stored with the login command";
diff --git a/hudson-core/src/main/java/hudson/cli/MailCommand.java b/hudson-core/src/main/java/hudson/cli/MailCommand.java
index 31b88b3..1597d40 100644
--- a/hudson-core/src/main/java/hudson/cli/MailCommand.java
+++ b/hudson-core/src/main/java/hudson/cli/MailCommand.java
@@ -7,10 +7,10 @@
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
- * Contributors:
+ * Contributors:
+ *
+ *
*
- *
- *
*
*******************************************************************************/
@@ -25,13 +25,14 @@ import hudson.tasks.Mailer;
/**
* Sends e-mail through Hudson.
*
- * <p>
- * Various platforms have different commands to do this, so on heterogenous platform, doing this via Hudson is easier.
+ * <p> Various platforms have different commands to do this, so on heterogenous
+ * platform, doing this via Hudson is easier.
*
* @author Kohsuke Kawaguchi
*/
@Extension
public class MailCommand extends CLICommand {
+
public String getShortDescription() {
return "Reads stdin and sends that out as an e-mail.";
}
diff --git a/hudson-core/src/main/java/hudson/cli/SetBuildDescriptionCommand.java b/hudson-core/src/main/java/hudson/cli/SetBuildDescriptionCommand.java
index f45462e..3653ecd 100644
--- a/hudson-core/src/main/java/hudson/cli/SetBuildDescriptionCommand.java
+++ b/hudson-core/src/main/java/hudson/cli/SetBuildDescriptionCommand.java
@@ -8,7 +8,7 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- *
+ *
*
*******************************************************************************/
@@ -32,31 +32,27 @@ public class SetBuildDescriptionCommand extends CLICommand implements Serializab
public String getShortDescription() {
return "Sets the description of a build";
}
-
- @Argument(metaVar="JOB",usage="Name of the job to build",required=true,index=0)
- public transient AbstractProject<?,?> job;
-
- @Argument(metaVar="BUILD#",usage="Number of the build",required=true,index=1)
+ @Argument(metaVar = "JOB", usage = "Name of the job to build", required = true, index = 0)
+ public transient AbstractProject<?, ?> job;
+ @Argument(metaVar = "BUILD#", usage = "Number of the build", required = true, index = 1)
public int number;
-
- @Argument(metaVar="DESCRIPTION",required=true,usage="Description to be set. '=' to read from stdin.", index=2)
+ @Argument(metaVar = "DESCRIPTION", required = true, usage = "Description to be set. '=' to read from stdin.", index = 2)
public String description;
protected int run() throws Exception {
- Run run = job.getBuildByNumber(number);
+ Run run = job.getBuildByNumber(number);
run.checkPermission(Run.UPDATE);
if ("=".equals(description)) {
- description = channel.call(new Callable<String,IOException>() {
- public String call() throws IOException {
- return IOUtils.toString(System.in);
- }
- });
+ description = channel.call(new Callable<String, IOException>() {
+ public String call() throws IOException {
+ return IOUtils.toString(System.in);
+ }
+ });
}
-
+
run.setDescription(description);
-
+
return 0;
}
-
}
diff --git a/hudson-core/src/main/java/hudson/cli/SetBuildResultCommand.java b/hudson-core/src/main/java/hudson/cli/SetBuildResultCommand.java
index 50f339b..2070d2a 100644
--- a/hudson-core/src/main/java/hudson/cli/SetBuildResultCommand.java
+++ b/hudson-core/src/main/java/hudson/cli/SetBuildResultCommand.java
@@ -7,10 +7,10 @@
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
- * Contributors:
+ * Contributors:
+ *
+ *
*
- *
- *
*
*******************************************************************************/
@@ -23,13 +23,15 @@ import hudson.model.Run;
import org.kohsuke.args4j.Argument;
/**
- * Sets the result of the current build. Works only if invoked from within a build.
- *
+ * Sets the result of the current build. Works only if invoked from within a
+ * build.
+ *
* @author Kohsuke Kawaguchi
*/
@Extension
public class SetBuildResultCommand extends CommandDuringBuild {
- @Argument(metaVar="RESULT",required=true)
+
+ @Argument(metaVar = "RESULT", required = true)
public Result result;
@Override
diff --git a/hudson-core/src/main/java/hudson/cli/UpdateJobCommand.java b/hudson-core/src/main/java/hudson/cli/UpdateJobCommand.java
index 2030ae5..ddb257e 100644
--- a/hudson-core/src/main/java/hudson/cli/UpdateJobCommand.java
+++ b/hudson-core/src/main/java/hudson/cli/UpdateJobCommand.java
@@ -7,10 +7,10 @@
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
- * Contributors:
+ * Contributors:
+ *
+ *
*
- *
- *
*
*******************************************************************************/
@@ -29,7 +29,7 @@ import org.kohsuke.args4j.Argument;
/**
* Updates or creates a job by reading stdin as a configuration XML file.
- *
+ *
* @author Henrik Lynggaard Hansen
*/
@Extension
@@ -39,7 +39,6 @@ public class UpdateJobCommand extends CLICommand {
public String getShortDescription() {
return "Updates and potentionally creates a job by reading stdin as a configuration XML file.";
}
-
@Argument(metaVar = "NAME", usage = "Name of the job to update", required = true)
public String name;
@Argument(metaVar = "CREATE", usage = "Create the job if needed", index = 1, required = true)
@@ -59,15 +58,15 @@ public class UpdateJobCommand extends CLICommand {
h.checkPermission(Item.CREATE);
h.createProjectFromXML(name, stdin);
} else {
- try {
+ try {
h.checkPermission(Job.CONFIGURE);
-
+
File rootDirOfJob = new File(new File(h.getRootDir(), "jobs"), name);
// place it as config.xml
File configXml = Items.getConfigFile(rootDirOfJob).getFile();
IOUtils.copy(stdin, configXml);
-
- item = h.reloadProjectFromDisk(configXml.getParentFile());
+
+ item = h.reloadProjectFromDisk(configXml.getParentFile());
} catch (IOException e) {
throw e;
}
diff --git a/hudson-core/src/main/java/hudson/cli/VersionCommand.java b/hudson-core/src/main/java/hudson/cli/VersionCommand.java
index c6a073a..64b1974 100644
--- a/hudson-core/src/main/java/hudson/cli/VersionCommand.java
+++ b/hudson-core/src/main/java/hudson/cli/VersionCommand.java
@@ -7,10 +7,10 @@
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
- * Contributors:
+ * Contributors:
+ *
+ *
*
- *
- *
*
*******************************************************************************/
@@ -26,6 +26,7 @@ import hudson.model.Hudson;
*/
@Extension
public class VersionCommand extends CLICommand {
+
@Override
public String getShortDescription() {
return "Shows the Hudson version";
diff --git a/hudson-core/src/main/java/hudson/cli/package-info.java b/hudson-core/src/main/java/hudson/cli/package-info.java
index 4699ff6..ffbb0c6 100644
--- a/hudson-core/src/main/java/hudson/cli/package-info.java
+++ b/hudson-core/src/main/java/hudson/cli/package-info.java
@@ -7,10 +7,10 @@
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
- * Contributors:
+ * Contributors:
+ *
+ *
*
- *
- *
*
*******************************************************************************/