Difference between revisions of "SMILA/Development Guidelines"

From Eclipsepedia

Jump to: navigation, search
m (When to use what log level and what information to provide?)
 
(47 intermediate revisions by 12 users not shown)
Line 1: Line 1:
 
This page covers a collection of development guidelines whose compliance should ensure that SMILA appears as a unified product rather than as a loose collection of parts worked on by a variety of individuals each with their own styles and ways of working. Furthermore it contains information on the used software components and requirements and provides descriptions (how-tos) of common tasks (e.g. setting up the development environment).
 
This page covers a collection of development guidelines whose compliance should ensure that SMILA appears as a unified product rather than as a loose collection of parts worked on by a variety of individuals each with their own styles and ways of working. Furthermore it contains information on the used software components and requirements and provides descriptions (how-tos) of common tasks (e.g. setting up the development environment).
 +
 +
== How-to manuals ==
 +
Find a list of How-To manuals at [[SMILA/HowTo|SMILA How-to manuals]].
  
 
== Development requirements ==
 
== Development requirements ==
  
=== Official JVM ===
+
=== Java ===
The official JVM for this project is Java 5.
+
  
=== OSGi runtime ===
+
The officially Java version needed for this project is Java 1.7.
The OSGi implementation of Equinox of Eclipse 3.3 or later and the corresponding OSGi specification(s).
+
  
== Development conventions ==
+
=== Eclipse  ===
  
=== Project setup ===
+
The official version is Eclipse 4.2, but you can also use Eclipse 3.7 or later.
The project folder setup is defined for this project at
+
 
[[SMILA/Development_Guidelines/Brox Java Project Setup|Brox Java Project Setup]].
+
== Development conventions ==
  
 
=== Description of make.xml ===
 
=== Description of make.xml ===
Line 19: Line 20:
  
 
=== Continuous integration ===
 
=== Continuous integration ===
 
+
Each developer should check his code before committing it to subversion regarding:
Everyone should be aware of the following workflow with Bamboo:
+
 
+
Bamboo should improve the source code quality but it should not be used as a (JUnit) test server.
+
Therefore each developer should check his code before committing it to subversion regarding:
+
 
* Compilation errors
 
* Compilation errors
* Checkstyle (see Brox Coding Conventions)
+
* Checkstyle (see [[#Checkstyle|Checkstyle]])
* Tests: Run a local build with the <tt>build.xml</tt> to test all existing JUnit tests.
+
* Build process: Check if your bundles and your test bundles are fully integrated in the whole build process
*:(see [[SMILA/Development_Guidelines|Development Guidelines]] for the setup)
+
*:Be aware that running tests in Eclipse doesn't mean that they run with the pdebbuild.
+
* Build process: Check if your bundles and your test bundle is fully integrated in the whole build process
+
 
*:(see [[SMILA/Development_Guidelines/How to integrate new bundle into build process|How to integrate new bundle into build process]] and [[SMILA/Development_Guidelines/How to integrate test bundle into build process|How to integrate test bundle into build process]])
 
*:(see [[SMILA/Development_Guidelines/How to integrate new bundle into build process|How to integrate new bundle into build process]] and [[SMILA/Development_Guidelines/How to integrate test bundle into build process|How to integrate test bundle into build process]])
 +
* Tests: Run a local build with the <tt>build.xml</tt> to test all existing JUnit tests.
 +
*:(see [[SMILA/Development_Guidelines/Howto_build_a_SMILA-Distribution|How to build a SMILA distribution]] for the setup)
 +
*: Be aware that running tests in Eclipse doesn't mean that they also run successful with the pde-build.
  
We have added a feature to the <tt>build.xml</tt>: The failed JUnit tests are reported at the end of the build output.
+
The failed JUnit tests are reported at the end of the build output.
  
 
Furthermore the full JUnit reports are generate under <tt>eclipse.build/reports/junit/</tt> and the
 
Furthermore the full JUnit reports are generate under <tt>eclipse.build/reports/junit/</tt> and the
Line 46: Line 43:
 
=== Eclipse code formatter profile ===
 
=== Eclipse code formatter profile ===
  
The Eclipse code formatter file is available in trunk at <tt>EILF.builder/eclipse-formatter/Eclipse-formatter-Brox-3.2-3.3.xml</tt>.
+
The Eclipse code formatter file is available in trunk at <tt>SMILA.builder/eclipse-formatter/Eclipse-formatter-Brox-3.2-3.3.xml</tt>.
  
 
To import the Eclipse code formatter profile:
 
To import the Eclipse code formatter profile:
# Download the profile configuration file.
 
 
# Select ''Window > Preferences'' in Eclipse and switch to the ''Java > Code Style > Formatter'' preferences page.
 
# Select ''Window > Preferences'' in Eclipse and switch to the ''Java > Code Style > Formatter'' preferences page.
 
# Click the ''Import'' button and select the downloaded formatter file.
 
# Click the ''Import'' button and select the downloaded formatter file.
 +
 +
{{Note|formatter vs. save actions|most source files have been edited with the save action turned on: "remove trailing white spaces on all lines". If you dont have this set then formatting the whole file will result in a lot white space of changes, which is cumbersome as is clutters diffs and poses problems to patches. So please turn this feature on.}}
  
 
=== Checkstyle ===
 
=== Checkstyle ===
  
Each Eclipse project (bundles) should follow the Brox Coding Conventions.
+
Each Eclipse project (bundles) should follow the SMILA Coding Conventions.
 +
 
 +
We use different checkstyle rules for "normal" bundles and test bundles. So there are two files containing the Checkstyle configurations in the trunk that you have to import (see below).
  
The file containing the Checkstyle rules is available in trunk at <tt>EILF.builder/checkstyle/brox_checks.xml</tt>.
+
'''Eclipse checkstyle plugin'''
  
'''Eclipse checkstyle plugin.'''
+
The eclipse-cs Checkstyle plugin integrates the source code analyzer Checkstyle into Eclipse IDE. By using this plugin your code is constantly inspected for problems. Within the Eclipse workbench you are notified of problems via the Eclipse ''Problems'' View and source code annotations just as you would see with compiler errors or warnings. The Checkstyle Eclipse plugin can be obtained from the update site: [http://eclipse-cs.sourceforge.net/update/ http://eclipse-cs.sourceforge.net/update/]. Instructions about how to set up the Checkstyle plugin for your project can be obtained from [http://eclipse-cs.sourceforge.net/basic_setup_project.html here].
  
The eclipse-cs Checkstyle plugin integrates the source code analyzer Checkstyle into Eclipse IDE. By using this plugin your code is constantly inspected for problems. Within the Eclipse workbench you are notified of problems via the Eclipse ''Problems'' View and source code annotations just as you would see with compiler errors or warnings. The Checkstyle Eclipse plugin can be obtained from the update site: [http://eclipse-cs.sourceforge.net/update/]. Instructions about how to set up the Checkstyle plugin for your project can be obtained from [http://eclipse-cs.sourceforge.net/basic_setup_project.html].
+
'''Setup checkstyle configuration'''
  
To use the plugin for all projects:
 
 
# Click ''Window > Preferences'' in Eclipse.
 
# Click ''Window > Preferences'' in Eclipse.
 
# Select the ''Checkstyle'' preference page and click the ''New'' button.  
 
# Select the ''Checkstyle'' preference page and click the ''New'' button.  
# Select ''External Configuration File'' as ''Type'' and point to the location of the file <tt>brox_checks.xml</tt>.
+
# Select ''External Configuration File'' as ''Type'' and point to the location of the file  
# The Checkstyle configuration profile should be named (while importing): "Brox Coding Conventions 1.06".
+
#: ''(if using checkstyle 4.x)''  <tt>SMILA.Builder/checkstyle/smila_checkstyle.xml</tt>.
 +
#: ''(if using checkstyle 5.x - recommended)''  <tt>SMILA.Builder/checkstyle/smila_checkstyle-5.xml</tt>.
 +
# This Checkstyle configuration profile should be named (while importing): <strong>"SMILA Checkstyle"</strong> and it should be set as ''default''.
 +
# Select ''External Configuration File'' as ''Type'' and point to the location of the file
 +
#: ''(if using checkstyle 4.x)''  <tt>SMILA.Builder/checkstyle/smila-test_checkstyle.xml</tt>.
 +
#: ''(if using checkstyle 5.x - recommended)'' <tt>SMILA.Builder/checkstyle/smila-test_checkstyle-5.xml</tt>.
 +
# This Checkstyle configuration profile should be named (while importing): <strong>"SMILA Test Checkstyle"</strong>.
  
The complete manual and other information on the plugin may be obtained from [http://eclipse-cs.sourceforge.net/].
+
'''Warnings'''
 +
 
 +
Most checkstyle warnings will be self-explaining. But there are two metrics considering method complexity that should be pointed to here explicitly, in case you got appropriate warnings:
 +
:* [http://checkstyle.sourceforge.net/config_metrics.html  CyclomaticComplexity]
 +
:* [http://checkstyle.sourceforge.net/config_metrics.html  NPathComplexity ]
 +
 
 +
=== Reduce javadoc overhead ===
 +
 
 +
Instead of writing member variable comments as
 +
<source lang="java">
 +
/**
 +
* switch to true to add newlines for better readability, but poorer performance.
 +
*/
 +
private final boolean _printPretty;
 +
</source>
 +
 
 +
it's more readable and clearer to write such javadoc comments as one line:
 +
<source lang="java">
 +
/** switch to true to add newlines for better readability, but poorer performance. */
 +
private final boolean _printPretty;
 +
</source>
  
 
=== Creation of bundles ===
 
=== Creation of bundles ===
For information on creating and integrating bundles refer to the folowing pages:
+
For information on creating and integrating bundles refer to the following pages:
  
 
* [[SMILA/Development_Guidelines/Create a bundle (plug-in)|Create a bundle (plug-in)]]
 
* [[SMILA/Development_Guidelines/Create a bundle (plug-in)|Create a bundle (plug-in)]]
 
* [[SMILA/Development_Guidelines/How to integrate new bundle into build process|How to integrate a new bundle into the build process]]
 
* [[SMILA/Development_Guidelines/How to integrate new bundle into build process|How to integrate a new bundle into the build process]]
 
* [[SMILA/Development_Guidelines/How to integrate test bundle into build process|How to integrate a test bundle into the build process]]
 
* [[SMILA/Development_Guidelines/How to integrate test bundle into build process|How to integrate a test bundle into the build process]]
 
+
* [[SMILA/Development_Guidelines/3rd party bundle|How to add 3rd party bundle]]
=== Version number ===
+
Until further notice, all own created bundles are V0.5.
+
 
+
=== XML schemas, namespace convention, and versioning ===
+
This subject is still very open to discussion right now, but I suggest to do the following:
+
# when defining a schema a name space must be defined also
+
## the URL of the namespace shall be like so: <nowiki>http://org.eclipse.eilf/<rest of bundle as path>/<version>##- <rest of bundle as path></nowiki> means that the '.' are converted to '/'. In case the bundle defines more than one schema then use the either packages or other properly identifying names (plz discuss this) to further qualify the name space.
+
* <version>
+
*:As we continue to develop the application, schemas will change over time. there are basically two options here: either encode the version in the *:name space or have an extra well defined attribute that needs to be added to the XML messages to tell which schema version it conforms to. Doing *:this with an attribute seem to be much more error prone (likely to be forgotten) and less xml-natural. (subject needs further discussion).
+
*:Further it is not clear how and when we will version a particular schema as those under development might be still very volatile. So the current *:idea is to version a schema on a milestone and releases.
+
*:Another idea is to integrate versioning in the daily build process where the version number may be constructed from
+
**Date / time stamp
+
**Build number
+
**Revision number
+
 
+
Example: <nowiki>http://org.eclipse.eilf/processing/bpel/xml/Record/0.7</nowiki>
+
  
 
=== Naming conventions for launch files (.launch) ===
 
=== Naming conventions for launch files (.launch) ===
Line 110: Line 119:
 
* Separate generated source code from handwritten code
 
* Separate generated source code from handwritten code
 
* Easier filtering for Checkstyle
 
* Easier filtering for Checkstyle
(see previous description in [[SMILA/Documentation/How_to_implement_a_Crawler|How to implement a crawler]])
+
(see [[SMILA/Development_Guidelines/Setup for JAXB code generation|Setup for JAXB code generation]] for details specific to creating crawler configurations.)
 
+
=== Sources of third party bundles ===
+
 
+
If you have to implement third party bundles into the SMILA project, please insert the sources into the <tt>3rdPartySources</tt> folder, not into the new bundle folder.
+
Each third party bundle should have an own folder suffixed by the corresponding version number, e.g. <tt>3rdPartySources\org.apache.tomcat-6.0.16\apache-tomcat-6.0.16-src.zip</tt>.
+
  
 
=== Logging guidelines ===
 
=== Logging guidelines ===
  
In SMILA apache commons logging is used with log4j. The log4j.properties are located in EILF.application. Here are some guidelines how and when logging should be used:
+
In SMILA apache commons logging is used with log4j. The log4j.properties are located in SMILA.application. Here are some guidelines how and when logging should be used:
* avoid static references to Log if possible
+
* use local Log instances in each class where you want to log:
 
<source lang="Java">
 
<source lang="Java">
 
private final Log _log = LogFactory.getLog(MyClass.class);
 
private final Log _log = LogFactory.getLog(MyClass.class);
 
</source>
 
</source>
* always check log level before logging, e.g.  
+
* always check log level before logging 'debug' and 'info', e.g.  
 
<source lang="Java">
 
<source lang="Java">
if (_log.isErrorEnabled()) {
+
if (_log.isDebugEnabled()) {
     _log.error("Your error message", e);
+
     _log.debug("Your debug message", e);
 
}
 
}
 
</source>
 
</source>
* log exceptions before throwing new exceptions, e.g.
+
For 'warn' and 'error' messages the log level check can be omitted.
 +
 
 +
* do '''not''' log exceptions before throwing new exceptions, e.g.
 
<source lang="Java">
 
<source lang="Java">
 
...
 
...
Line 141: Line 147:
 
</source>
 
</source>
  
When to use what log level and what information to provide?
+
'''When to use what log level and what information to provide?'''
 +
 
 
{| class="wikitable"
 
{| class="wikitable"
 
|-
 
|-
 
! FATAL
 
! FATAL
| tbd.
+
| designates very severe error events that will presumably lead the application to abort.
 
|-
 
|-
 
! ERROR
 
! ERROR
| tbd.
+
| designates error events that might still allow the application to continue running.  
 
|-
 
|-
 
! WARN
 
! WARN
| tbd.
+
| designates potentially harmful situations.  
 
|-
 
|-
 
! INFO
 
! INFO
| tbd.
+
| for the "high level" information. For example - interesting runtime events (startup/shutdown).  
 
|-
 
|-
 
! DEBUG
 
! DEBUG
| tbd.
+
| only for the software developer interesting messages (detailed information on the flow through the system).
|-
+
! TRACE
+
| tbd.
+
 
|-
 
|-
 
|}
 
|}
  
 +
A good resource on how to use the levels in regard to the ''Enterprise'' context offers [http://commons.apache.org/logging/guide.html#JCL%20Best%20Practices JCL Best Practices].
  
 
== Used technologies ==
 
== Used technologies ==
Line 170: Line 175:
  
 
* [[SMILA/Development Guidelines/Declarative Services|Declarative services]]
 
* [[SMILA/Development Guidelines/Declarative Services|Declarative services]]
 
=== Tuscany related information ===
 
* [[SMILA/Development Guidelines/Tuscany Integration|Tuscany integration]]
 
 
=== Launch configurations for OSGi wih SCA ===
 
'''This information is outdated. It will be updated when Tuscany integration is stable'''
 
[[User:Daniel.stucky.empolis.com|Daniel Stucky]]: I had some trouble selecting the right Bundles that were required to execute my sample application (org.eclipse.eilf.framework.test). Don't use the "Add required Bundles" button in the launch configuration dialog. It adds additional bundles that are not needed and starts all bundles with the same start level. I selected the required bundles manually (through try and error) and assigned the following start levels:
 
# all org.eclipse bundles (except for the eilf bundles)
 
# all org.apache.tuscany bundles
 
# all other third party bundles
 
# (default) all org.eclipse.eilf bundles
 
# the bundle with the test application (org.eclipse.eilf.framework.test)
 
 
I don't know if all these start levels are required, at least I got it working with these settings. Setting all to default does NOT work !!!
 
 
== How-to manuals ==
 
=== How to set up the development environment ===
 
Find this how-to manual at [[SMILA/Development Guidelines/Howto set up dev environment|How to set up the development environment]].
 
 
=== How to set up the test environment ===
 
Find this how-to manual at [[SMILA/Development Guidelines/Howto set up test environment|How to set up the test environment]].
 
 
=== Run and manage the connectivity framework ===
 
At the time of writing this there is the possibility to start EILF/SMILA as a separate application as described below:
 
# Update from SVN and refresh.
 
# Execute build and unzip <tt>eclipse.build/Application/ EILF-win32.win32.x86.zip</tt> to an arbitrary folder.
 
# Create the folder <tt>c:\data</tt> and add some TXT and/or HTML files (for file system crawler).
 
# Launch the application by calling <tt>eclipse.exe -console</tt> or <tt>launch.cmd</tt>.
 
# Run JConsole and connect to local.
 
# Open the ''EILF/org.eclipse.econnectivity...'' branch in JConsole.
 
# Switch to the the ''MBeans/Operations'' tab.
 
# Start the file system crawler by launching the "startCrawl()" operation and passing the "file" parameter.
 
# Start the web crawler by launching the "startCrawl()" operation and passing the "web" parameter.
 
# Have a look at the Eclipse console log and enjoy ;)
 
  
 
[[Category:SMILA]]
 
[[Category:SMILA]]

Latest revision as of 03:34, 9 April 2013

This page covers a collection of development guidelines whose compliance should ensure that SMILA appears as a unified product rather than as a loose collection of parts worked on by a variety of individuals each with their own styles and ways of working. Furthermore it contains information on the used software components and requirements and provides descriptions (how-tos) of common tasks (e.g. setting up the development environment).

Contents

[edit] How-to manuals

Find a list of How-To manuals at SMILA How-to manuals.

[edit] Development requirements

[edit] Java

The officially Java version needed for this project is Java 1.7.

[edit] Eclipse

The official version is Eclipse 4.2, but you can also use Eclipse 3.7 or later.

[edit] Development conventions

[edit] Description of make.xml

For a description of the build file make.xml refer to Introduction to make.xml.

[edit] Continuous integration

Each developer should check his code before committing it to subversion regarding:

The failed JUnit tests are reported at the end of the build output.

Furthermore the full JUnit reports are generate under eclipse.build/reports/junit/ and the error messages from the JUnit reports are stored under eclipse.build/reports_errors_txt/.

Everyone should monitor the trunk at the build server and if there is a "red" build everyone should look if he has committed the error.

If the error could not be solved within the next build, the developer should inform the developer team that there is a problem with the build and that he is working on the solution.

[edit] File header & copyright notice

For guidelines on file header and copyright notices see Project Guidelines.

[edit] Eclipse code formatter profile

The Eclipse code formatter file is available in trunk at SMILA.builder/eclipse-formatter/Eclipse-formatter-Brox-3.2-3.3.xml.

To import the Eclipse code formatter profile:

  1. Select Window > Preferences in Eclipse and switch to the Java > Code Style > Formatter preferences page.
  2. Click the Import button and select the downloaded formatter file.
Note.png
formatter vs. save actions
most source files have been edited with the save action turned on: "remove trailing white spaces on all lines". If you dont have this set then formatting the whole file will result in a lot white space of changes, which is cumbersome as is clutters diffs and poses problems to patches. So please turn this feature on.


[edit] Checkstyle

Each Eclipse project (bundles) should follow the SMILA Coding Conventions.

We use different checkstyle rules for "normal" bundles and test bundles. So there are two files containing the Checkstyle configurations in the trunk that you have to import (see below).

Eclipse checkstyle plugin

The eclipse-cs Checkstyle plugin integrates the source code analyzer Checkstyle into Eclipse IDE. By using this plugin your code is constantly inspected for problems. Within the Eclipse workbench you are notified of problems via the Eclipse Problems View and source code annotations just as you would see with compiler errors or warnings. The Checkstyle Eclipse plugin can be obtained from the update site: http://eclipse-cs.sourceforge.net/update/. Instructions about how to set up the Checkstyle plugin for your project can be obtained from here.

Setup checkstyle configuration

  1. Click Window > Preferences in Eclipse.
  2. Select the Checkstyle preference page and click the New button.
  3. Select External Configuration File as Type and point to the location of the file
    (if using checkstyle 4.x) SMILA.Builder/checkstyle/smila_checkstyle.xml.
    (if using checkstyle 5.x - recommended) SMILA.Builder/checkstyle/smila_checkstyle-5.xml.
  4. This Checkstyle configuration profile should be named (while importing): "SMILA Checkstyle" and it should be set as default.
  5. Select External Configuration File as Type and point to the location of the file
    (if using checkstyle 4.x) SMILA.Builder/checkstyle/smila-test_checkstyle.xml.
    (if using checkstyle 5.x - recommended) SMILA.Builder/checkstyle/smila-test_checkstyle-5.xml.
  6. This Checkstyle configuration profile should be named (while importing): "SMILA Test Checkstyle".

Warnings

Most checkstyle warnings will be self-explaining. But there are two metrics considering method complexity that should be pointed to here explicitly, in case you got appropriate warnings:

[edit] Reduce javadoc overhead

Instead of writing member variable comments as

 /** 
 * switch to true to add newlines for better readability, but poorer performance. 
 */
 private final boolean _printPretty;

it's more readable and clearer to write such javadoc comments as one line:

 /** switch to true to add newlines for better readability, but poorer performance. */
 private final boolean _printPretty;

[edit] Creation of bundles

For information on creating and integrating bundles refer to the following pages:

[edit] Naming conventions for launch files (.launch)

It is a good thing to share your launches and many do so already which helps greatly to run tests quickly from within Eclipse. However, in order that at least I don't get confused, we need to define a naming scheme for the .launch files!

Preliminary convention: <bundle name>[_config name].launch

The [config name] part is optional and needed when several .launch files exist for the same bundle but with different settings.

[edit] Generated source code goes into code/gen source folder (like Jaxb)

All generated source code (eg. JAXB) goes into the distinct source code folder code/gen. Where possible all generated classes should also have their own package. Reasons:

  • Separate generated source code from handwritten code
  • Easier filtering for Checkstyle

(see Setup for JAXB code generation for details specific to creating crawler configurations.)

[edit] Logging guidelines

In SMILA apache commons logging is used with log4j. The log4j.properties are located in SMILA.application. Here are some guidelines how and when logging should be used:

  • use local Log instances in each class where you want to log:
private final Log _log = LogFactory.getLog(MyClass.class);
  • always check log level before logging 'debug' and 'info', e.g.
if (_log.isDebugEnabled()) {
    _log.debug("Your debug message", e);
}

For 'warn' and 'error' messages the log level check can be omitted.

  • do not log exceptions before throwing new exceptions, e.g.
...
if( paramXY == null ) {
    if (_log.isErrorEnabled()) {
        _log.error("paramXY is not set");
    }
    throw new NullPointerException("paramXY is not set");
}

When to use what log level and what information to provide?

FATAL designates very severe error events that will presumably lead the application to abort.
ERROR designates error events that might still allow the application to continue running.
WARN designates potentially harmful situations.
INFO for the "high level" information. For example - interesting runtime events (startup/shutdown).
DEBUG only for the software developer interesting messages (detailed information on the flow through the system).

A good resource on how to use the levels in regard to the Enterprise context offers JCL Best Practices.

[edit] Used technologies

[edit] OSGi related information