(self, file_path, source_dir)
| 197 | return log |
| 198 | |
| 199 | def __get_issues_from_file(self, file_path, source_dir): |
| 200 | items = [] |
| 201 | lint_proj_dir = os.environ.get(PROJECT_DIR_ENV) |
| 202 | if not os.path.exists(file_path) or os.stat(file_path).st_size == 0: |
| 203 | return items |
| 204 | warning_data = ET.ElementTree(file=file_path) |
| 205 | for bug in warning_data.iter(tag="issue"): |
| 206 | rule = bug.attrib.get("id") |
| 207 | msg = bug.attrib.get("message") |
| 208 | if rule == "LintError": |
| 209 | LogPrinter.warning("Lint Error msg: %s" % msg) |
| 210 | continue |
| 211 | if len(bug) == 0: |
| 212 | LogPrinter.warning("The rule %s doesn't find the location" % rule) |
| 213 | continue |
| 214 | locations = bug.getchildren() # 旧方法只获取最后一个文件行号,此方法获取所有行号 |
| 215 | for location in locations: |
| 216 | if not location.tag == "location": |
| 217 | continue |
| 218 | path = location.get("file") |
| 219 | if not location.get("line"): |
| 220 | if path.endswith(".java") or path.endswith(".class"): |
| 221 | LogPrinter.warning("%s: can't find the accurate source position" % path) |
| 222 | continue |
| 223 | line = 1 # 图片文件或资源文件若无行号,则给一个1. |
| 224 | else: |
| 225 | line = int(location.get("line")) |
| 226 | if os.path.isabs(path): |
| 227 | path = os.path.relpath(path, source_dir) |
| 228 | if lint_proj_dir: |
| 229 | path = os.path.join(lint_proj_dir, path) |
| 230 | items.append({"path": path, "rule": rule, "msg": msg, "line": line}) |
| 231 | return items |
| 232 | |
| 233 | |
| 234 | tool = AndroidLint |
no test coverage detected