📄 jarclassloader.java
字号:
} // JDK 1.1.8 throws a GPF when we do an isAssignableFrom() // on an unresolved class Class clazz = loadClass(name,true); int modifiers = clazz.getModifiers(); if(!Modifier.isInterface(modifiers) && !Modifier.isAbstract(modifiers) && EditPlugin.class.isAssignableFrom(clazz)) { String label = jEdit.getProperty("plugin." + name + ".name"); String version = jEdit.getProperty("plugin." + name + ".version"); if(version == null) { Log.log(Log.ERROR,this,"Plugin " + name + " needs" + " 'name' and 'version' properties."); jar.addPlugin(new EditPlugin.Broken(name)); return false; } jar.getActions().setLabel(jEdit.getProperty( "action-set.plugin", new String[] { label })); Log.log(Log.NOTICE,this,"Starting plugin " + label + " (version " + version + ")"); jar.addPlugin((EditPlugin)clazz.newInstance()); return true; } else { // not a real plugin class return true; } } //}}} //{{{ checkDependencies() method private boolean checkDependencies(String name) { int i = 0; boolean ok = true; String dep; while((dep = jEdit.getProperty("plugin." + name + ".depend." + i++)) != null) { int index = dep.indexOf(' '); if(index == -1) { Log.log(Log.ERROR,this,name + " has an invalid" + " dependency: " + dep); return false; } String what = dep.substring(0,index); String arg = dep.substring(index + 1); if(what.equals("jdk")) { if(MiscUtilities.compareStrings( System.getProperty("java.version"), arg,false) < 0) { String[] args = { arg, System.getProperty("java.version") }; jEdit.pluginError(jar.getPath(),"plugin-error.dep-jdk",args); ok = false; } } else if(what.equals("jedit")) { if(arg.length() != 11) { Log.log(Log.ERROR,this,"Invalid jEdit version" + " number: " + arg); ok = false; } if(MiscUtilities.compareStrings( jEdit.getBuild(),arg,false) < 0) { String needs = MiscUtilities.buildToVersion(arg); String[] args = { needs, jEdit.getVersion() }; jEdit.pluginError(jar.getPath(), "plugin-error.dep-jedit",args); ok = false; } } else if(what.equals("plugin")) { int index2 = arg.indexOf(' '); if(index2 == -1) { Log.log(Log.ERROR,this,name + " has an invalid dependency: " + dep + " (version is missing)"); return false; } String plugin = arg.substring(0,index2); String needVersion = arg.substring(index2 + 1); String currVersion = jEdit.getProperty("plugin." + plugin + ".version"); if(currVersion == null) { String[] args = { needVersion, plugin }; jEdit.pluginError(jar.getPath(), "plugin-error.dep-plugin.no-version", args); ok = false; } else if(MiscUtilities.compareStrings(currVersion, needVersion,false) < 0) { String[] args = { needVersion, plugin, currVersion }; jEdit.pluginError(jar.getPath(), "plugin-error.dep-plugin",args); ok = false; } else if(jEdit.getPlugin(plugin) instanceof EditPlugin.Broken) { String[] args = { plugin }; jEdit.pluginError(jar.getPath(), "plugin-error.dep-plugin.broken",args); ok = false; } } else if(what.equals("class")) { try { loadClass(arg,false); } catch(Exception e) { String[] args = { arg }; jEdit.pluginError(jar.getPath(), "plugin-error.dep-class",args); ok = false; } } else { Log.log(Log.ERROR,this,name + " has unknown" + " dependency: " + dep); return false; } } return ok; } //}}} //{{{ _loadClass() method /** * Load class from this JAR only. */ private Class _loadClass(String clazz, boolean resolveIt) throws ClassNotFoundException { Class cls = findLoadedClass(clazz); if(cls != null) { if(resolveIt) resolveClass(cls); return cls; } String name = MiscUtilities.classToFile(clazz); try { ZipEntry entry = zipFile.getEntry(name); if(entry == null) throw new ClassNotFoundException(clazz); InputStream in = zipFile.getInputStream(entry); int len = (int)entry.getSize(); byte[] data = new byte[len]; int success = 0; int offset = 0; while(success < len) { len -= success; offset += success; success = in.read(data,offset,len); if(success == -1) { Log.log(Log.ERROR,this,"Failed to load class " + clazz + " from " + zipFile.getName()); throw new ClassNotFoundException(clazz); } } cls = defineClass(clazz,data,0,data.length); if(resolveIt) resolveClass(cls); return cls; } catch(IOException io) { Log.log(Log.ERROR,this,io); throw new ClassNotFoundException(clazz); } } //}}} //{{{ definePackages() method /** * Defines all packages found in the given Java archive file. The * attributes contained in the specified Manifest will be used to obtain * package version and sealing information. */ private void definePackages() { try { Manifest manifest = zipFile.getManifest(); if(manifest != null) { Map entries = manifest.getEntries(); Iterator i = entries.keySet().iterator(); while(i.hasNext()) { String path = (String)i.next(); if(!path.endsWith(".class")) { String name = path.replace('/', '.'); if(name.endsWith(".")) name = name.substring(0, name.length() - 1); // code url not implemented definePackage(path,name,manifest,null); } } } } catch (Exception ex) { // should never happen, not severe anyway Log.log(Log.ERROR, this,"Error extracting manifest info " + "for file " + zipFile); Log.log(Log.ERROR, this, ex); } } //}}} //{{{ definePackage() method /** * Defines a new package by name in this ClassLoader. The attributes * contained in the specified Manifest will be used to obtain package * version and sealing information. For sealed packages, the additional * URL specifies the code source URL from which the package was loaded. */ private Package definePackage(String path, String name, Manifest man, URL url) throws IllegalArgumentException { String specTitle = null; String specVersion = null; String specVendor = null; String implTitle = null; String implVersion = null; String implVendor = null; String sealed = null; URL sealBase = null; Attributes attr = man.getAttributes(path); if(attr != null) { specTitle = attr.getValue( Attributes.Name.SPECIFICATION_TITLE); specVersion = attr.getValue( Attributes.Name.SPECIFICATION_VERSION); specVendor = attr.getValue( Attributes.Name.SPECIFICATION_VENDOR); implTitle = attr.getValue( Attributes.Name.IMPLEMENTATION_TITLE); implVersion = attr.getValue( Attributes.Name.IMPLEMENTATION_VERSION); implVendor = attr.getValue( Attributes.Name.IMPLEMENTATION_VENDOR); sealed = attr.getValue(Attributes.Name.SEALED); } attr = man.getMainAttributes(); if (attr != null) { if (specTitle == null) { specTitle = attr.getValue( Attributes.Name.SPECIFICATION_TITLE); } if (specVersion == null) { specVersion = attr.getValue( Attributes.Name.SPECIFICATION_VERSION); } if (specVendor == null) { specVendor = attr.getValue( Attributes.Name.SPECIFICATION_VENDOR); } if (implTitle == null) { implTitle = attr.getValue( Attributes.Name.IMPLEMENTATION_TITLE); } if (implVersion == null) { implVersion = attr.getValue( Attributes.Name.IMPLEMENTATION_VERSION); } if (implVendor == null) { implVendor = attr.getValue( Attributes.Name.IMPLEMENTATION_VENDOR); } if (sealed == null) { sealed = attr.getValue(Attributes.Name.SEALED); } } //if("true".equalsIgnoreCase(sealed)) // sealBase = url; return super.definePackage(name, specTitle, specVersion, specVendor, implTitle, implVersion, implVendor, sealBase); } //}}} //}}}}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -