Skip to content

Commit

Permalink
[JENKINS-27177] Some polishment.
Browse files Browse the repository at this point in the history
  • Loading branch information
MRamonLeon committed Sep 25, 2018
1 parent 43a1611 commit 1062f9a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
16 changes: 8 additions & 8 deletions core/src/main/java/hudson/cli/DisablePluginCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
* continues, but the exit code is 16, instead of 0. Disabling an already disabled plugin does nothing. It only restart
* if, at least, one plugin has been disabled and the restart option was set.
*
* @since 2.136
* @since TODO
*/
@Extension
public class DisablePluginCommand extends CLICommand {
Expand All @@ -59,6 +59,7 @@ public String getShortDescription() {

@Override
protected void printUsageSummary(PrintStream stderr) {
super.printUsageSummary(stderr);
stderr.println(Messages.DisablePluginCommand_PrintUsageSummary());
}

Expand Down Expand Up @@ -91,10 +92,10 @@ protected int run() throws Exception {
* Try to disable a plugin.
* @param manager The PluginManager.
* @param shortName The name of the plugin to disable.
* @return The result of the disabling of this plugin. See {@link DISABLING_STATUS}
* @return The result of the disabling of this plugin. See {@link DisablingStatus}
* @throws IOException An exception disabling the plugin. See {@link PluginWrapper#disable()}
*/
private DISABLING_STATUS disablePlugin(PluginManager manager, String shortName) throws IOException {
private DisablingStatus disablePlugin(PluginManager manager, String shortName) throws IOException {
PluginWrapper plugin = manager.getPlugin(shortName);
if (plugin == null) {
throw new IllegalArgumentException(Messages.DisablePluginCommand_NoSuchPlugin(shortName)); // exit with 3
Expand All @@ -103,31 +104,30 @@ private DISABLING_STATUS disablePlugin(PluginManager manager, String shortName)
if (!plugin.isEnabled()) {
stdout.format(Messages.DisablePluginCommand_Already_Disabled(shortName));
stdout.println();
return DISABLING_STATUS.ALREADY_DISABLED;
return DisablingStatus.ALREADY_DISABLED;
}

Set<String> dependants = plugin.getDependants();
for (String dependant : dependants) {
PluginWrapper dependantPlugin = manager.getPlugin(dependant);
if (dependantPlugin != null && dependantPlugin.isEnabled()) {
// TO-DO: stdout or stderr? the process continues but as the result code is not 0, it looks like stderr
stderr.format(Messages.DisablePluginCommand_Plugin_Has_Dependant(shortName, dependant));
stderr.println();
return DISABLING_STATUS.NOT_DISABLED_DEPENDANTS;
return DisablingStatus.NOT_DISABLED_DEPENDANTS;
}
}

plugin.disable();
stdout.format(Messages.DisablePluginCommand_Plugin_Disabled(plugin.getShortName()));
stdout.println();

return DISABLING_STATUS.DISABLED;
return DisablingStatus.DISABLED;
}

/**
* An enum to hold the status of a disabling action. To do it more reader-friendly.
*/
private enum DISABLING_STATUS {
private enum DisablingStatus {
DISABLED,
ALREADY_DISABLED,
NOT_DISABLED_DEPENDANTS
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/resources/hudson/cli/Messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ CliProtocol2.displayName=Jenkins CLI Protocol/2 (transport encryption)
DisablePluginCommand.ShortDescription=\
Disables one or more installed plugins.
DisablePluginCommand.Already.Disabled=The plugin {0} was already disabled.
DisablePluginCommand.Plugin.Has.Dependant=The plugin {0} has, at least, one dependant plugin ({1}), so it can't be disabled.
DisablePluginCommand.Plugin.Has.Dependant=The plugin {0} has, at least, one dependant plugin ({1}), so it cannot be disabled.
DisablePluginCommand.Plugin.Disabled=Plugin {0} disabled.
DisablePluginCommand.NoSuchPlugin=No such plugin found with the name {0}.
DisablePluginCommand.PrintUsageSummary=\
Expand Down

0 comments on commit 1062f9a

Please sign in to comment.