code cleaning
This commit is contained in:
parent
656416c6a1
commit
dca1851212
@ -27,7 +27,6 @@ package sesim;
|
|||||||
|
|
||||||
import gui.Globals;
|
import gui.Globals;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileFilter;
|
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.reflect.Modifier;
|
import java.lang.reflect.Modifier;
|
||||||
@ -57,6 +56,10 @@ public class AutoTraderLoader {
|
|||||||
setPathList(pathlist);
|
setPathList(pathlist);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the path list where to search for traders
|
||||||
|
* @param pathlist List of paths
|
||||||
|
*/
|
||||||
public final void setPathList(ArrayList<String> pathlist) {
|
public final void setPathList(ArrayList<String> pathlist) {
|
||||||
this.pathlist = pathlist;
|
this.pathlist = pathlist;
|
||||||
this.traders_cache = null;
|
this.traders_cache = null;
|
||||||
@ -75,16 +78,7 @@ public class AutoTraderLoader {
|
|||||||
|
|
||||||
do {
|
do {
|
||||||
for (Class<?> i : cls.getInterfaces()) {
|
for (Class<?> i : cls.getInterfaces()) {
|
||||||
Globals.LOGGER.info(String.format("Interface: %s", i.getCanonicalName()));
|
if (i == (AutoTraderInterface.class)) {
|
||||||
|
|
||||||
String cn = AutoTraderInterface.class.getCanonicalName();
|
|
||||||
Globals.LOGGER.info(String.format("Interface1: %s", cn));
|
|
||||||
|
|
||||||
// if (i == (AutoTraderInterface.class)) {
|
|
||||||
if (cn.endsWith(i.getCanonicalName())) {
|
|
||||||
|
|
||||||
Globals.LOGGER.info("YEEEEA");
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -97,19 +91,19 @@ public class AutoTraderLoader {
|
|||||||
private ClassLoader cl;
|
private ClassLoader cl;
|
||||||
|
|
||||||
public AutoTraderInterface MakeInstance(Class<?> cls){
|
public AutoTraderInterface MakeInstance(Class<?> cls){
|
||||||
ClassLoader cur = Thread.currentThread().getContextClassLoader();
|
// ClassLoader cur = Thread.currentThread().getContextClassLoader();
|
||||||
Thread.currentThread().setContextClassLoader(cl);
|
// Thread.currentThread().setContextClassLoader(cl);
|
||||||
|
|
||||||
AutoTraderInterface ai;
|
AutoTraderInterface ai;
|
||||||
Globals.LOGGER.info("Going to load");
|
|
||||||
try {
|
try {
|
||||||
ai = (AutoTraderInterface)cls.newInstance();
|
ai = (AutoTraderInterface)cls.newInstance();
|
||||||
} catch (InstantiationException | IllegalAccessException ex) {
|
} catch (InstantiationException | IllegalAccessException ex) {
|
||||||
Globals.LOGGER.info("Ist was passiert");
|
|
||||||
Logger.getLogger(AutoTraderLoader.class.getName()).log(Level.SEVERE, null, ex);
|
Logger.getLogger(AutoTraderLoader.class.getName()).log(Level.SEVERE, null, ex);
|
||||||
ai=null;
|
ai=null;
|
||||||
}
|
}
|
||||||
Thread.currentThread().setContextClassLoader(cur);
|
// Thread.currentThread().setContextClassLoader(cur);
|
||||||
|
|
||||||
return ai;
|
return ai;
|
||||||
}
|
}
|
||||||
@ -117,11 +111,11 @@ public class AutoTraderLoader {
|
|||||||
|
|
||||||
Class<AutoTraderInterface> loadAutoTraderClass(String filename, String classname) {
|
Class<AutoTraderInterface> loadAutoTraderClass(String filename, String classname) {
|
||||||
|
|
||||||
System.out.printf("Comming in width %s %s", filename, classname);
|
// System.out.printf("Comming in width %s %s", filename, classname);
|
||||||
Globals.LOGGER.info(String.format("Comming in width %s %s\n", filename, classname));
|
// Globals.LOGGER.info(String.format("Comming in width %s %s\n", filename, classname));
|
||||||
|
|
||||||
if (classname == null) {
|
if (classname == null) {
|
||||||
System.out.printf("Calssname is null\n");
|
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
@ -137,7 +131,7 @@ public class AutoTraderLoader {
|
|||||||
Logger.getLogger(AutoTraderLoader.class.getName()).log(Level.SEVERE, null, ex);
|
Logger.getLogger(AutoTraderLoader.class.getName()).log(Level.SEVERE, null, ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
Globals.LOGGER.info(String.format("URL: %s", url.toString()));
|
// Globals.LOGGER.info(String.format("URL: %s", url.toString()));
|
||||||
|
|
||||||
URL[] urls = new URL[]{url};
|
URL[] urls = new URL[]{url};
|
||||||
|
|
||||||
@ -152,13 +146,13 @@ public class AutoTraderLoader {
|
|||||||
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Globals.LOGGER.info("try cl");
|
// Globals.LOGGER.info("try cl");
|
||||||
// Class<?> cls = cl.loadClass(clnam);
|
// Class<?> cls = cl.loadClass(clnam);
|
||||||
Class<?> c = cl.loadClass(clnam);
|
Class<?> c = cl.loadClass(clnam);
|
||||||
if (c == null) {
|
if (c == null) {
|
||||||
Globals.LOGGER.info("loader c was null");
|
Globals.LOGGER.info("loader c was null");
|
||||||
}
|
}
|
||||||
Globals.LOGGER.info("Ccast");
|
// Globals.LOGGER.info("Ccast");
|
||||||
Class<AutoTraderInterface> cls = (Class<AutoTraderInterface>) c; // cl.loadClass(clnam);
|
Class<AutoTraderInterface> cls = (Class<AutoTraderInterface>) c; // cl.loadClass(clnam);
|
||||||
// return cls;
|
// return cls;
|
||||||
if (cls == null) {
|
if (cls == null) {
|
||||||
@ -166,9 +160,9 @@ public class AutoTraderLoader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
System.out.printf("Check Class: %s\n", cls.getCanonicalName());
|
System.out.printf("Check Class: %s\n", cls.getCanonicalName());
|
||||||
Globals.LOGGER.info(String.format("Class prope %s", cls.getCanonicalName()));
|
// Globals.LOGGER.info(String.format("Class prope %s", cls.getCanonicalName()));
|
||||||
|
|
||||||
if (isAutoTrader(cls)) {
|
if (isAutoTrader(cls) ) {
|
||||||
Globals.LOGGER.info("We have found an autotrader interface");
|
Globals.LOGGER.info("We have found an autotrader interface");
|
||||||
Class<AutoTraderInterface> claa;
|
Class<AutoTraderInterface> claa;
|
||||||
claa = (Class<AutoTraderInterface>) cls;
|
claa = (Class<AutoTraderInterface>) cls;
|
||||||
@ -192,13 +186,13 @@ public class AutoTraderLoader {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* public ArrayList<Class<AutoTraderInterface>> getTradersX() {
|
|
||||||
String[] a = System.getProperty("java.class.path").split(System.getProperty("path.separator"));
|
|
||||||
this.pathlist=new ArrayList<>(Arrays.asList(a));
|
/**
|
||||||
return getTraders0();
|
* Get a list of all traders found in class path
|
||||||
}
|
* @return List of traders
|
||||||
*/
|
*/
|
||||||
public ArrayList<Class<AutoTraderInterface>> getTraders() {
|
public ArrayList<Class<AutoTraderInterface>> getInstalledTraders() {
|
||||||
|
|
||||||
if (traders_cache != null) {
|
if (traders_cache != null) {
|
||||||
return traders_cache;
|
return traders_cache;
|
||||||
@ -209,28 +203,24 @@ public class AutoTraderLoader {
|
|||||||
|
|
||||||
for (String classpathEntry : pathlist) {
|
for (String classpathEntry : pathlist) {
|
||||||
|
|
||||||
Globals.LOGGER.info(String.format("Here we ar looking now %s", classpathEntry));
|
|
||||||
|
|
||||||
Consumer<? super Path> pf = (Object t) -> {
|
Consumer<? super Path> pf = (Object t) -> {
|
||||||
|
|
||||||
String fn = ((Path) t).toString();
|
String fn = ((Path) t).toString();
|
||||||
// System.out.printf("Checking out file %s\n", fn);
|
|
||||||
Globals.LOGGER.info(String.format("Checking out file %s\n", fn));
|
|
||||||
|
|
||||||
|
// handle a .class file
|
||||||
if (fn.toLowerCase().endsWith(".class")) {
|
if (fn.toLowerCase().endsWith(".class")) {
|
||||||
String cl = fn.substring(classpathEntry.length());
|
String class_name = fn.substring(classpathEntry.length());
|
||||||
System.out.printf("The CL: %s\n", cl);
|
|
||||||
|
Class<AutoTraderInterface> cls = loadAutoTraderClass(fn, class_name);
|
||||||
Class<AutoTraderInterface> cls = loadAutoTraderClass(fn, cl);
|
|
||||||
if (cls == null) {
|
if (cls == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
traders.add(cls);
|
traders.add(cls);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// handle a .jar file
|
||||||
if (fn.toLowerCase().endsWith(".jar")) {
|
if (fn.toLowerCase().endsWith(".jar")) {
|
||||||
System.out.printf("Its a jar!\n");
|
|
||||||
Globals.LOGGER.info("Its a jar");
|
|
||||||
|
|
||||||
JarInputStream is = null;
|
JarInputStream is = null;
|
||||||
try {
|
try {
|
||||||
File jar = new File(fn);
|
File jar = new File(fn);
|
||||||
@ -243,12 +233,11 @@ public class AutoTraderLoader {
|
|||||||
|
|
||||||
if (entry.getName().endsWith(".class")) {
|
if (entry.getName().endsWith(".class")) {
|
||||||
|
|
||||||
System.out.printf("Entry: %s\n", entry.getName());
|
// System.out.printf("Entry: %s\n", entry.getName());
|
||||||
|
|
||||||
String fn0 = entry.getName();
|
// String fn0 = entry.getName();
|
||||||
Class<AutoTraderInterface> cls = loadAutoTraderClass(fn, "/" + entry.getName());
|
Class<AutoTraderInterface> cls = loadAutoTraderClass(fn, "/" + entry.getName());
|
||||||
if (cls != null) {
|
if (cls != null) {
|
||||||
Globals.LOGGER.info("Class is not null!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n");
|
|
||||||
traders.add(cls);
|
traders.add(cls);
|
||||||
}
|
}
|
||||||
//Globals.LOGGER.info("clas was null");
|
//Globals.LOGGER.info("clas was null");
|
||||||
@ -277,10 +266,11 @@ public class AutoTraderLoader {
|
|||||||
Logger.getLogger(AutoTraderLoader.class.getName()).log(Level.SEVERE, null, ex);
|
Logger.getLogger(AutoTraderLoader.class.getName()).log(Level.SEVERE, null, ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
traders_cache = traders;
|
traders_cache = traders;
|
||||||
|
|
||||||
Globals.LOGGER.info(String.format("We hav found %d traders", traders.size()));
|
// Globals.LOGGER.info(String.format("We have found %d traders", traders.size()));
|
||||||
|
|
||||||
return traders;
|
return traders;
|
||||||
|
|
||||||
@ -288,10 +278,10 @@ public class AutoTraderLoader {
|
|||||||
|
|
||||||
public ArrayList<String> getDefaultStrategyNames(boolean devel) {
|
public ArrayList<String> getDefaultStrategyNames(boolean devel) {
|
||||||
ArrayList<Class<AutoTraderInterface>> trclasses;
|
ArrayList<Class<AutoTraderInterface>> trclasses;
|
||||||
trclasses = this.getTraders();
|
// trclasses = this.getInstalledTraders();
|
||||||
|
|
||||||
ArrayList<String> ret = new ArrayList<>();
|
ArrayList<String> ret = new ArrayList<>();
|
||||||
trclasses = getTraders();
|
trclasses = getInstalledTraders();
|
||||||
|
|
||||||
for (int i = 0; i < trclasses.size(); i++) {
|
for (int i = 0; i < trclasses.size(); i++) {
|
||||||
try {
|
try {
|
||||||
@ -318,9 +308,19 @@ public class AutoTraderLoader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public AutoTraderInterface getStrategyBase(String name) {
|
public AutoTraderInterface getStrategyBase(String name) {
|
||||||
ArrayList<Class<AutoTraderInterface>> traders = this.getTraders();
|
ArrayList<Class<AutoTraderInterface>> traders = this.getInstalledTraders();
|
||||||
|
|
||||||
|
System.out.printf("Installed traders %d\n", traders.size());
|
||||||
|
// System.exit(0);
|
||||||
|
|
||||||
|
|
||||||
for (int i = 0; i < traders.size(); i++) {
|
for (int i = 0; i < traders.size(); i++) {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
|
traders.get(i).getCanonicalName();
|
||||||
|
// System.out.printf("Canon name %s\n", traders.get(i).getCanonicalName());
|
||||||
|
// System.exit(0);
|
||||||
|
|
||||||
Globals.LOGGER.info(String.format("Making lll instance of %s", traders.get(i).getCanonicalName()));
|
Globals.LOGGER.info(String.format("Making lll instance of %s", traders.get(i).getCanonicalName()));
|
||||||
|
|
||||||
if (traders.get(i)==null){
|
if (traders.get(i)==null){
|
||||||
|
Loading…
Reference in New Issue
Block a user