maven-plugins/checkstyle/plugin.jelly

139 lines
4.6 KiB
XML

<?xml version="1.0"?>
<project
xmlns:j="jelly:core"
xmlns:util="jelly:util"
xmlns:doc="doc">
<goal name="maven-checkstyle-plugin:register">
<doc:registerReport
name="Checkstyle"
pluginName="maven-checkstyle-plugin"
link="checkstyle-report"
description="Report on coding style conventions."/>
</goal>
<goal name="maven-checkstyle-plugin:deregister">
<doc:deregisterReport name="Checkstyle"/>
</goal>
<!-- ================================================================== -->
<!-- C H E C K S T Y L E -->
<!-- ================================================================== -->
<goal
name="maven-checkstyle-plugin:report"
description="Generate code convention conformance reports"
prereqs="checkstyle:check-license-file"/>
<goal
name="checkstyle:report">
<j:if test="${sourcesPresent == 'true'}">
<taskdef
name="checkstyle"
classname="com.puppycrawl.tools.checkstyle.CheckStyleTask">
</taskdef>
<attainGoal name="checkstyle:determine-properties" />
<!-- Create the directory for the checkstyle cache in case it doesn't exist already -->
<dirname property="maven.checkstyle.cache.dir" file="${maven.checkstyle.cache.file}"/>
<mkdir dir="${maven.checkstyle.cache.dir}"/>
<echo>Using ${checkstyleProperties} for checkstyle ...</echo>
<checkstyle
properties="${checkstyleProperties}"
failOnViolation="${maven.checkstyle.fail.on.violation}"
cacheFile="${maven.checkstyle.cache.file}">
<fileset
dir="${pom.build.sourceDirectory}"
includes="${maven.checkstyle.includes}"
excludes="${maven.checkstyle.excludes}"/>
<formatter type="xml" toFile="${maven.build.dir}/checkstyle-raw-report.xml"/>
<j:choose>
<j:when test="${maven.checkstyle.usefile}">
<formatter type="plain" toFile="${maven.build.dir}/checkstyle-raw-report.txt"/>
</j:when>
<j:otherwise>
<formatter type="plain"/>
</j:otherwise>
</j:choose>
</checkstyle>
<doc:jsl
input="${maven.build.dir}/checkstyle-raw-report.xml"
output="checkstyle-report.xml"
stylesheet="${plugin.resources}/checkstyle.jsl"
omitXmlDeclaration="true"
outputMode="xml"
prettyPrint="true"
/>
</j:if>
</goal>
<goal name="checkstyle:check-license-file"
description="Checks the existence of the LICENSE.txt file">
<attainGoal name="checkstyle:determine-properties" />
<j:scope>
<property file="${checkstyleProperties}" />
<j:set var="headerFile" scope="parent">${checkstyle.header.file}</j:set>
</j:scope>
<util:file name="${headerFile}" var="header"/>
<j:choose>
<j:when test="${not(header.exists()) and not(empty(headerFile))}">
<echo>
======================================================================
= W A R N I N G =
======================================================================
= Your project doesn't contain a header file specified as: =
= ${header}
= Checkstyle needs it to check the existence of the License in your =
= source files. If it can't find this file, it throws an error. =
= A temporary solution is to create an empty LICENSE.txt file. =
= Though, we recommend that you edit this License. =
======================================================================
</echo>
</j:when>
<j:otherwise>
<attainGoal name="checkstyle:report"/>
</j:otherwise>
</j:choose>
</goal>
<goal name="checkstyle:determine-properties">
<!--
|
| If an explicit properties file is set then use that. If one isn't then
| we will look for the maven.checkstyle.type property as there aren't going
| to be that many different formats: gnu, turbine, sun.
|
-->
<j:set var="checkstylePropertiesX" value="${maven.checkstyle.properties}X"/>
<j:choose>
<j:when test="${checkstylePropertiesX != 'X'}">
<j:set
var="checkstyleProperties"
value="${maven.checkstyle.properties}"/>
</j:when>
<j:otherwise>
<j:set
var="checkstyleProperties"
value="${plugin.resources}/${maven.checkstyle.format}-checkstyle.properties"/>
</j:otherwise>
</j:choose>
</goal>
</project>