Search in sources :

Example 1 with Validator

use of org.netbeans.api.autoupdate.InstallSupport.Validator in project netbeans-rcp-lite by outersky.

the class ModuleOptions method install.

@NbBundle.Messages({ "# {0} - module name", "# {1} - module version", "MSG_Installing=Installing {0}@{1}", "# {0} - paterns", "MSG_InstallNoMatch=Cannot install. No match for {0}." })
private void install(final Env env, String... pattern) throws CommandException {
    if (!initialized()) {
        refresh(env);
    }
    Pattern[] pats = findMatcher(env, pattern);
    List<UpdateUnit> units = UpdateManager.getDefault().getUpdateUnits();
    OperationContainer<InstallSupport> operate = OperationContainer.createForInstall();
    for (UpdateUnit uu : units) {
        if (uu.getInstalled() != null) {
            continue;
        }
        if (!matches(uu.getCodeName(), pats)) {
            continue;
        }
        if (uu.getAvailableUpdates().isEmpty()) {
            continue;
        }
        UpdateElement ue = uu.getAvailableUpdates().get(0);
        env.getOutputStream().println(Bundle.MSG_Installing(uu.getCodeName(), ue.getSpecificationVersion()));
        operate.add(ue);
    }
    final InstallSupport support = operate.getSupport();
    if (support == null) {
        env.getOutputStream().println(Bundle.MSG_InstallNoMatch(Arrays.asList(pats)));
        return;
    }
    try {
        // NOI18N
        env.getOutputStream().println("modules=" + operate.listAll().size());
        // NOI18N
        ProgressHandle downloadHandle = new CLIInternalHandle("downloading-modules", env).createProgressHandle();
        downloadHandle.setInitialDelay(0);
        final Validator res1 = support.doDownload(downloadHandle, null, false);
        Installer res2 = support.doValidate(res1, null);
        // NOI18N
        ProgressHandle installHandle = new CLIInternalHandle("installing-modules", env).createProgressHandle();
        installHandle.setInitialDelay(0);
        Restarter res3 = support.doInstall(res2, installHandle);
        if (res3 != null) {
            support.doRestart(res3, null);
        }
    } catch (OperationException ex) {
        // a hack
        if (OperationException.ERROR_TYPE.INSTALL.equals(ex.getErrorType())) {
            // probably timeout of loading
            env.getErrorStream().println(ex.getLocalizedMessage());
            throw (CommandException) new CommandException(34, ex.getMessage()).initCause(ex);
        } else {
            try {
                support.doCancel();
                throw (CommandException) new CommandException(32, ex.getMessage()).initCause(ex);
            } catch (OperationException ex1) {
                throw (CommandException) new CommandException(32, ex1.getMessage()).initCause(ex1);
            }
        }
    }
}
Also used : Pattern(java.util.regex.Pattern) Installer(org.netbeans.api.autoupdate.InstallSupport.Installer) CommandException(org.netbeans.api.sendopts.CommandException) Restarter(org.netbeans.api.autoupdate.OperationSupport.Restarter) ProgressHandle(org.netbeans.api.progress.ProgressHandle) Validator(org.netbeans.api.autoupdate.InstallSupport.Validator)

Example 2 with Validator

use of org.netbeans.api.autoupdate.InstallSupport.Validator in project netbeans-rcp-lite by outersky.

the class ModuleOptions method updateModules.

@NbBundle.Messages({ "MSG_UpdateNotFound=Updates not found.", "# {0} - pattern", "MSG_UpdateNoMatchPattern=Nothing to update. The pattern {0} has no match among available updates.", "# {0} - module name", "# {1} - installed version", "# {2} - available version", "MSG_Update=Will update {0}@{1} to version {2}", "# {0} - plugin name", "MSG_Download=Downloading {0}" })
private void updateModules(final Env env, String... pattern) throws CommandException {
    if (!initialized()) {
        refresh(env);
    }
    Pattern[] pats = findMatcher(env, pattern);
    List<UpdateUnit> units = UpdateManager.getDefault().getUpdateUnits(UpdateManager.TYPE.MODULE);
    final Collection<String> firstClass = getFirstClassModules();
    boolean firstClassHasUpdates = false;
    OperationContainer<InstallSupport> operate = OperationContainer.createForUpdate();
    if (!firstClass.isEmpty() && pattern.length == 0) {
        for (UpdateUnit uu : units) {
            if (uu.getInstalled() == null) {
                continue;
            }
            final List<UpdateElement> updates = uu.getAvailableUpdates();
            if (updates.isEmpty()) {
                continue;
            }
            if (!firstClass.contains(uu.getCodeName())) {
                continue;
            }
            final UpdateElement ue = updates.get(0);
            env.getOutputStream().println(Bundle.MSG_Update(uu.getCodeName(), uu.getInstalled().getSpecificationVersion(), ue.getSpecificationVersion()));
            if (operate.canBeAdded(uu, ue)) {
                LOG.fine("  ... update " + uu.getInstalled() + " -> " + ue);
                firstClassHasUpdates = true;
                OperationInfo<InstallSupport> info = operate.add(ue);
                if (info != null) {
                    Set<UpdateElement> requiredElements = info.getRequiredElements();
                    LOG.fine("      ... add required elements: " + requiredElements);
                    operate.add(requiredElements);
                }
            }
        }
    }
    if (!firstClassHasUpdates) {
        for (UpdateUnit uu : units) {
            if (uu.getInstalled() == null) {
                continue;
            }
            final List<UpdateElement> updates = uu.getAvailableUpdates();
            if (updates.isEmpty()) {
                continue;
            }
            if (pattern.length > 0 && !matches(uu.getCodeName(), pats)) {
                continue;
            }
            final UpdateElement ue = updates.get(0);
            env.getOutputStream().println(Bundle.MSG_Update(uu.getCodeName(), uu.getInstalled().getSpecificationVersion(), ue.getSpecificationVersion()));
            if (operate.canBeAdded(uu, ue)) {
                LOG.fine("  ... update " + uu.getInstalled() + " -> " + ue);
                OperationInfo<InstallSupport> info = operate.add(ue);
                if (info != null) {
                    Set<UpdateElement> requiredElements = info.getRequiredElements();
                    LOG.fine("      ... add required elements: " + requiredElements);
                    operate.add(requiredElements);
                }
            }
        }
    }
    final InstallSupport support = operate.getSupport();
    if (support == null) {
        env.getOutputStream().println(pats == null || pats.length == 0 ? Bundle.MSG_UpdateNotFound() : Bundle.MSG_UpdateNoMatchPattern(Arrays.asList(pats)));
        // NOI18N
        env.getOutputStream().println("updates=0");
        return;
    }
    // NOI18N
    env.getOutputStream().println("updates=" + operate.listAll().size());
    // NOI18N
    ProgressHandle downloadHandle = new CLIInternalHandle("downloading-updates", env).createProgressHandle();
    downloadHandle.setInitialDelay(0);
    try {
        final Validator res1 = support.doDownload(downloadHandle, null, false);
        Installer res2 = support.doValidate(res1, null);
        // NOI18N
        ProgressHandle installHandle = new CLIInternalHandle("installing-updates", env).createProgressHandle();
        installHandle.setInitialDelay(0);
        Restarter res3 = support.doInstall(res2, installHandle);
        if (res3 != null) {
            support.doRestart(res3, null);
        }
    } catch (OperationException ex) {
        try {
            support.doCancel();
            throw (CommandException) new CommandException(33, ex.getMessage()).initCause(ex);
        } catch (OperationException ex1) {
            throw (CommandException) new CommandException(33, ex1.getMessage()).initCause(ex1);
        }
    }
}
Also used : Pattern(java.util.regex.Pattern) Installer(org.netbeans.api.autoupdate.InstallSupport.Installer) CommandException(org.netbeans.api.sendopts.CommandException) Restarter(org.netbeans.api.autoupdate.OperationSupport.Restarter) ProgressHandle(org.netbeans.api.progress.ProgressHandle) Validator(org.netbeans.api.autoupdate.InstallSupport.Validator)

Example 3 with Validator

use of org.netbeans.api.autoupdate.InstallSupport.Validator in project netbeans-rcp-lite by outersky.

the class InstallStep method doDownloadAndVerificationAndInstall.

@SuppressWarnings("null")
private void doDownloadAndVerificationAndInstall() {
    OperationContainer<InstallSupport> installContainer = model.getInstallContainer();
    final InstallSupport support = installContainer.getSupport();
    assert support != null : "Operation failed: OperationSupport cannot be null because OperationContainer " + "contains elements: " + installContainer.listAll() + " and invalid elements " + installContainer.listInvalid() + "\ncontainer: " + installContainer;
    assert installContainer.listInvalid().isEmpty() : support + ".listInvalid().isEmpty() but " + installContainer.listInvalid() + " container: " + installContainer;
    if (support == null) {
        log.log(Level.WARNING, "Operation failed: OperationSupport was null because OperationContainer " + "either does not contain any elements: {0} or contains invalid elements {1}", new Object[] { model.getInstallContainer().listAll(), model.getInstallContainer().listInvalid() });
        return;
    }
    Validator v;
    // download
    if ((v = handleDownload(support)) != null) {
        Installer i;
        // verifation
        if ((i = handleValidation(v, support)) != null) {
            // installation
            Restarter r;
            if ((r = handleInstall(i, support)) != null) {
                presentInstallNeedsRestart(r, support);
            } else {
                presentInstallDone();
            }
        }
    }
    if (!canceled) {
        // delay the fire untilt he task completes
        org.netbeans.modules.autoupdate.ui.actions.Installer.RP.post(this::fireChange);
    }
}
Also used : Restarter(org.netbeans.api.autoupdate.OperationSupport.Restarter) InstallSupport(org.netbeans.api.autoupdate.InstallSupport) Installer(org.netbeans.api.autoupdate.InstallSupport.Installer) Validator(org.netbeans.api.autoupdate.InstallSupport.Validator)

Aggregations

Installer (org.netbeans.api.autoupdate.InstallSupport.Installer)3 Validator (org.netbeans.api.autoupdate.InstallSupport.Validator)3 Restarter (org.netbeans.api.autoupdate.OperationSupport.Restarter)3 Pattern (java.util.regex.Pattern)2 ProgressHandle (org.netbeans.api.progress.ProgressHandle)2 CommandException (org.netbeans.api.sendopts.CommandException)2 InstallSupport (org.netbeans.api.autoupdate.InstallSupport)1