Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Print reports to stdout #21

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion android-check-plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ dependencies {
}

group = 'com.noveogroup.android'
version = '1.2.3'
version = '1.3.0-SNAPSHOT'
description = 'Static code analysis plugin for Android project.'

task wrapper(type: Wrapper) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,16 @@ abstract class CommonCheck<Config extends CommonConfig> {
}
}

protected void reformatReport(Project project, File styleFile,
File xmlReportFile) {
def temp = File.createTempFile('android-check', '.txt')
project.ant.xslt(in: xmlReportFile, out: temp) {
style { string(styleFile.text) }
}
System.out << temp.text
System.out.flush()
}

void apply(Project target) {
target.task(
[group : 'verification',
Expand All @@ -72,6 +82,7 @@ abstract class CommonCheck<Config extends CommonConfig> {
boolean abortOnError = config.resolveAbortOnError(extension.abortOnError)
File configFile = config.resolveConfigFile(taskCode)
File styleFile = config.resolveStyleFile(taskCode)
File stdoutStyleFile = config.resolveStdoutStyleFile(taskCode)
File xmlReportFile = config.resolveXmlReportFile(taskCode)
File htmlReportFile = config.resolveHtmlReportFile(taskCode)
List<File> sources = config.getAndroidSources()
Expand All @@ -83,6 +94,7 @@ abstract class CommonCheck<Config extends CommonConfig> {
performCheck(target, sources, configFile, xmlReportFile)
htmlReportFile.parentFile.mkdirs()
reformatReport(target, styleFile, xmlReportFile, htmlReportFile)
reformatReport(target, stdoutStyleFile, xmlReportFile)

int errorCount = getErrorCount(xmlReportFile)
if (errorCount) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@ class CommonConfig {
return Utils.getResource(project, "$code/${code}.xsl")
}

private String resolveStdoutStyle(String code) {
return Utils.getResource(project, "$code/${code}.stdout.xsl")
}

File resolveStyleFile(String code) {
File file = new File(project.buildDir, "tmp/android-check/${code}.xsl")
file.parentFile.mkdirs()
Expand All @@ -146,6 +150,14 @@ class CommonConfig {
return file
}

File resolveStdoutStyleFile(String code) {
File file = new File(project.buildDir, "tmp/android-check/${code}.stdout.xsl")
file.parentFile.mkdirs()
file.delete()
file << resolveStdoutStyle(code)
return file
}

private File resolveReportFile(String extension, File reportFile, File reportDirectory, String code) {
if (reportFile) {
return reportFile
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

<xsl:output indent="yes" method="text" />
<xsl:decimal-format decimal-separator="." grouping-separator="," />

<xsl:key name="files" match="file" use="@name" />

<xsl:template match="checkstyle">
Checkstyle: <xsl:apply-templates mode="summary" select="." />
Files: <xsl:apply-templates select="file[@name and generate-id(.) = generate-id(key('files', @name))]" />

</xsl:template>

<xsl:template match="file">
<xsl:variable name="errorCount" select="count(error)" />
- <xsl:value-of select="@name" />
Errors: <xsl:value-of select="$errorCount" />
<xsl:for-each select="key('files', @name)/error">
<xsl:sort data-type="number" order="ascending" select="@line" />
Error Description: <xsl:value-of select="@message" />
Line: <xsl:value-of select="@line" />
</xsl:for-each>
</xsl:template>

<xsl:template match="checkstyle" mode="summary">
<xsl:variable name="fileCount" select="count(file[@name and generate-id(.) = generate-id(key('files', @name))])" />
<xsl:variable name="errorCount" select="count(file/error)" />
Summary:
Files: <xsl:value-of select="$fileCount" />
Errors: <xsl:value-of select="$errorCount" />
</xsl:template>

</xsl:stylesheet>
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

<xsl:output indent="yes" method="text" />
<xsl:decimal-format decimal-separator="." grouping-separator="," />

<xsl:template match="BugCollection">
Findbugs: <xsl:apply-templates mode="summary" select="." />
Files: <xsl:apply-templates select="FindBugsSummary/FileStats[@path and @bugCount]" />

</xsl:template>

<xsl:template match="FileStats">
<xsl:variable name="path" select="@path" />
- <xsl:value-of select="$path" />
Errors: <xsl:value-of select="@bugCount" />
<xsl:for-each select="//BugInstance[SourceLine/@sourcepath = $path]">
<xsl:sort data-type="number" order="ascending" select="SourceLine/@start" />
Error Description: <xsl:value-of select="@type" />
Line: <xsl:value-of select="LongMessage/text()" />
<xsl:value-of select="SourceLine/@start" /> - <xsl:value-of select="SourceLine/@end" />
</xsl:for-each>
</xsl:template>

<xsl:template match="BugCollection" mode="summary">
<xsl:variable name="fileCount" select="count(FindBugsSummary/FileStats)" />
<xsl:variable name="errorCount" select="count(BugInstance)" />
Summary:
Files: <xsl:value-of select="$fileCount" />
Errors: <xsl:value-of select="$errorCount" />
</xsl:template>

</xsl:stylesheet>
35 changes: 35 additions & 0 deletions android-check-plugin/src/main/resources/pmd/pmd.stdout.xsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

<xsl:output indent="yes" method="text" />
<xsl:decimal-format decimal-separator="." grouping-separator="," />

<xsl:key name="files" match="file" use="@name" />

<xsl:template match="pmd">
PMD: <xsl:apply-templates mode="summary" select="." />
Files: <xsl:apply-templates select="file[@name and generate-id(.) = generate-id(key('files', @name))]" />

</xsl:template>

<xsl:template match="file">
<xsl:variable name="violationCount" select="count(violation)" />
- <xsl:value-of select="@name" />
Violations: <xsl:value-of select="$violationCount" />
<xsl:for-each select="key('files', @name)/violation">
<xsl:sort data-type="number" order="ascending" select="@beginline" />
Violation: <xsl:value-of select="normalize-space(node())" />
Location: <xsl:value-of select="@beginline" />:<xsl:value-of select="@begincolumn" /> - <xsl:value-of select="@endline" />:<xsl:value-of select="@endcolumn" />
</xsl:for-each>
</xsl:template>

<xsl:template match="pmd" mode="summary">
<xsl:variable name="fileCount" select="count(file[@name and generate-id(.) = generate-id(key('files', @name))])" />
<xsl:variable name="violationCount" select="count(file/violation)" />
Summary:
Files: <xsl:value-of select="$fileCount" />
Violations: <xsl:value-of select="$violationCount" />
</xsl:template>

</xsl:stylesheet>