Search in sources :

Example 1 with AddOnChangesResult

use of org.zaproxy.zap.extension.autoupdate.AddOnDependencyChecker.AddOnChangesResult in project zaproxy by zaproxy.

the class ExtensionAutoUpdate method installLocalAddOn.

private void installLocalAddOn(Path file) throws Exception {
    AddOn ao;
    try {
        ao = new AddOn(file);
    } catch (AddOn.InvalidAddOnException e) {
        AddOn.ValidationResult result = e.getValidationResult();
        switch(result.getValidity()) {
            case INVALID_PATH:
                showWarningMessageInvalidAddOnFile(Constant.messages.getString("cfu.warn.invalidAddOn.invalidPath"));
                break;
            case INVALID_FILE_NAME:
                showWarningMessageInvalidAddOnFile(Constant.messages.getString("cfu.warn.invalidAddOn.noZapExtension"));
                break;
            case FILE_NOT_READABLE:
                showWarningMessageInvalidAddOnFile(Constant.messages.getString("cfu.warn.invalidAddOn.notReadable"));
                break;
            case UNREADABLE_ZIP_FILE:
                showWarningMessageInvalidAddOnFile(Constant.messages.getString("cfu.warn.invalidAddOn.errorZip", e.getMessage()));
                break;
            case IO_ERROR_FILE:
                showWarningMessageInvalidAddOnFile(Constant.messages.getString("cfu.warn.invalidAddOn.ioError", e.getMessage()));
                break;
            case MISSING_MANIFEST:
                showWarningMessageInvalidAddOnFile(Constant.messages.getString("cfu.warn.invalidAddOn.missingManifest"));
                break;
            case INVALID_MANIFEST:
                showWarningMessageInvalidAddOnFile(Constant.messages.getString("cfu.warn.invalidAddOn.invalidManifest", e.getMessage()));
                break;
            case INVALID_LIB:
                showWarningMessageInvalidAddOnFile(Constant.messages.getString("cfu.warn.invalidAddOn.invalidLib"));
                break;
            default:
                showWarningMessageInvalidAddOnFile(e.getMessage());
                logger.warn(e);
                break;
        }
        return;
    }
    if (!ao.canLoadInCurrentVersion()) {
        showWarningMessageCantLoadAddOn(ao);
        return;
    }
    AddOnDependencyChecker dependencyChecker = new AddOnDependencyChecker(getLocalVersionInfo(), latestVersionInfo == null ? getLocalVersionInfo() : latestVersionInfo);
    boolean update = false;
    boolean uninstallBeforeAddOnCopy = false;
    AddOnChangesResult result;
    AddOn installedAddOn = getLocalVersionInfo().getAddOn(ao.getId());
    if (installedAddOn != null) {
        if (ao.getVersion().equals(installedAddOn.getVersion())) {
            int reinstall = View.getSingleton().showYesNoDialog(getView().getMainFrame(), new Object[] { Constant.messages.getString("cfu.warn.addOnSameVersion", installedAddOn.getVersion(), View.getSingleton().getStatusUI(installedAddOn.getStatus()).toString(), ao.getVersion(), View.getSingleton().getStatusUI(ao.getStatus()).toString()) });
            if (reinstall != JOptionPane.YES_OPTION) {
                return;
            }
            uninstallBeforeAddOnCopy = true;
        } else if (!ao.isUpdateTo(installedAddOn)) {
            getView().showWarningDialog(Constant.messages.getString("cfu.warn.addOnOlderVersion", installedAddOn.getVersion(), View.getSingleton().getStatusUI(installedAddOn.getStatus()).toString(), ao.getVersion(), View.getSingleton().getStatusUI(ao.getStatus()).toString()));
            return;
        }
        result = dependencyChecker.calculateUpdateChanges(ao);
        update = true;
    } else {
        result = dependencyChecker.calculateInstallChanges(ao);
    }
    if (result.getOldVersions().isEmpty() && result.getUninstalls().isEmpty()) {
        AddOnRunRequirements reqs = ao.calculateInstallRequirements(getLocalVersionInfo().getAddOns());
        if (!reqs.isRunnable()) {
            if (!AddOnRunIssuesUtils.askConfirmationAddOnNotRunnable(Constant.messages.getString("cfu.warn.addOnNotRunnable.message"), Constant.messages.getString("cfu.warn.addOnNotRunnable.question"), getLocalVersionInfo(), ao)) {
                return;
            }
        }
        installLocalAddOn(ao, uninstallBeforeAddOnCopy);
        return;
    }
    if (update) {
        if (!dependencyChecker.confirmUpdateChanges(getView().getMainFrame(), result)) {
            return;
        }
        // The new version of the add-on is installed manually
        result.getNewVersions().remove(ao);
    } else {
        if (!dependencyChecker.confirmInstallChanges(getView().getMainFrame(), result)) {
            return;
        }
        // The add-on is installed manually
        result.getInstalls().remove(ao);
    }
    processAddOnChanges(getView().getMainFrame(), result);
    installLocalAddOn(ao, uninstallBeforeAddOnCopy);
}
Also used : AddOnRunRequirements(org.zaproxy.zap.control.AddOn.AddOnRunRequirements) AddOn(org.zaproxy.zap.control.AddOn) AddOnChangesResult(org.zaproxy.zap.extension.autoupdate.AddOnDependencyChecker.AddOnChangesResult)

Aggregations

AddOn (org.zaproxy.zap.control.AddOn)1 AddOnRunRequirements (org.zaproxy.zap.control.AddOn.AddOnRunRequirements)1 AddOnChangesResult (org.zaproxy.zap.extension.autoupdate.AddOnDependencyChecker.AddOnChangesResult)1