[Icemud-commits] IceMUD/src/mud/tools Plugin.java,1.7,1.8
Status: Alpha
Brought to you by:
gamerscloset
From: <jc...@us...> - 2003-12-12 18:40:31
|
Update of /cvsroot/icemud/IceMUD/src/mud/tools In directory sc8-pr-cvs1:/tmp/cvs-serv15531/tools Modified Files: Plugin.java Log Message: Fixed problem with non-jar files being treated as jars and improved error handling Index: Plugin.java =================================================================== RCS file: /cvsroot/icemud/IceMUD/src/mud/tools/Plugin.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** Plugin.java 4 Dec 2003 16:32:41 -0000 1.7 --- Plugin.java 12 Dec 2003 18:40:27 -0000 1.8 *************** *** 53,57 **** protected static Hashtable fetchPlugins(Class inClassType) throws Exception { File fDirectory = new File("plugins"); ! if (!fDirectory.exists()) return new Hashtable(); File[] fFiles = fDirectory.listFiles(); Hashtable hPlugins = new Hashtable(); --- 53,57 ---- protected static Hashtable fetchPlugins(Class inClassType) throws Exception { File fDirectory = new File("plugins"); ! if (!fDirectory.exists()) { return new Hashtable(); } File[] fFiles = fDirectory.listFiles(); Hashtable hPlugins = new Hashtable(); *************** *** 60,67 **** for (int i = 0; i < fFiles.length; i++) { //System.out.println("Processing:" + fFiles[i].getCanonicalPath()); - Hashtable hClasses = getClasses(fFiles[i].getCanonicalPath(), inClassType); ! hPlugins.putAll(hClasses); ! } return hPlugins; --- 60,65 ---- for (int i = 0; i < fFiles.length; i++) { //System.out.println("Processing:" + fFiles[i].getCanonicalPath()); Hashtable hClasses = getClasses(fFiles[i].getCanonicalPath(), inClassType); ! if (hClasses != null) { hPlugins.putAll(hClasses); } } return hPlugins; *************** *** 97,100 **** --- 95,103 ---- try { URLClassLoader classLoader; + if (!inFile.endsWith(".jar")) { + System.err.println("Found non jar file in plugins directory: "+ + inFile+"\nPlease ensure all jar files end in `.jar' suffix!"); + return null; + } URL urlForClassLoader = new URL("jar:file:" + inFile + "!/"); classLoader = new URLClassLoader(new URL[]{urlForClassLoader}); *************** *** 102,106 **** JarURLConnection urlConnection = (JarURLConnection)urlForClassLoader.openConnection(); - JarFile JR = urlConnection.getJarFile(); --- 105,108 ---- *************** *** 114,118 **** JarEntry je = (JarEntry)enum.nextElement(); String entryName = je.getName(); - System.out.println("JarEntry: "+entryName); if( entryName.endsWith( "class" )) { --- 116,119 ---- *************** *** 133,139 **** return hClasses; ! } catch (Exception e) { java.util.logging.Logger.getLogger("error").severe("Error "+ ! "processing plugins: "+e.toString()); } return null; --- 134,149 ---- return hClasses; ! } catch (InstantiationException e) { java.util.logging.Logger.getLogger("error").severe("Error "+ ! "instantiating plugin classes: "+e.toString()); ! } catch (IllegalAccessException e) { ! java.util.logging.Logger.getLogger("error").severe("Have you got "+ ! "permission to open the plugins?\n"+e.toString()); ! } catch (ClassNotFoundException e) { ! java.util.logging.Logger.getLogger("error").severe("Is this plugins "+ ! "file corrupt?"+e.toString()); ! } catch (java.io.IOException e) { ! java.util.logging.Logger.getLogger("error").severe("Error reading "+ ! "plugins file\n"+e.toString()); } return null; |