This document describes how developers and contributors should write code. The reasoning of these styles and conventions is mainly for consistency, readability and maintainability reasons.
All working files (java, xml, others) should respect the following conventions:
and the following style:
Note: The specific styles and conventions, listed in the next sections, could override these generic rules.
The recommended style - adopted in the bigger part of the existing components, but optional - for Java is mainly:
package org.apache.onami.{component} /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You 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. */ public abstract class QuartzModule extends AbstractModule { // ---------------------------------------------------------------------- // Static methods // ---------------------------------------------------------------------- ... // ---------------------------------------------------------------------- // class members // ---------------------------------------------------------------------- /** * Describe here... */ private Multibinder<JobListener> jobListeners; ... // ---------------------------------------------------------------------- // Public methods // ---------------------------------------------------------------------- ... // ---------------------------------------------------------------------- // Protected methods // ---------------------------------------------------------------------- /** * {@inheritDoc} */ @Override protected final void configure() { ... } // ---------------------------------------------------------------------- // Private methods // ---------------------------------------------------------------------- ... }
The following sections show how to set up the code style in IDEA and Eclipse. It is strongly preferred that patches use this style before they are applied.
Download onami-idea-codestyle.xml and copy it to ~/.IntelliJIDEA/config/codestyles then restart IDEA. On Windows, try C:\Documents and Settings<username>\.IntelliJIDEA\config\codestyles
After this, restart IDEA and open the settings to select the new code style.
Download onami-eclipse-codestyle.xml.
After this, select Window > Preferences, and open up the configuration for Java > Code Style > Code Formatter. Click on the button labeled Import... and select the file you downloaded. Give the style a name, and click OK.
For consistency reasons, our Java code convention is mainly:
TO BE DISCUSSED
The Maven style for XML files is mainly:
<aTag> <simpleType>This is a simple type</simpleType> <complexType> <simpleType>This is a complex type</simpleType> </complexType> </aTag>
In some cases, adding comments could improve the readability of blocks, for instance:
<!-- Simple XML documentation -->
or
<!-- | This | is | a | block | documentation -->
No generic code convention exists yet for XML files.
The Maven team has voted during the end of June 2008 to follow a specific POM convention to ordering POM elements. The consequence of this vote is that the Maven project descriptor is no more considered as the reference for the ordering.
The following is the recommended ordering for all Maven POM files:
<?xml version="1.0" encoding="UTF-8"?> <!-- | Licensed to the Apache Software Foundation (ASF) under one or more | contributor license agreements. See the NOTICE file distributed with | this work for additional information regarding copyright ownership. | The ASF licenses this file to You 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. --> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.apache.onami</groupId> <artifactId>onami-parent</artifactId> <version>{parent.version}</version> </parent> <groupId>org.apache.onami</groupId> <artifactId>onami-{component}</artifactId> <version/> <packaging/> <name>Apache Onami-{component}</name> <description>Apache Onami-{component} is a tool that ...</description> <url/> <inceptionYear/> <contributors/> <prerequisites/> <modules/> <scm/> <issueManagement/> <ciManagement/> <distributionManagement/> <properties/> <dependencyManagement/> <dependencies/> <build/> <reporting/> <profiles/> </project>
Comments:
For consistency and readability reasons, XDOC files should respect:
For readability reasons, FML files should respect: