public boolean isActivated() { if (pluginsWithCycle == null) { pluginsWithCycle = new ArrayList<String>(); for (PluginWrapper p : Jenkins.getInstance().getPluginManager().getPlugins()) { if (p.hasCycleDependency()) { pluginsWithCycle.add(p.getShortName()); isActive = true; } } } return isActive; }
/** TODO: revisit where/how to expose this. This is an experiment. */ public void dynamicLoad(File arc) throws IOException, InterruptedException, RestartRequiredException { LOGGER.info("Attempting to dynamic load " + arc); final PluginWrapper p = strategy.createPluginWrapper(arc); String sn = p.getShortName(); if (getPlugin(sn) != null) throw new RestartRequiredException( Messages._PluginManager_PluginIsAlreadyInstalled_RestartRequired(sn)); if (p.supportsDynamicLoad() == YesNoMaybe.NO) throw new RestartRequiredException( Messages._PluginManager_PluginDoesntSupportDynamicLoad_RestartRequired(sn)); // there's no need to do cyclic dependency check, because we are deploying one at a time, // so existing plugins can't be depending on this newly deployed one. plugins.add(p); activePlugins.add(p); try { p.resolvePluginDependencies(); strategy.load(p); Jenkins.getInstance().refreshExtensions(); p.getPlugin().postInitialize(); } catch (Exception e) { failedPlugins.add(new FailedPlugin(sn, e)); activePlugins.remove(p); plugins.remove(p); throw new IOException("Failed to install " + sn + " plugin", e); } // run initializers in the added plugin Reactor r = new Reactor(InitMilestone.ordering()); r.addAll( new InitializerFinder(p.classLoader) { @Override protected boolean filter(Method e) { return e.getDeclaringClass().getClassLoader() != p.classLoader || super.filter(e); } }.discoverTasks(r)); try { new InitReactorRunner().run(r); } catch (ReactorException e) { throw new IOException("Failed to initialize " + sn + " plugin", e); } LOGGER.info("Plugin " + sn + " dynamically installed"); }
/** * Get the plugin instance with the given short name. * * @param shortName the short name of the plugin * @return The plugin singleton or <code>null</code> if a plugin with the given short name does * not exist. */ public PluginWrapper getPlugin(String shortName) { for (PluginWrapper p : plugins) { if (p.getShortName().equals(shortName)) return p; } return null; }