use of org.zaproxy.zap.extension.autoupdate.UninstallationProgressDialogue.AddOnUninstallListener in project zaproxy by zaproxy.
the class ExtensionAutoUpdate method uninstallAddOnsWithView.
boolean uninstallAddOnsWithView(final Window caller, final Set<AddOn> addOns, final boolean updates, final Set<AddOn> failedUninstallations) {
if (addOns == null || addOns.isEmpty()) {
return true;
}
if (!EventQueue.isDispatchThread()) {
try {
EventQueue.invokeAndWait(new Runnable() {
@Override
public void run() {
uninstallAddOnsWithView(caller, addOns, updates, failedUninstallations);
}
});
} catch (InvocationTargetException | InterruptedException e) {
logger.error("Failed to uninstall add-ons:", e);
return false;
}
return failedUninstallations.isEmpty();
}
final Window parent = getWindowParent(caller);
final UninstallationProgressDialogue waitDialogue = new UninstallationProgressDialogue(parent, addOns);
waitDialogue.addAddOnUninstallListener(new AddOnUninstallListener() {
@Override
public void uninstallingAddOn(AddOn addOn, boolean updating) {
if (updating) {
String message = MessageFormat.format(Constant.messages.getString("cfu.output.replacing") + "\n", addOn.getName(), Integer.valueOf(addOn.getFileVersion()));
getView().getOutputPanel().append(message);
}
}
@Override
public void addOnUninstalled(AddOn addOn, boolean update, boolean uninstalled) {
if (uninstalled) {
if (!update && addonsDialog != null) {
addonsDialog.notifyAddOnUninstalled(addOn);
}
String message = MessageFormat.format(Constant.messages.getString("cfu.output.uninstalled") + "\n", addOn.getName(), Integer.valueOf(addOn.getFileVersion()));
getView().getOutputPanel().append(message);
} else {
if (addonsDialog != null) {
addonsDialog.notifyAddOnFailedUninstallation(addOn);
}
String message;
if (update) {
message = MessageFormat.format(Constant.messages.getString("cfu.output.replace.failed") + "\n", addOn.getName(), Integer.valueOf(addOn.getFileVersion()));
} else {
message = MessageFormat.format(Constant.messages.getString("cfu.output.uninstall.failed") + "\n", addOn.getName(), Integer.valueOf(addOn.getFileVersion()));
}
getView().getOutputPanel().append(message);
}
}
});
SwingWorker<Void, UninstallationProgressEvent> a = new SwingWorker<Void, UninstallationProgressEvent>() {
@Override
protected void process(List<UninstallationProgressEvent> events) {
waitDialogue.update(events);
}
@Override
protected Void doInBackground() {
UninstallationProgressHandler progressHandler = new UninstallationProgressHandler() {
@Override
protected void publishEvent(UninstallationProgressEvent event) {
publish(event);
}
};
for (AddOn addOn : addOns) {
if (!uninstall(addOn, updates, progressHandler)) {
failedUninstallations.add(addOn);
}
}
if (!failedUninstallations.isEmpty()) {
logger.warn("Not all add-ons were successfully uninstalled: " + failedUninstallations);
}
return null;
}
};
waitDialogue.bind(a);
a.execute();
waitDialogue.setSynchronous(updates);
waitDialogue.setVisible(true);
return failedUninstallations.isEmpty();
}
Aggregations