Skip to content

Commit 5e2d45c

Browse files
Rangeet PanRangeet Pan
authored andcommitted
add logic to run codenalyzer when target files are provided
1 parent 4424d28 commit 5e2d45c

1 file changed

Lines changed: 22 additions & 19 deletions

File tree

cldk/analysis/java/codeanalyzer/codeanalyzer.py

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -200,10 +200,9 @@ def _init_codeanalyzer(self, analysis_level=1) -> JApplication:
200200
"""
201201

202202
codeanalyzer_exec = self._get_codeanalyzer_exec()
203-
203+
codeanalyzer_args = ''
204204
if self.analysis_json_path is None:
205205
logger.info("Reading analysis from the pipe.")
206-
codeanalyzer_args = ''
207206
# If target file is provided, the input is merged into a single string and passed to codeanalyzer
208207
if self.target_files:
209208
target_file_options = '-t '.join([s.strip() for s in self.target_files])
@@ -227,24 +226,29 @@ def _init_codeanalyzer(self, analysis_level=1) -> JApplication:
227226
raise CodeanalyzerExecutionException(str(e)) from e
228227

229228
else:
229+
# Check if the code analyzer needs to be run
230+
is_run_code_analyzer = False
230231
analysis_json_path_file = Path(self.analysis_json_path).joinpath("analysis.json")
231-
if not analysis_json_path_file.exists() or self.eager_analysis:
232-
# If the analysis file does not exist, we'll run the analysis. Alternately, if the eager_analysis
233-
# flag is set, we'll run the analysis every time the object is created. This will happen regradless
234-
# of the existence of the analysis file.
235-
# Create the executable command for codeanalyzer.
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:
232+
# If target file is provided, the input is merged into a single string and passed to codeanalyzer
233+
if self.target_files:
234+
target_file_options = '-t '.join([s.strip() for s in self.target_files])
235+
codeanalyzer_args = codeanalyzer_exec + shlex.split(
236+
f"-i {Path(self.project_dir)} --analysis-level={analysis_level}"
237+
f" -o {self.analysis_json_path} -t {target_file_options}"
238+
)
239+
is_run_code_analyzer = True
240+
else:
241+
if not analysis_json_path_file.exists() or self.eager_analysis:
242+
# If the analysis file does not exist, we'll run the analysis. Alternately, if the eager_analysis
243+
# flag is set, we'll run the analysis every time the object is created. This will happen regradless
244+
# of the existence of the analysis file.
245+
# Create the executable command for codeanalyzer.
245246
codeanalyzer_args = codeanalyzer_exec + shlex.split(
246-
f"-i {Path(self.project_dir)} --analysis-level={analysis_level} -o {self.analysis_json_path}"
247-
)
247+
f"-i {Path(self.project_dir)} --analysis-level={analysis_level} -o {self.analysis_json_path}"
248+
)
249+
is_run_code_analyzer = True
250+
251+
if is_run_code_analyzer:
248252
try:
249253
logger.info(f"Running codeanalyzer subprocess with args {codeanalyzer_args}")
250254
subprocess.run(
@@ -258,7 +262,6 @@ def _init_codeanalyzer(self, analysis_level=1) -> JApplication:
258262

259263
except Exception as e:
260264
raise CodeanalyzerExecutionException(str(e)) from e
261-
262265
with open(analysis_json_path_file) as f:
263266
data = json.load(f)
264267
return JApplication(**data)

0 commit comments

Comments
 (0)