在Jenkins中显示Android Lint结果

时间:2012-01-05 16:25:50

标签: android jenkins android-lint

如何在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插件可以解析文件。或者我错过了什么?

3 个答案:

答案 0 :(得分:7)

Jenkins现在拥有Android Lint Plugin,如果您使用的是SDK工具r17或更新版本。

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

答案 1 :(得分:3)

Pavol,非常感谢你的灵感!不幸的是,你的正则表达式/脚本对我不起作用,但它是进一步调查的一个非常好的起点。这适用于我的配置:

姓名:Android Lint Parser

Regexp:([^\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);

答案 2 :(得分:0)

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

Regexp:^\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);