From 1065477765907981a7794ae37dd66cf64b7304a3 Mon Sep 17 00:00:00 2001 From: Jeremy Dubreil Date: Tue, 27 Dec 2016 14:44:36 -0800 Subject: [PATCH] [infer][java] indent the final JSON report for Buck projects Summary: This allows to create human readible JSON reports Reviewed By: sblackshear Differential Revision: D4367788 fbshipit-source-id: 907e630 --- infer/lib/python/inferlib/bucklib.py | 15 +++------------ infer/lib/python/inferlib/utils.py | 2 +- 2 files changed, 4 insertions(+), 13 deletions(-) diff --git a/infer/lib/python/inferlib/bucklib.py b/infer/lib/python/inferlib/bucklib.py index 031854afc..d834fc830 100644 --- a/infer/lib/python/inferlib/bucklib.py +++ b/infer/lib/python/inferlib/bucklib.py @@ -294,7 +294,7 @@ def collect_results(args, start_time, targets): with open(os.path.join(args.infer_out, ANALYSIS_SUMMARY_OUTPUT), 'w') as f: f.write(buck_stats) - all_json_rows = set() + all_json_rows = [] stats = init_stats(args, start_time) accumulation_whitelist = list(map(re.compile, [ @@ -328,9 +328,7 @@ def collect_results(args, start_time, targets): old_value = stats[type_k].get(key, 0) stats[type_k][key] = old_value + value - json_rows = load_json_report(jar) - for row in json_rows: - all_json_rows.add(json.dumps(row)) + all_json_rows += load_json_report(jar) # Override normals stats['normal'].update(target_stats.get('normal', {})) @@ -340,6 +338,7 @@ def collect_results(args, start_time, targets): logging.warn('Bad zip file %s', path) json_report = os.path.join(args.infer_out, config.JSON_REPORT_FILENAME) + utils.dump_json_to_path(all_json_rows, json_report) # Convert all float values to integer values for key, value in stats.get('float', {}).items(): @@ -348,15 +347,7 @@ def collect_results(args, start_time, targets): # Delete the float entries before exporting the results del(stats['float']) - with open(json_report, 'w') as report: - json_string = '[' - json_string += ','.join(all_json_rows) - json_string += ']' - report.write(json_string) - report.flush() - print('\n') - json_report = os.path.join(args.infer_out, config.JSON_REPORT_FILENAME) bugs_out = os.path.join(args.infer_out, config.BUGS_FILENAME) issues.print_and_save_errors(args.infer_out, args.project_root, json_report, bugs_out, args.pmd_xml) diff --git a/infer/lib/python/inferlib/utils.py b/infer/lib/python/inferlib/utils.py index fc09714c5..183fa1a26 100644 --- a/infer/lib/python/inferlib/utils.py +++ b/infer/lib/python/inferlib/utils.py @@ -97,7 +97,7 @@ def dump_json_to_path( skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, cls=None, indent=2, # customized - separators=None, + separators=(',', ': '), # default is (', ', ': ') with trailing space encoding=config.CODESET, # customized default=None, sort_keys=False, **kw): with codecs.open(path, 'w',