Merge branch '60-introspect' into 'master'
Perform a case insensitive match on jar name - Add some logging fixes #60 See merge request !11
This commit is contained in:
commit
65b1f7df74
@ -15,6 +15,7 @@ import java.net.URL;
|
|||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.jar.JarEntry;
|
import java.util.jar.JarEntry;
|
||||||
import java.util.jar.JarInputStream;
|
import java.util.jar.JarInputStream;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -25,6 +26,7 @@ import java.util.jar.JarInputStream;
|
|||||||
* @author mkron
|
* @author mkron
|
||||||
*/
|
*/
|
||||||
public class ReflectPackage {
|
public class ReflectPackage {
|
||||||
|
private static final Logger LOGGER = Logger.getLogger(ReflectPackage.class.getName());
|
||||||
static int missedJarsOnClassPath = 0;
|
static int missedJarsOnClassPath = 0;
|
||||||
static boolean useFilteredClassPath = true;
|
static boolean useFilteredClassPath = true;
|
||||||
static String[] dynCP = null;
|
static String[] dynCP = null;
|
||||||
@ -91,7 +93,7 @@ public class ReflectPackage {
|
|||||||
cntAdded += addClass(set, cls);
|
cntAdded += addClass(set, cls);
|
||||||
}
|
}
|
||||||
} catch (Exception | Error e) {
|
} catch (Exception | Error e) {
|
||||||
System.err.println("ReflectPackage: Couldnt get Class from jar for " + pckgname + '.' + file + ": " + e.getMessage());
|
System.err.println("ReflectPackage: Couldn't get Class from jar for " + pckgname + '.' + file + ": " + e.getMessage());
|
||||||
}
|
}
|
||||||
} else if (includeSubs) {
|
} else if (includeSubs) {
|
||||||
// do a recursive search over subdirs
|
// do a recursive search over subdirs
|
||||||
@ -115,7 +117,7 @@ public class ReflectPackage {
|
|||||||
|
|
||||||
private static int addClass(HashSet<Class> set, Class cls) {
|
private static int addClass(HashSet<Class> set, Class cls) {
|
||||||
if (set.contains(cls)) {
|
if (set.contains(cls)) {
|
||||||
System.err.println("warning, Class " + cls.getName() + " not added twice!");
|
LOGGER.warning("Class " + cls.getName() + " not added twice!");
|
||||||
return 0;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
set.add(cls);
|
set.add(cls);
|
||||||
@ -172,7 +174,7 @@ public class ReflectPackage {
|
|||||||
cntAdded += addClass(set, cls);
|
cntAdded += addClass(set, cls);
|
||||||
}
|
}
|
||||||
} catch (Exception | Error e) {
|
} catch (Exception | Error e) {
|
||||||
System.err.println("ReflectPackage: Couldn't get Class from jar for " + clsName + ": " + e.getMessage());
|
LOGGER.warning("ReflectPackage: Couldn't get Class from jar for " + clsName + ": " + e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -180,8 +182,7 @@ public class ReflectPackage {
|
|||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
missedJarsOnClassPath++;
|
missedJarsOnClassPath++;
|
||||||
if (missedJarsOnClassPath == 0) {
|
if (missedJarsOnClassPath == 0) {
|
||||||
System.err.println("Couldn't open jar from class path: " + e.getMessage());
|
LOGGER.warning("Couldn't open jar from class path. Dirty class path? " + e.getMessage());
|
||||||
System.err.println("Dirty class path?");
|
|
||||||
} else if (missedJarsOnClassPath == 2) {
|
} else if (missedJarsOnClassPath == 2) {
|
||||||
System.err.println("Couldn't open jar from class path more than once...");
|
System.err.println("Couldn't open jar from class path more than once...");
|
||||||
}
|
}
|
||||||
@ -204,7 +205,7 @@ public class ReflectPackage {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Collect classes from a given package on the classpath which have the given Class
|
* Collect classes from a given package on the classpath which have the given Class
|
||||||
* as superclass or superinterface. If includeSubs is true,
|
* as superclass or interface. If includeSubs is true,
|
||||||
* the sub-packages are listed as well.
|
* the sub-packages are listed as well.
|
||||||
*
|
*
|
||||||
* @param pkg
|
* @param pkg
|
||||||
@ -224,11 +225,13 @@ public class ReflectPackage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (String aDynCP : dynCP) {
|
for (String aDynCP : dynCP) {
|
||||||
|
|
||||||
if (aDynCP.endsWith(".jar")) {
|
if (aDynCP.endsWith(".jar")) {
|
||||||
// Skip JARs that don't start with the EvA substring.
|
// Skip JARs that don't start with the EvA substring.
|
||||||
// This improves performance a lot when having a lot of JARs on the classpath
|
// This improves performance a lot when having a lot of JARs on the classpath
|
||||||
int index = aDynCP.lastIndexOf(System.getProperty("file.separator"));
|
int index = aDynCP.lastIndexOf(System.getProperty("file.separator"));
|
||||||
if (index != -1 && !aDynCP.substring(index).contains("EvA")) {
|
if (index != -1 && !aDynCP.substring(index).toLowerCase().contains("eva")) {
|
||||||
|
LOGGER.fine("Skipping Jar (does not start with \"eva\": " + aDynCP);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
getClassesFromJarFltr(set, aDynCP, pkg, includeSubs, reqSuperCls);
|
getClassesFromJarFltr(set, aDynCP, pkg, includeSubs, reqSuperCls);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user