/** * Restart if at least one plugin was disabled in this process. * @param results the list of results after the disablement of the plugins. */ private void restartIfNecessary(List<PluginWrapper.PluginDisableResult> results) throws RestartNotSupportedException { if (restart) { for (PluginWrapper.PluginDisableResult oneResult : results) { if (restartIfNecessary(oneResult)) { break; } } } }
@Override protected int run() throws Exception { Jenkins jenkins = Jenkins.get(); jenkins.checkPermission(Jenkins.ADMINISTER); // get the strategy as an enum PluginWrapper.PluginDisableStrategy strategyToUse; try { strategyToUse = PluginWrapper.PluginDisableStrategy.valueOf(strategy.toUpperCase()); } catch (IllegalArgumentException iae) { throw new IllegalArgumentException(hudson.cli.Messages.DisablePluginCommand_NoSuchStrategy(strategy, String.format("%s, %s, %s", PluginWrapper.PluginDisableStrategy.NONE, PluginWrapper.PluginDisableStrategy.MANDATORY, PluginWrapper.PluginDisableStrategy.ALL))); } // disable... List<PluginWrapper.PluginDisableResult> results = jenkins.pluginManager.disablePlugins(strategyToUse, pluginNames); // print results ... printResults(results); // restart if it was required and it's necessary (at least one plugin was disabled in this execution) restartIfNecessary(results); // return the appropriate error code return getResultCode(results); }
/** * Restart if this particular result of the disablement of a plugin and its dependant plugins (depending on the * strategy used) has a plugin disablexd. * @param oneResult the result of a plugin (and its dependants). * @return true if it end up in restarting jenkins. */ private boolean restartIfNecessary(PluginWrapper.PluginDisableResult oneResult) throws RestartNotSupportedException { PluginWrapper.PluginDisableStatus status = oneResult.getStatus(); if (PluginWrapper.PluginDisableStatus.DISABLED.equals(status)) { Jenkins.get().safeRestart(); return true; } if (oneResult.getDependantsDisableStatus().size() > 0) { for (PluginWrapper.PluginDisableResult oneDependantResult : oneResult.getDependantsDisableStatus()) { if (restartIfNecessary(oneDependantResult)) { return true; } } } return false; }