Skip to content
Permalink
Browse files

[JENKINS-12302]

Make sure that we don't require Jenkins.getInstance() on CLICommand, since it can run on slaves.
  • Loading branch information...
kohsuke committed Mar 21, 2012
1 parent 196aadc commit 7110ddb7d2a2f141a6887ffe352526db91046867
Showing with 14 additions and 11 deletions.
  1. +14 −11 core/src/main/java/hudson/cli/CLICommand.java
@@ -472,17 +472,20 @@ public static CLICommand getCurrent() {
static {
// register option handlers that are defined
ClassLoaders cls = new ClassLoaders();
cls.put(Jenkins.getInstance().getPluginManager().uberClassLoader);

ResourceNameIterator servicesIter =
new DiscoverServiceNames(cls).findResourceNames(OptionHandler.class.getName());
final ResourceClassIterator itr =
new DiscoverClasses(cls).findResourceClasses(servicesIter);

while(itr.hasNext()) {
Class h = itr.nextResourceClass().loadClass();
Class c = Types.erasure(Types.getTypeArgument(Types.getBaseClass(h, OptionHandler.class), 0));
CmdLineParser.registerHandler(c,h);
Jenkins j = Jenkins.getInstance();
if (j!=null) {// only when running on the master
cls.put(j.getPluginManager().uberClassLoader);

ResourceNameIterator servicesIter =
new DiscoverServiceNames(cls).findResourceNames(OptionHandler.class.getName());
final ResourceClassIterator itr =
new DiscoverClasses(cls).findResourceClasses(servicesIter);

while(itr.hasNext()) {
Class h = itr.nextResourceClass().loadClass();
Class c = Types.erasure(Types.getTypeArgument(Types.getBaseClass(h, OptionHandler.class), 0));
CmdLineParser.registerHandler(c,h);
}
}
}
}

0 comments on commit 7110ddb

Please sign in to comment.
You can’t perform that action at this time.