[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
master
Jeremy Dubreil 8 years ago committed by Facebook Github Bot
parent d7f112a640
commit 1065477765

@ -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: with open(os.path.join(args.infer_out, ANALYSIS_SUMMARY_OUTPUT), 'w') as f:
f.write(buck_stats) f.write(buck_stats)
all_json_rows = set() all_json_rows = []
stats = init_stats(args, start_time) stats = init_stats(args, start_time)
accumulation_whitelist = list(map(re.compile, [ 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) old_value = stats[type_k].get(key, 0)
stats[type_k][key] = old_value + value stats[type_k][key] = old_value + value
json_rows = load_json_report(jar) all_json_rows += load_json_report(jar)
for row in json_rows:
all_json_rows.add(json.dumps(row))
# Override normals # Override normals
stats['normal'].update(target_stats.get('normal', {})) 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) logging.warn('Bad zip file %s', path)
json_report = os.path.join(args.infer_out, config.JSON_REPORT_FILENAME) 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 # Convert all float values to integer values
for key, value in stats.get('float', {}).items(): 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 # Delete the float entries before exporting the results
del(stats['float']) 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') 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) bugs_out = os.path.join(args.infer_out, config.BUGS_FILENAME)
issues.print_and_save_errors(args.infer_out, args.project_root, issues.print_and_save_errors(args.infer_out, args.project_root,
json_report, bugs_out, args.pmd_xml) json_report, bugs_out, args.pmd_xml)

@ -97,7 +97,7 @@ def dump_json_to_path(
skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True,
cls=None, cls=None,
indent=2, # customized indent=2, # customized
separators=None, separators=(',', ': '), # default is (', ', ': ') with trailing space
encoding=config.CODESET, # customized encoding=config.CODESET, # customized
default=None, sort_keys=False, **kw): default=None, sort_keys=False, **kw):
with codecs.open(path, 'w', with codecs.open(path, 'w',

Loading…
Cancel
Save