MCPcopy Create free account
hub / github.com/Tencent/CodeAnalysis / data_handle

Method data_handle

client/tool/findbugs.py:137–169  ·  view source on GitHub ↗

结果处理

(error_output, enabled_rules, ctf)

Source from the content-addressed store, hash-verified

135
136 @staticmethod
137 def data_handle(error_output, enabled_rules, ctf):
138 """结果处理
139 """
140 if not os.path.exists(error_output) or os.stat(error_output).st_size == 0:
141 LogPrinter.info("result is empty")
142 return []
143 raw_warning = ET.ElementTree(file=error_output)
144 items = []
145 for bug in raw_warning.iter(tag="BugInstance"):
146 path = None
147 msg = None
148 line = None
149 FILE_NOT_FOUND = False
150 rule = bug.attrib.get("type")
151 # 通过缺陷模式反推出的检测器所对应的缺陷模式集合是指定缺陷模式的父集(即规则名与缺陷模式是1对多的关系),故这里需要过滤
152 if enabled_rules and rule not in enabled_rules:
153 continue
154 for node in bug:
155 if node.tag == "SourceLine":
156 line = node.attrib.get("start")
157 path = ctf.get_file_path_from_sourcepath(node.attrib.get("sourcepath"))
158 if not path:
159 path = ctf.get_file_path_from_classname(node.attrib.get("classname"))
160 if not path or not line:
161 FILE_NOT_FOUND = True
162 break
163 line = int(line)
164 elif node.tag == "LongMessage":
165 msg = node.text
166 if FILE_NOT_FOUND:
167 continue
168 items.append({"path": path, "rule": rule, "msg": msg, "line": line})
169 return items
170
171
172

Callers 1

analyzeMethod · 0.45

Calls 4

infoMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected