Search in sources :

Example 21 with ModuleInfo

use of org.openide.modules.ModuleInfo in project constellation by constellation-app.

the class PluginRegistry method init.

private static synchronized void init() {
    if (pluginsMap != null) {
        return;
    }
    pluginsMap = new HashMap<>();
    aliasMap = new HashMap<>();
    final Map<String, Class<? extends Plugin>> pluginOverrides = new HashMap<>();
    final Result<Plugin> plugins = Lookup.getDefault().lookupResult(Plugin.class);
    final Modules modules = WindowManager.getDefault().getClass().getName().contains("org.openide.windows.DummyWindowManager") ? null : Modules.getDefault();
    for (Class<? extends Plugin> plugin : plugins.allClasses()) {
        final ModuleInfo mi = modules != null ? modules.ownerOf(plugin) : null;
        try {
            final String descr = NbBundle.getMessage(plugin, plugin.getSimpleName());
            final String msg = String.format("Discovered plugin %s (%s) in module %s (%s)", plugin.getName(), descr, mi != null ? mi.getDisplayName() : "unknown", mi != null ? mi.getCodeName() : "unknown");
            LOGGER.info(msg);
        } catch (final MissingResourceException ex) {
            final String msg = String.format("Plugin class %s has no description: add a class name bundle.", plugin.getSimpleName());
            LOGGER.severe(msg);
            NotificationDisplayer.getDefault().notify("Plugin registration", UserInterfaceIconProvider.ERROR.buildIcon(16, ConstellationColor.CHERRY.getJavaColor()), msg, null, NotificationDisplayer.Priority.HIGH);
        }
        // add the plugin to our registry.
        pluginsMap.put(plugin.getName(), plugin);
        aliasMap.put(getAlias(plugin.getName()), plugin.getName());
        // use reflection to limit the amount of plugins we have to instantiate to see if the plugin has been overridden
        for (final Method declaredMethod : plugin.getDeclaredMethods()) {
            if ("getOverriddenPlugins".equals(declaredMethod.getName())) {
                pluginOverrides.put(plugin.getName(), plugin);
            }
        }
    }
    // update the maps with the overridden plugin
    pluginOverrides.forEach((pluginName, overridingPlugin) -> {
        try {
            for (final String overriddenPlugin : overridingPlugin.getDeclaredConstructor().newInstance().getOverriddenPlugins()) {
                if (pluginsMap.containsKey(overriddenPlugin)) {
                    pluginsMap.remove(overriddenPlugin);
                    aliasMap.remove(getAlias(overriddenPlugin));
                }
                pluginsMap.put(overridingPlugin.getName(), overridingPlugin);
                aliasMap.put(getAlias(overridingPlugin.getName()), overridingPlugin.getName());
                LOGGER.log(Level.INFO, "Removed  plugin {0} as it is overriden by plugin {1})", new Object[] { overriddenPlugin, overridingPlugin.getName() });
            }
        } catch (final IllegalAccessException | IllegalArgumentException | InstantiationException | NoSuchMethodException | SecurityException | InvocationTargetException ex) {
            LOGGER.log(Level.SEVERE, ex.getLocalizedMessage(), ex);
        }
    });
}
Also used : HashMap(java.util.HashMap) Modules(org.openide.modules.Modules) MissingResourceException(java.util.MissingResourceException) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException) ModuleInfo(org.openide.modules.ModuleInfo)

Example 22 with ModuleInfo

use of org.openide.modules.ModuleInfo in project gephi by gephi.

the class ReportController method logModules.

private void logModules(Report report) {
    for (ModuleInfo m : Lookup.getDefault().lookupAll(ModuleInfo.class)) {
        String moduleStr = "";
        SpecificationVersion specVersion = m.getSpecificationVersion();
        if (specVersion != null) {
            moduleStr = m.getCodeName() + " [" + specVersion.toString() + "]";
        } else {
            moduleStr = m.getCodeName();
        }
        if (m.isEnabled()) {
            report.addEnabledModule(moduleStr);
        } else {
            report.addDisabledModule(moduleStr);
        }
    }
}
Also used : SpecificationVersion(org.openide.modules.SpecificationVersion) ModuleInfo(org.openide.modules.ModuleInfo)

Example 23 with ModuleInfo

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

the class ModuleDeleterImpl method delete.

@SuppressWarnings("SleepWhileInLoop")
public void delete(final ModuleInfo[] modules, ProgressHandle handle) throws IOException {
    storageFilesForDelete = null;
    if (modules == null) {
        throw new IllegalArgumentException("ModuleInfo argument cannot be null.");
    }
    if (handle != null) {
        handle.switchToDeterminate(modules.length + 1);
    }
    int i = 0;
    for (ModuleInfo moduleInfo : modules) {
        err.log(Level.FINE, "Locate and remove config file of " + moduleInfo.getCodeNameBase());
        removeControlModuleFile(moduleInfo, false);
    }
    if (handle != null) {
        handle.progress(++i);
    }
    refreshModuleList();
    int rerunWaitCount = 0;
    for (ModuleInfo moduleInfo : modules) {
        err.log(Level.FINE, "Locate and remove config file of " + moduleInfo.getCodeNameBase());
        if (handle != null) {
            handle.progress(moduleInfo.getDisplayName(), ++i);
        }
        for (; rerunWaitCount < 100 && !isModuleUninstalled(moduleInfo); rerunWaitCount++) {
            try {
                Thread.sleep(100);
            } catch (InterruptedException ex) {
                err.log(Level.INFO, "Overflow checks of uninstalled module " + moduleInfo.getCodeName());
                Thread.currentThread().interrupt();
            }
        }
        removeModuleFiles(moduleInfo, false);
    }
}
Also used : ModuleInfo(org.openide.modules.ModuleInfo)

Example 24 with ModuleInfo

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

the class ModuleCache method resultChanged.

@Override
public void resultChanged(LookupEvent ev) {
    for (ModuleInfo m : result.allInstances()) {
        m.removePropertyChangeListener(this);
        m.addPropertyChangeListener(this);
    }
    Map<String, ModuleInfo> tmp = new HashMap<String, ModuleInfo>();
    for (ModuleInfo mi : result.allInstances()) {
        tmp.put(mi.getCodeNameBase(), mi);
    }
    infos = tmp;
    if (ev != null) {
        fireChange();
    }
}
Also used : ModuleInfo(org.openide.modules.ModuleInfo) HashMap(java.util.HashMap)

Example 25 with ModuleInfo

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

the class DependencyChecker method findBrokenDependenciesTransitive.

public static Set<Dependency> findBrokenDependenciesTransitive(ModuleInfo info, Collection<ModuleInfo> modules, Set<ModuleInfo> seen) {
    if (seen.contains(info)) {
        return Collections.emptySet();
    }
    seen.add(info);
    Set<Dependency> res = new HashSet<Dependency>();
    for (Dependency dep : filterTypeRecommends(info.getDependencies())) {
        err.log(Level.FINE, "Dependency[" + dep.getType() + "]: " + dep);
        Collection<ModuleInfo> providers = null;
        switch(dep.getType()) {
            case (Dependency.TYPE_REQUIRES):
            case (Dependency.TYPE_NEEDS):
            case (Dependency.TYPE_RECOMMENDS):
                providers = findModuleMatchesDependencyRequires(dep, modules);
                if (providers.size() > 0) {
                    for (ModuleInfo m : providers) {
                        res.addAll(findBrokenDependenciesTransitive(m, modules, seen));
                    }
                } else {
                    // bad, report missing module
                    res.add(dep);
                }
                break;
            case (Dependency.TYPE_MODULE):
                ModuleInfo m = matchDependencyModule(dep, modules);
                if (m != null) {
                    res.addAll(findBrokenDependenciesTransitive(m, modules, seen));
                } else {
                    // bad, report missing module
                    res.add(dep);
                }
                break;
            case (Dependency.TYPE_JAVA):
                if (!matchDependencyJava(dep)) {
                    err.log(Level.FINE, "The Java platform version " + dep + " or higher was requested but only " + Dependency.JAVA_SPEC + " is running.");
                    res.add(dep);
                }
                break;
            case (Dependency.TYPE_PACKAGE):
                if (!matchPackageDependency(dep)) {
                    err.log(Level.FINE, "The package " + dep + " was requested but it is not in current ClassPath.");
                    res.add(dep);
                }
                break;
            default:
                // assert false : "Unknown type of Dependency, was " + dep.getType ();
                err.log(Level.FINE, "Uncovered Dependency " + dep);
        }
    }
    return res;
}
Also used : ModuleInfo(org.openide.modules.ModuleInfo) Dependency(org.openide.modules.Dependency)

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