Coding Standards

Code formatter

 Please format code using the following (Eclipse) formatter: amdatu-code-formatting.xml

Dependency manager callback methods

Dependency Manager uses reflection to access configured callback methods. As a result reviewers/analyzers may consider these as dead/unused code. Therefore, by convention we define them as protected final and add a comment to indicate their use (AMDATURS-58).

// Dependency Manager callback method
protected final void someServiceAdded(ServiceReference<T> reference, T service) {
  //do something 
}

Best practices

Defining external non-OSGi libraries as macros

Defining external non-OSGi libraries as macros makes it easier to maintain them, especially libraries which depend on a great variety of other libraries themselves as well.
Using the following approach, the library is defined in one place together with it's dependencies. The library can then easily be included on the build path as a single macro without having to reference a multitude of files and having to update them all throughout the entire project where needed.
Another bonus is that it allows easy use of multiple implementations which depend on the same libraries.

  1. Add/Move the library and it's dependencies to a lib folder inside the cnf project:

2. Create a bnd file which is used to define the macro:

3. Define the macro:

Bnd macro definition
alibrary:\
	${workspace}/cnf/lib/alibrary/alibrary-api-1.0.0.jar;version=file,\
	${workspace}/cnf/lib/alibrary/alibrary-dependency-2.3.1.jar;version=file


4. Use where applicable:

Example use of macro
-buildpath: osgi.core,\
	org.apache.felix.dependencymanager,\
	osgi.cmpn,\
	org.amdatu.bndtools.test,\
	junit.osgi,\
	${alibrary}


When maintenance needs to be performed on the library due to an update for example and/or change in dependencies, the only changes that need to be done are replacing the jar files themselves, and updating the macro definition which points to them.