Você está na página 1de 11

Tutorial: Checkstyle for Eclipse

Pre-requisite: Eclipse 3.x

Steps to Setup and use Checkstyle for Eclipse


1. Open the Eclipse and Navigate to Help | Software Updates | Find and Install

2. Select the 2nd radio button - Search for new features to install

3. Click on New Remote Site -- add Checkstyle in Name field and point it to
http://eclipse-cs.sourceforge.net/update

4. Follow the wizard and hit next after checking the box.

Click on the Finish button, it will start downloading the chackstyle jar file.
After download, Eclipse performs verification on the downloaded Jar file. It takes few
minutes to complete. Displays the verification details and asks for Install/Cancel.
Click on the Install button, to install the chackstyle plugin.

5. Create a new Project OR use any existing project


6. Build the project
7. In the Package explorer right-click on <project-name> and select Properties |
Checkstyle | Check code with Checkstyle
Note: This will run the Checkstyle for this project with the default ruleset [Sun
Checks (Eclipse) - (Global)]
8. Navigate to Window | Show view | Other In the dialog window, Select
Checkstyle | Checkstyle violations
9. In the Checkstyle violations view, click on the chart icon in the upper right corner.
This will open the pie chart view of the violations.

Using the Custom Checkstyle configuration file:


Pre-requisite: Copy the MyCheckstyle.xml to your local machine in the path:
%eclipse_home%\plugins\com.atlassw.tools.eclipse.checkstyle_4.3.2\
1. Navigate to Window | Preferences
Click on New

2. Provide any appropriate name in the Name field and Select External
Configuration File as Type from the drop down list.
Click on Browse and Select the appropriate configuration XML file. Click on
Open to return back to previous window

3. One new entry is created for the External Configuration File. Click Ok on the
Preferences window. It will save the settings and close the window.

4. In the Package explorer right-click on <project-name> and select Properties. It


will open the Properties dialog window.

5. On the Properties window (above), select the appropriate name (name provided in
step 3) from the drop-down list and click on Ok.

6. Click on Yes to Rebuild the project with the selected Checkstlye configuration
and violations will be shown in the View.

Modifying the default Rule Set configuration


Note: This is applicable to the particular instance of Eclipse

1. Navigate to Window | Preferences | Checkstyle and Click on New


2. Select Internal Configuration, enter a name and description. Click Import and
navigate to ECLIPSE_HOME/plugins/com.atlassw.tools.eclipse.checkstyle_x.x.x
and select any of the existing rules XML file (for e.g. MyCheckstyle.xml). This will
import all Sun Eclipse rules for the new custom ruleset. Also note that Checkstyle
will create a new custom ruleset xml file under
WORKSPACE/.metadata/.plugins/com.atlassw.tools.eclipse.checkstyle/internal_
config__xxxxxxxxxxx.xml. Click OK.
3. Double click the new ruleset. It opens a dialog window. Do the required
modification and Apply.
4. Click OK. It will rebuild the project and violations will be shown in the View.

Você também pode gostar