<html>
<head>
<base href="http://fiji.sc/bugzilla/" />
</head>
<body>
<p>
<div>
<b><a class="bz_bug_link
bz_status_NEW "
title="NEW - Fiji hangs when installing macro tool"
href="http://fiji.sc/bugzilla/show_bug.cgi?id=835#c11">Comment # 11</a>
on <a class="bz_bug_link
bz_status_NEW "
title="NEW - Fiji hangs when installing macro tool"
href="http://fiji.sc/bugzilla/show_bug.cgi?id=835">bug 835</a>
from <span class="vcard"><a class="email" href="mailto:ilan.tal@gmail.com" title="Ilan Tal <ilan.tal@gmail.com>"> <span class="fn">Ilan Tal</span></a>
</span></b>
<pre>I managed to track down the problem to Menus.java. Here is the relevant code
/** Returns a list of the plugins in the plugins menu. */
public static synchronized String[] getPlugins() {
File f = pluginsPath!=null?new File(pluginsPath):null;
if (f==null || (f!=null && !f.isDirectory()))
return null;
String[] list = f.list();
if (list==null)
return null;
Vector v = new Vector();
jarFiles = null;
macroFiles = null;
for (int i=0; i<list.length; i++) {
String name = list[i];
boolean isClassFile = name.endsWith(".class");
boolean hasUnderscore = name.indexOf('_')>=0;
if (hasUnderscore && isClassFile && name.indexOf('$')<0 ) {
name = name.substring(0, name.length()-6); // remove ".class"
v.addElement(name);
} else if (hasUnderscore && (name.endsWith(".jar") ||
name.endsWith(".zip"))) {
if (jarFiles==null) jarFiles = new Vector();
jarFiles.addElement(pluginsPath + name);
} else if (validMacroName(name,hasUnderscore)) {
if (macroFiles==null) macroFiles = new Vector();
macroFiles.addElement(name);
} else {
if (!isClassFile)
checkSubdirectory(pluginsPath, name, v);
}
}
list = new String[v.size()];
v.copyInto((String[])list);
StringSorter.sort(list);
return list;
}
/** Looks for plugins and jar files in a subdirectory of the plugins
directory. */
private static void checkSubdirectory(String path, String dir, Vector v) {
if (dir.endsWith(".java"))
return;
File f = new File(path, dir);
if (!f.isDirectory())
return;
String[] list = f.list();
if (list==null)
return;
dir += "/";
int classCount=0, otherCount=0;
String className = null;
for (int i=0; i<list.length; i++) {
String name = list[i];
boolean hasUnderscore = name.indexOf('_')>=0;
if (hasUnderscore && name.endsWith(".class") &&
name.indexOf('$')<0) {
name = name.substring(0, name.length()-6); // remove ".class"
v.addElement(dir+name);
classCount++;
className = name;
//IJ.write("File: "+f+"/"+name);
} else if (hasUnderscore && (name.endsWith(".jar") ||
name.endsWith(".zip"))) {
if (jarFiles==null) jarFiles = new Vector();
jarFiles.addElement(f.getPath() + File.separator + name);
otherCount++;
} else if (validMacroName(name,hasUnderscore)) {
if (macroFiles==null) macroFiles = new Vector();
macroFiles.addElement(dir + name);
otherCount++;
} else {
File f2 = new File(f, name);
if (f2.isDirectory()) installSubdirectorMacros(f2, dir+name);
}
}
if (Prefs.moveToMisc && classCount==1 && otherCount==0 &&
dir.indexOf("_")==-1)
v.setElementAt("Miscellaneous/" + className,
v.size() - 1);
}
The problem is macroFiles never gets a non null value in Fiji. In ImageJ, it
works with no problems. In the end the problem comes down to
private static boolean validMacroName(String name, boolean hasUnderscore) {
return
(hasUnderscore&&name.endsWith(".txt"))||name.endsWith(".ijm")||name.endsWith(".js")
||(name.endsWith(".bsh")&&!isFiji)||(name.endsWith(".py")&&!isFiji);
}
which returns a value of FALSE for a valid macro name. I verified that this
routine hasn't changed even in the latest 1.49f. It should return TRUE if the
name end in ".txt" and has an underscore, or if name ends in ".ijm" without any
connection to an underscore. Again, in ImageJ it works fine, but not in Fiji.
The process begins in getPlugins where macroFiles gets initialized to null.
>From there it looks for valid macros to store. In my case I've got
Postage_Action_Tool.ijm which is a perfectly valid macro file name. This file
name is in the Tools directory inside the plugins directory.
The getPlugins gets a file list where the interesting entry is Tools. Of course
Tools isn't a macro so it gets down to checkSubdirectory(...). Inside
checkSubdirectory there is directory list which includes my file
Postage_Action_Tool.ijm. Even though this is a perfectly valid macro name,
validMacroName insists it isn't valid. Thus macroFiles never gets a non null
value and no elements are added to it.
I thought maybe there were some invisible characters which might cause the
endsWith(".ijm") to fail, so I copied over the exact same file from ImageJ into
Fiji. I was going to suggest to add a trim to the list line
String name = list[i].trim();
but now I have strong doubts that it would help. This is especially after I
looked at some other macros which should have been added. They are
About_Plugins_Macros.txt
batch_convert_any_to_tif.txt
Polygon_.txt
RGB_Histogram.txt
All of them should have passed the test and none of them passed in fact. These
are all .txt files, but they all have underscores.
So the problem is wider than the bug I reported, but it also affects me, which
is the part which is most annoying to me. Someone may be familiar with one or
more of the above macros. If I knew what to expect from them, I might verify
that they work differently in ImageJ.
Thanks,
Ilan</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are the assignee for the bug.</li>
</ul>
</body>
</html>