Search in sources :

Example 1 with UpdateUnit

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

the class Utilities method findRequiredUpdateElements.

public static Set<UpdateElement> findRequiredUpdateElements(UpdateElement element, Collection<ModuleInfo> infos, Set<Dependency> brokenDependencies, boolean topAggressive, Collection<UpdateElement> recommended) {
    Set<UpdateElement> retval = new HashSet<UpdateElement>();
    switch(element.getUpdateUnit().getType()) {
        case KIT_MODULE:
        case MODULE:
            boolean avoidRecommended = recommended != null && !recommended.isEmpty();
            ModuleUpdateElementImpl el = (ModuleUpdateElementImpl) Trampoline.API.impl(element);
            Set<Dependency> deps = new HashSet<Dependency>(el.getModuleInfo().getDependencies());
            Set<ModuleInfo> availableInfos = new HashSet<ModuleInfo>(infos);
            maybeAddImplicitHostDependency(element, deps);
            int max_counter = el.getType().equals(UpdateManager.TYPE.KIT_MODULE) ? 2 : 1;
            int counter = max_counter;
            boolean aggressive = topAggressive && counter > 0;
            Set<Dependency> all = new HashSet<Dependency>();
            for (; ; ) {
                Set<Dependency> newones = processDependencies(deps, retval, availableInfos, brokenDependencies, element, aggressive, recommended, avoidRecommended);
                newones.removeAll(all);
                // issue #247884 Autoupdate should force restart when a new module enables module which is a fragment of other module
                for (Dependency dep : deps) {
                    UpdateUnit uu = toUpdateUnit(dep.getName());
                    if (uu != null && uu.getInstalled() != null) {
                        ModuleUpdateElementImpl em = (ModuleUpdateElementImpl) Trampoline.API.impl(uu.getInstalled());
                        // restart
                        if (em.getInstallInfo().getUpdateItemImpl().isFragment() && !uu.getInstalled().isEnabled()) {
                            String fh = em.getInstallInfo().getUpdateItemImpl().getFragmentHost();
                            Module m = Utilities.toModule(fh);
                            if (m != null && m.isEnabled()) {
                                el.getInstallInfo().getUpdateItemImpl().setNeedsRestart(true);
                            }
                        }
                    }
                }
                if (newones.isEmpty()) {
                    break;
                }
                all.addAll(newones);
                deps = newones;
            }
            Set<Dependency> moreBroken = new HashSet<Dependency>();
            Set<ModuleInfo> tmp = new HashSet<ModuleInfo>(availableInfos);
            Set<UpdateElement> more;
            counter = max_counter;
            aggressive = topAggressive && counter > 0;
            while (retval.addAll(more = handleBackwardCompatability(tmp, moreBroken, aggressive))) {
                if (!moreBroken.isEmpty()) {
                    brokenDependencies.addAll(moreBroken);
                    break;
                }
                for (UpdateElement e : more) {
                    // infos.addAll (Trampoline.API.impl (el).getModuleInfos ());
                    tmp.add(((ModuleUpdateElementImpl) Trampoline.API.impl(e)).getModuleInfo());
                }
                aggressive = aggressive && (counter--) > 0;
            }
            if (!moreBroken.isEmpty()) {
                brokenDependencies.addAll(moreBroken);
            }
            break;
        case STANDALONE_MODULE:
        case FEATURE:
            FeatureUpdateElementImpl feature = (FeatureUpdateElementImpl) Trampoline.API.impl(element);
            aggressive = topAggressive;
            for (ModuleUpdateElementImpl module : feature.getContainedModuleElements()) {
                retval.addAll(findRequiredUpdateElements(module.getUpdateElement(), infos, brokenDependencies, aggressive, recommended));
            }
            break;
        case CUSTOM_HANDLED_COMPONENT:
            // XXX
            getLogger().log(Level.INFO, "CUSTOM_HANDLED_COMPONENT doesn't care about required elements.");
            break;
        default:
            assert false : "Not implement for type " + element.getUpdateUnit() + " of UpdateElement " + element;
    }
    return retval;
}
Also used : UpdateUnit(org.netbeans.api.autoupdate.UpdateUnit) UpdateElement(org.netbeans.api.autoupdate.UpdateElement) DummyModuleInfo(org.netbeans.modules.autoupdate.updateprovider.DummyModuleInfo) Module(org.netbeans.Module)

Example 2 with UpdateUnit

use of org.netbeans.api.autoupdate.UpdateUnit 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 3 with UpdateUnit

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

the class UpdateManagerImpl method getAvailableProviders.

public Collection<ModuleInfo> getAvailableProviders(String token) {
    Collection<ModuleInfo> res;
    final Cache c = getCache();
    if (token.startsWith("cnb.")) {
        // NOI18N
        UpdateUnit updateUnit = c.getUpdateUnit(token.substring(4));
        if (updateUnit != null && !updateUnit.getAvailableUpdates().isEmpty()) {
            return Trampoline.API.impl(updateUnit.getAvailableUpdates().get(0)).getModuleInfos();
        }
    }
    Collection<ModuleInfo> providers = c.createMapToken2AvailableProviders().get(token);
    if (providers == null || providers.isEmpty()) {
        res = new HashSet<ModuleInfo>(0) {

            Cache keepIt = c;
        };
    } else {
        res = new HashSet<ModuleInfo>(providers) {

            Cache keepIt = c;
        };
    }
    return res;
}
Also used : UpdateUnit(org.netbeans.api.autoupdate.UpdateUnit) ModuleInfo(org.openide.modules.ModuleInfo)

Example 4 with UpdateUnit

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

the class UpdateManagerImpl method getInstalledProviders.

public Collection<ModuleInfo> getInstalledProviders(String token) {
    Collection<ModuleInfo> res;
    final Cache c = getCache();
    if (token.startsWith("cnb.")) {
        // NOI18N
        UpdateUnit updateUnit = c.getUpdateUnit(token.substring(4));
        if (updateUnit != null && updateUnit.getInstalled() != null) {
            return Trampoline.API.impl(updateUnit.getInstalled()).getModuleInfos();
        }
    }
    Collection<ModuleInfo> providers = c.createMapToken2InstalledProviders().get(token);
    if (providers == null || providers.isEmpty()) {
        res = new HashSet<ModuleInfo>(0) {

            Cache keepIt = c;
        };
    } else {
        res = new HashSet<ModuleInfo>(providers) {

            Cache keepIt = c;
        };
    }
    return res;
}
Also used : UpdateUnit(org.netbeans.api.autoupdate.UpdateUnit) ModuleInfo(org.openide.modules.ModuleInfo)

Example 5 with UpdateUnit

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

the class UpdateManagerImpl method filterUnitsByAskedTypes.

private static List<UpdateUnit> filterUnitsByAskedTypes(Collection<UpdateUnit> units, List<UpdateManager.TYPE> types) {
    List<UpdateUnit> askedUnits = new ArrayList<UpdateUnit>();
    // hotfix for #113193 - reevaluate and probably fix better
    List<UpdateManager.TYPE> tmpTypes = new ArrayList<UpdateManager.TYPE>(types);
    if (tmpTypes.contains(UpdateManager.TYPE.MODULE) && !tmpTypes.contains(UpdateManager.TYPE.KIT_MODULE)) {
        tmpTypes.add(UpdateManager.TYPE.KIT_MODULE);
    }
    for (UpdateUnit unit : units) {
        UpdateUnitImpl impl = Trampoline.API.impl(unit);
        if (tmpTypes.contains(impl.getType())) {
            askedUnits.add(unit);
        }
    }
    return askedUnits;
}
Also used : UpdateUnit(org.netbeans.api.autoupdate.UpdateUnit) ArrayList(java.util.ArrayList) UpdateManager(org.netbeans.api.autoupdate.UpdateManager)

Aggregations

UpdateUnit (org.netbeans.api.autoupdate.UpdateUnit)26 UpdateElement (org.netbeans.api.autoupdate.UpdateElement)13 ArrayList (java.util.ArrayList)6 HashSet (java.util.HashSet)5 ModuleInfo (org.openide.modules.ModuleInfo)5 Module (org.netbeans.Module)4 DummyModuleInfo (org.netbeans.modules.autoupdate.updateprovider.DummyModuleInfo)4 IOException (java.io.IOException)3 TreeSet (java.util.TreeSet)3 UpdateUnitProvider (org.netbeans.api.autoupdate.UpdateUnitProvider)3 File (java.io.File)2 JarFile (java.util.jar.JarFile)2 InstallSupport (org.netbeans.api.autoupdate.InstallSupport)2 OperationException (org.netbeans.api.autoupdate.OperationException)2 OperationSupport (org.netbeans.api.autoupdate.OperationSupport)2 ProgressHandle (org.netbeans.api.progress.ProgressHandle)2 Dialog (java.awt.Dialog)1 HashMap (java.util.HashMap)1 LinkedHashSet (java.util.LinkedHashSet)1 TreeMap (java.util.TreeMap)1