maven-plugins/checkstyle/plugin.jelly
evenisse ec2baff6e1 fixed MAVEN-493.
I register reports only if source, test,... exists.


git-svn-id: https://svn.apache.org/repos/asf/maven/maven-1/plugins/trunk@113563 13f79535-47bb-0310-9956-ffa450edef68
2003-07-01 13:53:42 +00:00

190 lines
6.7 KiB
XML

<?xml version="1.0"?>
<!--
=============================================================================
Checkstyle plugin for Maven.
=============================================================================
-->
<project
xmlns:j="jelly:core"
xmlns:ant="jelly:ant"
xmlns:util="jelly:util"
xmlns:doc="doc">
<!--
========================================================================
Default goal.
========================================================================
-->
<goal name="checkstyle" description="Perform checkstyle checks"
prereqs="checkstyle:report"/>
<!--
========================================================================
Initializations.
========================================================================
-->
<goal name="checkstyle:init">
<j:if test="${sourcesPresent == 'true'}">
<!-- If an explicit config file is set then use that. If one isn't
then we will look for the maven.checkstyle.format property and
load the predefined config set. -->
<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}_checks.xml"/>
</j:otherwise>
</j:choose>
<ant:taskdef name="checkstyle"
classname="com.puppycrawl.tools.checkstyle.CheckStyleTask">
<classpath>
<pathelement location="${plugin.getDependencyPath('checkstyle:checkstyle')}"/>
<pathelement location="${plugin.getDependencyPath('antlr:antlr')}"/>
<pathelement location="${plugin.getDependencyPath('regexp:regexp')}"/>
<pathelement location="${plugin.getDependencyPath('commons-beanutils:commons-beanutils')}"/>
<pathelement location="${plugin.getDependencyPath('commons-collections:commons-collections')}"/>
<pathelement location="${plugin.getDependencyPath('commons-logging:commons-logging')}"/>
</classpath>
</ant:taskdef>
</j:if>
</goal>
<!--
========================================================================
Check if license file is available, display warning if not and sets
the Ant "checkstyleShouldRun" property if the license file is
available.
========================================================================
-->
<goal name="checkstyle:license"
prereqs="checkstyle:init">
<j:if test="${sourcesPresent == 'true'}">
<util:file var="header" name="${maven.checkstyle.header.file}"/>
<j:choose>
<j:when test="${not(header.exists())}">
<ant: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. =
======================================================================
</ant:echo>
</j:when>
<j:otherwise>
<ant:property name="checkstyleShouldRun" value="true"/>
</j:otherwise>
</j:choose>
</j:if>
</goal>
<!--
========================================================================
Generate a checkstyle report by running checkstyle on the project
source code.
========================================================================
-->
<goal name="checkstyle:report"
description="Perform checkstyle checks"
prereqs="checkstyle:init,checkstyle:license">
<j:if test="${checkstyleShouldRun}">
<!-- Create the directory for the checkstyle cache in case it doesn't
exist already -->
<ant:dirname property="maven.checkstyle.cache.dir"
file="${maven.checkstyle.cache.file}"/>
<ant:mkdir dir="${maven.checkstyle.cache.dir}"/>
<ant:echo>Using ${checkstyleProperties} for checkstyle ...</ant:echo>
<ant:checkstyle
config="${checkstyleProperties}"
failOnViolation="${maven.checkstyle.fail.on.violation}">
<property key="checkstyle.header.file"
file="${maven.checkstyle.header.file}"/>
<property key="checkstyle.cache.file"
file="${maven.checkstyle.cache.file}"/>
<ant:fileset dir="${pom.build.sourceDirectory}"
includes="${maven.checkstyle.includes}"
excludes="${maven.checkstyle.excludes}"/>
<ant:formatter type="xml"
toFile="${maven.build.dir}/checkstyle-raw-report.xml"/>
<j:choose>
<j:when test="${maven.checkstyle.usefile}">
<ant:formatter type="plain"
toFile="${maven.build.dir}/checkstyle-raw-report.txt"/>
</j:when>
<j:otherwise>
<ant:formatter type="plain"/>
</j:otherwise>
</j:choose>
</ant:checkstyle>
<doc:jsl
input="${maven.build.dir}/checkstyle-raw-report.xml"
output="checkstyle-report.xml"
stylesheet="${plugin.resources}/checkstyle.jsl"
encoding="${maven.docs.outputencoding}"
omitXmlDeclaration="false"
outputMode="xml"
prettyPrint="true"/>
</j:if>
</goal>
<!--
========================================================================
Register a Checkstyle report to the "site" plugin.
========================================================================
-->
<goal name="maven-checkstyle-plugin:register">
<j:if test="${sourcesPresent == 'true'}">
<doc:registerReport
name="Checkstyle"
pluginName="checkstyle"
link="checkstyle-report"
description="Report on coding style conventions."/>
</j:if>
</goal>
<!--
========================================================================
Deregister a Checkstyle report to the "site" plugin.
========================================================================
-->
<goal name="maven-checkstyle-plugin:deregister">
<j:if test="${sourcesPresent == 'true'}">
<doc:deregisterReport name="Checkstyle"/>
</j:if>
</goal>
</project>