diff options
author | Tor Norbye <tnorbye@google.com> | 2012-08-02 12:32:09 -0700 |
---|---|---|
committer | Tor Norbye <tnorbye@google.com> | 2012-08-02 12:42:44 -0700 |
commit | a095cba88b027917bedf561dbd5cf94817702489 (patch) | |
tree | d23f8fbcc30e59e2bafc3f53cc0b66bb824cc024 /lint/cli | |
parent | af58169996f268a5e6fd4905c50b4858382c3f0f (diff) | |
download | sdk-a095cba88b027917bedf561dbd5cf94817702489.zip sdk-a095cba88b027917bedf561dbd5cf94817702489.tar.gz sdk-a095cba88b027917bedf561dbd5cf94817702489.tar.bz2 |
Include additional metadata in the XML report
This CL adds additional metadata into the lint XML report, such as the
full issue explanation, the issue priority, the issue summary, the
additional information URL, and the error line.
This allows for example the Jenkins plugin to provide all this
information for a build report without having to bundle a (possibly
out of date) snapshot of lint's metadata the way it does right now.
Change-Id: Iaf674ffa6bbef318ce3f636404d72c74de4b1c50
Diffstat (limited to 'lint/cli')
-rw-r--r-- | lint/cli/src/com/android/tools/lint/Main.java | 17 | ||||
-rw-r--r-- | lint/cli/src/com/android/tools/lint/XmlReporter.java | 49 |
2 files changed, 56 insertions, 10 deletions
diff --git a/lint/cli/src/com/android/tools/lint/Main.java b/lint/cli/src/com/android/tools/lint/Main.java index fbb0b16..f0cbf8b 100644 --- a/lint/cli/src/com/android/tools/lint/Main.java +++ b/lint/cli/src/com/android/tools/lint/Main.java @@ -683,8 +683,18 @@ public class Main extends LintClient { "\"lint --ignore UnusedResources,UselessLeaf /my/project/path\"\n"; } - @SuppressWarnings("resource") // Eclipse doesn't know about Closeables.closeQuietly private void printVersion() { + String revision = getRevision(); + if (revision != null) { + System.out.println(String.format("lint: version %1$s", revision)); + } else { + System.out.println("lint: unknown version"); + } + } + + @SuppressWarnings("resource") // Eclipse doesn't know about Closeables.closeQuietly + @Nullable + String getRevision() { File file = findResource("tools" + File.separator + //$NON-NLS-1$ "source.properties"); //$NON-NLS-1$ if (file != null && file.exists()) { @@ -696,8 +706,7 @@ public class Main extends LintClient { String revision = properties.getProperty("Pkg.Revision"); //$NON-NLS-1$ if (revision != null && revision.length() > 0) { - System.out.println(String.format("lint: version %1$s", revision)); - return; + return revision; } } catch (IOException e) { // Couldn't find or read the version info: just print out unknown below @@ -706,7 +715,7 @@ public class Main extends LintClient { } } - System.out.println("lint: unknown version"); + return null; } private void displayValidIds(IssueRegistry registry, PrintStream out) { diff --git a/lint/cli/src/com/android/tools/lint/XmlReporter.java b/lint/cli/src/com/android/tools/lint/XmlReporter.java index f924def..04ac1d9 100644 --- a/lint/cli/src/com/android/tools/lint/XmlReporter.java +++ b/lint/cli/src/com/android/tools/lint/XmlReporter.java @@ -16,6 +16,8 @@ package com.android.tools.lint; +import com.android.tools.lint.checks.BuiltinIssueRegistry; +import com.android.tools.lint.detector.api.Issue; import com.android.tools.lint.detector.api.Location; import com.android.tools.lint.detector.api.Position; import com.google.common.annotations.Beta; @@ -52,18 +54,53 @@ public class XmlReporter extends Reporter { @Override public void write(int errorCount, int warningCount, List<Warning> issues) throws IOException { - mWriter.write( - "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + //$NON-NLS-1$ - "<issues>\n"); //$NON-NLS-1$ + mWriter.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); //$NON-NLS-1$ + mWriter.write("<issues format=\"3\""); //$NON-NLS-1$ + String revision = mClient.getRevision(); + if (revision != null) { + mWriter.write(String.format(" by=\"lint %1$s\"", revision)); //$NON-NLS-1$ + } + mWriter.write(">\n"); //$NON-NLS-1$ if (issues.size() > 0) { for (Warning warning : issues) { mWriter.write('\n'); indent(mWriter, 1); mWriter.write("<issue"); //$NON-NLS-1$ - writeAttribute(mWriter, 2, "id", warning.issue.getId()); //$NON-NLS-1$ - writeAttribute(mWriter, 2, "severity", warning.severity.getDescription()); //$NON-NLS-1$ - writeAttribute(mWriter, 2, "message", warning.message); //$NON-NLS-1$ + Issue issue = warning.issue; + writeAttribute(mWriter, 2, "id", issue.getId()); //$NON-NLS-1$ + writeAttribute(mWriter, 2, "severity", + warning.severity.getDescription()); + writeAttribute(mWriter, 2, "message", warning.message); //$NON-NLS-1$ + + writeAttribute(mWriter, 2, "category", //$NON-NLS-1$ + issue.getCategory().getFullName()); + writeAttribute(mWriter, 2, "priority", //$NON-NLS-1$ + Integer.toString(issue.getPriority())); + writeAttribute(mWriter, 2, "summary", issue.getDescription()); //$NON-NLS-1$ + writeAttribute(mWriter, 2, "explanation", issue.getExplanation()); //$NON-NLS-1$ + if (issue.getMoreInfo() != null) { + writeAttribute(mWriter, 2, "url", issue.getMoreInfo()); //$NON-NLS-1$ + } + if (warning.errorLine != null && !warning.errorLine.isEmpty()) { + String line = warning.errorLine; + int index1 = line.indexOf('\n'); + if (index1 != -1) { + int index2 = line.indexOf('\n', index1 + 1); + if (index2 != -1) { + String line1 = line.substring(0, index1); + String line2 = line.substring(index1 + 1, index2); + writeAttribute(mWriter, 2, "errorLine1", line1); //$NON-NLS-1$ + writeAttribute(mWriter, 2, "errorLine2", line2); //$NON-NLS-1$ + } + } + } + if (mClient.getRegistry() instanceof BuiltinIssueRegistry && + ((BuiltinIssueRegistry) mClient.getRegistry()).hasAutoFix( + "adt", issue)) { //$NON-NLS-1$ + writeAttribute(mWriter, 2, "quickfix", "adt"); //$NON-NLS-1$ //$NON-NLS-2$ + } + assert (warning.file != null) == (warning.location != null); if (warning.file != null) { |