|
- <?xml version="1.0"?>
- <!--
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You 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.
- -->
- <project default="checkstyle" name="CheckAnt" xmlns:ivy="antlib:org.apache.ivy.ant">
-
- <description>
- Check Ants codebase against certain code styleguide rules using
- checkstyle and simian.
-
- Checkstyle uses an abstract syntax tree (AST) for doing checks
- against java sources. It is available at http://checkstyle.sourceforge.net/
- under GPL 2.1 license.
-
- "Simian (Similarity Analyser) identifies duplication in Java, C#, C,
- CPP, COBOL, JSP, HTML source code and even plain text files."
- It is available at http://www.redhillconsulting.com.au/products/simian/
- and is for free use in open source projects.
-
- See external task page and homepages for more information.
- </description>
-
- <import file="build.xml"/>
- <property name="config.dir" location="${etc.dir}/checkstyle"/>
-
- <property name="checkstyle.reportdir" location="${build.dir}/reports/checkstyle"/>
- <property name="checkstyle.raw" location="${checkstyle.reportdir}/raw.xml"/>
- <property name="stylesheet.html" location="${config.dir}/checkstyle-frames.xsl"/>
- <property name="stylesheet.text" location="${config.dir}/checkstyle-text.xsl"/>
- <property name="stylesheet.xdoc" location="${config.dir}/checkstyle-xdoc.xsl"/>
-
- <property name="checkstyle.basedir" location="${java.dir}"/>
-
- <!-- Ant Checkstyle report -->
- <property name="tocheck" value="**/*.java"/>
- <property name="javadoc.scope" value="public"/>
-
- <taskdef resource="simiantask.properties"/>
-
- <!-- Findbugs: Getting Findbugs -->
- <property name="findbugs.download.name"
- value="findbugs-1.3.5"
- description="Name of the download file without suffix. Also the internal root directory of the ZIP."/>
- <property name="findbugs.download.file"
- value="${findbugs.download.name}.zip"
- description="The filename of the ZIP."/>
- <property name="findbugs.download.url"
- value="http://garr.dl.sourceforge.net/sourceforge/findbugs/${findbugs.download.file}"
- description="The download adress at a mirror of Sourceforge."/>
- <property name="findbugs.download.to"
- value=".downloads"
- description="Where to store the download and 'install' Findbugs."/>
- <available
- property="findbugs.home"
- value="${findbugs.download.to}/${findbugs.download.name}"
- file="${findbugs.download.to}/${findbugs.download.name}/lib/findbugs.jar"
- description="Check if Findbugs is already installed."
- />
-
- <!-- Findbugs: Running Findbugs -->
- <property name="findbugs.reportdir"
- location="${build.dir}/reports/findbugs"
- description="Where to store Findbugs results"/>
- <property name="findbugs.raw"
- value="raw.xml"
- description="Findbugs Output xml-file"/>
- <property name="findbugs.xsl"
- value="fancy.xsl"
- description="Which XSL to use for generating Output: default, fancy, plain, summary"/>
- <property name="findbugs.jvmargs"
- value="-Xms128m -Xmx512m"
- description="JVMArgs for invoking Findbugs"/>
-
- <!-- RAT Release Auditing Tool -->
- <property name="rat.report.dir"
- value="${build.dir}/reports/rat"
- description="Where to store the RAT reports"/>
- <property name="rat.report.file"
- value="${rat.report.dir}/report.html"
- description="RAT-Report file"/>
- <property name="rat.version"
- value="0.6"
- description="Which Version of RAT to use"/>
-
-
-
- <target name="init-ivy">
- <property name="ivy.version" value="2.0.0-beta1"/>
- <property name="ivy.jar.url" value="http://repo1.maven.org/maven2/org/apache/ivy/ivy/${ivy.version}/ivy-${ivy.version}.jar"/>
- <property name="ivy.jar.dir" value="${build.dir}/ivy"/>
- <property name="ivy.jar.file" value="${ivy.jar.dir}/ivy.jar"/>
- <mkdir dir="${ivy.jar.dir}"/>
- <get src="${ivy.jar.url}" dest="${ivy.jar.file}" usetimestamp="true"/>
- <path id="ivy.lib.path">
- <fileset dir="${ivy.jar.dir}" includes="*.jar"/>
- </path>
- <taskdef resource="org/apache/ivy/ant/antlib.xml" uri="antlib:org.apache.ivy.ant" classpathref="ivy.lib.path"/>
- </target>
-
- <target name="checkstyle" description="--> checks Ant codebase according to ${config.dir}/checkstyle-config" depends="init-ivy">
- <ivy:cachepath organisation="checkstyle" module="checkstyle" revision="4.3"
- inline="true" conf="default" pathid="checkstyle.classpath" transitive="true"/>
- <taskdef resource="checkstyletask.properties" classpathref="checkstyle.classpath" />
- <mkdir dir="${checkstyle.reportdir}"/>
- <checkstyle config="${config.dir}/checkstyle-config" failOnViolation="false">
- <formatter type="xml" toFile="${checkstyle.raw}"/>
- <fileset dir="${java.dir}">
- <include name="${tocheck}"/>
- <exclude name="**/bzip2/*.java"/>
- <exclude name="**/CVSPass.java"/>
- </fileset>
- </checkstyle>
- </target>
-
- <target name="htmlreport" description="--> generates a html checkstyle report" depends="init-ivy">
- <mkdir dir="${checkstyle.reportdir}"/>
- <xslt in="${checkstyle.raw}" style="${stylesheet.html}"
- out="${checkstyle.reportdir}/html/output.txt">
- <param name="basedir" expression="${checkstyle.basedir}"/>
- <param name="output.dir" expression="${checkstyle.reportdir}"/>
- </xslt>
- </target>
-
- <target name="textreport" description="--> generates a text checkstyle report">
- <xslt in="${checkstyle.raw}" style="${stylesheet.text}"
- out="${checkstyle.reportdir}/report.txt">
- </xslt>
- </target>
-
- <target name="textreport-display" depends="textreport" description="--> generates a text checkstyle report and displays it immediately">
- <loadfile property="report" srcfile="${checkstyle.reportdir}/report.txt"/>
- <echo>${report}</echo>
- </target>
-
- <target name="xdocreport" description="--> generates a xdoc checkstyle report">
- <xslt in="${checkstyle.raw}" style="${stylesheet.xdoc}"
- out="${checkstyle.reportdir}/xdocs/index.xml">
- <param name="basedir" expression="${checkstyle.basedir}"/>
- </xslt>
- </target>
-
- <target name="dumphtml" depends="checkstyle, htmlreport" description="--> runs the checkstyle and generates a html report"/>
- <target name="dumptext" depends="checkstyle, textreport" description="--> runs the checkstyle and displays result as text">
- <concat>
- <filelist dir="${checkstyle.reportdir}" files="report.txt"/>
- </concat>
- </target>
-
- <target name="simiancheck" description="--> runs the check for duplicates">
- <simian>
- <fileset dir="${java.dir}" />
- </simian>
- </target>
-
- <target name="fixTS" description="--> fix checkstyle errors 'Line has trailing spaces'">
- <fail message="Define path to java file 'path'">
- <condition><not><isset property="path"/></not></condition>
- </fail>
- <replaceregexp match="\s+$" replace="" flags="g" byline="true">
- <fileset dir="src/main" includes="${path}"/>
- </replaceregexp>
- </target>
-
- <target name="fixTab" description="--> fix checkstyle errors 'Line contains TAB sign'">
- <fail message="Define path to java file 'path'">
- <condition><not><isset property="path"/></not></condition>
- </fail>
- <fixcrlf srcdir="src/main" includes="${path}" javafiles="yes" tab="remove" tablength="4"/>
- </target>
-
- <target name="init-findbugs" unless="findbugs.home">
- <mkdir dir="${findbugs.download.to}"/>
- <get src="${findbugs.download.url}" dest="${findbugs.download.to}/${findbugs.download.file}"/>
- <unzip src="${findbugs.download.to}/${findbugs.download.file}" dest="${findbugs.download.to}"/>
- <property name="findbugs.home" location="${findbugs.download.to}/${findbugs.download.name}"/>
- <mkdir dir="${findbugs.home}/plugin"/>
- </target>
-
- <target name="findbugs" description="--> checks Ant codebase with Findbugs" depends="init-findbugs" xmlns:fb="http://findbugs.sourceforge.net/">
- <path id="findbugs.real.classpath">
- <fileset dir="${findbugs.home}/lib" includes="*.jar"/>
- </path>
-
- <!-- Load the Findbugs AntTasks -->
- <taskdef uri="http://findbugs.sourceforge.net/" resource="edu/umd/cs/findbugs/anttask/tasks.properties" classpathref="findbugs.real.classpath" />
-
- <!-- Start Findbugs -->
- <mkdir dir="${findbugs.reportdir}"/>
- <fb:findbugs home="${findbugs.home}"
- classpathref="findbugs.real.classpath"
- output="xml:withMessages"
- outputFile="${findbugs.reportdir}/${findbugs.raw}"
- jvmargs="${findbugs.jvmargs}"
- projectName="${Name} ${project.version}">
- <class location="${build.classes}" />
- <sourcePath path="${java.dir}" />
- </fb:findbugs>
-
- <!-- Generate (human) readable output -->
- <xslt basedir="${findbugs.reportdir}" includes="${findbugs.raw}" destdir="${findbugs.reportdir}">
- <style>
- <javaresource name="${findbugs.xsl}" classpathref="findbugs.real.classpath"/>
- </style>
- </xslt>
- </target>
-
-
- <target name="rat" description="--> Runs the ReleaseAuditingTool" depends="init-ivy">
- <ivy:cachepath organisation="org.apache.rat" module="apache-rat-tasks" revision="${rat.version}"
- inline="true" conf="default" pathid="rat.classpath" transitive="true"/>
- <typedef resource="org/apache/rat/anttasks/antlib.xml"
- uri="antlib:org.apache.rat.anttasks"
- classpathref="rat.classpath"/>
- <mkdir dir="${rat.report.dir}"/>
- <rat:report xmlns:rat="antlib:org.apache.rat.anttasks" reportfile="${build.dir}/reports/rat/report.txt">
- <fileset dir="${java.dir}">
- <exclude name="org/apache/tools/ant/defaultManifest.mf"/>
- <exclude name="org/apache/tools/ant/version.txt"/>
- </fileset>
- </rat:report>
- </target>
-
- </project>
|