Skip to content

Commit

Permalink
Merge pull request #879 from phpmd/document-junit
Browse files Browse the repository at this point in the history
Document junit export using third-party
  • Loading branch information
ravage84 committed Apr 19, 2021
2 parents c6eec43 + 266cc18 commit 9e531d6
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
42 changes: 42 additions & 0 deletions src/site/resources/web/junit.xslt
@@ -0,0 +1,42 @@
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" indent="yes" encoding="utf-8"/>

<xsl:template match="/pmd">
<testsuites failures="{count(./file/violation)}" errors="{count(./error)}">
<xsl:apply-templates select="file" />
<xsl:apply-templates select="error" />
</testsuites>
</xsl:template>

<xsl:template match="/pmd/file">
<testsuite name="{@name}" tests="{count(./violation)}" failures="{count(./violation)}" errors="0">
<xsl:apply-templates select="violation" />
</testsuite>
</xsl:template>

<xsl:template match="/pmd/error">
<testsuite name="{@name}" tests="1" failures="0" errors="1">
<testcase name="error">
<error message="{@msg}" type="error">
<xsl:value-of select="@msg" />
</error>
</testcase>
</testsuite>
</xsl:template>

<xsl:template match="/pmd/file/violation">
<testcase name="{@rule}">
<failure message="{normalize-space(text())}" type="{@ruleset}">
<xsl:value-of select="normalize-space(text())" />
<xsl:text>&#x0A;</xsl:text>
<xsl:text>Lines: </xsl:text>
<xsl:value-of select="@beginline" />
<xsl:text>-</xsl:text>
<xsl:value-of select="@endline" />
<xsl:text>&#x0A;</xsl:text>
<xsl:value-of select="@externalInfoUrl" />
</failure>
</testcase>
</xsl:template>
</xsl:stylesheet>
6 changes: 6 additions & 0 deletions src/site/rst/documentation/index.rst
Expand Up @@ -131,6 +131,12 @@ At the moment PHPMD comes with the following five renderers:
- *json*, formats JSON report.
- *github*, a format that GitHub Actions understands (see `CI Integration </documentation/ci-integration.html#github-actions>`_).

Some more formats can be obtained by conversion such as:

*junit* can be obtained using `xsltproc` package on the Debian-based systems or `libxslt` on Alpine and CentOS. with this given `junit.xslt config file <https://phpmd.org/junit.xslt>`_::

~ $ phpmd src xml cleancode | xsltproc junit.xslt -

Baseline
=========

Expand Down

0 comments on commit 9e531d6

Please sign in to comment.