在 Jenkins 中显示 Android Lint 结果

发布于 2024-12-24 23:08:46 字数 853 浏览 1 评论 0原文

如何在 Jenkins 中显示 Android Lint 的结果,例如作为警告?我想从 Jenkins GUI 浏览警告,就像编译器警告和 PMD / Checkstyle 警告一样。

Jenkins 作业的输出是这样的:

 [exec] 
 [exec] Scanning org.digitalcure.ccnf.app: ..........Incorrect detector reported disabled issue TooManyViews
 [exec] Incorrect detector reported disabled issue TooManyViews
 [exec] ...
 [exec] 
 [exec] Scanning org.digitalcure.android.common: ...
 [exec] res/values/strings.xml: Warning: The resource R.string.display_unit_abc appears to be unused [UnusedResources]
 [exec] res/values/strings.xml: Warning: The resource R.string.edit_error_abc appears to be unused [UnusedResources]
 [exec] Warning: Missing density variation folders in res: drawable-xhdpi [IconMissingDensityFolder]
 [exec] 
 [exec] 0 errors, 3 warnings

Android Lint 也可以创建 XML 文件,但恐怕没有 Jenkins 插件能够解析该文件。或者我错过了什么?

How can I display the results from Android Lint in Jenkins, e.g. as warnings? I want to browse the warnings from the Jenkins GUI, just like compiler warnings and PMD / Checkstyle warnings.

The output from the Jenkins job is something like this:

 [exec] 
 [exec] Scanning org.digitalcure.ccnf.app: ..........Incorrect detector reported disabled issue TooManyViews
 [exec] Incorrect detector reported disabled issue TooManyViews
 [exec] ...
 [exec] 
 [exec] Scanning org.digitalcure.android.common: ...
 [exec] res/values/strings.xml: Warning: The resource R.string.display_unit_abc appears to be unused [UnusedResources]
 [exec] res/values/strings.xml: Warning: The resource R.string.edit_error_abc appears to be unused [UnusedResources]
 [exec] Warning: Missing density variation folders in res: drawable-xhdpi [IconMissingDensityFolder]
 [exec] 
 [exec] 0 errors, 3 warnings

Android Lint can create a XML file too, but I'm afraid that there is no Jenkins plugin able to parse the file. Or am I missing something?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

浊酒尽余欢 2024-12-31 23:08:46

您可以使用 Jenkins 的警告 NG 插件(取代了 Android Lint 插件)来执行此操作, 2012 年发布)。

这将解析 Lint XML 并以与 Jenkins 的其他静态分析插件相同的方式显示结果。

You can do this with the Warnings NG Plugin for Jenkins (which superseded the Android Lint Plugin, released in 2012).

This will parse Lint XML and display results in the same style as other static analysis plugins for Jenkins.

为人所爱 2024-12-31 23:08:46

帕沃尔,非常感谢你的灵感!不幸的是,您的正则表达式/脚本对我不起作用,但这是进一步调查的一个非常好的起点。以下是适合我的配置的内容:

名称:Android Lint Parser

正则表达式:([^\s]*: )?([^ ]*):\s+(.*)\[ (.*)\]$

Groovy 脚本:

import hudson.plugins.warnings.parser.Warning;
import hudson.plugins.analysis.util.model.Priority;

String fileName = matcher.group(1);
String lineNumber = "";
String priority = matcher.group(2);
String message = matcher.group(3);
String category = matcher.group(4);

if (fileName == null) {
  fileName = "(no file)";
} else {
  int idx =  fileName.indexOf(':');
  if (idx > -1) {
    lineNumber = fileName.substring(idx + 1, fileName.size());
    fileName = fileName.substring(0, idx);

    int idx2 = lineNumber.indexOf(':');
    if (idx2 > -1) {
      lineNumber = lineNumber.substring(0, idx2);
    }

    idx2 = lineNumber.indexOf(' ');
    if (idx2 > -1) {
      lineNumber = lineNumber.substring(0, idx2);
    }
  }
}

return new Warning(fileName, lineNumber.size() > 0 ? Integer.parseInt(lineNumber) : 0, "Android Lint Parser", category, message, priority.equals("Error") ? Priority.HIGH : Priority.NORMAL);

Pavol, thank you very much for your inspiration! Unfortunately your regexp/script doesn't work for me, but it was a very good starting point for further investigations. Here is what works for my configuration:

Name: Android Lint Parser

Regexp: ([^\s]*: )?([^ ]*):\s+(.*)\[(.*)\]$

Groovy script:

import hudson.plugins.warnings.parser.Warning;
import hudson.plugins.analysis.util.model.Priority;

String fileName = matcher.group(1);
String lineNumber = "";
String priority = matcher.group(2);
String message = matcher.group(3);
String category = matcher.group(4);

if (fileName == null) {
  fileName = "(no file)";
} else {
  int idx =  fileName.indexOf(':');
  if (idx > -1) {
    lineNumber = fileName.substring(idx + 1, fileName.size());
    fileName = fileName.substring(0, idx);

    int idx2 = lineNumber.indexOf(':');
    if (idx2 > -1) {
      lineNumber = lineNumber.substring(0, idx2);
    }

    idx2 = lineNumber.indexOf(' ');
    if (idx2 > -1) {
      lineNumber = lineNumber.substring(0, idx2);
    }
  }
}

return new Warning(fileName, lineNumber.size() > 0 ? Integer.parseInt(lineNumber) : 0, "Android Lint Parser", category, message, priority.equals("Error") ? Priority.HIGH : Priority.NORMAL);
短叹 2024-12-31 23:08:46

在某些版本的编译警告插件中,您可以使用 regexp 和 groovy 脚本从 jenkins 的配置站点创建解析器。我为作为 shell 脚本运行的 lint 创建了一个,并输出到某个文件。

正则表达式:^\s*([^ ]*): ([^ ]*):\s*(.*)\[(.*)\]$

Groovy 脚本:

import hudson.plugins.warnings.parser.Warning;
import hudson.plugins.analysis.util.model.Priority;

String fileName = matcher.group(1)
String lineNumber = ""; //matcher.group(1)
String priority = matcher.group(2)
String message = matcher.group(3)
String category = matcher.group(4)
int idx =  fileName.indexOf(':');
if (idx > -1) {
  lineNumber = fileName.substring(idx+1,fileName.size());
  fileName = fileName.substring(0,idx);
}

return new Warning(fileName, lineNumber.size() > 0 ? Integer.parseInt(lineNumber) : 0, "Android Lint Parser", category, message, priority.equals("Error") ? Priority.HIGH : Priority.NORMAL);

In compile warnings plugin from some version you can create parser from the configuration site of jenkins using regexp and groovy script. I created one for the lint I run as shell script with output to some file.

Regexp: ^\s*([^ ]*): ([^ ]*):\s*(.*)\[(.*)\]$

Groovy script:

import hudson.plugins.warnings.parser.Warning;
import hudson.plugins.analysis.util.model.Priority;

String fileName = matcher.group(1)
String lineNumber = ""; //matcher.group(1)
String priority = matcher.group(2)
String message = matcher.group(3)
String category = matcher.group(4)
int idx =  fileName.indexOf(':');
if (idx > -1) {
  lineNumber = fileName.substring(idx+1,fileName.size());
  fileName = fileName.substring(0,idx);
}

return new Warning(fileName, lineNumber.size() > 0 ? Integer.parseInt(lineNumber) : 0, "Android Lint Parser", category, message, priority.equals("Error") ? Priority.HIGH : Priority.NORMAL);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文