@Test public void should_handle_spring_boot_executable_jar() { int numClasses = scanner.scanSignatures( new CodeBase( AgentConfigFactory.createSampleAgentConfig().toBuilder() .codeBase(new File(SPRING_BOOT_EXECUTABLE_JAR_DIR).getAbsolutePath()) .packages("sample.springboot, sample.lib") .build())); assertThat(numClasses, is(4 + 7 + 1)); }
public int scanSignatures(CodeBase codeBase) { long startedAt = System.currentTimeMillis(); logger.log(finest, "Scanning " + codeBase); Set<String> scanned = new HashSet<>(); try (ScanResult scanResult = scanCodeBase(codeBase)) { for (ClassPath.ClassInfo classInfo : scanResult.getClassInfos()) { if (scanned.add(classInfo.getResourceName())) { try { Class<?> clazz = classInfo.load(); findConstructors(codeBase, clazz); findMethods(codeBase, clazz, codeBase.getConfig().getNormalizedPackages()); } catch (Throwable t) { if (classInfo.getPackageName().contains(".WEB-INF.classes.")) { logger.log(finest, "Ignoring " + classInfo); } else { logger.log(Level.WARNING, "Cannot analyze " + classInfo, t); } } } else { logger.log(finest, "Ignoring duplicate " + classInfo); } } } if (codeBase.isEmpty()) { logger.warning( String.format( "%s does not contain any classes within packages %s.'", codeBase, codeBase.getConfig().getNormalizedPackages())); } int result = scanned.size(); logger.info( String.format( "Scanned %s with package prefix %s in %d ms, found %d methods in %d classes.", codeBase.getFingerprint(), codeBase.getConfig().getNormalizedPackages(), System.currentTimeMillis() - startedAt, codeBase.size(), result)); return result; }
CodeBaseScanner { public int scanSignatures(CodeBase codeBase) { long startedAt = System.currentTimeMillis(); logger.log(finest, "Scanning " + codeBase); Set<String> scanned = new HashSet<>(); try (ScanResult scanResult = scanCodeBase(codeBase)) { for (ClassPath.ClassInfo classInfo : scanResult.getClassInfos()) { if (scanned.add(classInfo.getResourceName())) { try { Class<?> clazz = classInfo.load(); findConstructors(codeBase, clazz); findMethods(codeBase, clazz, codeBase.getConfig().getNormalizedPackages()); } catch (Throwable t) { if (classInfo.getPackageName().contains(".WEB-INF.classes.")) { logger.log(finest, "Ignoring " + classInfo); } else { logger.log(Level.WARNING, "Cannot analyze " + classInfo, t); } } } else { logger.log(finest, "Ignoring duplicate " + classInfo); } } } if (codeBase.isEmpty()) { logger.warning( String.format( "%s does not contain any classes within packages %s.'", codeBase, codeBase.getConfig().getNormalizedPackages())); } int result = scanned.size(); logger.info( String.format( "Scanned %s with package prefix %s in %d ms, found %d methods in %d classes.", codeBase.getFingerprint(), codeBase.getConfig().getNormalizedPackages(), System.currentTimeMillis() - startedAt, codeBase.size(), result)); return result; } }
CodeBaseScanner { public int scanSignatures(CodeBase codeBase) { long startedAt = System.currentTimeMillis(); logger.log(finest, "Scanning " + codeBase); Set<String> scanned = new HashSet<>(); try (ScanResult scanResult = scanCodeBase(codeBase)) { for (ClassPath.ClassInfo classInfo : scanResult.getClassInfos()) { if (scanned.add(classInfo.getResourceName())) { try { Class<?> clazz = classInfo.load(); findConstructors(codeBase, clazz); findMethods(codeBase, clazz, codeBase.getConfig().getNormalizedPackages()); } catch (Throwable t) { if (classInfo.getPackageName().contains(".WEB-INF.classes.")) { logger.log(finest, "Ignoring " + classInfo); } else { logger.log(Level.WARNING, "Cannot analyze " + classInfo, t); } } } else { logger.log(finest, "Ignoring duplicate " + classInfo); } } } if (codeBase.isEmpty()) { logger.warning( String.format( "%s does not contain any classes within packages %s.'", codeBase, codeBase.getConfig().getNormalizedPackages())); } int result = scanned.size(); logger.info( String.format( "Scanned %s with package prefix %s in %d ms, found %d methods in %d classes.", codeBase.getFingerprint(), codeBase.getConfig().getNormalizedPackages(), System.currentTimeMillis() - startedAt, codeBase.size(), result)); return result; }  }
CodeBaseScanner { public int scanSignatures(CodeBase codeBase) { long startedAt = System.currentTimeMillis(); logger.log(finest, "Scanning " + codeBase); Set<String> scanned = new HashSet<>(); try (ScanResult scanResult = scanCodeBase(codeBase)) { for (ClassPath.ClassInfo classInfo : scanResult.getClassInfos()) { if (scanned.add(classInfo.getResourceName())) { try { Class<?> clazz = classInfo.load(); findConstructors(codeBase, clazz); findMethods(codeBase, clazz, codeBase.getConfig().getNormalizedPackages()); } catch (Throwable t) { if (classInfo.getPackageName().contains(".WEB-INF.classes.")) { logger.log(finest, "Ignoring " + classInfo); } else { logger.log(Level.WARNING, "Cannot analyze " + classInfo, t); } } } else { logger.log(finest, "Ignoring duplicate " + classInfo); } } } if (codeBase.isEmpty()) { logger.warning( String.format( "%s does not contain any classes within packages %s.'", codeBase, codeBase.getConfig().getNormalizedPackages())); } int result = scanned.size(); logger.info( String.format( "Scanned %s with package prefix %s in %d ms, found %d methods in %d classes.", codeBase.getFingerprint(), codeBase.getConfig().getNormalizedPackages(), System.currentTimeMillis() - startedAt, codeBase.size(), result)); return result; }  int scanSignatures(CodeBase codeBase); }
CodeBaseScanner { public int scanSignatures(CodeBase codeBase) { long startedAt = System.currentTimeMillis(); logger.log(finest, "Scanning " + codeBase); Set<String> scanned = new HashSet<>(); try (ScanResult scanResult = scanCodeBase(codeBase)) { for (ClassPath.ClassInfo classInfo : scanResult.getClassInfos()) { if (scanned.add(classInfo.getResourceName())) { try { Class<?> clazz = classInfo.load(); findConstructors(codeBase, clazz); findMethods(codeBase, clazz, codeBase.getConfig().getNormalizedPackages()); } catch (Throwable t) { if (classInfo.getPackageName().contains(".WEB-INF.classes.")) { logger.log(finest, "Ignoring " + classInfo); } else { logger.log(Level.WARNING, "Cannot analyze " + classInfo, t); } } } else { logger.log(finest, "Ignoring duplicate " + classInfo); } } } if (codeBase.isEmpty()) { logger.warning( String.format( "%s does not contain any classes within packages %s.'", codeBase, codeBase.getConfig().getNormalizedPackages())); } int result = scanned.size(); logger.info( String.format( "Scanned %s with package prefix %s in %d ms, found %d methods in %d classes.", codeBase.getFingerprint(), codeBase.getConfig().getNormalizedPackages(), System.currentTimeMillis() - startedAt, codeBase.size(), result)); return result; }  int scanSignatures(CodeBase codeBase);  }