aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenrik Lynggaard Hansen2012-07-10 15:14:14 (EDT)
committerHenrik Lynggaard Hansen2012-07-10 15:14:14 (EDT)
commitad70099a670d602d4c6805b970c526fa66fbc5e9 (patch)
treecadf9da7d024ae1a4f2a424d19a0dbc6b59ce82c
parent6b2a021db07f935226235132973fb64223c07d91 (diff)
downloadorg.eclipse.hudson.core-ad70099a670d602d4c6805b970c526fa66fbc5e9.zip
org.eclipse.hudson.core-ad70099a670d602d4c6805b970c526fa66fbc5e9.tar.gz
org.eclipse.hudson.core-ad70099a670d602d4c6805b970c526fa66fbc5e9.tar.bz2
reformat hudson.cli subpackagesrefs/changes/95/6695/1
Reformat of the hudson.cli subpackages. Change-Id: Ia60dc6864d3a4fcf070667778b2dcf8d4f6d29f4 Signed-off-by: Henrik Lynggaard Hansen <henrik@hlyh.dk>
-rw-r--r--hudson-core/src/main/java/hudson/cli/declarative/CLIMethod.java31
-rw-r--r--hudson-core/src/main/java/hudson/cli/declarative/CLIRegisterer.java66
-rw-r--r--hudson-core/src/main/java/hudson/cli/declarative/CLIResolver.java51
-rw-r--r--hudson-core/src/main/java/hudson/cli/declarative/MethodBinder.java35
-rw-r--r--hudson-core/src/main/java/hudson/cli/declarative/OptionHandlerExtension.java6
-rw-r--r--hudson-core/src/main/java/hudson/cli/declarative/package-info.java6
-rw-r--r--hudson-core/src/main/java/hudson/cli/handlers/AbstractProjectOptionHandler.java17
-rw-r--r--hudson-core/src/main/java/hudson/cli/handlers/TopLevelItemOptionHandler.java8
-rw-r--r--hudson-core/src/main/java/hudson/cli/handlers/package-info.java2
9 files changed, 120 insertions, 102 deletions
diff --git a/hudson-core/src/main/java/hudson/cli/declarative/CLIMethod.java b/hudson-core/src/main/java/hudson/cli/declarative/CLIMethod.java
index 5c392e8..70f61f0 100644
--- a/hudson-core/src/main/java/hudson/cli/declarative/CLIMethod.java
+++ b/hudson-core/src/main/java/hudson/cli/declarative/CLIMethod.java
@@ -7,10 +7,10 @@
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
- * Contributors:
+ * Contributors:
+ *
+ *
*
- *
- *
*
*******************************************************************************/
@@ -30,21 +30,19 @@ import java.lang.annotation.Target;
/**
* Annotates methods on model objects to expose them as CLI commands.
*
- * <p>
- * You need to have <tt>Messages.properties</tt> in the same package with the
- * <tt>CLI.<i>command-name</i>.shortDescription</tt> key to describe the command.
- * This is used for the same purpose as {@link CLICommand#getShortDescription()}.
+ * <p> You need to have <tt>Messages.properties</tt> in the same package with
+ * the <tt>CLI.<i>command-name</i>.shortDescription</tt> key to describe the
+ * command. This is used for the same purpose as
+ * {@link CLICommand#getShortDescription()}.
*
- * <p>
- * If you put a {@link CLIMethod} on an instance method (as opposed to a static method),
- * you need a corresponding {@linkplain CLIResolver CLI resolver method}.
+ * <p> If you put a {@link CLIMethod} on an instance method (as opposed to a
+ * static method), you need a corresponding
+ * {@linkplain CLIResolver CLI resolver method}.
*
- * <p>
- * A CLI method can have its parameters annotated with {@link Option} and {@link Argument},
- * to receive parameter/argument injections.
+ * <p> A CLI method can have its parameters annotated with {@link Option} and
+ * {@link Argument}, to receive parameter/argument injections.
*
- * <p>
- * A CLI method needs to be public.
+ * <p> A CLI method needs to be public.
*
* @author Kohsuke Kawaguchi
* @see CLICommand
@@ -55,8 +53,9 @@ import java.lang.annotation.Target;
@Target({METHOD})
@Documented
public @interface CLIMethod {
+
/**
- * CLI command name. Used as {@link CLICommand#getName()}
+ * CLI command name. Used as {@link CLICommand#getName()}
*/
String name();
}
diff --git a/hudson-core/src/main/java/hudson/cli/declarative/CLIRegisterer.java b/hudson-core/src/main/java/hudson/cli/declarative/CLIRegisterer.java
index bfcae42..3f56dbe 100644
--- a/hudson-core/src/main/java/hudson/cli/declarative/CLIRegisterer.java
+++ b/hudson-core/src/main/java/hudson/cli/declarative/CLIRegisterer.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.declarative;
@@ -50,17 +50,20 @@ import java.util.logging.Logger;
import org.eclipse.hudson.security.HudsonSecurityEntitiesHolder;
/**
- * Discover {@link CLIMethod}s and register them as {@link CLICommand} implementations.
+ * Discover {@link CLIMethod}s and register them as {@link CLICommand}
+ * implementations.
*
* @author Kohsuke Kawaguchi
*/
@Extension
public class CLIRegisterer extends ExtensionFinder {
+
public <T> Collection<ExtensionComponent<T>> find(Class<T> type, Hudson hudson) {
- if (type==CLICommand.class)
- return (List)discover(hudson);
- else
+ if (type == CLICommand.class) {
+ return (List) discover(hudson);
+ } else {
return Collections.emptyList();
+ }
}
/**
@@ -68,10 +71,13 @@ public class CLIRegisterer extends ExtensionFinder {
*/
private Method findResolver(Class type) throws IOException {
List<Method> resolvers = Util.filter(Index.list(CLIResolver.class, Hudson.getInstance().getPluginManager().uberClassLoader), Method.class);
- for ( ; type!=null; type=type.getSuperclass())
- for (Method m : resolvers)
- if (m.getReturnType()==type)
+ for (; type != null; type = type.getSuperclass()) {
+ for (Method m : resolvers) {
+ if (m.getReturnType() == type) {
return m;
+ }
+ }
+ }
return null;
}
@@ -80,13 +86,13 @@ public class CLIRegisterer extends ExtensionFinder {
List<ExtensionComponent<CLICommand>> r = new ArrayList<ExtensionComponent<CLICommand>>();
try {
- for ( final Method m : Util.filter(Index.list(CLIMethod.class, hudson.getPluginManager().uberClassLoader),Method.class)) {
+ for (final Method m : Util.filter(Index.list(CLIMethod.class, hudson.getPluginManager().uberClassLoader), Method.class)) {
try {
// command name
final String name = m.getAnnotation(CLIMethod.class).name();
final ResourceBundleHolder res = loadMessageBundle(m);
- res.format("CLI."+name+".shortDescription"); // make sure we have the resource, to fail early
+ res.format("CLI." + name + ".shortDescription"); // make sure we have the resource, to fail early
r.add(new ExtensionComponent<CLICommand>(new CloneableCLICommand() {
@Override
@@ -96,7 +102,7 @@ public class CLIRegisterer extends ExtensionFinder {
public String getShortDescription() {
// format by using the right locale
- return res.format("CLI."+name+".shortDescription");
+ return res.format("CLI." + name + ".shortDescription");
}
@Override
@@ -117,56 +123,61 @@ public class CLIRegisterer extends ExtensionFinder {
Method method = m;
while (true) {
chains.push(method);
- if (Modifier.isStatic(method.getModifiers()))
+ if (Modifier.isStatic(method.getModifiers())) {
break; // the chain is complete.
-
+ }
// the method in question is an instance method, so we need to resolve the instance by using another resolver
Class<?> type = method.getDeclaringClass();
method = findResolver(type);
- if (method==null) {
- stderr.println("Unable to find the resolver method annotated with @CLIResolver for "+type);
+ if (method == null) {
+ stderr.println("Unable to find the resolver method annotated with @CLIResolver for " + type);
return 1;
}
}
List<MethodBinder> binders = new ArrayList<MethodBinder>();
- while (!chains.isEmpty())
- binders.add(new MethodBinder(chains.pop(),parser));
+ while (!chains.isEmpty()) {
+ binders.add(new MethodBinder(chains.pop(), parser));
+ }
// authentication
CliAuthenticator authenticator = HudsonSecurityEntitiesHolder.getHudsonSecurityManager().getSecurityRealm().createCliAuthenticator(this);
- new ClassParser().parse(authenticator,parser);
+ new ClassParser().parse(authenticator, parser);
// fill up all the binders
parser.parseArgument(args);
Authentication auth = authenticator.authenticate();
- if (auth==Hudson.ANONYMOUS)
+ if (auth == Hudson.ANONYMOUS) {
auth = loadStoredAuthentication();
+ }
sc.setAuthentication(auth); // run the CLI with the right credential
hudson.checkPermission(Hudson.READ);
// resolve them
Object instance = null;
- for (MethodBinder binder : binders)
+ for (MethodBinder binder : binders) {
instance = binder.call(instance);
+ }
- if (instance instanceof Integer)
+ if (instance instanceof Integer) {
return (Integer) instance;
- else
+ } else {
return 0;
+ }
} catch (InvocationTargetException e) {
Throwable t = e.getTargetException();
- if (t instanceof Exception)
+ if (t instanceof Exception) {
throw (Exception) t;
+ }
throw e;
} finally {
sc.setAuthentication(old); // restore
}
} catch (CmdLineException e) {
stderr.println(e.getMessage());
- printUsage(stderr,parser);
+ printUsage(stderr, parser);
return 1;
} catch (Exception e) {
e.printStackTrace(stderr);
@@ -179,11 +190,11 @@ public class CLIRegisterer extends ExtensionFinder {
}
}));
} catch (ClassNotFoundException e) {
- LOGGER.log(SEVERE,"Failed to process @CLIMethod: "+m,e);
+ LOGGER.log(SEVERE, "Failed to process @CLIMethod: " + m, e);
}
}
} catch (IOException e) {
- LOGGER.log(SEVERE, "Failed to discvoer @CLIMethod",e);
+ LOGGER.log(SEVERE, "Failed to discvoer @CLIMethod", e);
}
return r;
@@ -197,6 +208,5 @@ public class CLIRegisterer extends ExtensionFinder {
Class<?> msg = c.getClassLoader().loadClass(c.getName().substring(0, c.getName().lastIndexOf(".")) + ".Messages");
return ResourceBundleHolder.get(msg);
}
-
private static final Logger LOGGER = Logger.getLogger(CLIRegisterer.class.getName());
}
diff --git a/hudson-core/src/main/java/hudson/cli/declarative/CLIResolver.java b/hudson-core/src/main/java/hudson/cli/declarative/CLIResolver.java
index 9a7d20b..76412b7 100644
--- a/hudson-core/src/main/java/hudson/cli/declarative/CLIResolver.java
+++ b/hudson-core/src/main/java/hudson/cli/declarative/CLIResolver.java
@@ -7,10 +7,10 @@
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
- * Contributors:
+ * Contributors:
+ *
+ *
*
- *
- *
*
*******************************************************************************/
@@ -28,29 +28,28 @@ import static java.lang.annotation.RetentionPolicy.RUNTIME;
import java.lang.annotation.Target;
/**
- * Annotates a resolver method that binds a portion of the command line arguments and parameters
- * to an instance whose {@link CLIMethod} is invoked for the final processing.
- *
- * <p>
- * Hudson uses the return type of the resolver method
- * to pick the resolver method to use, of all the resolver methods it discovers. That is,
- * if Hudson is looking to find an instance of type <tt>T</tt> for the current command, it first
- * looks for the resolver method whose return type is <tt>T</tt>, then it checks for the base type of <tt>T</tt>,
- * and so on.
- *
- * <p>
- * If the chosen resolver method is an instance method on type <tt>S</tt>, the "parent resolver" is then
- * located to resolve an instance of type 'S'. This process repeats until a static resolver method is discovered
- * (since most of Hudson's model objects are anchored to the root {@link Hudson} object, normally that would become
- * the top-most resolver method.)
- *
- * <p>
- * Parameters of the resolver method receives the same parameter/argument injections that {@link CLIMethod}s receive.
- * Parameters and arguments consumed by the resolver will not be visible to {@link CLIMethod}s.
- *
- * <p>
- * The resolver method shall never return null &mdash; it should instead indicate a failure by throwing
- * {@link CmdLineException}.
+ * Annotates a resolver method that binds a portion of the command line
+ * arguments and parameters to an instance whose {@link CLIMethod} is invoked
+ * for the final processing.
+ *
+ * <p> Hudson uses the return type of the resolver method to pick the resolver
+ * method to use, of all the resolver methods it discovers. That is, if Hudson
+ * is looking to find an instance of type <tt>T</tt> for the current command, it
+ * first looks for the resolver method whose return type is <tt>T</tt>, then it
+ * checks for the base type of <tt>T</tt>, and so on.
+ *
+ * <p> If the chosen resolver method is an instance method on type <tt>S</tt>,
+ * the "parent resolver" is then located to resolve an instance of type 'S'.
+ * This process repeats until a static resolver method is discovered (since most
+ * of Hudson's model objects are anchored to the root {@link Hudson} object,
+ * normally that would become the top-most resolver method.)
+ *
+ * <p> Parameters of the resolver method receives the same parameter/argument
+ * injections that {@link CLIMethod}s receive. Parameters and arguments consumed
+ * by the resolver will not be visible to {@link CLIMethod}s.
+ *
+ * <p> The resolver method shall never return null &mdash; it should instead
+ * indicate a failure by throwing {@link CmdLineException}.
*
* @author Kohsuke Kawaguchi
* @see CLICommand
diff --git a/hudson-core/src/main/java/hudson/cli/declarative/MethodBinder.java b/hudson-core/src/main/java/hudson/cli/declarative/MethodBinder.java
index c80bc34..0338cf3 100644
--- a/hudson-core/src/main/java/hudson/cli/declarative/MethodBinder.java
+++ b/hudson-core/src/main/java/hudson/cli/declarative/MethodBinder.java
@@ -7,10 +7,10 @@
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
- * Contributors:
+ * Contributors:
+ *
+ *
*
- *
- *
*
*******************************************************************************/
@@ -31,9 +31,9 @@ import java.lang.reflect.Method;
import java.util.List;
/**
- * Binds method parameters to CLI arguments and parameters via args4j.
- * Once the parser fills in the instance state, {@link #call(Object)}
- * can be used to invoke a method.
+ * Binds method parameters to CLI arguments and parameters via args4j. Once the
+ * parser fills in the instance state, {@link #call(Object)} can be used to
+ * invoke a method.
*
* @author Kohsuke Kawaguchi
*/
@@ -72,27 +72,31 @@ class MethodBinder {
}
};
Option option = p.annotation(Option.class);
- if (option!=null) {
- parser.addOption(setter,option);
+ if (option != null) {
+ parser.addOption(setter, option);
}
Argument arg = p.annotation(Argument.class);
- if (arg!=null) {
- if (bias>0) arg = new ArgumentImpl(arg,bias);
- parser.addArgument(setter,arg);
+ if (arg != null) {
+ if (bias > 0) {
+ arg = new ArgumentImpl(arg, bias);
+ }
+ parser.addArgument(setter, arg);
}
- if (p.type().isPrimitive())
+ if (p.type().isPrimitive()) {
arguments[index] = ReflectionUtils.getVmDefaultValueForPrimitiveType(p.type());
+ }
}
}
public Object call(Object instance) throws Exception {
try {
- return method.invoke(instance,arguments);
+ return method.invoke(instance, arguments);
} catch (InvocationTargetException e) {
Throwable t = e.getTargetException();
- if (t instanceof Exception)
+ if (t instanceof Exception) {
throw (Exception) t;
+ }
throw e;
}
}
@@ -102,6 +106,7 @@ class MethodBinder {
*/
@SuppressWarnings({"ClassExplicitlyAnnotation"})
private static final class ArgumentImpl implements Argument {
+
private final Argument base;
private final int bias;
@@ -127,7 +132,7 @@ class MethodBinder {
}
public int index() {
- return base.index()+bias;
+ return base.index() + bias;
}
public boolean multiValued() {
diff --git a/hudson-core/src/main/java/hudson/cli/declarative/OptionHandlerExtension.java b/hudson-core/src/main/java/hudson/cli/declarative/OptionHandlerExtension.java
index 72b4908..82e0c11 100644
--- a/hudson-core/src/main/java/hudson/cli/declarative/OptionHandlerExtension.java
+++ b/hudson-core/src/main/java/hudson/cli/declarative/OptionHandlerExtension.java
@@ -7,10 +7,10 @@
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
- * Contributors:
+ * Contributors:
+ *
+ *
*
- *
- *
*
*******************************************************************************/
diff --git a/hudson-core/src/main/java/hudson/cli/declarative/package-info.java b/hudson-core/src/main/java/hudson/cli/declarative/package-info.java
index f6d036f..ee32dfd 100644
--- a/hudson-core/src/main/java/hudson/cli/declarative/package-info.java
+++ b/hudson-core/src/main/java/hudson/cli/declarative/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:
+ *
+ *
*
- *
- *
*
*******************************************************************************/
diff --git a/hudson-core/src/main/java/hudson/cli/handlers/AbstractProjectOptionHandler.java b/hudson-core/src/main/java/hudson/cli/handlers/AbstractProjectOptionHandler.java
index c4b618c..4f4235b 100644
--- a/hudson-core/src/main/java/hudson/cli/handlers/AbstractProjectOptionHandler.java
+++ b/hudson-core/src/main/java/hudson/cli/handlers/AbstractProjectOptionHandler.java
@@ -7,10 +7,10 @@
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
- * Contributors:
+ * Contributors:
+ *
+ *
*
- *
- *
*
*******************************************************************************/
@@ -26,11 +26,13 @@ import org.kohsuke.args4j.spi.Parameters;
import org.kohsuke.args4j.spi.Setter;
/**
- * Refer to {@link AbstractProject} by its name. Registered at META-INF/services.
+ * Refer to {@link AbstractProject} by its name. Registered at
+ * META-INF/services.
*
* @author Kohsuke Kawaguchi
*/
public class AbstractProjectOptionHandler extends OptionHandler<AbstractProject> {
+
public AbstractProjectOptionHandler(CmdLineParser parser, OptionDef option, Setter<AbstractProject> setter) {
super(parser, option, setter);
}
@@ -40,9 +42,10 @@ public class AbstractProjectOptionHandler extends OptionHandler<AbstractProject>
Hudson h = Hudson.getInstance();
String src = params.getParameter(0);
- AbstractProject s = h.getItemByFullName(src,AbstractProject.class);
- if (s==null)
- throw new CmdLineException(owner, "No such job '"+src+"' perhaps you meant "+ AbstractProject.findNearest(src)+"?");
+ AbstractProject s = h.getItemByFullName(src, AbstractProject.class);
+ if (s == null) {
+ throw new CmdLineException(owner, "No such job '" + src + "' perhaps you meant " + AbstractProject.findNearest(src) + "?");
+ }
setter.addValue(s);
return 1;
}
diff --git a/hudson-core/src/main/java/hudson/cli/handlers/TopLevelItemOptionHandler.java b/hudson-core/src/main/java/hudson/cli/handlers/TopLevelItemOptionHandler.java
index 4882f89..3687157 100644
--- a/hudson-core/src/main/java/hudson/cli/handlers/TopLevelItemOptionHandler.java
+++ b/hudson-core/src/main/java/hudson/cli/handlers/TopLevelItemOptionHandler.java
@@ -8,7 +8,7 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- *
+ *
*
*******************************************************************************/
@@ -30,6 +30,7 @@ import org.kohsuke.args4j.spi.Setter;
* @author Kohsuke Kawaguchi
*/
public class TopLevelItemOptionHandler extends OptionHandler<TopLevelItem> {
+
public TopLevelItemOptionHandler(CmdLineParser parser, OptionDef option, Setter<TopLevelItem> setter) {
super(parser, option, setter);
}
@@ -40,8 +41,9 @@ public class TopLevelItemOptionHandler extends OptionHandler<TopLevelItem> {
String src = params.getParameter(0);
TopLevelItem s = h.getItem(src);
- if (s==null)
- throw new CmdLineException(owner, "No such job '"+src+"' perhaps you meant "+ AbstractProject.findNearest(src)+"?");
+ if (s == null) {
+ throw new CmdLineException(owner, "No such job '" + src + "' perhaps you meant " + AbstractProject.findNearest(src) + "?");
+ }
setter.addValue(s);
return 1;
}
diff --git a/hudson-core/src/main/java/hudson/cli/handlers/package-info.java b/hudson-core/src/main/java/hudson/cli/handlers/package-info.java
index 43cfc72..d42194b 100644
--- a/hudson-core/src/main/java/hudson/cli/handlers/package-info.java
+++ b/hudson-core/src/main/java/hudson/cli/handlers/package-info.java
@@ -8,7 +8,7 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- *
+ *
*
*******************************************************************************/