Class PluginsConfigBuilder

java.lang.Object
imagingbook.core.plugin.PluginsConfigBuilder

public class PluginsConfigBuilder extends Object

The main() method of this class creates the plugins.config file for a given plugins project, which is to be included in the associated JAR file. The execution is to be triggered during the Maven build or manually by

 mvn exec:java -Dexec.mainClass="imagingbook.pluginutils.PluginsConfigBuilder"

(at the root of a plugins project). The format of the entries in plugins.config have the following structure:

 menu-level, "plugin-name", package.classname
for example:
 Plugins>Binary>Regions, "Convex Hull Demo", Binary_Regions.Convex_Hull_Demo

Note that, technically, menu paths may be more than 2 levels deep, but this does not seem useful.

Plugin classes (implementing PlugIn or PlugInFilter) may be annotated with IjPluginPath and IjPluginName to specify where in ImageJ's menu tree and by which name the plugin should be installed. This information is stored in the plugins.config file at the root of the associated project, which is automatically added to the project's output JAR file during the Maven build. Example:

 // file MySuperPlugin.java
 import ij.plugin.filter.PlugInFilter;
 import imagingbook.pluginutils.annotations.IjPluginName;
 import imagingbook.pluginutils.annotations.IjPluginPath;
 ...
 @IjPluginPath("Plugins>Mine")
 @IjPluginName("Super Plugin")
 public class MySuperPlugin implements PlugInFilter {
        // plugin code ...
 }

In this case, plugin MySuperPlugin should be installed in ImageJ's menu tree as

 Plugins > Mine > Super Plugin

By default (i.e., if no annotations are present), plugins in the default package are installed at the top-level of 'Plugins' whereas plugins inside a named package are installed in 'Plugins>package-name' (see below). A IjPluginPath annotation may also be attached to a whole package in the associated package-info.java file. The following example specifies Plugins>Binary Regions as the default menu path for all plugins in package Binary_Regions:

 // file Binary_Regions/package-info.java
 @IjPluginPath("Plugins>Binary Regions")
 package Binary_Regions;
 import imagingbook.pluginutils.annotations.IjPluginPath;

Individual plugins may override the menu path specified for the containing package, as summarized below:

Plugin path priority rules summary:

  1. Value of a @IjPluginPath annotation at class level (always overrules if exists).
  2. Value of a @IjPluginPath annotation at package level (if exists).
  3. DefaultMenuPath + ">" + package-name if the plugin is inside a named package.
  4. DefaultMenuPath if the plugin is in the (unnamed) default package.

Plugin entry priority rules summary:

  1. Value of IjPluginName annotation at class level (if exists).
  2. Simple name of the plugin class.

Note that, in general, ImageJ uses the information in file plugins.config only for plugins loaded from a JAR file!

See Also:
  • Field Details

  • Method Details

    • collectPluginClasses

      public List<Class<?>> collectPluginClasses(String rootPath)
    • isIjPlugin

      public boolean isIjPlugin(Class<?> clazz)
      Returns true if the specified Class object is a sub-type of PlugIn or PlugInFilter.
      Parameters:
      clazz - a Class object
      Returns:
      true if a plugin type
    • main

      public static void main(String[] args)

      Method to be called from the command line. Builds the plugins.config file from the .class files found in the specified build directory and stores the file in the same directory. Takes two (optional) arguments:

      1. The project's build (output) directory (where .class files reside).
      2. The project's Maven artifact id.
      If no build directory is specified, the current directory is used.
      Parameters:
      args - args[0]: project build (output) directory, args[1]: project artefact id