Customizing code generation

If you need to customize the generated code, simply provide custom templates to the JOMC Plugin. This is done by adding a template artifact as a plugin dependency and setting the templateProfile parameter of the JOMC Plugin. As a starting point you can copy the default templates from the JOMC Tools artifact from directory org/jomc/tools/templates/jomc-java to a org/jomc/tools/templates/sub-directory of your template artifact.

For example, copying the default templates to directory org/jomc/tools/templates/custom-profile, you need to set the templateProfile parameter to custom-profile and add your template artifact as a plugin dependency for the templates to be found.

See class SourceFileProcessor for details, especially the getVelocityTemplate method and the getSourceFilesType methods.

<project>
  ...
  <build>
    <plugins>
      ...
      <plugin>
        <groupId>org.jomc</groupId>
        <artifactId>maven-jomc-plugin</artifactId>
        <version>1.4</version>
        ...
        <dependencies>
          <dependency>
            <groupId>your.group.id</groupId>
            <artifactId>your-custom-templates</artifactId>
            <version>1.4</version>
          </dependency>
        </dependencies>
        ...
        <configuration>
          <templateProfile>custom-profile</templateProfile>
        </configuration>
        ...
      </plugin>
      ...
    </plugins>
  </build>
  ...
</project>

Controlling behaviour of the default templates

As of JOMC 1.2, the behaviour of the default templates can be controlled using the templateParameters parameter. The default values are shown below.

<project>
  ...
  <build>
    <plugins>
      ...
      <plugin>
        <groupId>org.jomc</groupId>
        <artifactId>maven-jomc-plugin</artifactId>
        <version>1.4</version>
        ...
        <configuration>
          <templateParameters>

            <!-- Flag indicating generated code to contain checks for illegal null references using the 'assert' keyword. -->
            <templateParameter>
              <key>with-assertions</key>
              <value>true</value>
              <type>java.lang.Boolean</type>
            </templateParameter>

            <!-- Flag indicating generated code to contain copyright notices based on model object authors. -->
            <templateParameter>
              <key>with-author-copyright</key>
              <value>true</value>
              <type>java.lang.Boolean</type>
            </templateParameter>

            <!-- Flag indicating generated code to contain editor folds for the Netbeans IDE and compatible editors. -->
            <templateParameter>
              <key>with-editor-fold</key>
              <value>true</value>
              <type>java.lang.Boolean</type>
            </templateParameter>

            <!-- Flag indicating generated code to contain javadoc documentation. -->
            <templateParameter>
              <key>with-javadoc</key>
              <value>true</value>
              <type>java.lang.Boolean</type>
            </templateParameter>

            <!-- Flag indicating generated code to contain '@author' javadoc documentation tags. -->
            <templateParameter>
              <key>with-javadoc-author</key>
              <value>true</value>
              <type>java.lang.Boolean</type>
            </templateParameter>

            <!-- Flag indicating generated code to contain '@version' javadoc documentation tags. -->
            <templateParameter>
              <key>with-javadoc-version</key>
              <value>true</value>
              <type>java.lang.Boolean</type>
            </templateParameter>

            <!-- Flag indicating generated code to contain JSR-250 '@Generated' annotations. -->
            <templateParameter>
              <key>with-jsr-250</key>
              <value>true</value>
              <type>java.lang.Boolean</type>
            </templateParameter>

            <!-- Name of the project. -->
            <templateParameter>
              <key>with-project-name</key>
            </templateParameter>

            <!-- SCM file identification keyword. The given value will be surrounded by '$' characters. -->
            <templateParameter>
              <key>with-revision-keyword</key>
              <value>Id</value>
            </templateParameter>

            <!-- Since 1.3: Flag indicating generated code to contain '@SuppressWarnings' annotations with the given value. -->
            <templateParameter>
              <key>with-suppress-warnings</key>
              <value>unused</value>
            </templateParameter>

            <!-- Flag indicating generated code to contain copyright notices based on model object vendor information. -->
            <templateParameter>
              <key>with-vendor-copyright</key>
              <value>true</value>
              <type>java.lang.Boolean</type>
            </templateParameter>

          </templateParameters>
        </configuration>
      </plugin>
      ...
    </plugins>
  </build>
  ...
</project>