- CheckStyle is a tool to help programmers to write JAVA coding standard.
- Download and unzip checkstyle-5.3 into a convenient directory.
- It is a program to inspect your JAVA source code and list/point out errors that deviate from a defined set of JAVA coding standard.
- By default it supports the Sun JAVA Code Conventions (sun_checks.xml), and also support any customize coding standard.
- It can be invoked with an ANT task, a command line program and integrated into IDE (Eclipse, IntelliJ, NetBeans) and other tools (TextPad).
- Run CheckStyle - command line program with configuration file sun_checks.xml
java -jar "C:\Program Files\checkstyle-5.3\checkstyle-5.3-all.jar" \ -c "C:\Program Files\checkstyle-5.3\sun_checks.xml" JavaFileName.java - Configuring CheckStyle - Eclipse
- In Eclipse go to Help->Install New Software
- Enter Work With : Eclipse CheckStyle - http://eclipse-cs.sourceforge.net/update, then check CheckStyle checkbox, then Next button and finally accept terms and press the Finish button. Restart Eclipse.
- Right click the project Properties->select Checkstyle.
- Check CheckStyle active for this project checkbox. Then press OK button.
- After, some warnings from Checkstyle point/list to the code locations where your code not followed the Sun Checks configuration.
- Configuring CheckStyle - TextPad with configuration file sun_checks.xml
- In TextPad, click on the Configure menu and then Preferences, the Preferences dialog window appears.
- Click on the Tools node of the left tree, You will see a Tools list box and an Add drop-down menu.
- Click on the Add button and then Program. The Select a file dialog appears. Change the "Files of type:" setting to All Programs (*.*).
- Browse to where you installed CheckStyle, select the checkstyle-5.3-all.jar file and Press the Apply button. CheckStyle should now appear as a choice in the Tools menu.
- Expand the Tools menu and click on the CheckStyle tool.
Change the Command line to: java
Change the Parameters line to:
-jar "C:\Program Files\checkstyle-5.3\checkstyle-5.3-all.jar" \ -c "C:\Program Files\checkstyle-5.3\sun_checks.xml" $FileName
Check the Capture output checkbox.
Set the Regular expression to match output to:
^\(\(\(.[^:]\)\|\([A-Za-z]:\)\)[^:]+\):\([0-9]+\):
Set the Registers:File: 1, Line: 4, Column: (blank)
Press the OK button. - Run a sample commented/non-commented HelloWorld.java java program to verify it works correctly.
/**
* The HelloWorld class for testing CheckStyle + TextPad.
*
* @author Daynight
* @version 1.0 03/04/11
*/
public class HelloWorld {
/**
* The main method for the application.
*
* @param args Not used.
*/
public static void main(String[] args) {
System.out.println("Hello, world!");
}
} - To test the CheckStyle configuration: From the Tools menu->External Tools->choose CheckStyle
No comments:
Post a Comment