Skip to main content
Jump to: navigation, search

Difference between revisions of "MoDisco/CodingConventions"

(Add details about checkstyle)
Line 13: Line 13:
 
=== Checkstyle Usage  ===
 
=== Checkstyle Usage  ===
  
For code style verification, a ''checkstyle'' configuration file is directly available from the MoDisco SVN:
+
For MoDisco internal developments, the ''org.eclipse.gmt.modisco.dev.core'' project defines a MoDisco.checkstyle file.
 +
This file defines coding rules. It was initiated from the "sun conventions for Eclipse" checkstyle file. Some constraining rules have been disabled.
  
*https://dev.eclipse.org/svnroot/modeling/org.eclipse.gmt.modisco/plugins/trunk/org.eclipse.gmt.modisco.dev.core/checkstyle/MoDisco.checkstyle
+
This project is available in SVN: https://dev.eclipse.org/svnroot/modeling/org.eclipse.gmt.modisco/plugins/trunk/org.eclipse.gmt.modisco.dev.core/checkstyle/MoDisco.checkstyle
  
To use this file, you first need to download the [http://eclipse-cs.sourceforge.net/ Checkstyle plug-in].  
+
For configuring a new IDE :
 +
* Install [http://eclipse-cs.sourceforge.net/ Checkstyle plug-in]
 +
 
 +
* Go in ''Window > Preferences > Checkstyle'', and define a new global configuration of type 'Project Relative Configuration', pointing to the MoDisco.checkstyle file
 +
 
 +
Then each new MoDisco source project should have this checkstyle file applied (popup menu, ''Checkstyle > Activate Checkstyle''). Additional warnings are then computed on source code. A new builder and a .checkstyle file are created in the project.
 +
 
 +
Some generated files (such as EMF generated files) do not comply with these rules. For such files, the warnings should be ignored.
 +
 
 +
==== Local configuration ====
 +
It is also possible to configure checkstyle on a project, thus removing the need to configure it at the workspace level.
 +
 
 +
Here is an example checkstyle configuration file (.checkstyle). It references the checkstyle configuration file in the "modisco.dev.core" project and ignores warnings on "Messages.java":
 +
 
 +
  <?xml version="1.0" encoding="UTF-8"?>
 +
  <fileset-config file-format-version="1.2.0" simple-config="true">
 +
    <local-check-config name="MoDisco" location="../org.eclipse.gmt.modisco.dev.core/checkstyle/MoDisco.checkstyle" type="project" description=""/>
 +
    <fileset name="all" enabled="true" check-config-name="MoDisco" local="true">
 +
      <file-match-pattern match-pattern="." include-pattern="true"/>
 +
      <file-match-pattern match-pattern="Messages.java" include-pattern="false"/>
 +
    </fileset>
 +
  </fileset-config>
 +
 
 +
Reference:
 +
http://robertmarkbramprogrammer.blogspot.com/2007/07/eclipse-checkstyle-for-new-project.html
 +
 
 +
==== Checkstyle is not an Eclipse.org tool  ====
  
 
Note that Checkstyle is not an Eclipse.org tool. However, its source code is under the EPL, and its current use has been formally IP-validated for the MoDisco project:  
 
Note that Checkstyle is not an Eclipse.org tool. However, its source code is under the EPL, and its current use has been formally IP-validated for the MoDisco project:  
Line 24: Line 51:
 
*http://dev.eclipse.org/mhonarc/lists/modeling-pmc/msg01391.html (email thread for Modeling PMC validation)
 
*http://dev.eclipse.org/mhonarc/lists/modeling-pmc/msg01391.html (email thread for Modeling PMC validation)
  
Also note that Checkstyle is not intended to be distributed with MoDisco.  
+
Also note that Checkstyle is not intended to be distributed with MoDisco.
 
+
[[Category:MoDisco]]
+

Revision as of 12:38, 12 February 2010


Eclipse JDT Warnings Level

For code style verification, it is recommended to configure Eclipse jdt settings for errors/warning levels : all rules levels set as "ignored" should be set as "warning".

Some rules might create too many constraints in some java circumstances. The developer is allowed to disactivate the rules in specific areas :

- with projects specific errors/warning levels.

- with @SuppressWarnings, in adding some explanation to the deviation.

Checkstyle Usage

For MoDisco internal developments, the org.eclipse.gmt.modisco.dev.core project defines a MoDisco.checkstyle file. This file defines coding rules. It was initiated from the "sun conventions for Eclipse" checkstyle file. Some constraining rules have been disabled.

This project is available in SVN: https://dev.eclipse.org/svnroot/modeling/org.eclipse.gmt.modisco/plugins/trunk/org.eclipse.gmt.modisco.dev.core/checkstyle/MoDisco.checkstyle

For configuring a new IDE :

  • Go in Window > Preferences > Checkstyle, and define a new global configuration of type 'Project Relative Configuration', pointing to the MoDisco.checkstyle file

Then each new MoDisco source project should have this checkstyle file applied (popup menu, Checkstyle > Activate Checkstyle). Additional warnings are then computed on source code. A new builder and a .checkstyle file are created in the project.

Some generated files (such as EMF generated files) do not comply with these rules. For such files, the warnings should be ignored.

Local configuration

It is also possible to configure checkstyle on a project, thus removing the need to configure it at the workspace level.

Here is an example checkstyle configuration file (.checkstyle). It references the checkstyle configuration file in the "modisco.dev.core" project and ignores warnings on "Messages.java":

 <?xml version="1.0" encoding="UTF-8"?>
 <fileset-config file-format-version="1.2.0" simple-config="true">
   <local-check-config name="MoDisco" location="../org.eclipse.gmt.modisco.dev.core/checkstyle/MoDisco.checkstyle" type="project" description=""/>
   <fileset name="all" enabled="true" check-config-name="MoDisco" local="true">
     <file-match-pattern match-pattern="." include-pattern="true"/>
     <file-match-pattern match-pattern="Messages.java" include-pattern="false"/>
   </fileset>
 </fileset-config>

Reference: http://robertmarkbramprogrammer.blogspot.com/2007/07/eclipse-checkstyle-for-new-project.html

Checkstyle is not an Eclipse.org tool

Note that Checkstyle is not an Eclipse.org tool. However, its source code is under the EPL, and its current use has been formally IP-validated for the MoDisco project:

Also note that Checkstyle is not intended to be distributed with MoDisco.

Back to the top