maven-plugins/checkstyle/plugin.jelly
ltheussl 7bf50e3ea3 PR: MPCHECKSTYLE-38
RSS file has incorrect links when used in multiproject build.


git-svn-id: https://svn.apache.org/repos/asf/maven/maven-1/plugins/trunk@375824 13f79535-47bb-0310-9956-ffa450edef68
2006-02-08 01:29:52 +00:00

333 lines
12 KiB
XML

<?xml version="1.0"?>
<!--
/*
* Copyright 2001-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-->
<!--
=============================================================================
Checkstyle plugin for Maven.
=============================================================================
-->
<project
xmlns:j="jelly:core"
xmlns:ant="jelly:ant"
xmlns:util="jelly:util"
xmlns:doc="doc"
xmlns:assert="assert"
xmlns:maven="jelly:maven"
xmlns:define="jelly:define"
xmlns:checkstyle="checkstyle">
<!-- ======================================================================== -->
<goal name="checkstyle" description="Call checkstyle:report"
prereqs="checkstyle:report"/>
<!-- ======================================================================== -->
<goal name="checkstyle:init" description="Initialize plugin">
<j:if test="${sourcesPresent == 'true'}">
<!-- If an explicit config file or URL 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:set var="checkstylePropertiesURLX" value="${maven.checkstyle.propertiesURL}X"/>
<j:choose>
<j:when test="${checkstylePropertiesX != 'X'}">
<j:set
var="checkstyleProperties"
value="file:${maven.checkstyle.properties}"/>
<util:replace oldChar="\\" newChar="/" value="${checkstyleProperties}" var="checkstyleProperties" />
</j:when>
<j:when test="${checkstylePropertiesURLX != 'X'}">
<j:set
var="checkstyleProperties"
value="${maven.checkstyle.propertiesURL}"/>
</j:when>
<j:otherwise>
<j:set
var="checkstyleProperties"
value="file:${plugin.resources}/${maven.checkstyle.format}_checks.xml"/>
<util:replace oldChar="\\" newChar="/" value="${checkstyleProperties}" var="checkstyleProperties" />
</j:otherwise>
</j:choose>
<ant:taskdef resource="checkstyletask.properties">
<ant:classpath>
<ant:pathelement location="${plugin.getDependencyPath('checkstyle:checkstyle')}"/>
<ant:pathelement location="${plugin.getDependencyPath('checkstyle:checkstyle-optional')}"/>
<ant:pathelement location="${plugin.getDependencyPath('antlr:antlr')}"/>
<ant:pathelement location="${plugin.getDependencyPath('regexp:regexp')}"/>
<ant:pathelement location="${plugin.getDependencyPath('commons-beanutils:commons-beanutils-core')}"/>
<ant:path refid="maven.dependency.classpath"/>
<ant:pathelement path="${maven.build.dest}"/>
</ant:classpath>
</ant:taskdef>
</j:if>
</goal>
<!-- ======================================================================== -->
<goal name="checkstyle:report"
description="Run checkstyle on project source code and generate reports"
prereqs="checkstyle:init">
<j:if test="${sourcesPresent == 'true'}">
<util:file var="headerFile" name="${maven.checkstyle.header.file}"/>
<j:if test="${!headerFile.exists()}">
<ant:echo>
=================================================================
= W A R N I N G =
=================================================================
= Your project doesn't contain a header file specified as: =
= ${maven.checkstyle.header.file}
= 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:if test="${!maven.build.dir.exists()}">
<ant:mkdir dir="${maven.build.dir}"/>
</j:if>
<j:set var="maven.checkstyle.header.file" value="${maven.build.dir}/LICENSE_DUMMY.txt" />
<j:file name="${maven.checkstyle.header.file}" />
</j:if>
<attainGoal name="checkstyle:run"/>
<attainGoal name="checkstyle:report-internal"/>
</j:if>
</goal>
<!-- ======================================================================== -->
<goal name="checkstyle:run" description="Run checkstyle on the sources and generate the xml report">
<!-- 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}"/>
<j:set var="localeCountry" value="en"/>
<!-- maven.xdoc.locale.default is only defined in xdoc-plugin >= 1.10 -->
<maven:get var="currentLocale" plugin="maven-xdoc-plugin" property="maven.xdoc.locale.default"/>
<!-- Set localeCountry to maven.xdoc.locale.default, if defined-->
<j:choose>
<j:when test="${!empty(currentLocale)}">
<j:choose>
<j:when test="${currentLocale.length() >= 2}">
<j:set var="localeCountry" value="${currentLocale.substring(0,2)}"/>
</j:when>
<j:otherwise>
<echo>The locale defined in maven.xdoc.locale.default is invalid, using "en" instead.</echo>
</j:otherwise>
</j:choose>
</j:when>
<j:otherwise>
<echo>No locale defined in maven.xdoc.locale.default, using "en".</echo>
</j:otherwise>
</j:choose>
<ant:echo>Using ${checkstyleProperties} for checkstyle ...</ant:echo>
<ant:echo>LocaleCountry : ${localeCountry}</ant:echo>
<ant:checkstyle
configURL="${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}"/>
<property key="checkstyle.suppressions.file"
file="${maven.checkstyle.suppressions.file}"/>
<property key="checkstyle.localeCountry"
value="${localeCountry}"/>
<ant:fileset dir="${pom.build.sourceDirectory}"
includes="${maven.checkstyle.includes}"
excludes="${maven.checkstyle.excludes}">
<!-- FIXME: This is a bad cut and paste -->
<!-- handle source modifications -->
<j:forEach var="sm" items="${pom.build.sourceModifications}">
<ant:available property="classPresent" classname="${sm.className}"/>
<j:if test="${classPresent != 'true'}">
<j:forEach var="exclude" items="${sm.excludes}">
<ant:exclude name="${exclude}"/>
</j:forEach>
<j:forEach var="include" items="${sm.includes}">
<ant:include name="${include}"/>
</j:forEach>
</j:if>
</j:forEach>
</ant:fileset>
<!-- run checkstyle on tests -->
<j:if test="${(unitTestSourcesPresent == 'true') and (context.getVariable('maven.checkstyle.check.tests'))}">
<ant:pathconvert property="testSrcSetString" pathSep="||||"
refid="maven.test.compile.src.set"/>
<util:tokenize var="testDirs" delim="||||">${testSrcSetString}</util:tokenize>
<j:forEach var="testDir" items="${testDirs}">
<ant:fileset dir="${testDir}"
includes="${maven.checkstyle.includes}"
excludes="${maven.checkstyle.excludes}"/>
</j:forEach>
</j:if>
<ant:classpath>
<ant:path refid="maven.dependency.classpath"/>
<ant:pathelement path="${maven.build.dest}"/>
</ant:classpath>
<ant:formatter type="xml"
toFile="${maven.checkstyle.output.xml}"/>
<j:choose>
<j:when test="${maven.checkstyle.usefile}">
<ant:formatter type="plain"
toFile="${maven.checkstyle.output.txt}"/>
</j:when>
<j:otherwise>
<ant:formatter type="plain"/>
</j:otherwise>
</j:choose>
</ant:checkstyle>
</goal>
<!-- ======================================================================== -->
<goal name="checkstyle:report-internal" description="Generate xdocs from checkstyle xml report">
<mkdir dir="${maven.gen.docs}/checkstyle"/>
<!-- Make sure xalan is used for ant's style task -->
${systemScope.setProperty('javax.xml.transform.TransformerFactory','org.apache.xalan.processor.TransformerFactoryImpl')}
<style
in="${maven.checkstyle.output.xml}"
out="${maven.checkstyle.output.summary.xml}"
style="${plugin.resources}/checkstyle-summary.xsl"/>
<style
in="${maven.checkstyle.output.summary.xml}"
out="${maven.gen.docs}/checkstyle/index.xml"
style="${plugin.resources}/checkstyle.xsl"/>
<doc:jsl
input="${maven.checkstyle.output.xml}"
output="checkstyle/all.xml"
stylesheet="${plugin.resources}/checkstyle-all.jsl"
encoding="${maven.docs.outputencoding}"
outputMode="xml"
prettyPrint="true"/>
<!-- Generate filtered pages for each severity level -->
<checkstyle:report-filtered severity="error"/>
<checkstyle:report-filtered severity="warning"/>
<checkstyle:report-filtered severity="info"/>
<tstamp>
<format property="currentYear" pattern="yyyy"/>
</tstamp>
<j:set var="baseurl" value="${pom.url}/checkstyle"/>
<maven:get plugin="maven-multiproject-plugin" property="maven.multiproject.navigation" var="navType" />
<j:if test="${navType == 'aggregate'}">
<maven:get plugin="maven-multiproject-plugin" property="maven.multiproject.aggregateDir" var="aggregateDir" />
<j:set var="baseurl" value="${pom.url}/${aggregateDir}/${pom.artifactId}"/>
</j:if>
<!-- Generate a RSS feed of the checktyle errors -->
<doc:jsl
input="${maven.checkstyle.output.xml}"
output="checkstyle/checkstyle.rss"
stylesheet="${plugin.resources}/checkstyle2rss.jsl"
encoding="${maven.docs.outputencoding}"
outputMode="xml"
prettyPrint="true"/>
<!-- Copy the RSS XML logo -->
<mkdir dir="${maven.docs.dest}/images"/>
<copy todir="${maven.docs.dest}/images" file="${plugin.resources}/images/rss.png"/>
</goal>
<!-- ======================================================================== -->
<goal name="maven-checkstyle-plugin:register" description="Register a Checkstyle report to the site plugin">
<j:if test="${sourcesPresent == 'true'}">
<doc:registerReport
name="Checkstyle"
pluginName="checkstyle"
link="checkstyle/index"
description="Report on coding style conventions."/>
</j:if>
</goal>
<!-- ======================================================================== -->
<goal name="maven-checkstyle-plugin:deregister" description="Deregister a Checkstyle report to the site plugin.">
<j:if test="${sourcesPresent == 'true'}">
<doc:deregisterReport name="Checkstyle"/>
</j:if>
</goal>
<!-- ======================================================================== -->
<!-- Generate a report filtering errors by severity -->
<define:taglib uri="checkstyle">
<define:tag name="report-filtered">
<!-- @severity: severity for which to generate the report -->
<echo>Generating report for severity ${severity}...</echo>
<doc:jsl
input="${maven.checkstyle.output.xml}"
output="checkstyle/${severity}.xml"
stylesheet="${plugin.resources}/checkstyle_severity_filter.jsl"
encoding="${maven.docs.outputencoding}"
outputMode="xml"
prettyPrint="true"/>
</define:tag>
</define:taglib>
</project>