2424
2525import java .io .IOException ;
2626import java .nio .charset .StandardCharsets ;
27+ import java .nio .file .FileVisitResult ;
2728import java .nio .file .Files ;
2829import java .nio .file .Path ;
2930import java .nio .file .Paths ;
31+ import java .nio .file .SimpleFileVisitor ;
32+ import java .nio .file .attribute .BasicFileAttributes ;
3033import java .util .ArrayDeque ;
3134import java .util .ArrayList ;
3235import java .util .Collections ;
3841import java .util .Set ;
3942import java .util .regex .Matcher ;
4043import java .util .regex .Pattern ;
41- import java .util .stream .Stream ;
4244
4345public class IPlanVisitorInheritanceConstraintTest {
4446
@@ -58,11 +60,8 @@ public void testIPlanVisitorSubtypesAlsoInheritICoreQueryPlanVisitor() throws IO
5860 final Path iotdbCoreDir = projectRoot .resolve ("iotdb-core" );
5961
6062 final Map <String , List <TypeDefinition >> typeDefinitions = new HashMap <>();
61- try (Stream <Path > paths = Files .walk (iotdbCoreDir )) {
62- paths
63- .filter (path -> path .toString ().endsWith (".java" ))
64- .filter (path -> path .toString ().contains ("/src/main/java/" ))
65- .forEach (path -> collectTypeDefinitions (iotdbCoreDir , path , typeDefinitions ));
63+ for (Path sourceRoot : collectSourceRoots (iotdbCoreDir )) {
64+ collectTypeDefinitionsUnderSourceRoot (iotdbCoreDir , sourceRoot , typeDefinitions );
6665 }
6766
6867 final List <String > violations = new ArrayList <>();
@@ -107,6 +106,49 @@ private static Path resolveModuleBaseDir() {
107106 + "Please run the test from the iotdb project workspace." );
108107 }
109108
109+ private static List <Path > collectSourceRoots (final Path moduleDir ) {
110+ final List <Path > sourceRoots = new ArrayList <>();
111+ try {
112+ Files .walkFileTree (
113+ moduleDir ,
114+ new SimpleFileVisitor <Path >() {
115+ @ Override
116+ public FileVisitResult preVisitDirectory (
117+ final Path dir , final BasicFileAttributes attrs ) {
118+ if ("target" .equals (dir .getFileName ().toString ())) {
119+ return FileVisitResult .SKIP_SUBTREE ;
120+ }
121+ if (dir .endsWith (Paths .get ("src" , "main" , "java" ))) {
122+ sourceRoots .add (dir );
123+ return FileVisitResult .SKIP_SUBTREE ;
124+ }
125+ return FileVisitResult .CONTINUE ;
126+ }
127+ });
128+ } catch (final IOException e ) {
129+ throw new RuntimeException ("Failed to collect source roots under " + moduleDir , e );
130+ }
131+ return sourceRoots ;
132+ }
133+
134+ private static void collectTypeDefinitionsUnderSourceRoot (
135+ final Path scanRoot ,
136+ final Path sourceRoot ,
137+ final Map <String , List <TypeDefinition >> typeDefinitions )
138+ throws IOException {
139+ Files .walkFileTree (
140+ sourceRoot ,
141+ new SimpleFileVisitor <Path >() {
142+ @ Override
143+ public FileVisitResult visitFile (final Path file , final BasicFileAttributes attrs ) {
144+ if (file .toString ().endsWith (".java" )) {
145+ collectTypeDefinitions (scanRoot , file , typeDefinitions );
146+ }
147+ return FileVisitResult .CONTINUE ;
148+ }
149+ });
150+ }
151+
110152 private static void collectTypeDefinitions (
111153 final Path scanRoot ,
112154 final Path javaFile ,
0 commit comments