5

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?

Bananeweizen
  • 21,797
  • 8
  • 68
  • 88
stefan222
  • 669
  • 1
  • 11
  • 30
  • 2
    Yeah, it's tough as the Lint XML format isn't compatible with other similar Java tools. I've been working on a Jenkins plugin to parse Lint results. – Christopher Orr Jan 14 '12 at 17:52
  • Christopher, an Android Lint Plug-in for Jenkins would be very helpful. Anyway, with the help of Pavol I solved my issue. Please post a comment when the plug-in is available for testing. Thank you! – stefan222 Jan 27 '12 at 18:03

3 Answers3

7

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.

Christopher Orr
  • 110,418
  • 27
  • 198
  • 193
  • I tried to use this plugin too but it does not pick up the lint results (see http://stackoverflow.com/questions/12716150/jenkins-lint-plugin-not-picking-up-results) - any tips on what could be wrong? – Thomas Einwaller Oct 09 '12 at 08:38
  • 1
    Distribution of this plugin was suspended. All the features were merged into [Warning Next Generation](https://plugins.jenkins.io/warnings-ng/) plugin. – Tomasz Dzieniak Jun 17 '21 at 18:16
3

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);
stefan222
  • 669
  • 1
  • 11
  • 30
0

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