|
|
@@ -35,14 +35,14 @@ public class InstrumentationAgent {
|
|
|
if (Files.exists(base.resolve(DYNAMIC_JARS))) {
|
|
|
load(base, DYNAMIC_JARS);
|
|
|
}
|
|
|
- load(base, STORE_JARS);
|
|
|
- load(base, COMMONS_EXT);
|
|
|
+ loadWithCfg(base, STORE_JARS);
|
|
|
+ loadWithCfg(base, COMMONS_EXT);
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private static void load(Path base, String sub) throws IOException {
|
|
|
+ private static void loadWithCfg(Path base, String sub) throws IOException {
|
|
|
Path dir = base.resolve(sub);
|
|
|
Path cfg = dir.resolve(CFG);
|
|
|
if (Files.exists(dir) && Files.isDirectory(dir) && Files.exists(cfg) && Files.isRegularFile(cfg)) {
|
|
|
@@ -74,6 +74,25 @@ public class InstrumentationAgent {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private static void load(Path base, String sub) throws IOException {
|
|
|
+ Path dir = base.resolve(sub);
|
|
|
+ if (Files.exists(dir) && Files.isDirectory(dir)) {
|
|
|
+ try (Stream<Path> stream = Files.list(dir)) {
|
|
|
+ stream.filter(
|
|
|
+ o -> o.toString().toLowerCase().endsWith(".zip") || o.toString().toLowerCase().endsWith(".jar"))
|
|
|
+ .forEach(o -> {
|
|
|
+ try {
|
|
|
+ INST.appendToSystemClassLoaderSearch(new JarFile(o.toString()));
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ throw new IOException(String.format("invalid directory: %s", sub));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
private static Path getBasePath() throws IOException, URISyntaxException {
|
|
|
Path path = Paths.get(InstrumentationAgent.class.getProtectionDomain().getCodeSource().getLocation().toURI());
|
|
|
Path version = path.resolveSibling("version.o2");
|