@DisplayName("test_scan") @Test void testScan() throws ClassNotFoundException, IOException { ClassPathScanner scanner = new ClassPathScanner(); scanner.addIncludeFilter(new AnnotationTypeFilter(Include.class)); scanner.addExcludeFilter(new AnnotationTypeFilter(Exclude.class)); Set<Class> candidate = scanner.scan(new String[]{"io.github.ukuz.piccolo.api.common"}); assertEquals(1, candidate.size()); assertEquals(ClassWithInclude.class, candidate.iterator().next()); }
public Set<Class> scan(String[] scanPackages) throws ClassNotFoundException, IOException { Set<Class> result = new HashSet<>(); String javaPath = System.getProperty("java.class.path"); String pathSeparator = System.getProperty("path.separator"); for (String p :javaPath.split(pathSeparator)) { int prefixIndex = p.indexOf(":"); if (prefixIndex == 1) { p = StringUtils.uncapitalize(p); } File baseDir = new File(p); Path basePath = baseDir.toPath(); for (String scanPackage : scanPackages) { String scanPath = scanPackage.replace(PACKAGE_SEPARATOR, PATH_SEPARATOR); File file = new File(baseDir, scanPath); if (file.exists()) { if (LOGGER.isInfoEnabled()) { LOGGER.info("scan path: {}", file.getAbsolutePath()); } doCandidate(basePath, file.toPath(), result); } } } return result; }
ClassPathScanner { public Set<Class> scan(String[] scanPackages) throws ClassNotFoundException, IOException { Set<Class> result = new HashSet<>(); String javaPath = System.getProperty("java.class.path"); String pathSeparator = System.getProperty("path.separator"); for (String p :javaPath.split(pathSeparator)) { int prefixIndex = p.indexOf(":"); if (prefixIndex == 1) { p = StringUtils.uncapitalize(p); } File baseDir = new File(p); Path basePath = baseDir.toPath(); for (String scanPackage : scanPackages) { String scanPath = scanPackage.replace(PACKAGE_SEPARATOR, PATH_SEPARATOR); File file = new File(baseDir, scanPath); if (file.exists()) { if (LOGGER.isInfoEnabled()) { LOGGER.info("scan path: {}", file.getAbsolutePath()); } doCandidate(basePath, file.toPath(), result); } } } return result; } }
ClassPathScanner { public Set<Class> scan(String[] scanPackages) throws ClassNotFoundException, IOException { Set<Class> result = new HashSet<>(); String javaPath = System.getProperty("java.class.path"); String pathSeparator = System.getProperty("path.separator"); for (String p :javaPath.split(pathSeparator)) { int prefixIndex = p.indexOf(":"); if (prefixIndex == 1) { p = StringUtils.uncapitalize(p); } File baseDir = new File(p); Path basePath = baseDir.toPath(); for (String scanPackage : scanPackages) { String scanPath = scanPackage.replace(PACKAGE_SEPARATOR, PATH_SEPARATOR); File file = new File(baseDir, scanPath); if (file.exists()) { if (LOGGER.isInfoEnabled()) { LOGGER.info("scan path: {}", file.getAbsolutePath()); } doCandidate(basePath, file.toPath(), result); } } } return result; }  }
ClassPathScanner { public Set<Class> scan(String[] scanPackages) throws ClassNotFoundException, IOException { Set<Class> result = new HashSet<>(); String javaPath = System.getProperty("java.class.path"); String pathSeparator = System.getProperty("path.separator"); for (String p :javaPath.split(pathSeparator)) { int prefixIndex = p.indexOf(":"); if (prefixIndex == 1) { p = StringUtils.uncapitalize(p); } File baseDir = new File(p); Path basePath = baseDir.toPath(); for (String scanPackage : scanPackages) { String scanPath = scanPackage.replace(PACKAGE_SEPARATOR, PATH_SEPARATOR); File file = new File(baseDir, scanPath); if (file.exists()) { if (LOGGER.isInfoEnabled()) { LOGGER.info("scan path: {}", file.getAbsolutePath()); } doCandidate(basePath, file.toPath(), result); } } } return result; }  void addIncludeFilter(AnnotationTypeFilter filter); void addExcludeFilter(AnnotationTypeFilter filter); Set<Class> scan(String[] scanPackages); }
ClassPathScanner { public Set<Class> scan(String[] scanPackages) throws ClassNotFoundException, IOException { Set<Class> result = new HashSet<>(); String javaPath = System.getProperty("java.class.path"); String pathSeparator = System.getProperty("path.separator"); for (String p :javaPath.split(pathSeparator)) { int prefixIndex = p.indexOf(":"); if (prefixIndex == 1) { p = StringUtils.uncapitalize(p); } File baseDir = new File(p); Path basePath = baseDir.toPath(); for (String scanPackage : scanPackages) { String scanPath = scanPackage.replace(PACKAGE_SEPARATOR, PATH_SEPARATOR); File file = new File(baseDir, scanPath); if (file.exists()) { if (LOGGER.isInfoEnabled()) { LOGGER.info("scan path: {}", file.getAbsolutePath()); } doCandidate(basePath, file.toPath(), result); } } } return result; }  void addIncludeFilter(AnnotationTypeFilter filter); void addExcludeFilter(AnnotationTypeFilter filter); Set<Class> scan(String[] scanPackages);  }