mirror of
https://github.com/DanilaFe/abacus
synced 2026-01-11 01:35:18 +00:00
Add external plugin support
This commit is contained in:
51
src/org/nwapw/abacus/plugin/ClassFinderV2.java
Normal file
51
src/org/nwapw/abacus/plugin/ClassFinderV2.java
Normal 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();
|
||||
}
|
||||
}
|
||||
BIN
src/org/nwapw/abacus/plugin/Standard.jar
Normal file
BIN
src/org/nwapw/abacus/plugin/Standard.jar
Normal file
Binary file not shown.
Reference in New Issue
Block a user