Skip to content

Commit

Permalink
Improve compatability with IDE debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
ME1312 committed May 25, 2019
1 parent b3e2b00 commit fd1c16b
Showing 1 changed file with 26 additions and 11 deletions.
37 changes: 26 additions & 11 deletions GalaxiEngine/src/net/ME1312/Galaxi/Engine/PluginManager.java
Expand Up @@ -13,6 +13,7 @@
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.*;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
Expand All @@ -37,20 +38,34 @@ public class PluginManager extends net.ME1312.Galaxi.Plugin.PluginManager {
public String[] findClasses(Class<?> clazz) throws IOException {
LinkedList<String> classes = new LinkedList<String>();
try {
JarFile jarFile = new JarFile(new File(clazz.getProtectionDomain().getCodeSource().getLocation().toURI()));
Enumeration<JarEntry> entries = jarFile.entries();
URL source = clazz.getProtectionDomain().getCodeSource().getLocation();
if (source != null && source.getProtocol().equals("file")) {
File file = new File(source.toURI());

while (entries.hasMoreElements()) {
JarEntry entry = entries.nextElement();
if (!entry.isDirectory() && entry.getName().endsWith(".class")) {
String e = entry.getName().substring(0, entry.getName().length() - 6).replace('/', '.');
if (!knownClasses.keySet().contains(e)) knownClasses.put(e, clazz.getClassLoader());
if (!classes.contains(e)) classes.add(e);
if (file.isDirectory()) {
for (String entry : Util.<List<String>>getDespiteException(() -> Util.reflect(Util.class.getDeclaredMethod("zipsearch", File.class, File.class), null, file, file), null)) {
if (!(new File(file.getAbsolutePath() + File.separator + entry).isDirectory()) && entry.endsWith(".class")) {
String e = entry.substring(0, entry.length() - 6).replace(File.separatorChar, '.');
if (!knownClasses.keySet().contains(e)) knownClasses.put(e, clazz.getClassLoader());
if (!classes.contains(e)) classes.add(e);
}
}
}
if (file.isFile()) {
JarFile jarFile = new JarFile(file);
Enumeration<JarEntry> entries = jarFile.entries();

while (entries.hasMoreElements()) {
JarEntry entry = entries.nextElement();
if (!entry.isDirectory() && entry.getName().endsWith(".class")) {
String e = entry.getName().substring(0, entry.getName().length() - 6).replace('/', '.');
if (!knownClasses.keySet().contains(e)) knownClasses.put(e, clazz.getClassLoader());
if (!classes.contains(e)) classes.add(e);
}
}
}
}
} catch (URISyntaxException e) {
engine.getAppInfo().getLogger().error.println(e);
}
} catch (URISyntaxException e) {}
return classes.toArray(new String[0]);
}

Expand Down

0 comments on commit fd1c16b

Please sign in to comment.