stefan222
stefan222

Reputation: 679

Display Android Lint results in 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?

Upvotes: 5

Views: 5076

Answers (3)

Christopher Orr
Christopher Orr

Reputation: 111625

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.

Upvotes: 7

stefan222
stefan222

Reputation: 679

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);

Upvotes: 3

Pavol Zibrita
Pavol Zibrita

Reputation: 1

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);

Upvotes: 0

Related Questions