Vous êtes sur la page 1sur 2

QB-SDP QCCommon - Checkstyle

QB-SDP QCCommon

QCCommon Wiki

Page 1 of 2

Checkstyle

QB-SDP QCCommon

Checkstyle
Checkstyle is a development tool to help programmers write Java code that adheres to a coding standards and makes them ideal for projects. It provides various checks that can be run on
the code and most of the checks are configurable.
Set up checkstyle with the help of Eclipse plugin Download the checkstyle plugin from http://eclipse-cs.sourceforge.net/downloads.html. Then go to Eclipse --> window-->preferences --> CheckStyle & add qcc
-critical-checks.xml, qcc-checkstyle-checks.xml. Whichever check you want to do, make that file as default. Then open the java file which ever you want to
check. Right click and select "CheckStyle" then select "Check Code with CheckStyle". It will highlight the code to be corrected.

Setting Up
Download the Checkstyle source file which contains the ant task from http://sourceforge.net/projects/checkstyle/files/checkstyle/ and add it to your
current project.

Checks
Checkstyle supports a variety of checks. These checks are specified in an XML file called the Configuration File. The entire list of checks can be found at http://checkstyle.sourceforge.net.
Some checks were selected from the entire list of checkstyle checks. All the style related checks were discarded to begin with. These checks were further divided on basis of their
priorities into high, medium and low priority

Checks.xlsx

Usage
Checkstyle is highly configurable and can be made to support most of the coding standards.
It can be used as
i) An Ant Task or
ii)CommandLine Tool

Command line usage


java D<property>=<value> \ com.puppycrawl.tools.checkstyle.Main \ c <configurationFile> [n <packageNameFile>] \ [f <format>] [p <propertiesFile>] [o <file>] \ [r <dir>] file...
Command line options are:
* n (packageNamesFile) specify a package names file to use.
* f (format) specify the output format. Options are "plain" for the DefaultLogger and "xml" for the XMLLogger. Defaults to "plain".
* p (propertiesFile) specify a properties file to use.
* o (O/P file) specify the file to output to.
* r (root dir) specify the directory to traverse for Java source files.

Ant Task
We need to first have a Configuration XML file which will have all the checks that is to be run on the code.
The build.xml is provided along with the Checkstyle Distribution.
* The qccommon build.xml is modified to call checkstyles build.xml. The following lines of code are added
<target name="Checkstyle" >
<ant antfile="${checkstyle.build}/build.xml" />
</target>
where checkstyle.build contains checkstyles path and is defined in the cuid.qoacommon.build.properties file.
eg : checkstyle.build = C:/workspace/qoacommon/checkstyle5/checkstyle5.5
* Checkstyles build.xml may have multiple ant tasks each corresponding to different Configuration XML files.
*The critical checks are specified under
*

qcccriticalchecks.xml, they are meant to fail the build on its failure. These checks are executed on running QCCommon build.

qcccheckstylechecks.xml contains all the checks, and they can be run optionally from time to time from checkstyles build.xml

* Both of these xml files should be placed in the folder where the checkstyles build.xml resides. Replace the build.xml in the checkstyle folder with this

build.xml file.

File Set
* The fileset tag specifies all the files on which the checks are to be performed upon. It is present in checkstyles build.xml file. We have different set of filesets for the different tasks .
* When a specific file is changed instead of running the checks on all the files in the specified directory, we can mention only the changed file.
eg :
<fileset dir="../../pb/modules/autoassign/src"
includes="**/StoredProcInvoker.java"/>
Here dir corresponds to the directory and includes specifies the files to be included. Hence in the above example the checks are run only on StoredProcInvoker.

Configuration XML File


Each check is specified in a module tag. Some of the checks have a property sub tag, the value of these can be varied upon to meet the requirements of you code.
eg :

<module name="StrictDuplicateCode">
<property name="min"
value="12"/>
<property name="fileExtensions" value=""/>
</module>

Output
* Create a folder under your project where the output xmls will be stored.
eg: metric/checkstyle
* Define checkstyle.report in the cuid.qoacommon.build.properties file with the above folder path.

http://collaboration.ad.qintra.com/bu/it/PPS/QMS/QBPS/QBSDP%20QCCommon/QCCom... 4/2/2015

QB-SDP QCCommon - Checkstyle

Page 2 of 2

eg: checkstyle.report=C:/workspace/qoacommon/metric/checkstyle
* The output generated is in the form of an xml , with related data such as the files, the errors and the corresponding line nos where it has occured.
* The various output xmls can be identified by its timestamp that is set as its default name.
* The xml is formatted by using an xsl

ErrorCount.xsl which is added to the above folder. This xsl helps format the xml output when opened in a web browser, it gives the Filename

and the count of errors in that file along with the error names in a tabular format.
* Each output xml has a reference to ErrorCount.xsl by default, and this can be changed by modifying the href attribute of the xmlstylesheet tag.
eg: <? xmlstylesheet type="text/xsl" href="checkstyleauthor.xsl"?>
* Other XSL files for formatting are

checkstyleauthor.xsl ,

checkstyle.xsl .

Developer Dashboard

Request (GET:http://collaboration.ad.qintra.com:80/bu/it/PPS/QMS/QBPS/QBSDP%20QCCommon/QCCommon%20Wiki/Checkstyle.aspx) (276.25 ms)


Web Server
BeginRequestHandler (0.07 ms)
Execution Time
276.49 ms
PostAuthenticateRequestHandler (0.09 ms)
Current User
i:0#.w|ctl\\aa83696
PostResolveRequestCacheHandler (52.94 ms)
Page Checkout Level
Published
GetWebPartPageContent (47.28 ms)
GetFileAndMetaInfo (46.85 ms)
Current SharePoint Operations 2
EnsureListItemsData (102.07 ms)
Log Correlation Id
ee8821d7-542b-43db-ab93-33f4f5c54dfc
PortalSiteMapDataSource: Determining Starting Node (0.03 ms)
Asserts and Critical Events
PortalSiteMapDataSource: Determining Starting Node#1 (0.02 ms)
Wiki Edit OnInit (0.11 ms)
Database Queries
Wiki Edit OnInitComplete (0.32 ms)
proc_FetchDocForHttpGet
46.14 ms
Add WebParts (0.11 ms)
Wiki Edit OnLoad (1.56 ms)
SELECT t1.[TimeCreated]
96.27 ms
ToolBarMenuButton.CreateChildControls for SiteActions (0.33 ms)
SELECT TOP(@NUMROWS)
8.88 ms
ToolBarMenuButton.CreateChildControls for PersonalActions (0.14 ms)
proc_GetTpWebMetaDataAndListMetaData 13.46 ms
SearchBoxEx.OnLoad (0.70 ms)
proc_SecRefreshToken
6.29 ms
SearchCommon::GetSearchDropDownDisplayGroupName (0.09 ms)
proc_GetTpWebMetaDataAndListMetaData 8.49 ms
SearchCommon::GetSiteCollectionLanguage (0.02 ms)
SearchBoxEx.HandleContextualScoping (0.10 ms)
SELECT t1.[TimeCreated]
7.19 ms
SearchBoxEx.GetSpWeb (0.00 ms)
Service Calls
EnsureListItemsData#1 (10.53 ms)
IsCheckedOutToSystem (0.06 ms)
SPRequest Allocations
SPPageStateControl:OnLoad (0.22 ms)
SPWeb: http://collaboration.ad.qintra.com/bu/it/PPS/QMS/QBPS/QBSDP QCCommon/QCCommon Wiki/Chec
Activate web part connections (0.04 ms)
Wiki Edit OnPreRender (0.33 ms)
SPWeb: http://collaboration.ad.qintra.com/bu/it/PPS/QMS/QBPS/QBSDP QCCommon/QCCommon Wiki/Chec
CachedObjectFactory: Caching ListItem at: /bu/it/PPS/QMS/QBPS/QBSDP QCCommon/QCCommon Wiki/Checkstyle.aspx (56.21 ms)
WebPart Events Offsets
EnsureListItemsData (14.16 ms)
SPPageStateControl:OnPreRender (0.22 ms)
SPWebPartManager OnLoad
+0.00 ms
Wiki Edit OnPreRenderComplete (0.15 ms)
SPWebPartManager OnPreRender +0.01 ms
Wiki Edit Render (11.51 ms)
Render Ribbon. (2.69 ms)

http://collaboration.ad.qintra.com/bu/it/PPS/QMS/QBPS/QBSDP%20QCCommon/QCCom... 4/2/2015

Vous aimerez peut-être aussi