Creates a configuration file for JAR/ZIP files that do not have one.
(String jar)
| 1024 | |
| 1025 | /** Creates a configuration file for JAR/ZIP files that do not have one. */ |
| 1026 | InputStream autoGenerateConfigFile(String jar) { |
| 1027 | StringBuffer sb = null; |
| 1028 | try { |
| 1029 | ZipFile jarFile = new ZipFile(jar); |
| 1030 | Enumeration entries = jarFile.entries(); |
| 1031 | while (entries.hasMoreElements()) { |
| 1032 | ZipEntry entry = (ZipEntry) entries.nextElement(); |
| 1033 | String name = entry.getName(); |
| 1034 | if (name.endsWith(".class") && name.indexOf("_")>0 && name.indexOf("$")==-1 |
| 1035 | && name.indexOf("/_")==-1 && !name.startsWith("_")) { |
| 1036 | if (Character.isLowerCase(name.charAt(0))&&name.indexOf("/")!=-1) |
| 1037 | continue; |
| 1038 | if (sb==null) sb = new StringBuffer(); |
| 1039 | String className = name.substring(0, name.length()-6); |
| 1040 | int slashIndex = className.lastIndexOf('/'); |
| 1041 | String plugins = "Plugins"; |
| 1042 | if (slashIndex >= 0) { |
| 1043 | plugins += ">" + className.substring(0, slashIndex).replace('/', '>').replace('_', ' '); |
| 1044 | name = className.substring(slashIndex + 1); |
| 1045 | } else |
| 1046 | name = className; |
| 1047 | name = name.replace('_', ' '); |
| 1048 | className = className.replace('/', '.'); |
| 1049 | sb.append(plugins + ", \""+name+"\", "+className+"\n"); |
| 1050 | } |
| 1051 | } |
| 1052 | jarFile.close(); |
| 1053 | } |
| 1054 | catch (Throwable e) { |
| 1055 | IJ.log(jar+": "+e); |
| 1056 | } |
| 1057 | if (sb==null) |
| 1058 | return null; |
| 1059 | else |
| 1060 | return new ByteArrayInputStream(sb.toString().getBytes()); |
| 1061 | } |
| 1062 | |
| 1063 | /** Returns a list of the plugins with directory names removed. */ |
| 1064 | String[] getStrippedPlugins(String[] plugins) { |