private static String findNamespace(Path file, Set<Path> roots) { Path root = roots.stream() .filter(file::startsWith) .findFirst() .orElseThrow(() -> new IllegalStateException("No source root found for " + file.toString())); String fileName = file.getFileName().toString(); Path relPath = root.relativize(file).resolveSibling(fileName.substring(0, fileName.lastIndexOf('.'))); return StreamSupport.stream(relPath.spliterator(), false) .map(Path::toString) .map(Namespaces::demunge) .collect(Collectors.joining(".")); }
private static String findNamespace(Path file, Set<Path> roots) { Path root = roots.stream() .filter(file::startsWith) .findFirst() .orElseThrow(() -> new IllegalStateException("No source root found for " + file.toString())); String fileName = file.getFileName().toString(); Path relPath = root.relativize(file).resolveSibling(fileName.substring(0, fileName.lastIndexOf('.'))); return StreamSupport.stream(relPath.spliterator(), false) .map(Path::toString) .map(Namespaces::demunge) .collect(Collectors.joining(".")); }
@Override public final List<String> classNames() { try { if(Files.notExists(path)) { return List.empty(); } final List<String> classes = Files.find(path, Integer.MAX_VALUE, (p, bf) -> p.toString().endsWith(".class")) .map(path::relativize) .map(p -> List.ofAll(StreamSupport.stream(p.spliterator(), false))) .map(pl -> pl.map(Object::toString).collect(Collectors.joining("."))) .map(s -> s.replace(".class", "")) .filter(s -> !"module-info".equals(s)) .collect(List.collector()); return classes; } catch(Exception ex) { throw new RuntimeException(ex); } } }