Skip to content

Commit cbffdde

Browse files
authored
Merge pull request diffblue#599 from diffblue/jd/feature/more_verbose_logging
More verbose logging in Python
2 parents c879304 + b785abe commit cbffdde

File tree

2 files changed

+29
-12
lines changed

2 files changed

+29
-12
lines changed

driver/mkbench.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import os
22
import re
33
import sys
4-
54
import analyser
65
import filecmp
76
import shutil
@@ -250,11 +249,6 @@ def collect_java_binaries(cmdline):
250249
with utility.PushCwd(classes_temp_dir):
251250
utility.check_call(["jar", "cf", java_binaries.jar_file, "."], "jar", 0)
252251

253-
entry_points_file = configuration["detectedEntryPointsPath"]
254-
if not os.path.exists(entry_points_file):
255-
print("WARNING: Unable to find any detected entry points. No analysis will be run.")
256-
return
257-
258252
# Copy the current commandline and transpose into a dictionary.
259253
copied_command_line = {key.replace("_", "-"): val for key, val in vars(cmdline).items()}
260254

@@ -276,8 +270,22 @@ def collect_java_binaries(cmdline):
276270
else:
277271
print("DI generation failed, continuing without synthetic entry points.", file=sys.stderr)
278272

279-
with open(entry_points_file) as ep_config_file:
280-
ep_config = json.load(ep_config_file)
273+
entry_points_file = configuration["detectedEntryPointsPath"]
274+
if not os.path.exists(entry_points_file):
275+
print("WARNING: Unable to find the detected entry points file at " + entry_points_file + ". No analysis will be run.")
276+
return
277+
278+
try:
279+
with open(entry_points_file) as ep_config_file:
280+
ep_config = json.load(ep_config_file)
281+
except json.JSONDecodeError as ex:
282+
print("ERROR: Entry points file at " + entry_points_file + " is invalid json. " + ex.msg)
283+
return
284+
285+
# Print out if we have the file, but it has nothing in it.
286+
if not ep_config["entryPoints"]:
287+
print("WARNING: No entry points have been detected. No analysis can be run.")
288+
return
281289

282290
previously_created_folders = set()
283291
for ep_data in ep_config["entryPoints"]:

driver/run.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,8 @@ def create_parser():
195195
parser.add_argument("--prepare-scan", type=str, const='', nargs='?',
196196
help="Path to the configuration file used to do the pre-analysis stage")
197197
parser.add_argument("--run-scan", type=str, const='', nargs="?",
198-
help="Flag for whether a security scan should be run. Target will be the results folder.")
198+
help="Flag for whether a security scan should be run. If left empty, will run on all folders in results-dir."
199+
"If passed a path to a command_line.json file, it will only run on that folder.")
199200
parser.add_argument("--skip-di-generation", action='store_true',
200201
help="Turns off DI overlay generation. This overrides the automatic detection of DI usage.")
201202

@@ -282,9 +283,13 @@ def load_config_and_run_scan(config_path):
282283

283284
# We save the json with '-' as seperators to mimic the arguments coming in
284285
# but the parser replaces those with '_' and here we want to mimic that.
285-
with open(config_path) as config_file:
286-
json_output = { key.replace("-", "_"): val for key, val in json.load(config_file).items()}
287-
cmdline = SimpleNamespace(**json_output)
286+
try:
287+
with open(config_path) as config_file:
288+
json_output = { key.replace("-", "_"): val for key, val in json.load(config_file).items()}
289+
cmdline = SimpleNamespace(**json_output)
290+
except json.JSONDecodeError as ex:
291+
print("ERROR: Command line configuration at " + config_path + " is invalid json. " + ex.msg)
292+
return
288293

289294
run_scan(cmdline)
290295

@@ -512,6 +517,10 @@ def extract_wildcard_paths(path):
512517
" and the default file can't be found at {0}.".format(default_config_path))
513518
return
514519

520+
if not os.path.isfile(cmdline.prepare_scan):
521+
print("ERROR: The path passed in via cmdline.prepare_scan, " + cmdline.prepare_scan + ", dosen't exist.")
522+
return
523+
515524
if cmdline.name is None:
516525
cmdline.name = os.path.basename(cmdline.install_dir)
517526

0 commit comments

Comments
 (0)