Class PluginUtils


  • public class PluginUtils
    extends java.lang.Object
    Utility class for plugin-related methods.
    • Constructor Summary

      Constructors 
      Constructor Description
      PluginUtils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void assertUniquePluginName​(java.lang.Class<? extends Plugin> pluginClass)
      Ensures the specified Plugin has a unique name among all Plugin classes found in the current ClassSearcher's reach.
      static java.util.List<java.lang.Class<?>> findLoadedPlugins​(java.util.Set<ExtensionDetails> extensions)
      Finds all plugin classes loaded from a given set of extensions.
      static java.lang.Class<? extends Plugin> forName​(java.lang.String pluginClassName)
      Returns the Class for a Plugin, by class name.
      static java.lang.Class<? extends Plugin> getDefaultProviderForServiceClass​(java.lang.Class<?> serviceClass)
      Returns the Plugin Class that is specified as being the defaultProvider for a Service, or null if no default provider is specified.
      static java.util.List<PluginDescription> getPluginDescriptions​(PluginTool tool, java.util.List<java.lang.Class<?>> plugins)
      Finds all PluginDescription objects that match a given set of plugin classes.
      static java.lang.String getPluginNameFromClass​(java.lang.Class<? extends Plugin> pluginClass)
      Returns the name of a Plugin based on its class.
      static <T extends Plugin>
      T
      instantiatePlugin​(java.lang.Class<T> pluginClass, PluginTool tool)
      Returns a new instance of a Plugin.
      static boolean isValidPluginClass​(java.lang.Class<? extends Plugin> pluginClass)
      Returns true if the specified Plugin class is well-formed and meets requirements for Ghidra Plugins: Has a constructor with a signature of ThePlugin(PluginTool tool) Has a @PluginInfo annotation.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • PluginUtils

        public PluginUtils()
    • Method Detail

      • getPluginDescriptions

        public static java.util.List<PluginDescription> getPluginDescriptions​(PluginTool tool,
                                                                              java.util.List<java.lang.Class<?>> plugins)
        Finds all PluginDescription objects that match a given set of plugin classes. This effectively tells the caller which of the given plugins have been loaded by the class loader.

        eg: If the list of plugin classes contains the class "FooPlugin.class", this method will search the PluginConfigurationModel for any plugin with the name "FooPlugin" and return its PluginDescription.

        Note that this method does not take path/package information into account when finding plugins; in the example above, if there is more than one plugin with the name "FooPlugin", only one will be found (the one found is not guaranteed to be the first).

        Parameters:
        tool - the current tool
        plugins - the list of plugin classes to search for
        Returns:
        list of plugin descriptions
      • findLoadedPlugins

        public static java.util.List<java.lang.Class<?>> findLoadedPlugins​(java.util.Set<ExtensionDetails> extensions)
        Finds all plugin classes loaded from a given set of extensions.
        Parameters:
        extensions - set of extensions to search
        Returns:
        list of loaded plugin classes, or empty list if none found
      • instantiatePlugin

        public static <T extends Plugin> T instantiatePlugin​(java.lang.Class<T> pluginClass,
                                                             PluginTool tool)
                                                      throws PluginException
        Returns a new instance of a Plugin.
        Parameters:
        pluginClass - Specific Plugin Class
        tool - The PluginTool that is the parent of the new Plugin
        Returns:
        a new Plugin instance, never NULL.
        Throws:
        PluginException - if problem constructing the Plugin instance.
      • forName

        public static java.lang.Class<? extends Plugin> forName​(java.lang.String pluginClassName)
                                                         throws PluginException
        Returns the Class for a Plugin, by class name.
        Parameters:
        pluginClassName - String class name
        Returns:
        Class that is a Plugin, never null.
        Throws:
        PluginException - if specified class does not exist or is not a Plugin.
      • getDefaultProviderForServiceClass

        public static java.lang.Class<? extends Plugin> getDefaultProviderForServiceClass​(java.lang.Class<?> serviceClass)
        Returns the Plugin Class that is specified as being the defaultProvider for a Service, or null if no default provider is specified.

        Parameters:
        serviceClass - Service interface class
        Returns:
        Plugin class that provides the specified service
      • getPluginNameFromClass

        public static java.lang.String getPluginNameFromClass​(java.lang.Class<? extends Plugin> pluginClass)
        Returns the name of a Plugin based on its class.
        Parameters:
        pluginClass - Class to get name from
        Returns:
        String name, based on Class's getSimpleName()
      • assertUniquePluginName

        public static void assertUniquePluginName​(java.lang.Class<? extends Plugin> pluginClass)
                                           throws PluginException
        Ensures the specified Plugin has a unique name among all Plugin classes found in the current ClassSearcher's reach.
        Parameters:
        pluginClass - Class
        Throws:
        PluginException - throws exception if Plugin class is not uniquely named
      • isValidPluginClass

        public static boolean isValidPluginClass​(java.lang.Class<? extends Plugin> pluginClass)
        Returns true if the specified Plugin class is well-formed and meets requirements for Ghidra Plugins:
        • Has a constructor with a signature of ThePlugin(PluginTool tool)
        • Has a @PluginInfo annotation.

        See Plugin.

        Parameters:
        pluginClass - Class to examine.
        Returns:
        boolean true if well formed.