Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Updating the link to the best Practices Guide (resides in OFBIZ recently)

Table of Contents

General Formatting Conventions

The Open For Business projects OFBiz project follows the Sun coding standards for Java source code. For information regarding this standard please visit http://java.sun.com/docs/codeconv/html/CodeConvTOC.doc.html

The line length of 150 is an exception to the Sun standard

Here is an example of a Java formatter for Eclipse

For Groovy we suggest you read http://www.groovy-lang.org/style-guide.html but we don't expect people to follow all details there, still a good read..

HTML code should be XHTML compliant. Groovy and Javascript files should follow the same conventions as Java files.

...

  1. Java -> Code Style -> Code Formatter -> Show... In dropdown pick -> Java Conventions built-in -> Indentation, select Tab policy as "Spaces Only". Enter a new name for this profile and click "OK".Java -> Editor -> Typing, and check "Insert spaces for tab".
  2. General -> Editors -> Text Editors -> Insert spaces for tabs
  3. Ant -> Editor -> Formatter, and uncheck "Use tab character instead of spaces".
  4. If you installed Colorer, Colorer Library Editor -> Uses spaces instead of tabs.
  5. If you installed XML Buddy, XMLBuddy -> Formatting -> Uses spaces instead of tabs.
  6. If you installed Oxygen, Oxygen -> Editor -> Format -> uncheck Indent with tabs, indent size 2 (beware for existing files with 4 spaces, always a trouble :/)
  7. XML -> XML Files -> Editors -> Text Editors -> Indent using spaces (4)
  8. Unfortunately the main FreeMarker plugins has no Unfortunaltely neither of the 2 main FreeMarker plugins have similar functionnality yet. But there is somehow a (sometimes annoying) solution :
    • Install AnyEdit plugin (http://andrei.gmxhome.de/eclipse/) and set its parameters in General -> Editors -> AnyEdit Tools. When using AnyEdit plugin, you should set it to
      • Convert tab to space (it's by default in last versions)
      • Add filters (like *.js, *.css) for files you don't want to auto-convert)

In Eclipse, for Java, you may use Ctrl+I to be sure of correct indentation.

For Javascript in Eclipse we suggest to use Aptana and to import /tools/ofbiz.aptana.js.format.xml (from Windows/Preferences/Aptana/Editors/Javascript/Formatting/Import in Eclipse).

Files paths

Info
titleBranches concerned

Only in trunk and R16.11 for now

  • Java
    The OFBiz project follows the Maven Standard Directory Layout to organise its Java files. At the moment of writing there are only a few unit tests (but a lot of what we so far call integration tests) so you will mostly find the ../src/main/java/org/apache/ofbiz.. path in components. As of today in few components in framework (base, entity, start, webapp) you will also find the ..src/test/java/org/apache/ofbiz.. path
  • Groovy
    We decided to use a groovyScripts sub-folder under components folders to put parsed Groovy scripts. We named it groovyScripts rather than script because other script languages could be used in the future
    Even if it's no used yet we reserved the groovy sub-folder under components folders for pre-compiled Groovy scripts. A distant goal is to replace Minilang by a Groovy DSL...
  • Freemarker
    The Freemarker templates are in template sub-folders under components folders
  • Minilang
    The Minilang map processors and minilang scripts are in minilang sub-folders under components folders

Misc.

In OFBiz we don't set serialVersionUID but let the system handles that for us and rather use @SuppressWarnings("serial") where necessary.
More at https://markmail.org/message/jjhf5p5hbhon7vam and above.Personaly (Jacques Le Roux), I use Eclipse and format my Java code with this attached file: ofbiz.xml

Entity Definitions

Entity Names

...

Service Definitions

Best Practices

Apache OFBiz Best Practices Guide


License Headers

Each and every source file should contain the ASL2.0 header:

 http://svn.apache.org/repos/asf/ofbiz/trunk/APACHE2_HEADER

Adding author information to source files (.e.g. using the @author tag) is a discouraged practice: clearer information about the contributors of a file should be derived from the commit logs.

Naming Conventions for Artifacts and controller entries

Controller

A Most of the time, a controller file (in OFBiz controller.xml) contains a lot 's of request-map maps and view-mapmaps. To help the reader, set a blank line between request-map or view-map element only when you change the functionnal group (entity, workflow or IHM treatment). Of course comments at the top of sections are welcome...

Request without event

Most In most of case, the request name is the same that than the view-map called. For the request-map name use java naming conventions object convention for Objects (ex : "FindParty"), and declare all in one line.

Code Block
languagexml
themeConfluencelanguagexml
     <request-map uri="FindParty"><security https="true" auth="true"/><response name="success" type="view" value="FindParty"/></request-map>

Request with event

For the request-map name use java naming conventions convention for field or method (ex : "editParty"), and declare each xml element on separate line

Code Block
languagexml
themeConfluence
languagexml
   <request-map uri="createPerson">
        <security https="true" auth="true"/>
        <event type="service" invoke="createPerson"/>
        <response name="success" type="view" value="EditPerson"/>
        <response name="error" type="view" value="EditPerson"/>
    </request-map>

View

For the view-map name use java naming conventions object convention for Objects (ex : "FindParty"), and declare all in one line.

Code Block
languagexml
themeConfluence
languagexml
    <view-map name="FindParty" type="screen" page="component://mycomponent/widget/PartyScreens.xml#FindParty"/>

...


widget screens

TODO: conventions for screen names (top-level screens, included screens, decorators)

...

TODO: conventions for menu names

Improve MacroXXXRenderer and FtlMacroXXXLibrary

Whn you realize some modification on the MacroXXX Renderer (XXX can take value Screen, Form, Menu and Tree) and you change a macro ftl definition change on each MacroXXXlibrary corresponding.

Example ; if your change renderTextField on htmlMacroFromLibrary, propage the improvment on \{csv|xml|text|fop}MacroFromLibrary

TODO: conventions for artifacts names such as ftl templates and bsh scripts