Search in sources :

Example 1 with PluginManager

use of com.ibm.java.diagnostics.utils.plugins.PluginManager in project openj9 by eclipse.

the class DTFJContext method refresh.

/**
 * Refresh this context.
 */
public void refresh() {
    // used to detect command name clashes
    ArrayList<String> names = new ArrayList<String>();
    commands.clear();
    loadedPlugins.clear();
    failedPlugins.clear();
    // these are the only hardwired commands that are always available within any context
    addGlobalCommandsToContext();
    PluginManager pluginManager = PluginManagerLocator.getManager();
    DTFJPluginManager manager = new DTFJPluginManager(pluginManager);
    try {
        pluginManager.refreshSearchPath();
        pluginManager.scanForClassFiles();
    } catch (CommandException e) {
        // may catch a CommandException when loading plugins
        logger.log(Level.FINE, "Problem loading DTFJ View plugins: " + e.getMessage());
        logger.log(Level.FINEST, "Problem loading DTFJ View plugins: ", e);
    }
    ClassLoader thisloader = this.getClass().getClassLoader();
    if (thisloader == null) {
        thisloader = ClassLoader.getSystemClassLoader();
    }
    LocalPriorityClassloader loader = new LocalPriorityClassloader(pluginManager.getClasspath(), thisloader);
    for (PluginConfig config : manager.getPlugins(apiLevel, hasImage, (rt != null))) {
        try {
            ICommand cmd = config.newInstance(loader);
            loadedPlugins.add(config);
            for (String cmdname : cmd.getCommandNames()) {
                // check for a name space clash i.e. two plugins could potentially be invoked by a single command
                if (names.contains(cmdname)) {
                    logger.fine("Name space clash detected for " + config.getClassName() + ". The command name " + cmdname + " is already in use");
                } else {
                    names.add(cmdname);
                }
            }
            commands.add(cmd);
        } catch (CommandException e) {
            failedPlugins.add(config);
            logger.log(Level.FINE, "Failed to create a new plugin instance for " + config.getClassName());
            logger.log(Level.FINEST, "Failed to create a new plugin instance: ", e);
        }
    }
}
Also used : PluginManager(com.ibm.java.diagnostics.utils.plugins.PluginManager) DTFJPluginManager(com.ibm.java.diagnostics.utils.plugins.DTFJPluginManager) PluginConfig(com.ibm.java.diagnostics.utils.plugins.PluginConfig) ICommand(com.ibm.java.diagnostics.utils.commands.ICommand) DTFJPluginManager(com.ibm.java.diagnostics.utils.plugins.DTFJPluginManager) LocalPriorityClassloader(com.ibm.java.diagnostics.utils.plugins.LocalPriorityClassloader) ArrayList(java.util.ArrayList) CommandException(com.ibm.java.diagnostics.utils.commands.CommandException)

Aggregations

CommandException (com.ibm.java.diagnostics.utils.commands.CommandException)1 ICommand (com.ibm.java.diagnostics.utils.commands.ICommand)1 DTFJPluginManager (com.ibm.java.diagnostics.utils.plugins.DTFJPluginManager)1 LocalPriorityClassloader (com.ibm.java.diagnostics.utils.plugins.LocalPriorityClassloader)1 PluginConfig (com.ibm.java.diagnostics.utils.plugins.PluginConfig)1 PluginManager (com.ibm.java.diagnostics.utils.plugins.PluginManager)1 ArrayList (java.util.ArrayList)1