1
0
mirror of https://github.com/DanilaFe/abacus synced 2024-12-22 23:40:08 -08:00

Add external plugin support

This commit is contained in:
rileyJones 2017-07-28 11:17:54 -07:00
parent 7755a04bd7
commit 408c4f0379
4 changed files with 86 additions and 2 deletions

6
.idea/vcs.xml Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>

View File

@ -1,10 +1,14 @@
package org.nwapw.abacus;
import org.nwapw.abacus.plugin.PluginManager;
import org.nwapw.abacus.plugin.StandardPlugin;
//import org.nwapw.abacus.plugin.StandardPlugin;
import org.nwapw.abacus.window.Window;
import org.nwapw.abacus.plugin.ClassFinderV2;
import javax.swing.*;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
public class Abacus {
@ -22,10 +26,33 @@ public class Abacus {
e.printStackTrace();
}
manager = new PluginManager();
manager.addInstantiated(new StandardPlugin(manager));
ArrayList<String> names = new ArrayList();
try {
ClassFinderV2 classFinder = new ClassFinderV2();
File pluginFile = new File("C:\\Users\\galbraithja\\Desktop\\.git\\abacus\\src\\org\\nwapw\\abacus\\plugin");
for(File classes:pluginFile.listFiles()){
if(classes.getName().endsWith(".jar")){
names.addAll(classFinder.addJar("C:\\Users\\galbraithja\\Desktop\\.git\\abacus\\src\\org\\nwapw\\abacus\\plugin\\Standard.jar"));
}
}
for(String name:names){
System.out.println(name);
}
ArrayList<Class> classes = classFinder.getClasses();
for(Class classGet:classes){
manager.addClass(classGet);
}
} catch (IOException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
mainUi = new Window(manager);
mainUi.setVisible(true);
manager.load();
}
public static void main(String[] args){

View File

@ -0,0 +1,51 @@
package org.nwapw.abacus.plugin;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
public class ClassFinderV2 {
ArrayList<Class> classes;
URL[] urls;
public ClassFinderV2(){
classes = new ArrayList();
}
public ArrayList<String> addJar(String path) throws IOException, ClassNotFoundException {
//urls = new URL[]{new URL("jar:file:" + path + "!/")};
return addJar(new File(path));
}
public ArrayList<String> addJar(File jarLocation) throws IOException, ClassNotFoundException {
String path = jarLocation.getPath();
urls = new URL[]{new URL("jar:file:" + path + "!/")};
URLClassLoader classLoader = URLClassLoader.newInstance(urls);
JarFile jarFolder = new JarFile(jarLocation);
Enumeration jarList = jarFolder.entries();
ArrayList<String> classNames = new ArrayList();
while(jarList.hasMoreElements()){
JarEntry tempJar = (JarEntry)jarList.nextElement();
if(tempJar.getName().endsWith(".class")){
//System.out.println(tempJar.getName());
classNames.add(tempJar.getName());
classes.add(classLoader.loadClass(tempJar.getName().replace('/','.').substring(0,tempJar.getName().length()-6)));
}
}
return classNames;
}
public ArrayList<Class> getClasses(){
return classes;
}
public Class getClass(int number){
return classes.get(number);
}
public void delClasses(){
classes=new ArrayList();
}
public int classCount(){
return classes.size();
}
}

Binary file not shown.