44import com .neuvem .java2graph .models .GraphContext ;
55
66import java .io .BufferedReader ;
7+ import java .io .BufferedWriter ;
78import java .io .InputStreamReader ;
89import java .nio .file .Files ;
910import java .nio .file .Path ;
1011import java .util .ArrayList ;
1112import java .util .List ;
13+ import java .util .stream .Collectors ;
14+ import java .util .stream .Stream ;
1215
1316public class DelombokPass implements Pass {
1417
@@ -18,13 +21,29 @@ public void execute(Java2GraphConfig config, GraphContext context) throws Except
1821 return ;
1922 }
2023
21- System .out .println ("Processing Lombok annotations via isolated process..." );
24+ System .out .println ("Processing Lombok annotations via isolated process (filtering builds/hidden) ..." );
2225
2326 Path delombokDir = Files .createTempDirectory ("delombok" );
2427 String javaHome = System .getProperty ("java.home" );
2528 String javaBin = javaHome + "/bin/java" ;
2629 String classpath = System .getProperty ("java.class.path" );
2730
31+ // Identify source directories while excluding build/hidden folders
32+ List <String > srcPaths = findSourceDirs (config .getSrcDir ());
33+ if (srcPaths .isEmpty ()) {
34+ System .out .println ("No Java source files found in " + config .getSrcDir ());
35+ return ;
36+ }
37+
38+ // Use a response file for delombok to avoid command-line length limits and manage inputs
39+ Path argFile = Files .createTempFile ("delombok_args" , ".args" );
40+ try (BufferedWriter writer = Files .newBufferedWriter (argFile )) {
41+ for (String path : srcPaths ) {
42+ writer .write ("\" " + path .replace ("\\ " , "\\ \\ " ) + "\" " );
43+ writer .newLine ();
44+ }
45+ }
46+
2847 List <String > command = new ArrayList <>();
2948 command .add (javaBin );
3049
@@ -46,7 +65,9 @@ public void execute(Java2GraphConfig config, GraphContext context) throws Except
4665 command .add (classpath );
4766 command .add ("lombok.launch.Main" );
4867 command .add ("delombok" );
49- command .add (config .getSrcDir ().toAbsolutePath ().toString ());
68+ command .add ("--nocopy" );
69+ command .add ("--quiet" );
70+ command .add ("@" + argFile .toAbsolutePath ());
5071 command .add ("-d" );
5172 command .add (delombokDir .toAbsolutePath ().toString ());
5273
@@ -58,11 +79,15 @@ public void execute(Java2GraphConfig config, GraphContext context) throws Except
5879 try (BufferedReader reader = new BufferedReader (new InputStreamReader (process .getInputStream ()))) {
5980 String line ;
6081 while ((line = reader .readLine ()) != null ) {
82+ // Suppress verbose hidden directory messages from Lombok
83+ if (line .contains ("hidden directory" )) continue ;
6184 output .append (line ).append ("\n " );
6285 }
6386 }
6487
6588 int exitCode = process .waitFor ();
89+ Files .deleteIfExists (argFile ); // Clean up the temp args file
90+
6691 if (exitCode != 0 ) {
6792 System .err .println ("Delombok failed with exit code " + exitCode );
6893 System .err .println ("--- Delombok Output ---" );
@@ -76,4 +101,37 @@ public void execute(Java2GraphConfig config, GraphContext context) throws Except
76101
77102 System .out .println ("Lombok processing complete. Delomboked to: " + delombokDir );
78103 }
104+
105+ private List <String > findSourceDirs (Path root ) throws Exception {
106+ try (Stream <Path > walk = Files .walk (root )) {
107+ return walk .filter (Files ::isDirectory )
108+ .filter (path -> !isExcluded (path ))
109+ .filter (this ::hasJavaFiles )
110+ .map (path -> path .toAbsolutePath ().toString ())
111+ .collect (Collectors .toList ());
112+ }
113+ }
114+
115+ private boolean isExcluded (Path path ) {
116+ for (Path part : path ) {
117+ String name = part .toString ();
118+ if (name .startsWith ("." ) ||
119+ name .equals ("build" ) ||
120+ name .equals ("target" ) ||
121+ name .equals ("bin" ) ||
122+ name .equals ("out" ) ||
123+ name .equals ("node_modules" )) {
124+ return true ;
125+ }
126+ }
127+ return false ;
128+ }
129+
130+ private boolean hasJavaFiles (Path dir ) {
131+ try (Stream <Path > files = Files .list (dir )) {
132+ return files .anyMatch (p -> p .getFileName ().toString ().endsWith (".java" ));
133+ } catch (Exception e ) {
134+ return false ;
135+ }
136+ }
79137}
0 commit comments