public @Nonnull PluginDisableResult disable(@Nonnull PluginDisableStrategy strategy) {
        PluginDisableResult result = new PluginDisableResult(shortName);

        if (!this.isEnabled()) {
            result.setMessage(Messages.PluginWrapper_Already_Disabled(shortName));
            result.setStatus(ALREADY_DISABLED);
            return result;
        }

        // Act as a flag indicating if this plugin, finally, can be disabled. If there is a not-disabled-dependent
        // plugin, this one couldn't be disabled.
        String aDependentNotDisabled = null;

        // List of dependents plugins to 'check'. 'Check' means disable for mandatory or all strategies, or review if
        // this dependent-mandatory plugin is enabled in order to return an error for the NONE strategy.
        Set<String> dependentsToCheck = dependentsToCheck(strategy);

        // Review all the dependents and add to the plugin result what happened with its dependents
        for (String dependent : dependentsToCheck) {
            PluginWrapper dependentPlugin = parent.getPlugin(dependent);

            // The dependent plugin doesn't exist, add an error to the report
            if (dependentPlugin == null) {
                PluginDisableResult dependentStatus = new PluginDisableResult(dependent, NO_SUCH_PLUGIN, Messages.PluginWrapper_NoSuchPlugin(dependent));
                result.addDependentDisableStatus(dependentStatus);

            // If the strategy is none and there is some enabled dependent plugin, the plugin cannot be disabled. If
            // this dependent plugin is not enabled, continue searching for one enabled.
            } else if (strategy.equals(PluginDisableStrategy.NONE)) {
                if (dependentPlugin.isEnabled()) {
                    aDependentNotDisabled = dependent;
                    break; // in this case, we don't need to continue with the rest of its dependents
                }

            // If the strategy is not none and this dependent plugin is not enabled, add it as already disabled
            } else if (!dependentPlugin.isEnabled()) {
                PluginDisableResult dependentStatus = new PluginDisableResult(dependent, ALREADY_DISABLED, Messages.PluginWrapper_Already_Disabled(dependent));
                result.addDependentDisableStatus(dependentStatus);

            // If the strategy is not none and this dependent plugin is enabled, disable it
            } else {
                // As there is no cycles in the plugin dependencies, the recursion shouldn't be infinite. The
                // strategy used is the same for its dependents plugins
                PluginDisableResult dependentResult = dependentPlugin.disable(strategy);
                PluginDisableStatus dependentStatus = dependentResult.status;

                // If something wrong happened, flag this dependent plugin to set the plugin later as not-disabled due
                // to its dependents plugins.
                if (ERROR_DISABLING.equals(dependentStatus) || NOT_DISABLED_DEPENDANTS.equals(dependentStatus)) {
                    aDependentNotDisabled = dependent;
                    break; // we found a dependent plugin enabled, stop looking for dependent plugins to disable.
                }
                result.addDependentDisableStatus(dependentResult);
            }
        }

        // If there is no enabled-dependent plugin, disable this plugin and add it to the result
        if (aDependentNotDisabled == null) {
            try {
                this.disableWithoutCheck();
                result.setMessage(Messages.PluginWrapper_Plugin_Disabled(shortName));
                result.setStatus(DISABLED);
            } catch (IOException io) {
                result.setMessage(Messages.PluginWrapper_Error_Disabling(shortName, io.toString()));
                result.setStatus(ERROR_DISABLING);
            }
        // if there is yet some not disabled dependent plugin (only possible with none strategy), this plugin cannot
        // be disabled.
        } else {
            result.setMessage(Messages.PluginWrapper_Plugin_Has_Dependent(shortName, aDependentNotDisabled, strategy));
            result.setStatus(NOT_DISABLED_DEPENDANTS);
        }

        return result;
    }
public @ Nonnull PluginDisableResult disable ( @ Nonnull PluginDisableStrategy strategy ) { PluginDisableResult result = new PluginDisableResult ( shortName ) ; if ( ! this . isEnabled ( ) ) { result . setMessage ( Messages . PluginWrapper_Already_Disabled ( shortName ) ) ; result . setStatus ( ALREADY_DISABLED ) ; return result ; } String aDependentNotDisabled = null ; Set < String > dependentsToCheck = dependentsToCheck ( strategy ) ; for ( String dependent : dependentsToCheck ) { PluginWrapper dependentPlugin = parent . getPlugin ( dependent ) ; if ( dependentPlugin == null ) { PluginDisableResult dependentStatus = new PluginDisableResult ( dependent , NO_SUCH_PLUGIN , Messages . PluginWrapper_NoSuchPlugin ( dependent ) ) ; result . addDependentDisableStatus ( dependentStatus ) ; } else if ( strategy . equals ( PluginDisableStrategy . NONE ) ) { if ( dependentPlugin . isEnabled ( ) ) { aDependentNotDisabled = dependent ; break ; } } else if ( ! dependentPlugin . isEnabled ( ) ) { PluginDisableResult dependentStatus = new PluginDisableResult ( dependent , ALREADY_DISABLED , Messages . PluginWrapper_Already_Disabled ( dependent ) ) ; result . addDependentDisableStatus ( dependentStatus ) ; } else { PluginDisableResult dependentResult = dependentPlugin . disable ( strategy ) ; PluginDisableStatus dependentStatus = dependentResult . status ; if ( ERROR_DISABLING . equals ( dependentStatus ) || NOT_DISABLED_DEPENDANTS . equals ( dependentStatus ) ) { aDependentNotDisabled = dependent ; break ; } result . addDependentDisableStatus ( dependentResult ) ; } } if ( aDependentNotDisabled == null ) { try { this . disableWithoutCheck ( ) ; result . setMessage ( Messages . PluginWrapper_Plugin_Disabled ( shortName ) ) ; result . setStatus ( DISABLED ) ; } catch ( IOException io ) { result . setMessage ( Messages . PluginWrapper_Error_Disabling ( shortName , io . toString ( ) ) ) ; result . setStatus ( ERROR_DISABLING ) ; } } else { result . setMessage ( Messages . PluginWrapper_Plugin_Has_Dependent ( shortName , aDependentNotDisabled , strategy ) ) ; result . setStatus ( NOT_DISABLED_DEPENDANTS ) ; } return result ; }
Disable this plugin using a strategy.
@param strategy strategy to use
@return an object representing the result of the disablement of this plugin and its dependents plugins.