分享
 
 
 

使用 ant 让你愉快编程(4)

王朝java/jsp·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

使用 ant 让你愉快编程(4)

摘要: checkstyle_checks.xml, java.header

现在已经有了目录结构, 有了 build_common.xml, common.xml, usage.txt,

build.xml, build.properties 等文件, 已经可以完成大部分任务了.

现在介绍如何进行辅助任务, 比如代码检查.

代码检查在 build_common.xml 中已经有这个任务了, 但是还需要两个配置

文件配合, 还需要到这里下载 checkstyle 的 jar 包并将

它放到 work/common/lib/ 目录下.

这两个配置文件是: work/common/template/build/ 目录下的

checkstyle_checks.xml 文件和 java.header 文件

checkstyle_checks.xml 文件说明了对 java 文件应该如何进行检查,

java.header 文件指出每个 java 文件的头部构造.

. checkstyle_checks.xml 文件如下, 是借用的Johan

的源文件, 作了一点儿修改. 其中每项配置的具体说明都有给出链接, 不明白的

话可以仔细看看.

<?xml version="1.0" encoding="iso-8859-1"?>

<!--

Copyright 2004 Johan K?ng?d, http://dev.kanngard.net

This program is free software; you can redistribute it and/or modify

it under the terms of the GNU General Public License as published by

the Free Software Foundation; either version 2 of the License, or

(at your option) any later version.

This program is distributed in the hope that it will be useful,

but WITHOUT ANY WARRANTY; without even the implied warranty of

MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the

GNU General Public License for more details.

You should have received a copy of the GNU General Public License

along with this program; if not, write to the Free Software

Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

-->

<!DOCTYPE module PUBLIC

"-//Puppy Crawl//DTD Check Configuration 1.2//EN"

"http://www.puppycrawl.com/dtds/configuration_1_2.dtd">

<!--

Based on the Checkstyle configuration file sun_checks.xml with some minor

modifications..

Checkstyle is very configurable. Be sure to read the documentation at

http://checkstyle.sf.net

-->

<module name="Checker">

<!-- Checks that a package.html file exists for each package. -->

<!-- See http://checkstyle.sf.net/config_javadoc.html#PackageHtml -->

<module name="PackageHtml"/>

<!-- Checks whether files end with a new line. -->

<!-- See http://checkstyle.sf.net/config_misc.html#NewlineAtEndOfFile -->

<module name="NewlineAtEndOfFile"/>

<!-- Checks that property files contain the same keys. -->

<!-- See http://checkstyle.sf.net/config_misc.html#Translation -->

<module name="Translation"/>

<module name="TreeWalker">

<!-- Checks for Javadoc comments. -->

<!-- See http://checkstyle.sf.net/config_javadoc.html -->

<module name="JavadocMethod"/>

<module name="JavadocType"/>

<module name="JavadocVariable"/>

<module name="JavadocStyle"/>

<!-- Checks for Naming Conventions. -->

<!-- See http://checkstyle.sf.net/config_naming.html -->

<module name="ConstantName"/>

<module name="LocalFinalVariableName"/>

<module name="LocalVariableName"/>

<module name="MemberName">

<property name="format" value="^[_A-Z][a-zA-Z0-9]*$"/>

</module>

<module name="MethodName"/>

<module name="PackageName"/>

<module name="ParameterName"/>

<module name="StaticVariableName"/>

<module name="TypeName"/>

<!-- Checks for Headers -->

<!-- See http://checkstyle.sf.net/config_header.html -->

<module name="Header">

<!-- The follow property value demonstrates the ability -->

<!-- to have access to ANT properties. In this case it uses -->

<!-- the ${basedir} property to allow Checkstyle to be run -->

<!-- from any directory within a project. See property -->

<!-- expansion, -->

<!-- http://checkstyle.sf.net/config.html#properties -->

<property

name="headerFile"

value="${basedir}/build/java.header"/>

<property name="ignoreLines" value="3,5,8"/>

</module>

<!-- Following interprets the header file as regular expressions. -->

<!-- <module name="RegexpHeader"/> -->

<!-- Checks for imports -->

<!-- See http://checkstyle.sf.net/config_import.html -->

<module name="AvoidStarImport"/>

<module name="IllegalImport"/> <!-- defaults to sun.* packages -->

<module name="RedundantImport"/>

<module name="UnusedImports"/>

<!-- Checks for Size Violations. -->

<!-- See http://checkstyle.sf.net/config_sizes.html -->

<module name="FileLength"/>

<module name="LineLength"/>

<module name="MethodLength"/>

<module name="ParameterNumber"/>

<!-- Checks for whitespace -->

<!-- See http://checkstyle.sf.net/config_whitespace.html -->

<module name="EmptyForIteratorPad"/>

<module name="MethodParamPad"/>

<module name="NoWhitespaceAfter"/>

<module name="NoWhitespaceBefore"/>

<module name="OperatorWrap"/>

<module name="ParenPad"/>

<module name="TypecastParenPad"/>

<!-- <module name="TabCharacter"/>-->

<module name="WhitespaceAfter"/>

<module name="WhitespaceAround"/>

<!-- Modifier Checks -->

<!-- See http://checkstyle.sf.net/config_modifiers.html -->

<module name="ModifierOrder"/>

<module name="RedundantModifier"/>

<!-- Checks for blocks. You know, those {}'s -->

<!-- See http://checkstyle.sf.net/config_blocks.html -->

<module name="AvoidNestedBlocks"/>

<module name="EmptyBlock"/>

<module name="LeftCurly"/>

<module name="NeedBraces"/>

<module name="RightCurly"/>

<!-- Checks for common coding problems -->

<!-- See http://checkstyle.sf.net/config_coding.html -->

<module name="AvoidInlineConditionals"/>

<module name="DoubleCheckedLocking"/> <!-- MY FAVOURITE -->

<module name="EmptyStatement"/>

<module name="EqualsHashCode"/>

<module name="HiddenField">

<property name="tokens" value="VARIABLE_DEF"/>

</module>

<module name="IllegalInstantiation"/>

<module name="InnerAssignment"/>

<module name="MagicNumber"/>

<module name="MissingSwitchDefault"/>

<module name="RedundantThrows"/>

<module name="SimplifyBooleanExpression"/>

<module name="SimplifyBooleanReturn"/>

<!-- Checks for class design -->

<!-- See http://checkstyle.sf.net/config_design.html -->

<!-- <module name="DesignForExtension"/> -->

<module name="FinalClass"/>

<module name="HideUtilityClassConstructor"/>

<module name="InterfaceIsType"/>

<module name="VisibilityModifier"/>

<!-- Miscellaneous other checks. -->

<!-- See http://checkstyle.sf.net/config_misc.html -->

<module name="ArrayTypeStyle"/>

<module name="FinalParameters"/>

<module name="GenericIllegalRegexp">

<property name="format" value="\s+$"/>

<property name="message" value="Line has trailing spaces."/>

</module>

<module name="TodoComment"/>

<module name="UpperEll"/>

</module>

</module>

. 以下是我的 java 文件头部构造, 当然每个团队可以有自己的约定.

因为第3,5,8行是随文件的改变而改变的, 因此我忽略了对他们的检查,

这一点可以从上面的 checkstyle_checks.xml 文件中看出来.

/*

* -----------------------------------------------------------

* file name : _filename_

* authors : camry(camry@gmail.com)

* created : _datetime_

* copyright : (c) 2003 Vitular Inc. All Rights Reserved.

*

* modifications:

*

* -----------------------------------------------------------

*/

有的朋友可能觉得每次都在文件前写这么一个头岂不是很麻烦, 但是对于我来说,

这一点非常容易就可以让 vim 做到了. 当我用 vim 新建一个 java 文件时,

它会自动加入这个头部说明, 并用适当的文件名和时间替换 _filename_ 和

_datetime_ 这两个参数. 如何做到这一点将来会做说明.

使用这个 checkstyle 时会有这么一个麻烦的地方: 它不允许在行尾有多余的

空格. 对于程序员来说, 谁在乎这么几个空格呢, 可是程序是非常严谨的:)

使用vim的朋友可以在这里发现如何轻松消除行尾空格.

下一篇[url=http://blog.csdn.net/camry_camry/archive/2004/10/21/145818.aspx]上一篇

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有