Search in sources :

Example 1 with InstallSupport

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

the class ModuleInstallerSupport method installPlugins.

public Object installPlugins(final String displayName, Set<String> cnbs) throws OperationException {
    Collection<UpdateUnit> units = findModules(cnbs);
    if (units == null) {
        final String searchMessage = displayName != null ? searching_handle_single(displayName) : searching_handle();
        final String resolveTitle = displayName != null ? resolve_title_single(displayName) : resolve_title();
        final ProgressHandle handle = ProgressHandleFactory.createHandle(searchMessage);
        initButtons();
        final DialogDescriptor searching = new DialogDescriptor(searchingPanel(new JLabel(searchMessage), ProgressHandleFactory.createProgressComponent(handle)), resolveTitle, true, null);
        handle.setInitialDelay(0);
        handle.start();
        searching.setOptions(new Object[] { NotifyDescriptor.CANCEL_OPTION });
        searching.setMessageType(NotifyDescriptor.PLAIN_MESSAGE);
        final Dialog dlg = DialogDisplayer.getDefault().createDialog(searching);
        RP.post(new Runnable() {

            @Override
            public void run() {
                // May be first start, when no update lists have yet been downloaded.
                try {
                    for (UpdateUnitProvider p : UpdateUnitProviderFactory.getDefault().getUpdateUnitProviders(true)) {
                        p.refresh(handle, true);
                    }
                    // close searching
                    dlg.dispose();
                } catch (IOException ex) {
                    LOG.log(Level.FINE, ex.getMessage(), ex);
                    if (!dlg.isVisible()) {
                        LOG.fine("dialog not visible => do nothing");
                        return;
                    }
                    DialogDescriptor networkProblem = new DialogDescriptor(// message
                    problemPanel(resolveTitle, networkproblem_message()), // title
                    networkproblem_header(), // modal
                    true, null);
                    networkProblem.setOptions(new Object[] { tryAgain, proxySettings, NotifyDescriptor.CANCEL_OPTION });
                    networkProblem.setAdditionalOptions(closingOptions);
                    networkProblem.setClosingOptions(fullClosingOptions);
                    networkProblem.setMessageType(NotifyDescriptor.WARNING_MESSAGE);
                    Dialog networkProblemDialog = DialogDisplayer.getDefault().createDialog(networkProblem);
                    networkProblemDialog.setVisible(true);
                    Object answer = networkProblem.getValue();
                    if (NotifyDescriptor.CANCEL_OPTION.equals(answer) || Arrays.asList(closingOptions).contains(answer) || answer.equals(NotifyDescriptor.DEFAULT_OPTION)) /* escape */
                    {
                        LOG.fine("cancel network problem dialog");
                        searching.setValue(answer);
                        dlg.dispose();
                    } else if (tryAgain.equals(answer)) {
                        LOG.fine("try again searching");
                        RP.post(this);
                    } else {
                        assert false : "Unknown " + answer;
                    }
                }
            }
        });
        dlg.setVisible(true);
        handle.finish();
        if (NotifyDescriptor.CANCEL_OPTION.equals(searching.getValue()) || searching.getValue().equals(NotifyDescriptor.DEFAULT_OPTION)) /* escape */
        {
            LOG.log(Level.FINE, "user canceled searching for {0}", cnbs);
            return showNoDownloadDialog(displayName, cnbs);
        } else if (Arrays.asList(closingOptions).contains(searching.getValue())) {
            return searching.getValue();
        }
        units = findModules(cnbs);
        if (units == null) {
            LOG.log(Level.FINE, "could not find {0} on any update site", cnbs);
            return showNoDownloadDialog(displayName, cnbs);
        }
    }
    List<UpdateUnit> toHandle = new ArrayList<UpdateUnit>(units);
    OperationContainer<OperationSupport> oc = null;
    for (Iterator<UpdateUnit> it = toHandle.iterator(); it.hasNext(); ) {
        UpdateUnit unit = it.next();
        // check if module installed
        if (unit.getInstalled() != null) {
            if (LOG.isLoggable(Level.FINE)) {
                LOG.fine(unit.getInstalled() + " already installed. Is active? " + unit.getInstalled().isEnabled());
            }
            if (unit.getInstalled().isEnabled()) {
                it.remove();
                continue;
            } else {
                if (oc == null) {
                    oc = OperationContainer.createForEnable();
                }
                if (!oc.canBeAdded(unit, unit.getInstalled())) {
                    throw new OperationException(OperationException.ERROR_TYPE.ENABLE, "could not add " + unit.getInstalled() + " for activation");
                }
                for (UpdateElement req : oc.add(unit.getInstalled()).getRequiredElements()) {
                    oc.add(req);
                }
                it.remove();
                continue;
            }
        }
    }
    if (oc != null) {
        ProgressHandle activeHandle = ProgressHandleFactory.createHandle(displayName != null ? active_handle_single(displayName) : active_handle());
        Restarter restarter = oc.getSupport().doOperation(activeHandle);
        assert restarter == null : "No Restater need to make units active";
    }
    if (toHandle.isEmpty()) {
        return null;
    }
    OperationContainer<InstallSupport> ocInstall = OperationContainer.createForInstall();
    for (Iterator<UpdateUnit> it = toHandle.iterator(); it.hasNext(); ) {
        UpdateUnit unit = it.next();
        List<UpdateElement> updates = unit.getAvailableUpdates();
        if (updates.isEmpty()) {
            throw new OperationException(OperationException.ERROR_TYPE.INSTALL, "no updates for " + unit);
        }
        UpdateElement element = updates.get(0);
        if (!ocInstall.canBeAdded(unit, element)) {
            throw new OperationException(OperationException.ERROR_TYPE.INSTALL, "could not add " + element + " to updates");
        }
        for (UpdateElement req : ocInstall.add(element).getRequiredElements()) {
            ocInstall.add(req);
        }
        it.remove();
    }
    assert toHandle.isEmpty() : "These unit were not handled " + toHandle;
    if (!PluginManager.openInstallWizard(ocInstall)) {
        LOG.fine("user canceled PM");
        return showNoDownloadDialog(displayName, cnbs);
    }
    return null;
}
Also used : InstallSupport(org.netbeans.api.autoupdate.InstallSupport) UpdateUnit(org.netbeans.api.autoupdate.UpdateUnit) UpdateElement(org.netbeans.api.autoupdate.UpdateElement) ArrayList(java.util.ArrayList) JLabel(javax.swing.JLabel) IOException(java.io.IOException) OperationSupport(org.netbeans.api.autoupdate.OperationSupport) UpdateUnitProvider(org.netbeans.api.autoupdate.UpdateUnitProvider) Restarter(org.netbeans.api.autoupdate.OperationSupport.Restarter) ProgressHandle(org.netbeans.api.progress.ProgressHandle) Dialog(java.awt.Dialog) DialogDescriptor(org.openide.DialogDescriptor) OperationException(org.netbeans.api.autoupdate.OperationException)

Example 2 with InstallSupport

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

the class InstallStep method storeSettings.

@Override
public void storeSettings(WizardDescriptor wd) {
    assert !WizardDescriptor.PREVIOUS_OPTION.equals(wd.getValue()) : "Cannot invoke Back in this case.";
    if (wasStored) {
        return;
    }
    this.wasStored = true;
    InstallSupport support = model.getBaseContainer().getSupport();
    if (WizardDescriptor.CANCEL_OPTION.equals(wd.getValue()) || WizardDescriptor.CLOSED_OPTION.equals(wd.getValue())) {
        try {
            model.doCleanup(true);
        } catch (OperationException x) {
            Logger.getLogger(InstallStep.class.getName()).log(Level.INFO, x.getMessage(), x);
        }
    } else if (restarter != null) {
        if (support == null) {
            assert model.getInstallContainer().listAll() == null : "storeSettings failed. OperationSupport is null because OperationContainer " + "contains no elements: " + model.getInstallContainer().listAll();
            return;
        }
        if (panel.restartNow()) {
            resetLastCheckWhenUpdatingFirstClassModules(model.getAllUpdateElements());
            handleLazyUnits(clearLazyUnits, false);
            try {
                support.doRestart(restarter, null);
            } catch (OperationException x) {
                log.log(Level.INFO, x.getMessage(), x);
            }
        } else {
            resetLastCheckWhenUpdatingFirstClassModules(model.getAllUpdateElements());
            support.doRestartLater(restarter);
            handleLazyUnits(clearLazyUnits, true);
            try {
                model.doCleanup(false);
            } catch (OperationException x) {
                log.log(Level.INFO, x.getMessage(), x);
            }
            // NOI18N
            notifyInstallRestartNeeded(support, restarter);
        }
    } else {
        try {
            model.doCleanup(!WizardDescriptor.FINISH_OPTION.equals(wd.getValue()));
        } catch (OperationException x) {
            log.log(Level.INFO, x.getMessage(), x);
        }
    }
}
Also used : InstallSupport(org.netbeans.api.autoupdate.InstallSupport) OperationException(org.netbeans.api.autoupdate.OperationException)

Example 3 with InstallSupport

use of org.netbeans.api.autoupdate.InstallSupport 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)

Example 4 with InstallSupport

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

the class AutoupdateCheckScheduler method checkUpdateElements.

public static Collection<UpdateElement> checkUpdateElements(OperationType type, Collection<String> problems, boolean forceReload, Collection<UpdateElement> visibleUpdateElement) {
    // check
    err.log(Level.FINEST, "Check UpdateElements for " + type);
    if (forceReload) {
        // NOI18N
        ProgressHandle dummyHandler = ProgressHandleFactory.createHandle("dummy-check-for-updates");
        ProgressHandleFactory.createProgressComponent(dummyHandler);
        dummyHandler.start();
        Collection<String> updateProblems = refreshUpdateCenters(dummyHandler);
        if (problems != null && updateProblems != null) {
            problems.addAll(updateProblems);
        }
    }
    List<UpdateUnit> units = UpdateManager.getDefault().getUpdateUnits(UpdateManager.TYPE.MODULE);
    boolean handleUpdates = OperationType.UPDATE == type;
    Collection<UnitCategory> cats = handleUpdates ? Utilities.makeUpdateCategories(units, false) : Utilities.makeAvailableCategories(units, false);
    if (cats == null || cats.isEmpty()) {
        err.log(Level.FINE, "findUpdateElements(" + type + ") doesn't find any elements.");
        return null;
    }
    // 1. try to install all available updates
    Collection<UpdateElement> updates = new HashSet<UpdateElement>();
    boolean somePendingElements = false;
    boolean someBrokenDependencies = false;
    OperationContainer<InstallSupport> container = handleUpdates ? OperationContainer.createForUpdate() : OperationContainer.createForInstall();
    List<UpdateElement> elements = new ArrayList<UpdateElement>();
    for (UnitCategory cat : cats) {
        for (Unit u : cat.getUnits()) {
            if (u instanceof Unit.Available) {
                elements.add(((Unit.Available) u).getRelevantElement());
            } else if (u instanceof Unit.CompoundUpdate) {
                for (UpdateUnit uu : ((Unit.CompoundUpdate) u).getUpdateUnits()) {
                    elements.add(uu.getAvailableUpdates().get(0));
                }
                if (((Unit.CompoundUpdate) u).getRealUpdate() != null) {
                    elements.add(((Unit.CompoundUpdate) u).getRealUpdate());
                }
            } else if (u instanceof Unit.Update) {
                elements.add(((Unit.Update) u).getRelevantElement());
            }
        }
    }
    for (UpdateElement element : elements) {
        if (!somePendingElements) {
            if (container.canBeAdded(element.getUpdateUnit(), element)) {
                OperationInfo<InstallSupport> operationInfo = container.add(element);
                if (operationInfo == null) {
                    updates.add(element);
                    continue;
                }
                Collection<UpdateElement> reqs = new HashSet<UpdateElement>(operationInfo.getRequiredElements());
                Collection<String> brokenDeps = operationInfo.getBrokenDependencies();
                if (!brokenDeps.isEmpty()) {
                    err.log(Level.WARNING, // NOI18N
                    "Plugin " + operationInfo + " cannot be installed because some dependencies cannot be satisfied: " + // NOI18N
                    brokenDeps);
                    someBrokenDependencies = true;
                    break;
                }
                for (UpdateElement tmpEl : reqs) {
                    if (tmpEl.getUpdateUnit().isPending()) {
                        err.log(Level.WARNING, // NOI18N
                        "Plugin " + operationInfo.getUpdateElement() + " depends on " + tmpEl + " in pending state.");
                        somePendingElements = true;
                        updates = Collections.emptySet();
                        break;
                    }
                }
                if (!somePendingElements) {
                    container.add(reqs);
                    updates.add(element);
                }
            }
        }
    }
    if (!somePendingElements && !container.listInvalid().isEmpty()) {
        err.log(Level.WARNING, // NOI18N
        "Plugins " + updates + " cannot be installed, Install Container contains invalid elements " + // NOI18N
        container.listInvalid());
    }
    if (!somePendingElements && someBrokenDependencies) {
        // 2. if some problem then try one by one
        updates = new HashSet<UpdateElement>();
        for (UpdateElement element : elements) {
            OperationContainer<InstallSupport> oc = handleUpdates ? OperationContainer.createForUpdate() : OperationContainer.createForInstall();
            UpdateUnit unit = element.getUpdateUnit();
            if (oc.canBeAdded(unit, element)) {
                OperationInfo<InstallSupport> operationInfo = oc.add(element);
                if (operationInfo == null) {
                    updates.add(element);
                    continue;
                }
                boolean skip = false;
                Collection<UpdateElement> reqs = new HashSet<UpdateElement>(operationInfo.getRequiredElements());
                for (UpdateElement tmpEl : reqs) {
                    if (tmpEl.getUpdateUnit().isPending()) {
                        err.log(Level.WARNING, // NOI18N
                        "Plugin " + element + " depends on " + tmpEl + " in pending state.");
                        skip = true;
                    }
                }
                if (skip) {
                    continue;
                }
                oc.add(reqs);
                Collection<String> brokenDeps = new HashSet<String>();
                for (OperationInfo<InstallSupport> info : oc.listAll()) {
                    brokenDeps.addAll(info.getBrokenDependencies());
                }
                if (brokenDeps.isEmpty() && oc.listInvalid().isEmpty()) {
                    updates.add(element);
                } else {
                    oc.removeAll();
                    if (!brokenDeps.isEmpty()) {
                        err.log(Level.WARNING, // NOI18N
                        "Plugin " + element + " cannot be installed because some dependencies cannot be satisfied: " + // NOI18N
                        brokenDeps);
                    } else {
                        err.log(Level.WARNING, // NOI18N
                        "Plugin " + element + " cannot be installed, Install Container contains invalid elements " + // NOI18N
                        oc.listInvalid());
                    }
                }
            }
        }
    }
    // if any then notify updates
    if (visibleUpdateElement == null) {
        err.log(Level.FINE, "findUpdateElements(" + type + ") returns " + updates.size() + " elements.");
        return updates;
    } else {
        for (UnitCategory cat : cats) {
            for (Unit u : cat.getUnits()) {
                assert u instanceof Unit.Update : u + " has to be instanceof Unit.Update";
                if (u instanceof Unit.Update) {
                    visibleUpdateElement.add(((Unit.Update) u).getRelevantElement());
                }
            }
        }
        err.log(Level.FINE, "findUpdateElements(" + type + ") returns " + visibleUpdateElement.size() + " visible elements (" + updates.size() + " in all)");
        return updates;
    }
}
Also used : InstallSupport(org.netbeans.api.autoupdate.InstallSupport) UpdateUnit(org.netbeans.api.autoupdate.UpdateUnit) UpdateElement(org.netbeans.api.autoupdate.UpdateElement) ArrayList(java.util.ArrayList) UpdateUnit(org.netbeans.api.autoupdate.UpdateUnit) LazyUnit(org.netbeans.modules.autoupdate.ui.wizards.LazyInstallUnitWizardIterator.LazyUnit) Unit(org.netbeans.modules.autoupdate.ui.Unit) ProgressHandle(org.netbeans.api.progress.ProgressHandle) UnitCategory(org.netbeans.modules.autoupdate.ui.UnitCategory) HashSet(java.util.HashSet)

Example 5 with InstallSupport

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

the class PluginManager method openInstallWizard.

/**
 * Open standard dialog for installing set of modules. Shows it to the user,
 * asks for confirmation, license acceptance, etc. The whole operation requires
 * AWT dispatch thread access (to show the dialog) and blocks
 * (until the user clicks through), so either call from AWT dispatch thread
 * directly, or be sure you hold no locks and block no progress of other
 * threads to avoid deadlocks.
 *
 * @param container the container with list of modules for install
 * @param runInBackground if <code>true</code> then installation run in the background after license acceptance
 */
public static void openInstallWizard(OperationContainer<InstallSupport> container, boolean runInBackground) {
    if (container == null) {
        // NOI18N
        throw new IllegalArgumentException("OperationContainer cannot be null.");
    }
    List<OperationContainer.OperationInfo<InstallSupport>> all = container.listAll();
    if (all.isEmpty()) {
        // NOI18N
        throw new IllegalArgumentException("OperationContainer cannot be empty.");
    }
    List<OperationContainer.OperationInfo<InstallSupport>> invalid = container.listInvalid();
    if (!invalid.isEmpty()) {
        // NOI18N
        throw new IllegalArgumentException("OperationContainer cannot contain invalid elements but " + invalid);
    }
    OperationInfo<InstallSupport> info = all.get(0);
    OperationType doOperation = info.getUpdateUnit().getInstalled() == null ? OperationType.INSTALL : OperationType.UPDATE;
    new InstallUnitWizard().invokeWizard(new InstallUnitWizardModel(doOperation, container), true, runInBackground);
}
Also used : OperationInfo(org.netbeans.api.autoupdate.OperationContainer.OperationInfo) InstallSupport(org.netbeans.api.autoupdate.InstallSupport) InstallUnitWizard(org.netbeans.modules.autoupdate.ui.wizards.InstallUnitWizard) OperationType(org.netbeans.modules.autoupdate.ui.wizards.OperationWizardModel.OperationType) InstallUnitWizardModel(org.netbeans.modules.autoupdate.ui.wizards.InstallUnitWizardModel)

Aggregations

InstallSupport (org.netbeans.api.autoupdate.InstallSupport)6 ArrayList (java.util.ArrayList)2 OperationInfo (org.netbeans.api.autoupdate.OperationContainer.OperationInfo)2 OperationException (org.netbeans.api.autoupdate.OperationException)2 Restarter (org.netbeans.api.autoupdate.OperationSupport.Restarter)2 UpdateElement (org.netbeans.api.autoupdate.UpdateElement)2 UpdateUnit (org.netbeans.api.autoupdate.UpdateUnit)2 ProgressHandle (org.netbeans.api.progress.ProgressHandle)2 InstallUnitWizard (org.netbeans.modules.autoupdate.ui.wizards.InstallUnitWizard)2 InstallUnitWizardModel (org.netbeans.modules.autoupdate.ui.wizards.InstallUnitWizardModel)2 OperationType (org.netbeans.modules.autoupdate.ui.wizards.OperationWizardModel.OperationType)2 Dialog (java.awt.Dialog)1 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1 JLabel (javax.swing.JLabel)1 Installer (org.netbeans.api.autoupdate.InstallSupport.Installer)1 Validator (org.netbeans.api.autoupdate.InstallSupport.Validator)1 OperationSupport (org.netbeans.api.autoupdate.OperationSupport)1 UpdateUnitProvider (org.netbeans.api.autoupdate.UpdateUnitProvider)1 Unit (org.netbeans.modules.autoupdate.ui.Unit)1