Summary: Turns out it was useful, so it is now reborn in OCaml. Fixes https://github.com/facebook/infer/issues/1262. Reviewed By: skcho Differential Revision: D22016185 fbshipit-source-id: 31ccb7540master
parent
7221c93980
commit
97feb81c3b
@ -0,0 +1,53 @@
|
|||||||
|
(*
|
||||||
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
|
*
|
||||||
|
* This source code is licensed under the MIT license found in the
|
||||||
|
* LICENSE file in the root directory of this source tree.
|
||||||
|
*)
|
||||||
|
|
||||||
|
open! IStd
|
||||||
|
module F = Format
|
||||||
|
|
||||||
|
let pp_current_date_and_time f =
|
||||||
|
let {Unix.tm_year; tm_mon; tm_mday; tm_hour; tm_min; tm_sec} = Unix.time () |> Unix.localtime in
|
||||||
|
F.fprintf f "%d-%02d-%dT%d:%d:%d.000000" (1900 + tm_year) tm_mon tm_mday tm_hour tm_min tm_sec
|
||||||
|
|
||||||
|
|
||||||
|
let pp_xml_issue f (issue : Jsonbug_t.jsonbug) =
|
||||||
|
let java_class_name, java_package, method_name =
|
||||||
|
let java_result =
|
||||||
|
let open IOption.Let_syntax in
|
||||||
|
if String.is_suffix ~suffix:".java" issue.file then
|
||||||
|
let* package_class_method, _formals_types = String.lsplit2 ~on:'(' issue.procedure in
|
||||||
|
let* package_class, method_ = String.rsplit2 ~on:'.' package_class_method in
|
||||||
|
let+ package, class_ = String.rsplit2 ~on:'.' package_class in
|
||||||
|
(package, class_, method_)
|
||||||
|
else None
|
||||||
|
in
|
||||||
|
match java_result with None -> ("", "", issue.procedure) | Some result -> result
|
||||||
|
in
|
||||||
|
F.fprintf f
|
||||||
|
{|<file name="%s">
|
||||||
|
<violation begincolumn="%d" beginline="%d" endcolumn="%d" endline="%d" class="%s" method="%s" package="%s" priority="1" rule="%s" ruleset="Infer Rules" externalinfourl="https://fbinfer.com/docs/next/%s">%s</violation>
|
||||||
|
</file>|}
|
||||||
|
issue.file (max issue.column 0) issue.line (max issue.column 0) (issue.line + 1) java_class_name
|
||||||
|
method_name java_package issue.bug_type
|
||||||
|
(Help.url_fragment_of_issue_type issue.bug_type)
|
||||||
|
issue.qualifier
|
||||||
|
|
||||||
|
|
||||||
|
let is_user_visible (issue : Jsonbug_t.jsonbug) =
|
||||||
|
Option.is_none issue.censored_reason && not (String.equal issue.severity "INFO")
|
||||||
|
|
||||||
|
|
||||||
|
let pp_xml_issue_filter f issue = if is_user_visible issue then pp_xml_issue f issue
|
||||||
|
|
||||||
|
let write ~xml_path ~json_path =
|
||||||
|
let report = Atdgen_runtime.Util.Json.from_file Jsonbug_j.read_report json_path in
|
||||||
|
Utils.with_file_out xml_path ~f:(fun out_channel ->
|
||||||
|
let f = F.formatter_of_out_channel out_channel in
|
||||||
|
F.fprintf f {|@[%cpmd version="5.4.1" date="%t">
|
||||||
|
%a
|
||||||
|
</pmd>@.|} '<' pp_current_date_and_time
|
||||||
|
(Pp.seq ~sep:"\n" pp_xml_issue_filter)
|
||||||
|
report )
|
@ -0,0 +1,11 @@
|
|||||||
|
(*
|
||||||
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
|
*
|
||||||
|
* This source code is licensed under the MIT license found in the
|
||||||
|
* LICENSE file in the root directory of this source tree.
|
||||||
|
*)
|
||||||
|
|
||||||
|
open! IStd
|
||||||
|
|
||||||
|
val write : xml_path:string -> json_path:string -> unit
|
||||||
|
(** read the JSON report at [json_path] and translates it to a PMD-style XML report in [xml_path] *)
|
@ -0,0 +1,20 @@
|
|||||||
|
# Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
|
#
|
||||||
|
# This source code is licensed under the MIT license found in the
|
||||||
|
# LICENSE file in the root directory of this source tree.
|
||||||
|
|
||||||
|
TESTS_DIR = ../..
|
||||||
|
|
||||||
|
CODETOANALYZE_DIR = ../codetoanalyze
|
||||||
|
|
||||||
|
CLANG_OPTIONS = -c
|
||||||
|
INFER_OPTIONS = --project-root $(CODETOANALYZE_DIR) --pmd-xml
|
||||||
|
INFERPRINT_OPTIONS = --issues-tests
|
||||||
|
SOURCES = $(CODETOANALYZE_DIR)/hello.c
|
||||||
|
|
||||||
|
include $(TESTS_DIR)/clang.make
|
||||||
|
|
||||||
|
issues.exp.test: infer-out/report.json
|
||||||
|
# massage the first line of the XML to delete non-reproducible information (the current date)
|
||||||
|
$(QUIET)sed -e 's/date="[^"]*"/date=""/' infer-out/report.xml > $@
|
||||||
|
|
@ -0,0 +1,5 @@
|
|||||||
|
<pmd version="5.4.1" date="">
|
||||||
|
<file name="hello.c">
|
||||||
|
<violation begincolumn="3" beginline="12" endcolumn="3" endline="13" class="" method="test" package="" priority="1" rule="NULL_DEREFERENCE" ruleset="Infer Rules" externalinfourl="https://fbinfer.com/docs/next/all-issue-types#null_dereference">pointer `s` last assigned on line 11 could be null and is dereferenced at line 12, column 3.</violation>
|
||||||
|
</file>
|
||||||
|
</pmd>
|
Loading…
Reference in new issue