Fix up URLDecoding as per @zreed's recommendation

This commit is contained in:
libraryaddict 2014-05-25 17:57:34 +12:00
parent e24f404e42
commit 6652959553

View File

@ -4,6 +4,7 @@ import org.bukkit.entity.Entity;
import java.io.IOException; import java.io.IOException;
import java.net.URL; import java.net.URL;
import java.net.URLDecoder;
import java.security.CodeSource; import java.security.CodeSource;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Enumeration; import java.util.Enumeration;
@ -43,30 +44,34 @@ public class ClassGetter {
} }
private static void processJarfile(URL resource, String pkgname, ArrayList<Class<?>> classes) { private static void processJarfile(URL resource, String pkgname, ArrayList<Class<?>> classes) {
String relPath = pkgname.replace('.', '/');
String resPath = resource.getPath().replace("%20", " ");
String jarPath = resPath.replaceFirst("[.]jar[!].*", ".jar").replaceFirst("file:", "");
JarFile jarFile;
try { try {
jarFile = new JarFile(jarPath); String relPath = pkgname.replace('.', '/');
} catch (IOException e) { String resPath = URLDecoder.decode(resource.getPath(), "UTF-8");
throw new RuntimeException("Unexpected IOException reading JAR File '" + jarPath String jarPath = resPath.replaceFirst("[.]jar[!].*", ".jar").replaceFirst("file:", "");
+ "'. Do you have strange characters in your folders? Such as #?", e); JarFile jarFile;
} try {
Enumeration<JarEntry> entries = jarFile.entries(); jarFile = new JarFile(jarPath);
while (entries.hasMoreElements()) { } catch (IOException e) {
JarEntry entry = entries.nextElement(); throw new RuntimeException("Unexpected IOException reading JAR File '" + jarPath
String entryName = entry.getName(); + "'. Do you have strange characters in your folders? Such as #?", e);
String className = null;
if (entryName.endsWith(".class") && entryName.startsWith(relPath)
&& entryName.length() > (relPath.length() + "/".length())) {
className = entryName.replace('/', '.').replace('\\', '.').replace(".class", "");
} }
if (className != null) { Enumeration<JarEntry> entries = jarFile.entries();
Class<?> c = loadClass(className); while (entries.hasMoreElements()) {
if (c != null) JarEntry entry = entries.nextElement();
classes.add(c); String entryName = entry.getName();
String className = null;
if (entryName.endsWith(".class") && entryName.startsWith(relPath)
&& entryName.length() > (relPath.length() + "/".length())) {
className = entryName.replace('/', '.').replace('\\', '.').replace(".class", "");
}
if (className != null) {
Class<?> c = loadClass(className);
if (c != null)
classes.add(c);
}
} }
} catch (Exception ex) {
ex.printStackTrace();
} }
} }
} }