Search in sources :

Example 11 with ModuleInfo

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

the class DependencyChecker method findModuleMatchesDependencyRequires.

static Collection<ModuleInfo> findModuleMatchesDependencyRequires(Dependency dep, Collection<ModuleInfo> modules) {
    UpdateManagerImpl mgr = UpdateManagerImpl.getInstance();
    Set<ModuleInfo> providers = new HashSet<ModuleInfo>();
    providers.addAll(mgr.getAvailableProviders(dep.getName()));
    providers.addAll(mgr.getInstalledProviders(dep.getName()));
    Set<ModuleInfo> res = new HashSet<ModuleInfo>(providers);
    for (ModuleInfo mi : providers) {
        for (ModuleInfo input : modules) {
            if (mi.getCodeName().equals(input.getCodeName())) {
                res.add(mi);
            }
        }
    }
    return res;
}
Also used : ModuleInfo(org.openide.modules.ModuleInfo)

Example 12 with ModuleInfo

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

the class OperationValidator method filterCandidatesToDeactivate.

private static Set<Module> filterCandidatesToDeactivate(final Collection<Module> requested, final Collection<Module> candidates, ModuleManager mm) {
    // go down and find all modules (except other kits) which can be deactivated
    Set<Module> result = new HashSet<Module>();
    Set<Module> compactSet = new HashSet<Module>(candidates);
    // create collection of all installed eagers
    Set<Module> installedEagers = new HashSet<Module>();
    for (UpdateElement eagerEl : UpdateManagerImpl.getInstance().getInstalledEagers()) {
        // take a module
        UpdateElementImpl impl = Trampoline.API.impl(eagerEl);
        if (impl instanceof ModuleUpdateElementImpl) {
            ModuleInfo mi = ((ModuleUpdateElementImpl) impl).getModuleInfo();
            installedEagers.add(Utilities.toModule(mi));
        } else if (impl instanceof FeatureUpdateElementImpl) {
            List<ModuleInfo> infos = ((FeatureUpdateElementImpl) impl).getModuleInfos();
            for (ModuleInfo mi : infos) {
                installedEagers.add(Utilities.toModule(mi));
            }
        } else {
            assert false : eagerEl + " is instanceof neither ModuleUpdateElementImpl nor FeatureUpdateElementImpl";
        }
    }
    // add installedEagers into affected modules to don't break uninstall of candidates
    compactSet.addAll(installedEagers);
    Set<Module> mustRemain = new HashSet<Module>();
    Set<Module> affectedEagers = new HashSet<Module>();
    for (Module depM : candidates) {
        if ((Utilities.isKitModule(depM) || Utilities.isEssentialModule(depM)) && !requested.contains(depM)) {
            if (LOGGER.isLoggable(Level.FINE)) {
                LOGGER.log(Level.FINE, "The module " + depM.getCodeNameBase() + " is KIT_MODULE and won't be deactivated now not even " + Utilities.findRequiredModules(depM, mm, module2required));
            }
            mustRemain.add(depM);
        } else if (mustRemain.contains(depM)) {
            LOGGER.log(Level.FINE, "The module " + depM.getCodeNameBase() + " was investigated already and won't be deactivated now.");
        } else {
            Set<Module> depends = Utilities.findDependingModules(depM, mm, module2depending);
            if (!compactSet.containsAll(depends)) {
                mustRemain.add(depM);
                Set<Module> otherRequiredModules = Utilities.findRequiredModules(depM, mm, module2required);
                mustRemain.addAll(otherRequiredModules);
                LOGGER.log(Level.FINE, "The module " + depM.getCodeNameBase() + " is shared and cannot be deactivated now.");
                if (LOGGER.isLoggable(Level.FINER)) {
                    Set<Module> outsideModules = new HashSet<Module>(depends);
                    outsideModules.removeAll(compactSet);
                    LOGGER.log(Level.FINER, "On " + depM.getCodeNameBase() + " depending modules outside of set now deactivating modules: " + outsideModules);
                    LOGGER.log(Level.FINER, "With " + depM.getCodeNameBase() + " must remain also these required modules: " + otherRequiredModules);
                }
            } else {
                result.add(depM);
                Collection<Module> reducedDepends = new HashSet<Module>(depends);
                reducedDepends.retainAll(installedEagers);
                if (!reducedDepends.isEmpty()) {
                    affectedEagers.addAll(reducedDepends);
                }
            }
        }
    }
    result.removeAll(installedEagers);
    // add only affected eagers again
    LOGGER.log(Level.FINE, "Possible affected eagers are " + affectedEagers);
    result.removeAll(findDeepRequired(mustRemain, mm));
    // once again check the eagers
    Set<Module> notAffectedEagers = new HashSet<Module>();
    for (Module eager : affectedEagers) {
        Set<Module> requiredByEager = Utilities.findRequiredModules(eager, mm, module2depending);
        if (!requiredByEager.removeAll(result)) {
            notAffectedEagers.add(eager);
        }
    }
    affectedEagers.removeAll(notAffectedEagers);
    result.addAll(affectedEagers);
    LOGGER.log(Level.FINE, "Real affected eagers are " + affectedEagers);
    return result;
}
Also used : UpdateElement(org.netbeans.api.autoupdate.UpdateElement) ModuleInfo(org.openide.modules.ModuleInfo) Module(org.netbeans.Module)

Example 13 with ModuleInfo

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

the class PersistenceManager method findModule.

/**
 * Searches for module with given code name and specification version.
 * @param codeNameBase unique string base name of the module
 * (without release number)
 * @param spec string form of specification version of the module, null if
 * not important
 * @param strRelease release number of the module or null if not important
 *
 * @return module info of found module or null if module not found
 * (not installed).
 * @deprecated will be replaced by similar method in Modules Open APIs in
 * future releases
 */
@Deprecated
static final ModuleInfo findModule(String codeNameBase, String strRelease, String strSpec) {
    SpecificationVersion spec = null;
    int release = -1;
    if (strRelease != null) {
        try {
            release = Integer.parseInt(strRelease);
        } catch (NumberFormatException nfe) {
            LOG.log(Level.INFO, null, nfe);
        }
    }
    if (strSpec != null) {
        spec = new SpecificationVersion(strSpec);
    }
    Lookup.Result<ModuleInfo> modulesResult = Lookup.getDefault().lookup(new Lookup.Template<ModuleInfo>(ModuleInfo.class));
    for (ModuleInfo curInfo : modulesResult.allInstances()) {
        // spec numbers, if present
        if (curInfo.getCodeNameBase().equals(codeNameBase)) {
            if (((release < 0) && (spec == null)) || (curInfo.getCodeNameRelease() >= release)) {
                return curInfo;
            } else if ((release < 0) || (curInfo.getCodeNameRelease() == release)) {
                if (spec == null) {
                    return curInfo;
                } else {
                    if ((curInfo.getSpecificationVersion() != null) && (curInfo.getSpecificationVersion().compareTo(spec) >= 0)) {
                        return curInfo;
                    }
                }
            }
        }
    }
    return null;
}
Also used : SpecificationVersion(org.openide.modules.SpecificationVersion) ModuleInfo(org.openide.modules.ModuleInfo) Lookup(org.openide.util.Lookup)

Example 14 with ModuleInfo

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

the class ModuleInfoManager method replaceReloadedModules.

/**
 * replace old MIs of reloaded modules with new ones
 * @return the list of PCLs of reloaded modules
 */
private List<PCL> replaceReloadedModules() {
    if (mapOfListeners == null)
        return Collections.emptyList();
    Iterator<ModuleInfo> it = new ArrayList<ModuleInfo>(mapOfListeners.keySet()).iterator();
    List<PCL> reloaded = new ArrayList<PCL>();
    while (it.hasNext()) {
        ModuleInfo mi = it.next();
        ModuleInfo miNew = modules.get(mi.getCodeNameBase());
        if (mi != miNew && miNew != null) {
            PCL lsnr = mapOfListeners.remove(mi);
            lsnr.setModuleInfo(miNew);
            reloaded.add(lsnr);
            mapOfListeners.put(miNew, lsnr);
        }
    }
    return reloaded;
}
Also used : ModuleInfo(org.openide.modules.ModuleInfo)

Example 15 with ModuleInfo

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

the class ModuleInfoManager method getModulesResult.

private Lookup.Result<ModuleInfo> getModulesResult() {
    synchronized (this) {
        if (modulesResult == null) {
            Lookup lookup = getModuleLookup();
            modulesResult = lookup.lookup(new Lookup.Template<ModuleInfo>(ModuleInfo.class));
            modulesResult.addLookupListener(new LookupListener() {

                public void resultChanged(LookupEvent ev) {
                    Collection<? extends ModuleInfo> l = getModulesResult().allInstances();
                    // NOI18N
                    XMLSettingsSupport.err.fine("Modules changed: " + l);
                    List reloaded;
                    synchronized (this) {
                        fillModules(l);
                        reloaded = replaceReloadedModules();
                        // NOI18N
                        XMLSettingsSupport.err.fine("Reloaded modules: " + reloaded);
                    }
                    notifyReloads(reloaded);
                }
            });
        }
        return modulesResult;
    }
}
Also used : LookupEvent(org.openide.util.LookupEvent) LookupListener(org.openide.util.LookupListener) ModuleInfo(org.openide.modules.ModuleInfo) MainLookup(org.netbeans.core.startup.MainLookup) Lookup(org.openide.util.Lookup)

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