From 7ca742713cf6dbeb4ee4fe78518831e87f47091a Mon Sep 17 00:00:00 2001 From: 7u83 <7u83@maiol.ru> Date: Mon, 20 Mar 2017 08:11:06 +0100 Subject: [PATCH] Load traders from jar --- src/sesim/AutoTraderLoader.java | 80 +++++++++++++++++++++------------ 1 file changed, 52 insertions(+), 28 deletions(-) diff --git a/src/sesim/AutoTraderLoader.java b/src/sesim/AutoTraderLoader.java index d504be8..4576dd0 100644 --- a/src/sesim/AutoTraderLoader.java +++ b/src/sesim/AutoTraderLoader.java @@ -60,9 +60,13 @@ public class AutoTraderLoader { return false; } + System.out.printf("Trav. modifiers\n"); do { for (Class i : cls.getInterfaces()) { + + System.out.printf("Interface: %s\n", i.getCanonicalName()); if (i.equals(AutoTraderInterface.class)) { + System.out.printf("Yea! An autotrader\n"); return true; } } @@ -73,6 +77,14 @@ public class AutoTraderLoader { Class loadAutoTraderClass(String filename, String classname) { + System.out.printf("Comming in width %s %s\n", filename, classname); + if (classname == null) { + System.out.printf("Calssname is null\n"); + + return null; + + } + String clnam = classname.substring(1, classname.length() - 6).replace('/', '.'); File f = new File(filename); @@ -97,6 +109,7 @@ public class AutoTraderLoader { } } catch (ClassNotFoundException ex) { // something wnet wrong, but we ignore it + System.out.printf("Class not found\n"); } return null; @@ -115,44 +128,55 @@ public class AutoTraderLoader { ArrayList> traders; traders = new ArrayList<>(); + String cp = System.getProperty("java.class.path"); + System.out.printf("Calss Pass: %s\n", cp); + for (String classpathEntry : System.getProperty("java.class.path").split(System.getProperty("path.separator"))) { - Consumer pf = new Consumer() { - @Override - public void accept(Object t) { - String fn = ((Path) t).toString(); - if (fn.toLowerCase().endsWith(".class")) { - Class cls = loadAutoTraderClass(fn, fn.substring(classpathEntry.length())); - if (cls == null) { - return; - } - traders.add(cls); - } - if (fn.toLowerCase().endsWith(".jar")) { - JarInputStream is = null; - try { - File jar = new File(fn); - is = new JarInputStream(new FileInputStream(jar)); - JarEntry entry; - while ((entry = is.getNextJarEntry()) != null) { - if (entry.getName().endsWith(".class")) { + Consumer pf = (Object t) -> { - // System.out.printf("Entry: %s\n", entry.getDisplayName()); + String fn = ((Path) t).toString(); + System.out.printf("Checking out file %s\n", fn); + + if (fn.toLowerCase().endsWith(".class")) { + String cl = fn.substring(classpathEntry.length()); + System.out.printf("The CL: %s\n", cl); + + Class cls = loadAutoTraderClass(fn, cl); + if (cls == null) { + return; + } + traders.add(cls); + } + if (fn.toLowerCase().endsWith(".jar")) { + System.out.printf("Its a jar!\n"); + JarInputStream is = null; + try { + File jar = new File(fn); + is = new JarInputStream(new FileInputStream(jar)); + JarEntry entry; + while ((entry = is.getNextJarEntry()) != null) { + if (entry.getName().endsWith(".class")) { + + System.out.printf("Entry: %s\n", entry.getName()); + String fn0 = entry.getName(); + Class cls = loadAutoTraderClass(fn, "/" + entry.getName()); + if (cls != null) { + traders.add(cls); } + } + } + } catch (IOException ex) { + Logger.getLogger(AutoTraderLoader.class.getName()).log(Level.SEVERE, null, ex); + } finally { + try { + is.close(); } catch (IOException ex) { Logger.getLogger(AutoTraderLoader.class.getName()).log(Level.SEVERE, null, ex); - } finally { - try { - is.close(); - } catch (IOException ex) { - Logger.getLogger(AutoTraderLoader.class.getName()).log(Level.SEVERE, null, ex); - } } } - } - }; try {