@@ -51,14 +51,15 @@ class JCodeanalyzer:
5151 """
5252
5353 def __init__ (
54- self ,
55- project_dir : Union [str , Path ],
56- source_code : str | None ,
57- analysis_backend_path : Union [str , Path , None ],
58- analysis_json_path : Union [str , Path , None ],
59- analysis_level : str ,
60- use_graalvm_binary : bool ,
61- eager_analysis : bool ,
54+ self ,
55+ project_dir : Union [str , Path ],
56+ source_code : str | None ,
57+ analysis_backend_path : Union [str , Path , None ],
58+ analysis_json_path : Union [str , Path , None ],
59+ analysis_level : str ,
60+ use_graalvm_binary : bool ,
61+ eager_analysis : bool ,
62+ target_files : List [str ] | None
6263 ) -> None :
6364 self .project_dir = project_dir
6465 self .source_code = source_code
@@ -67,6 +68,7 @@ def __init__(
6768 self .use_graalvm_binary = use_graalvm_binary
6869 self .eager_analysis = eager_analysis
6970 self .analysis_level = analysis_level
71+ self .target_files = target_files
7072 self .application = self ._init_codeanalyzer (
7173 analysis_level = 1 if analysis_level == AnalysisLevel .symbol_table else 2 )
7274 # Attributes related the Java code analysis...
@@ -201,8 +203,17 @@ def _init_codeanalyzer(self, analysis_level=1) -> JApplication:
201203
202204 if self .analysis_json_path is None :
203205 logger .info ("Reading analysis from the pipe." )
204- codeanalyzer_args = codeanalyzer_exec + shlex .split (
205- f"-i { Path (self .project_dir )} --analysis-level={ analysis_level } " )
206+ codeanalyzer_args = ''
207+ # If target file is provided, the input is merged into a single string and passed to codeanalyzer
208+ if self .target_files :
209+ target_file_options = '-t ' .join ([s .strip () for s in self .target_files ])
210+ codeanalyzer_args = codeanalyzer_exec + shlex .split (
211+ f"-i { Path (self .project_dir )} --analysis-level={ analysis_level } -t { target_file_options } "
212+ )
213+ else :
214+ codeanalyzer_args = codeanalyzer_exec + shlex .split (
215+ f"-i { Path (self .project_dir )} --analysis-level={ analysis_level } "
216+ )
206217 try :
207218 logger .info (f"Running codeanalyzer: { ' ' .join (codeanalyzer_args )} " )
208219 console_out : CompletedProcess [str ] = subprocess .run (
@@ -222,9 +233,18 @@ def _init_codeanalyzer(self, analysis_level=1) -> JApplication:
222233 # flag is set, we'll run the analysis every time the object is created. This will happen regradless
223234 # of the existence of the analysis file.
224235 # Create the executable command for codeanalyzer.
225- codeanalyzer_args = codeanalyzer_exec + shlex .split (
226- f"-i { Path (self .project_dir )} --analysis-level={ analysis_level } -o { self .analysis_json_path } " )
227-
236+ codeanalyzer_args = ''
237+ # If target file is provided, the input is merged into a single string and passed to codeanalyzer
238+ if self .target_files :
239+ target_file_options = '-t ' .join ([s .strip () for s in self .target_files ])
240+ codeanalyzer_args = codeanalyzer_exec + shlex .split (
241+ f"-i { Path (self .project_dir )} --analysis-level={ analysis_level } "
242+ f" -o { self .analysis_json_path } -t { target_file_options } "
243+ )
244+ else :
245+ codeanalyzer_args = codeanalyzer_exec + shlex .split (
246+ f"-i { Path (self .project_dir )} --analysis-level={ analysis_level } -o { self .analysis_json_path } "
247+ )
228248 try :
229249 logger .info (f"Running codeanalyzer subprocess with args { codeanalyzer_args } " )
230250 subprocess .run (
@@ -252,7 +272,6 @@ def _codeanalyzer_single_file(self):
252272 JApplication
253273 The application view of the Java code with the analysis results.
254274 """
255- # self.source_code: str = re.sub(r"[\r\n\t\f\v]+", lambda x: " " if x.group() in "\t\f\v" else " ", self.source_code)
256275 codeanalyzer_exec = self ._get_codeanalyzer_exec ()
257276 codeanalyzer_args = ["--source-analysis" , self .source_code ]
258277 codeanalyzer_cmd = codeanalyzer_exec + codeanalyzer_args
0 commit comments