Include compile options
Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
This commit is contained in:
parent
bcaa025af2
commit
d17b0635f5
Binary file not shown.
BIN
plugins/TestPlugin.class
Normal file
BIN
plugins/TestPlugin.class
Normal file
Binary file not shown.
Binary file not shown.
@ -1,33 +1,85 @@
|
|||||||
package sig;
|
package sig;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.FileInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.net.MalformedURLException;
|
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLClassLoader;
|
import java.net.URLClassLoader;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
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 class PluginLoader {
|
||||||
public static void LoadPlugins() {
|
public static void LoadPlugins() {
|
||||||
Path p = Path.of("..","plugins");
|
Path p = Path.of("..","plugins");
|
||||||
try {
|
try {
|
||||||
Files.walk(p).filter((f)->Files.isRegularFile(f)&&f.getFileName().toString().contains(".jar")).forEach((f)->{
|
Files.walk(p).filter((f)->Files.isRegularFile(f)&&f.getFileName().toString().contains(".java")).forEach((f)->{
|
||||||
LoadPlugin(f);
|
System.out.println(LoadPlugin(f));
|
||||||
});
|
});
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void LoadPlugin(Path f) {
|
public static List getClasseNames(String jarName) {
|
||||||
|
boolean debug=true;
|
||||||
|
ArrayList classes = new ArrayList();
|
||||||
|
|
||||||
|
if (debug)
|
||||||
|
System.out.println("Jar " + jarName );
|
||||||
try {
|
try {
|
||||||
System.out.println("Loading "+f);
|
JarInputStream jarFile = new JarInputStream(new FileInputStream(
|
||||||
URL l = f.toUri().toURL();
|
jarName));
|
||||||
URLClassLoader loader = new URLClassLoader(new URL[]{l});
|
JarEntry jarEntry;
|
||||||
Object newPlugin = Class.forName(f.getFileName().toString().replace(".jar",""),true,loader).getDeclaredConstructor().newInstance();
|
|
||||||
} catch (MalformedURLException | InstantiationException | IllegalAccessException | ClassNotFoundException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) {
|
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();
|
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("jar cfm TestPlugin.jar ../manifest .");
|
||||||
|
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
|
||||||
|
StringBuilder line=new StringBuilder();
|
||||||
|
String lin;
|
||||||
|
while ((lin = reader.readLine()) != null) {
|
||||||
|
line.append(lin).append("\n");
|
||||||
|
}
|
||||||
|
process = Runtime.getRuntime().exec(new String[]{"jar","cfm","TestPlugin.jar","../manifest","../plugins/TestPlugin.class"});
|
||||||
|
reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
|
||||||
|
while ((lin = reader.readLine()) != null) {
|
||||||
|
line.append(lin).append("\n");
|
||||||
|
}
|
||||||
|
URL l = Paths.get(f.getFileName().toString().replace(".java","")+".jar").toUri().toURL();
|
||||||
|
URLClassLoader loader = new URLClassLoader(new URL[]{l});
|
||||||
|
Object newPlugin = Class.forName(f.getFileName().toString().replace(".java",""),true,loader).getDeclaredConstructor().newInstance();
|
||||||
|
return line.toString();
|
||||||
|
} catch (IllegalArgumentException | SecurityException | IOException | InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException | ClassNotFoundException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user