Coding Guidelines

General Guidlines

Follow the general good practices of Java development, regarding naming conventions, coding, managing packages, testing etc.

License Information

Every source file should contain a license information in the header. The following snippet demonstrates license information for Java files:

/*
 * Copyright 2012 AMG.lab, a Bull Group Company
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *    http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

Code formatters

If you are using Eclipse IDE, configure code template and code formatter as described below.

Don't format existing code, as it makes tracking changes in source code virtually impossible. Commits with extensive and unnecessary formatting will be rejected from pushing to blessed repository.

Eclipse

Installation

Download and install Eclipse: http://www.eclipse.org/

Plugins

Install following plugins:

Configuration

Code Style

General

  1. We use ${user} variable in comments so we need to configure eclipse.ini file by adding following line: -Duser.name=Piotr Kulasek
  2. Use spaces instead of tabs: Window -> Preferences -> General -> Editors -> Text Editors and check Insert spaces for tabs
  3. Set Displayed tab width to 2.

Java

  1. Download code formatter and template files from http://gitorious.ow2.org/xlcloud/xlcloud/trees/master/development:
  2. Installation in Eclipse:
  • xlc_codetemplates.xml
    Window -> Preferences -> Java -> Code Style -> Code Template -> Import 
    • tick "Automatically add comments for new methods and types"
  • xlc_codeformatter.xml
    Window -> Preferences -> Java -> Code Style -> Formatter -> Import
    • choose XLC-Profile from list

HTML and CSS

  1. Go to: Window -> Preferences → Web → HTML Files → Editor
  2. Set Indent using spaces to 2
  3. Set Line width to 140
  4. Go to: Window -> Preferences → Web → CSS Files → Editor
  5. Repeat steps: 2 and 3. 

XML

  1. Go to: Window -> Preferences → XML → XML Files → Editor
  2. Set Line width to 140
  3. Check Indent using spaces
  4. Set Indentation size to 2

Character encoding

All *.java files must be encoded in UTF-8 (especially if you use Windows):

  • Window -> Preferences -> General -> Content Types -> Text
  • fill in "Default encoding" with value UTF-8
  • Update

Dependency management

All project dependencies versions should be managed from parent POM - so when you want to add new dependency to project, start with its definition in dependencyManagement section in top parent POM.

The same applies to plugins.


This wiki is licensed under a Creative Commons 2.0 license
XWiki Enterprise 5.4.6 - Documentation - Legal Notice

Site maintained by