Created
December 13, 2018 17:21
-
-
Save alexives/4803bbed430da6f4ecab1c56af38abfc to your computer and use it in GitHub Desktop.
Detekt task with junit output for Gitlab
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
detekt { | |
reports { | |
xml { | |
enabled = true // enable the checkstyle report | |
} | |
} | |
} | |
task junitDetekt { | |
def inXslt = "$rootDir/xslt/checkstyle2junit.xslt" // comes from https://github.com/koalaman/shellcheck/wiki/JUnit | |
def inXml = "${project.buildDir}/reports/detekt/detekt.xml" // Uses project.buildDir so that you can use this with a multiproject setup | |
def out = "${project.buildDir}/reports/detekt/junit.xml" | |
description "Converts Checkstyle from Detekt to junit for gitlab" | |
inputs.files inXslt, inXml | |
outputs.files out | |
doLast { | |
ant.xslt(in: inXml, out: out, style: inXslt) | |
println "Wrote junit detekt file out to $out" | |
} | |
} | |
project.tasks.findByName("detekt").finalizedBy junitDetekt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?><!-- FROM https://github.com/koalaman/shellcheck/wiki/JUnit --> | |
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> | |
<xsl:output encoding="UTF-8" method="xml"></xsl:output> | |
<xsl:template match="/"> | |
<testsuite> | |
<xsl:attribute name="tests"> | |
<xsl:value-of select="count(.//file)" /> | |
</xsl:attribute> | |
<xsl:attribute name="failures"> | |
<xsl:value-of select="count(.//error)" /> | |
</xsl:attribute> | |
<xsl:for-each select="//checkstyle"> | |
<xsl:apply-templates /> | |
</xsl:for-each> | |
</testsuite> | |
</xsl:template> | |
<xsl:template match="file"> | |
<testcase> | |
<xsl:attribute name="classname"> | |
<xsl:value-of select="@name" /> | |
</xsl:attribute> | |
<xsl:attribute name="name"> | |
<xsl:value-of select="@name" /> | |
</xsl:attribute> | |
<xsl:apply-templates select="node()" /> | |
</testcase> | |
</xsl:template> | |
<xsl:template match="error"> | |
<failure> | |
<xsl:attribute name="type"> | |
<xsl:value-of select="@source" /> | |
</xsl:attribute> | |
<xsl:text>Line </xsl:text> | |
<xsl:value-of select="@line" /> | |
<xsl:text>: </xsl:text> | |
<xsl:value-of select="@message" /> | |
</failure> | |
</xsl:template> | |
</xsl:stylesheet> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment