Search in sources :

Example 1 with MindMapPlugin

use of com.igormaznitsa.mindmap.plugins.api.MindMapPlugin in project netbeans-mmd-plugin by raydac.

the class ExternalPlugins method init.

public void init() {
    final Collection<File> plugins = FileUtils.listFiles(this.pluginsFolder, new String[] { PLUGIN_EXTENSION, PLUGIN_EXTENSION.toUpperCase(Locale.ENGLISH) }, false);
    LOGGER.info("Detected " + plugins.size() + " plugin(s)");
    for (final File plugin : plugins) {
        try {
            final PluginClassLoader loader = new PluginClassLoader(plugin);
            final String pluginTitle = GetUtils.ensureNonNull(loader.getAttributes(Attribute.TITLE), "<unknown>");
            final Version pluginVersion = new Version(loader.getAttributes(Attribute.VERSION));
            LOGGER.info(String.format("Detected plugin %s [%s]", pluginTitle, pluginVersion.toString()));
            final Version pluginApiVersion = loader.getApiVersion();
            if (this.pluginApiValidator.isValid(pluginApiVersion)) {
                LOGGER.info(String.format("Plugin %s [%s] is valid for API", pluginTitle, pluginVersion.toString()));
                final String[] classes = loader.extractPluginClassNames();
                for (final String klazzName : classes) {
                    LOGGER.info(String.format("Loading plugin class %s from %s", klazzName, pluginTitle));
                    final MindMapPlugin pluginInstance = (MindMapPlugin) loader.loadClass(klazzName).newInstance();
                    MindMapPluginRegistry.getInstance().registerPlugin(pluginInstance);
                }
            } else {
                LOGGER.warn(String.format("Plugin %s [%s] is not valid for API : %s", pluginTitle, pluginVersion.toString(), pluginApiVersion.toString()));
            }
        } catch (Exception ex) {
            LOGGER.error("Can't load plugin from : " + plugin.getAbsolutePath(), ex);
        }
    }
}
Also used : Version(com.igormaznitsa.commons.version.Version) MindMapPlugin(com.igormaznitsa.mindmap.plugins.api.MindMapPlugin) File(java.io.File)

Example 2 with MindMapPlugin

use of com.igormaznitsa.mindmap.plugins.api.MindMapPlugin in project netbeans-mmd-plugin by raydac.

the class MindMapPluginRegistry method unregisterPluginForClass.

public void unregisterPluginForClass(@Nonnull final Class<? extends MindMapPlugin> pluginClass) {
    synchronized (FIND_CACHE) {
        final Iterator<MindMapPlugin> iterator = this.pluginList.iterator();
        while (iterator.hasNext()) {
            final MindMapPlugin plugin = iterator.next();
            if (pluginClass.isAssignableFrom(plugin.getClass())) {
                LOGGER.info("Unregistered plugin " + plugin.getClass().getName() + " for class " + pluginClass.getName());
                iterator.remove();
            }
        }
    }
}
Also used : MindMapPlugin(com.igormaznitsa.mindmap.plugins.api.MindMapPlugin)

Example 3 with MindMapPlugin

use of com.igormaznitsa.mindmap.plugins.api.MindMapPlugin in project netbeans-mmd-plugin by raydac.

the class MindMapPluginRegistry method findFor.

@Nonnull
@MustNotContainNull
public <T extends MindMapPlugin> List<T> findFor(@Nullable final Class<T> klazz) {
    synchronized (FIND_CACHE) {
        List<T> result = (List<T>) FIND_CACHE.get(klazz);
        if (result == null) {
            result = new ArrayList<T>();
            if (klazz != null) {
                for (final MindMapPlugin p : this.pluginList) {
                    if (klazz.isInstance(p)) {
                        result.add(klazz.cast(p));
                    }
                }
            }
            result = Collections.unmodifiableList(result);
            FIND_CACHE.put(klazz, result);
        }
        return result;
    }
}
Also used : MindMapPlugin(com.igormaznitsa.mindmap.plugins.api.MindMapPlugin) Nonnull(javax.annotation.Nonnull) MustNotContainNull(com.igormaznitsa.meta.annotation.MustNotContainNull)

Aggregations

MindMapPlugin (com.igormaznitsa.mindmap.plugins.api.MindMapPlugin)3 Version (com.igormaznitsa.commons.version.Version)1 MustNotContainNull (com.igormaznitsa.meta.annotation.MustNotContainNull)1 File (java.io.File)1 Nonnull (javax.annotation.Nonnull)1