Search in sources :

Example 6 with UpdateUnit

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

the class UpdateUnitFactory method getUpdateUnits.

public Map<String, UpdateUnit> getUpdateUnits(UpdateProvider provider) {
    // TODO: this call should be forced not to be called from AWT
    // assert !SwingUtilities.isEventDispatchThread();
    // NOI18N
    resetRunTime("Measuring UpdateUnitFactory.getUpdateUnits (" + provider.getDisplayName() + ")");
    // append units from provider
    Map<String, UpdateUnit> temp = appendUpdateItems(new HashMap<String, UpdateUnit>(), provider);
    reportRunTime("Get appendUpdateItems for " + provider.getDisplayName());
    Map<String, UpdateUnit> retval = new HashMap<String, UpdateUnit>();
    for (UpdateUnit unit : temp.values()) {
        retval.put(unit.getCodeName(), mergeInstalledUpdateUnit(unit));
    }
    reportRunTime("Get filltering by " + provider.getDisplayName());
    return temp;
}
Also used : UpdateUnit(org.netbeans.api.autoupdate.UpdateUnit) HashMap(java.util.HashMap)

Example 7 with UpdateUnit

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

the class UpdateUnitFactory method addElement.

private void addElement(Map<String, UpdateUnit> impls, UpdateElement element, UpdateProvider provider) {
    // find if corresponding element exists
    UpdateUnit unit = impls.get(element.getCodeName());
    // XXX: it's should be moved in UI what should filter all elements w/ broken dependencies
    // #101515: Plugin Manager must filter updates by platform dependency
    boolean passed = false;
    UpdateElementImpl elImpl = Trampoline.API.impl(element);
    if (elImpl instanceof ModuleUpdateElementImpl && elImpl.getModuleInfos() != null && elImpl.getModuleInfos().size() == 1) {
        for (Dependency d : elImpl.getModuleInfos().get(0).getDependencies()) {
            if (Dependency.TYPE_REQUIRES == d.getType()) {
                // log.log (Level.FINEST, "Dependency: NAME: " + d.getName () + ", TYPE: " + d.getType () + ": " + d.toString ());
                if (d.getName().startsWith("org.openide.modules.os")) {
                    // NOI18N
                    for (ModuleInfo info : InstalledModuleProvider.getInstalledModules().values()) {
                        if (Arrays.asList(info.getProvides()).contains(d.getName())) {
                            log.log(Level.FINEST, element + " which requires OS " + d + " succeed.");
                            passed = true;
                            break;
                        }
                    }
                    if (!passed) {
                        log.log(Level.FINE, element + " which requires OS " + d + " fails.");
                        return;
                    }
                }
            }
        }
    }
    UpdateUnitImpl unitImpl = null;
    if (unit == null) {
        switch(elImpl.getType()) {
            case MODULE:
                unitImpl = new ModuleUpdateUnitImpl(element.getCodeName());
                break;
            case KIT_MODULE:
                unitImpl = new KitModuleUpdateUnitImpl(element.getCodeName());
                break;
            case STANDALONE_MODULE:
            case FEATURE:
                unitImpl = new FeatureUpdateUnitImpl(element.getCodeName(), elImpl.getType());
                break;
            case CUSTOM_HANDLED_COMPONENT:
                unitImpl = new NativeComponentUpdateUnitImpl(element.getCodeName());
                break;
            case LOCALIZATION:
                unitImpl = new LocalizationUpdateUnitImpl(element.getCodeName());
                break;
            default:
                assert false : "Unsupported for type " + elImpl.getType();
        }
        unit = Trampoline.API.createUpdateUnit(unitImpl);
        impls.put(unit.getCodeName(), unit);
    } else {
        unitImpl = Trampoline.API.impl(unit);
    }
    if (provider == InstalledUpdateProvider.getDefault()) {
        if (unitImpl.getInstalled() == null) {
            unitImpl.setInstalled(element);
        }
    } else if (provider instanceof BackupUpdateProvider) {
        unitImpl.setBackup(element);
    } else {
        // suppose common UpdateProvider
        unitImpl.addUpdate(element);
    }
    // set UpdateUnit into element
    elImpl.setUpdateUnit(unit);
}
Also used : UpdateUnit(org.netbeans.api.autoupdate.UpdateUnit) Dependency(org.openide.modules.Dependency) ModuleInfo(org.openide.modules.ModuleInfo) BackupUpdateProvider(org.netbeans.modules.autoupdate.updateprovider.BackupUpdateProvider)

Example 8 with UpdateUnit

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

the class ModuleUpdateUnitImpl method getVisibleAncestor.

@Override
public UpdateUnit getVisibleAncestor() {
    if (visibleAncestor == null) {
        assert getInstalled() != null : this + " is installed";
        ModuleUpdateElementImpl installedImpl = (ModuleUpdateElementImpl) Trampoline.API.impl(getInstalled());
        TreeSet<Module> visible = new TreeSet<Module>(new Comparator<Module>() {

            @Override
            public int compare(Module o1, Module o2) {
                return o1.getCodeNameBase().compareTo(o2.getCodeNameBase());
            }
        });
        Set<Module> seen = new HashSet<Module>();
        for (ModuleInfo mi : installedImpl.getModuleInfos()) {
            visible.addAll(findVisibleAncestor(Utilities.toModule(mi), seen));
        }
        String cat = installedImpl.getCategory();
        String installationCluster = installedImpl.getInstallationCluster();
        if (BROAD_CATEGORY.contains(cat)) {
            cat = null;
        }
        UpdateUnit shot = null;
        UpdateUnit spare = null;
        UpdateUnit strike = null;
        for (Module visMod : visible) {
            visibleAncestor = Utilities.toUpdateUnit(visMod);
            UpdateElementImpl visibleImpl = Trampoline.API.impl(visibleAncestor.getInstalled());
            String visTargetCluster = null;
            String visCat = null;
            if (visibleImpl != null && visibleImpl instanceof ModuleUpdateElementImpl) {
                visTargetCluster = ((ModuleUpdateElementImpl) visibleImpl).getInstallationCluster();
                visCat = visibleImpl.getCategory();
            }
            if (installationCluster != null && installationCluster.equals(visTargetCluster)) {
                spare = visibleAncestor;
            } else if (visCat != null && visCat.equals(cat)) {
                strike = visibleAncestor;
                break;
            } else if (shot == null) {
                shot = visibleAncestor;
            }
        }
        visibleAncestor = strike != null ? strike : spare != null ? spare : shot;
        // if it's still unknown - try visible representative in given cluster
        if (visibleAncestor == null && installationCluster != null) {
            for (UpdateElement visEl : UpdateManagerImpl.getInstance().getInstalledKits(installationCluster)) {
                visibleAncestor = visEl.getUpdateUnit();
                if (installedImpl.getRawCategory().equals(visEl.getCategory())) {
                    visibleAncestor = visEl.getUpdateUnit();
                    break;
                }
            }
        }
    }
    return visibleAncestor;
}
Also used : UpdateUnit(org.netbeans.api.autoupdate.UpdateUnit) UpdateElement(org.netbeans.api.autoupdate.UpdateElement) ModuleInfo(org.openide.modules.ModuleInfo) TreeSet(java.util.TreeSet) Module(org.netbeans.Module) HashSet(java.util.HashSet)

Example 9 with UpdateUnit

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

the class DependencyAggregator method getRequested.

public static Collection<UpdateUnit> getRequested(Dependency dep) {
    switch(dep.getType()) {
        case Dependency.TYPE_MODULE:
            return Collections.singleton(UpdateManagerImpl.getInstance().getUpdateUnit(dep.getName()));
        case Dependency.TYPE_NEEDS:
        case Dependency.TYPE_REQUIRES:
        case Dependency.TYPE_RECOMMENDS:
            Collection<UpdateUnit> requestedUnits = new HashSet<UpdateUnit>();
            Collection<ModuleInfo> installedProviders = UpdateManagerImpl.getInstance().getInstalledProviders(dep.getName());
            if (installedProviders.isEmpty()) {
                Collection<ModuleInfo> availableProviders = UpdateManagerImpl.getInstance().getAvailableProviders(dep.getName());
                if (availableProviders.isEmpty()) {
                    return null;
                } else {
                    for (ModuleInfo mi : availableProviders) {
                        UpdateUnit availableUnit = UpdateManagerImpl.getInstance().getUpdateUnit(mi.getCodeNameBase());
                        if (availableUnit != null) {
                            requestedUnits.add(availableUnit);
                        }
                    }
                    return requestedUnits;
                }
            } else {
                for (ModuleInfo mi : installedProviders) {
                    UpdateUnit installedUnit = UpdateManagerImpl.getInstance().getUpdateUnit(mi.getCodeNameBase());
                    if (installedUnit != null) {
                        requestedUnits.add(installedUnit);
                    }
                }
                return requestedUnits;
            }
        case Dependency.TYPE_JAVA:
        case Dependency.TYPE_PACKAGE:
            break;
    }
    return null;
}
Also used : UpdateUnit(org.netbeans.api.autoupdate.UpdateUnit) ModuleInfo(org.openide.modules.ModuleInfo) HashSet(java.util.HashSet)

Example 10 with UpdateUnit

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

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