提交 cf1a9a23 编写于 作者: K ksrini

7110974: (javac) add coding conventions and style checkers for langtools

Reviewed-by: jjg
上级 bf0d054e
......@@ -196,3 +196,7 @@ import.jdk.stub.files = \
# An empty value means all tests
# Override as desired to run a specific set of tests
jtreg.tests =
# Check style configuration
# overridable name and version
checkstyle.name.version = checkstyle-5.4
......@@ -131,8 +131,10 @@
<property name="dist.bin.dir" location="${dist.dir}/bin"/>
<property name="dist.coverage.dir" location="${dist.dir}/coverage"/>
<property name="dist.findbugs.dir" location="${dist.dir}/findbugs"/>
<property name="dist.checkstyle.dir" location="${dist.dir}/checkstyle"/>
<property name="dist.lib.dir" location="${dist.dir}/lib"/>
<property name="make.dir" location="make"/>
<property name="make.conf.dir" location="${make.dir}/conf"/>
<property name="make.tools.dir" location="${make.dir}/tools"/>
<property name="src.dir" location="src"/>
<property name="src.bin.dir" location="${src.dir}/share/bin"/>
......@@ -263,6 +265,41 @@
<jtreg-tool name="all" tests="${jtreg.tests}"/>
</target>
<target name="checkstyle" depends="-def-checkstyle"
description="Generates reports for code convention violations.">
<mkdir dir="${dist.checkstyle.dir}"/>
<checkstyle config="${make.conf.dir}/checkstyle-langtools.xml"
failureProperty="checkstyle.failure"
failOnViolation="false">
<formatter type="xml" tofile="${dist.checkstyle.dir}/checkstyle_report.xml"/>
<fileset dir="src" includes="**/*.java, **/*.properties"/>
</checkstyle>
<!-- transform the output to a simple html -->
<xslt in="${dist.checkstyle.dir}/checkstyle_report.xml"
out="${dist.checkstyle.dir}/checkstyle_report.html"
style="${checkstyle.home}/contrib/checkstyle-simple.xsl"/>
<!-- transform the output to a very simple emacs friendly text file -->
<xslt in="${dist.checkstyle.dir}/checkstyle_report.xml"
out="${dist.checkstyle.dir}/checkstyle_report.tmp"
style="${make.conf.dir}/checkstyle-emacs.xsl"/>
<!-- beautify remove extra lines -->
<move file="${dist.checkstyle.dir}/checkstyle_report.tmp"
toFile="${dist.checkstyle.dir}/checkstyle_report.emacs.txt">
<filterchain>
<ignoreblank/>
<replaceregex byline="true" pattern="^File:" replace="${line.separator}File:"/>
</filterchain>
</move>
</target>
<!-- target can be invoked from an ide, the output of which can be used
to access and fix the errors directly.
-->
<target name="checkstyle-ide" depends="checkstyle">
<concat>
<fileset file="${dist.checkstyle.dir}/checkstyle_report.emacs.txt"/>
</concat>
</target>
<target name="findbugs" depends="-def-findbugs,build-all-tools">
<property name="findbugs.reportLevel" value="medium"/>
<mkdir dir="${dist.findbugs.dir}"/>
......@@ -406,6 +443,7 @@
<echo level="info">target.java.home = ${target.java.home}</echo>
<echo level="info">jtreg.home = ${jtreg.home}</echo>
<echo level="info">findbugs.home = ${findbugs.home}</echo>
<echo level="info">checkstyle.home = ${checkstyle.home}</echo>
</target>
<target name="post-sanity" depends="-def-jtreg,sanity,build"
......@@ -690,6 +728,10 @@
<check name="findbugs" property="findbugs.home" marker="lib/findbugs.jar"/>
</target>
<target name="-check-checkstyle.home" depends="-def-check">
<check name="checkstyle" property="checkstyle.home" marker="${checkstyle.name.version}.jar"/>
</target>
<target name="-check-jtreg.home" depends="-def-check">
<check name="jtreg" property="jtreg.home" marker="lib/jtreg.jar"/>
</target>
......@@ -989,6 +1031,16 @@
<taskdef classpathref="cobertura.classpath" resource="tasks.properties"/>
</target>
<target name="-def-checkstyle" unless="checkstyle.defined"
depends="-check-checkstyle.home">
<taskdef resource="checkstyletask.properties">
<classpath>
<pathelement location="${checkstyle.home}/${checkstyle.name.version}-all.jar"/>
</classpath>
</taskdef>
<property name="checkstyle.defined" value="true"/>
</target>
<target name="-def-findbugs" unless="findbugs.defined"
depends="-check-findbugs.home,-check-target.java.home">
<taskdef name="findbugs" classname="edu.umd.cs.findbugs.anttask.FindBugsTask">
......
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" omit-xml-declaration="yes"/>
<xsl:template match="/">
Coding Style Check Results
--------------------------
Total files checked: <xsl:number level="any" value="count(descendant::file)"/>
Files with errors: <xsl:number level="any" value="count(descendant::file[error])"/>
Total errors: <xsl:number level="any" value="count(descendant::error)"/>
Errors per file: <xsl:number level="any" value="count(descendant::error) div count(descendant::file)"/>
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="file[error]">
<xsl:apply-templates select="error"/>
</xsl:template>
<xsl:template match="error">
<xsl:value-of select="../@name"/>:<xsl:value-of select="@line"/><xsl:text>: </xsl:text><xsl:value-of select="@message"/><xsl:text>
</xsl:text>
</xsl:template>
</xsl:stylesheet>
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
"-//Puppy Crawl//DTD Check Configuration 1.3//EN"
"http://www.puppycrawl.com/dtds/configuration_1_3.dtd">
<!--
Checks for initial langtools code conventions, we are starting with
imports and import orders and this will grow to encompass other
violations over time.
-->
<module name="Checker">
<!-- Checks for whitespace. -->
<module name="FileTabCharacter">
<property name="fileExtensions" value=".java"/>
</module>
<!-- Miscellaneous other checks. -->
<module name="RegexpSingleline">
<property name="format" value="\s+$"/>
<property name="minimum" value="0"/>
<property name="maximum" value="0"/>
<property name="message" value="Line has trailing spaces."/>
<property name="fileExtensions" value=".java .html"/>
</module>
<module name="TreeWalker">
<!-- Checks for imports -->
<!--
<module name="AvoidStarImport"/>
<module name="IllegalImport"/>
-->
<module name="GenericWhitespace"/>
<module name="RedundantImport"/>
<module name="UnusedImports"/>
<module name="ImportOrder">
<property name="groups" value="java, javax, org, com"/>
<property name="ordered" value="true"/>
<property name="separated" value="true"/>
</module>
<module name="EmptyForInitializerPad">
<property name="option" value="space"/>
</module>
<module name="WhitespaceAfter"/>
</module>
</module>
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册