Compile and load plugins dynamically

Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
main
sigonasr2, Sig, Sigo 2 years ago committed by GitHub
parent d17b0635f5
commit 686d673212
  1. BIN
      bin/TestPlugin.jar
  2. BIN
      bin/sig/PluginLoader.class
  3. BIN
      bin/sig/SigsUniverse.class
  4. 2
      plugins/TestPlugin.java
  5. 36
      src/sig/PluginLoader.java

Binary file not shown.

Binary file not shown.

Binary file not shown.

@ -1,5 +1,5 @@
public class TestPlugin {
public TestPlugin() {
System.out.println("Loaded me!");
System.out.println("Loaded me! Yay!");
}
}

@ -1,7 +1,6 @@
package sig;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.reflect.InvocationTargetException;
@ -10,10 +9,6 @@ import java.net.URLClassLoader;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import java.util.jar.JarEntry;
import java.util.jar.JarInputStream;
public class PluginLoader {
public static void LoadPlugins() {
@ -27,40 +22,11 @@ public class PluginLoader {
}
}
public static List getClasseNames(String jarName) {
boolean debug=true;
ArrayList classes = new ArrayList();
if (debug)
System.out.println("Jar " + jarName );
try {
JarInputStream jarFile = new JarInputStream(new FileInputStream(
jarName));
JarEntry jarEntry;
while (true) {
jarEntry = jarFile.getNextJarEntry();
if (jarEntry == null) {
break;
}
if (jarEntry.getName().endsWith(".class")) {
if (debug)
System.out.println("Found "
+ jarEntry.getName().replaceAll("/", "\\."));
classes.add(jarEntry.getName().replaceAll("/", "\\."));
}
}
} catch (Exception e) {
e.printStackTrace();
}
return classes;
}
private static String LoadPlugin(Path f) {
try {
System.out.println("Loading "+f);
System.out.println(" Compiling "+f.getParent().toAbsolutePath()+"...");
Process process = Runtime.getRuntime().exec(new String[]{"javac","../plugins/TestPlugin.java"});
Process process = Runtime.getRuntime().exec(new String[]{"javac","-Xlint:unchecked","-cp","../plugins","-d",".","../plugins/TestPlugin.java"});
//Process process = Runtime.getRuntime().exec("jar cfm TestPlugin.jar ../manifest .");
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
StringBuilder line=new StringBuilder();

Loading…
Cancel
Save