Information about loaded Plugin

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Information about loaded Plugin

Phase GmbH
Hi,

is there a way to find out, whether an other instance of ImageJ has loaded a certain Plugin?

Thanks

Christian
Reply | Threaded
Open this post in threaded view
|

Re: Information about loaded Plugin

ctrueden
Hi Christian,

is there a way to find out, whether an other instance of ImageJ has loaded a
> certain Plugin?
>

I'm not sure I understand your question. If the plugin has an underscore in
the name, it should appear in the Plugins menu. What do you mean by "an
other instance"?

I've been working on some code lately to help diagnose whether various
libraries are available within the ImageJ environment. I grabbed some of my
code and turned it into a standalone plugin (below) that you can use to
verify from where (if anywhere) ImageJ is loading a particular Java class.
It requirs that you know the fully qualified class name of the plugin you
want to check, though. Also note that ImageJ's class loader does not
properly identify Java class versions, so my plugin always lists the version
as "null" at the moment.

-Curtis

--
//
// Plugin_Finder.java
//

import ij.IJ;
import ij.plugin.PlugIn;
import ij.gui.GenericDialog;
import java.io.File;
import java.net.URLDecoder;

/**
 * Utility class for finding location of a given plugin or other Java class.
 * @author Curtis Rueden ctrueden at wisc.edu
 */
public class Plugin_Finder implements PlugIn {

  public void run(String arg) {
    GenericDialog gd = new GenericDialog("Plugin Finder");
    gd.addStringField("Class_name: ", "Plugin_Finder", 30);
    gd.showDialog();
    if (gd.wasCanceled()) return;
    String fqcn = gd.getNextString();

    // load class
    try {
      Class c = Class.forName(fqcn);

      // try to detect version from the package
      String version = null;
      if (c != null) {
        Package p = c.getPackage();
        if (p != null) {
          String pVendor = p.getImplementationVendor();
          String pVersion = p.getImplementationVersion();
          if (pVendor != null && pVersion != null) {
            version = pVersion + " (" + pVendor + ")";
          }
          else if (pVersion != null) version = pVersion;
          else if (pVendor != null) version = pVendor;
        }
      }

      // get resource containing the class
      String className = fqcn.substring(fqcn.lastIndexOf(".") + 1);
      String path = c.getResource(className + ".class").toString();
      path = path.replaceAll("^jar:", "");
      path = path.replaceAll("^file:", "");
      path = path.replaceAll("^/*/", "/");
      path = path.replaceAll("^/([A-Z]:)", "$1");
      path = path.replaceAll("!.*", "");
      path = URLDecoder.decode(path, "UTF-8");
      String slash = File.separator;
      if (slash.equals("\\")) slash = "\\\\";
      path = path.replaceAll("/", slash);

      IJ.showMessage("Found class " + fqcn + ":\n" +
        "    Path = " + path + "\n" +
        "    Version = " + version);
    }
    catch (Throwable t) {
      IJ.showMessage("Could not find class " + fqcn + ":\n" + t);
    }
  }

}

On Tue, Apr 8, 2008 at 11:52 AM, Phase GmbH <[hidden email]> wrote:

> Hi,
>
> is there a way to find out, whether an other instance of ImageJ has loaded
> a certain Plugin?
>
> Thanks
>
> Christian
>