use of org.zaproxy.zap.extension.autoupdate.AddOnDependencyChecker.UninstallationResult in project zaproxy by zaproxy.
the class ExtensionAutoUpdate method uninstallAddOns.
/**
* Uninstalls the specified add-ons
*
* @param addons The identifiers of the add-ons to be installed
* @return A string containing any error messages, will be empty if there were no problems
*/
public synchronized String uninstallAddOns(List<String> addons) {
StringBuilder errorMessages = new StringBuilder();
AddOnCollection aoc = this.getLocalVersionInfo();
if (aoc == null) {
String error = Constant.messages.getString("cfu.cmdline.nocfu");
errorMessages.append(error);
CommandLine.error(error);
} else {
for (String aoName : addons) {
AddOn ao = aoc.getAddOn(aoName);
if (ao == null) {
String error = Constant.messages.getString("cfu.cmdline.noaddon", aoName);
errorMessages.append(error);
errorMessages.append("\n");
CommandLine.error(error);
continue;
}
if (ao.isMandatory()) {
String error = Constant.messages.getString("cfu.cmdline.mandatoryaddon", aoName);
errorMessages.append(error);
errorMessages.append("\n");
CommandLine.error(error);
continue;
}
AddOnDependencyChecker addOnDependencyChecker = new AddOnDependencyChecker(getLocalVersionInfo(), aoc);
Set<AddOn> addonSet = new HashSet<>();
addonSet.add(ao);
UninstallationResult result = addOnDependencyChecker.calculateUninstallChanges(addonSet);
// Check to see if other add-ons depend on it
if (result.getUninstallations().size() > 1) {
// Will always report this add-on as needing to be uninstalled
// Remove the specified add-on for the error message
result.getUninstallations().remove(ao);
String error = Constant.messages.getString("cfu.cmdline.addonuninst.uninstalls.required", result.getUninstallations());
errorMessages.append(error);
errorMessages.append("\n");
CommandLine.error(error);
continue;
}
if (this.uninstallAddOn(null, ao, false)) {
CommandLine.info(Constant.messages.getString("cfu.cmdline.uninstallok", aoName));
} else {
String error = Constant.messages.getString("cfu.cmdline.uninstallfail", aoName);
errorMessages.append(error);
errorMessages.append("\n");
CommandLine.error(error);
}
}
}
return errorMessages.toString();
}
Aggregations