Search in sources :

Example 26 with ModuleInfo

use of org.openide.modules.ModuleInfo in project netbeans-rcp-lite by outersky.

the class OperationContainerImpl method listAllWithPossibleEager.

public synchronized List<OperationInfo<Support>> listAllWithPossibleEager() {
    if (upToDate) {
        return listAll();
    }
    clearCache();
    // if operations contains only first class modules - don`t search for eagers.
    boolean checkEagers = false;
    for (OperationInfo<?> i : operations) {
        if (!Utilities.isFirstClassModule(i.getUpdateElement())) {
            checkEagers = true;
            break;
        }
    }
    if ((type == OperationType.INSTALL || type == OperationType.UPDATE || type == OperationType.INTERNAL_UPDATE) && checkEagers) {
        Collection<UpdateElement> all = new HashSet<UpdateElement>(operations.size());
        for (OperationInfo<?> i : operations) {
            all.add(i.getUpdateElement());
        }
        for (OperationInfo<?> i : operations) {
            all.addAll(i.getRequiredElements());
        }
        // so unless they are also eager, they won't be autoincluded.
        for (UpdateElement eagerEl : UpdateManagerImpl.getInstance().getAvailableEagers()) {
            if (eagerEl.getUpdateUnit().isPending() || eagerEl.getUpdateUnit().getAvailableUpdates().isEmpty()) {
                continue;
            }
            UpdateElementImpl impl = Trampoline.API.impl(eagerEl);
            List<ModuleInfo> infos = new ArrayList<ModuleInfo>();
            if (impl instanceof ModuleUpdateElementImpl) {
                ModuleUpdateElementImpl eagerImpl = (ModuleUpdateElementImpl) impl;
                infos.add(eagerImpl.getModuleInfo());
            } else if (impl instanceof FeatureUpdateElementImpl) {
                FeatureUpdateElementImpl eagerImpl = (FeatureUpdateElementImpl) impl;
                infos.addAll(eagerImpl.getModuleInfos());
            } else {
                assert false : eagerEl + " must instanceof ModuleUpdateElementImpl or FeatureUpdateElementImpl";
            }
            for (ModuleInfo mi : infos) {
                Set<UpdateElement> reqs = new HashSet<UpdateElement>();
                for (Dependency dep : mi.getDependencies()) {
                    Collection<UpdateElement> requestedElements = Utilities.handleDependency(eagerEl, dep, Collections.singleton(mi), new HashSet<Dependency>(), type == OperationType.UPDATE || type == OperationType.INTERNAL_UPDATE);
                    if (requestedElements != null) {
                        for (UpdateElement req : requestedElements) {
                            reqs.add(req);
                        }
                    }
                }
                if ((!reqs.isEmpty() && all.containsAll(reqs) && !all.contains(eagerEl)) || (reqs.isEmpty() && impl.getUpdateUnit().getInstalled() != null && type == OperationType.UPDATE && operations.size() > 0)) {
                    // adds affectedEager into list of elements for the operation
                    OperationInfo<Support> i = null;
                    try {
                        if (impl instanceof ModuleUpdateElementImpl) {
                            i = add(eagerEl.getUpdateUnit(), eagerEl);
                        } else if (impl instanceof FeatureUpdateElementImpl) {
                            FeatureUpdateElementImpl eagerImpl = (FeatureUpdateElementImpl) impl;
                            for (UpdateElementImpl contained : eagerImpl.getContainedModuleElements()) {
                                if (contained.isEager()) {
                                    i = add(contained.getUpdateUnit(), contained.getUpdateElement());
                                }
                            }
                        }
                    } catch (IllegalArgumentException e) {
                        // investigate the reason of 172220, 171975, 169588
                        boolean firstCondition = (!reqs.isEmpty() && all.containsAll(reqs) && !all.contains(eagerEl));
                        boolean secondCondition = reqs.isEmpty() && impl.getUpdateUnit().getInstalled() != null && type == OperationType.UPDATE && operations.size() > 0;
                        StringBuilder sb = new StringBuilder();
                        sb.append("\nIAE while adding eager element to the ").append(type).append(" container\n");
                        sb.append("\nEager: ").append(eagerEl);
                        sb.append("\nFirst condition : ").append(firstCondition);
                        sb.append("\nSecond condition : ").append(secondCondition);
                        sb.append("\nInstalled: ").append(impl.getUpdateUnit().getInstalled());
                        sb.append("\nPending: ").append(impl.getUpdateUnit().isPending());
                        sb.append("\nreqs: ").append(reqs).append(" (total : ").append(reqs.size()).append(")");
                        sb.append("\nall: ").append(all).append(" (total : ").append(all.size()).append(")");
                        sb.append("\noperation: ").append(operations).append(" (total: ").append(operations.size());
                        sb.append("\neager available updates: ").append(eagerEl.getUpdateUnit().getAvailableUpdates());
                        sb.append("\nUpdateElements in operations:");
                        for (OperationInfo<?> op : operations) {
                            sb.append("\n  ").append(op.getUpdateElement());
                        }
                        sb.append("\nUpdateElements in all:");
                        for (UpdateElement elem : all) {
                            sb.append("\n  ").append(elem);
                        }
                        sb.append("\n");
                        LOGGER.log(Level.INFO, sb.toString(), e);
                        throw e;
                    }
                    if (i != null) {
                        affectedEagers.add(i);
                    }
                }
            }
        }
    }
    if (LOGGER.isLoggable(Level.FINE)) {
        LOGGER.log(Level.FINE, "== do listAllWithPossibleEager for " + type + " operation ==");
        for (OperationInfo info : operations) {
            LOGGER.log(Level.FINE, "--> " + info.getUpdateElement());
        }
        if (affectedEagers != null) {
            LOGGER.log(Level.FINE, "   == includes affected eagers for " + type + " operation ==");
            for (OperationInfo eagerInfo : affectedEagers) {
                LOGGER.log(Level.FINE, "   --> " + eagerInfo.getUpdateElement());
            }
            LOGGER.log(Level.FINE, "   == done eagers. ==");
        }
        LOGGER.log(Level.FINE, "== done. ==");
    }
    upToDate = true;
    return listAll();
}
Also used : OperationInfo(org.netbeans.api.autoupdate.OperationContainer.OperationInfo) ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) Dependency(org.openide.modules.Dependency) ModuleInfo(org.openide.modules.ModuleInfo) HashSet(java.util.HashSet)

Example 27 with ModuleInfo

use of org.openide.modules.ModuleInfo in project netbeans-rcp-lite by outersky.

the class Status method installed.

@NbBundle.Messages({ "MSG_Enabled=Enabled", "MSG_Disabled=Installed", "# {0} - available version", "MSG_UpdateAvailable=Upgrade to {0}", "MSG_Unknown=Unknown state" })
private static Status installed(UpdateUnit uu) {
    assert uu.getInstalled() != null;
    String install;
    ModuleInfo mi = find(uu.getCodeName());
    List<UpdateElement> updates = uu.getAvailableUpdates();
    if (!updates.isEmpty()) {
        install = Bundle.MSG_UpdateAvailable(updates.get(0).getSpecificationVersion());
    } else {
        if (mi == null) {
            install = Bundle.MSG_Unknown();
        } else {
            install = mi.isEnabled() ? Bundle.MSG_Enabled() : Bundle.MSG_Disabled();
        }
    }
    return new Status(install);
}
Also used : UpdateElement(org.netbeans.api.autoupdate.UpdateElement) ModuleInfo(org.openide.modules.ModuleInfo)

Example 28 with ModuleInfo

use of org.openide.modules.ModuleInfo in project netbeans-rcp-lite by outersky.

the class ArtificialFeaturesProvider method createVersion.

// XXX: should be move somewhere into utils
public static String createVersion(Collection<ModuleInfo> modules) {
    String version = "";
    for (ModuleInfo info : modules) {
        SpecificationVersion spec = info.getSpecificationVersion();
        version = addVersion(version, spec);
    }
    return version;
}
Also used : SpecificationVersion(org.openide.modules.SpecificationVersion) ModuleInfo(org.openide.modules.ModuleInfo)

Example 29 with ModuleInfo

use of org.openide.modules.ModuleInfo in project netbeans-rcp-lite by outersky.

the class ArtificialFeaturesProvider method getUpdateItems.

@Override
public Map<String, UpdateItem> getUpdateItems() throws IOException {
    if (!generateArtificialFeatures()) {
        return Collections.emptyMap();
    }
    Map<String, UpdateItem> res = new HashMap<String, UpdateItem>();
    // crate features built on installed modules
    Map<String, Set<ModuleInfo>> categoryToModules = new HashMap<String, Set<ModuleInfo>>();
    for (UpdateItem item : originalItems) {
        UpdateItemImpl impl = Utilities.getUpdateItemImpl(item);
        if (impl instanceof InstalledModuleItem) {
            InstalledModuleItem installedModule = (InstalledModuleItem) impl;
            String category = (String) installedModule.getModuleInfo().getLocalizedAttribute("OpenIDE-Module-Display-Category");
            Module module = Utilities.toModule(installedModule.getModuleInfo().getCodeNameBase(), installedModule.getModuleInfo().getSpecificationVersion());
            assert module != null : "Module found for " + installedModule.getModuleInfo().getCodeNameBase() + ", " + installedModule.getModuleInfo().getSpecificationVersion();
            if (module.isAutoload() || module.isFixed()) {
                continue;
            } else if (module.isEager()) {
                continue;
            } else if (category == null || category.length() == 0) {
                category = UNSORTED_CATEGORY;
            }
            if (!categoryToModules.containsKey(category)) {
                categoryToModules.put(category, new HashSet<ModuleInfo>());
            }
            categoryToModules.get(category).add(installedModule.getModuleInfo());
        } else if (impl instanceof ModuleItem) {
            ModuleItem updateModule = (ModuleItem) impl;
            String category = (String) updateModule.getModuleInfo().getLocalizedAttribute("OpenIDE-Module-Display-Category");
            if (LIBRARIES_CATEGORY.equals(category) || BRIDGES_CATEGORY.equals(category) || FEATURES_CATEGORY.equals(category)) {
                continue;
            }
            if (category == null || category.length() == 0) {
                String dn = (String) updateModule.getModuleInfo().getLocalizedAttribute("OpenIDE-Module-Display-Category");
                if (dn == null || dn.length() == 0) {
                    category = UNSORTED_CATEGORY;
                } else {
                    category = dn;
                }
            }
            if (!categoryToModules.containsKey(category)) {
                categoryToModules.put(category, new HashSet<ModuleInfo>());
            }
            categoryToModules.get(category).add(updateModule.getModuleInfo());
        } else {
        // XXX: ignore other types now
        }
    }
    // make a feature for each one category
    for (String category : categoryToModules.keySet()) {
        if (true) {
            throw new UnsupportedOperationException("Not supported yet.");
        }
        FeatureItem featureItemImpl = createFeatureItem(category, null, /*categoryToModules.get (category)*/
        null, null, null);
        log.log(Level.FINE, "Create FeatureItem[" + category + ", " + featureItemImpl.getSpecificationVersion().toString() + "] containing modules " + featureItemImpl.getDependenciesToModules());
        UpdateItem featureItem = Utilities.createUpdateItem(featureItemImpl);
        res.put(featureItemImpl.getCodeName() + '_' + featureItemImpl.getSpecificationVersion(), featureItem);
    }
    return res;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) UpdateItem(org.netbeans.spi.autoupdate.UpdateItem) ModuleInfo(org.openide.modules.ModuleInfo) Module(org.netbeans.Module) HashSet(java.util.HashSet)

Example 30 with ModuleInfo

use of org.openide.modules.ModuleInfo in project netbeans-rcp-lite by outersky.

the class ModuleInfoManager method fillModules.

/**
 * recompute accessible modules.
 * @param l a collection of module infos
 */
private void fillModules(Collection<? extends ModuleInfo> l) {
    HashMap<String, ModuleInfo> m = new HashMap<String, ModuleInfo>((l.size() << 2) / 3 + 1);
    for (ModuleInfo mi : l) {
        m.put(mi.getCodeNameBase(), mi);
    }
    modules = m;
}
Also used : ModuleInfo(org.openide.modules.ModuleInfo)

Aggregations

ModuleInfo (org.openide.modules.ModuleInfo)33 HashSet (java.util.HashSet)8 SpecificationVersion (org.openide.modules.SpecificationVersion)7 HashMap (java.util.HashMap)6 UpdateUnit (org.netbeans.api.autoupdate.UpdateUnit)5 UpdateElement (org.netbeans.api.autoupdate.UpdateElement)4 IOException (java.io.IOException)3 Module (org.netbeans.Module)3 Dependency (org.openide.modules.Dependency)3 File (java.io.File)2 ArrayList (java.util.ArrayList)2 Iterator (java.util.Iterator)2 UpdateItem (org.netbeans.spi.autoupdate.UpdateItem)2 DataLoader (org.openide.loaders.DataLoader)2 Lookup (org.openide.util.Lookup)2 NbMarshalledObject (org.openide.util.io.NbMarshalledObject)2 InfoTextPanel (au.gov.asd.tac.constellation.utilities.gui.InfoTextPanel)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 Enumeration (java.util.Enumeration)1