Chapter 14. Third Party Integration
Prev | Part 6. Kodo JPA/JDO Reference Guide | Next

## Chapter 14. Third Party Integration

Kodo provides a number of mechanisms for integrating with third-party tools. The following chapter will illustrate these integration features.

## 14.1. Apache Ant

Ant is a very popular tool for building Java projects. It is similar to the `make` command, but is Java-centric and has more modern features. Ant is open source, and can be downloaded from Apache's Ant web page at http://jakarta.apache.org/ant/. Ant has become the de-facto standard build tool for Java, and many commercial integrated development environments provide some support for using ant build files. The remainder of this section assumes familiarity with writing Ant `build.xml` files.

Kodo provides pre-built Ant task definitions for all bundled tools:

- Enhancer Task

- Application Identity Tool Task

- Mapping Tool Task

- Reverse Mapping Tool Task

- Schema Tool Task

The source code for all the ant tasks is provided with the distribution under the `src` directory. This allows you to customize various aspects of the ant tasks in order to better integrate into your development environment.

### 14.1.1. Common Ant Configuration Options

All Kodo tasks accept a nested `config` element, which defines the configuration environment in which the specified task will run. The attributes for the `config` tag are defined by the `JDBCConfiguration` bean methods. Note that excluding the `config` element will cause the Ant task to use the default system configuration mechanism, such as the configuration defined in the `kodo.xml` or `kodo.properties` file.

Following is an example of how to use the nested `config` tag in a `build.xml` file:

Example 14.1. Using the <config> Ant Tag

    <mappingtool>
      <fileset dir="${basedir}">
        <include name="**/model/*.java" />
      </fileset>
      <config connectionUserName="scott" connectionPassword="tiger"
        connectionURL="jdbc:oracle:thin:@saturn:1521:solarsid"
        connectionDriverName="oracle.jdbc.driver.OracleDriver" />
    </mappingtool>

It is also possible to specify a `properties` or `propertiesFile` attribute on the `config` tag, which will be used to locate a properties resource or file. The resource will be loaded relative to the current CLASSPATH.

Example 14.2. Using the Properties Attribute of the <config> Tag

    <mappingtool>
      <fileset dir="${basedir}">
        <include name="**/model/*.java"/>
      </fileset>
      <config properties="kodo-dev.properties"/>
    </mappingtool>

Example 14.3. Using the PropertiesFile Attribute of the <config> Tag

    <mappingtool>
      <fileset dir="${basedir}">
        <include name="**/model/*.java"/>
      </fileset>
      <config propertiesFile="../conf/kodo-dev.properties"/>
    </mappingtool>

Tasks also accept a nested `classpath` element, which you can use in place of the default classpath. The `classpath` argument behaves the same as it does for Ant's standard `javac` element. It is sometimes the case that projects are compiled to a separate directory than the source tree. If the target path for compiled classes is not included in the project's classpath, then a `classpath` element that includes the target class directory needs to be included so the enhancer and mapping tool can locate the relevant classes.

Following is an example of using a `classpath` tag:

Example 14.4. Using the <classpath> Ant Tag

    <kodoc>
      <fileset dir="${basedir}/source">
        <include name="**/model/*.java" />
      </fileset>
      <classpath>
        <pathelement location="${basedir}/classes"/>
        <pathelement location="${basedir}/source"/>
        <pathelement path="${java.class.path}"/>
      </classpath>
    </kodoc>

Finally, tasks that invoke code-generation tools like the application identity tool and reverse mapping tool accept a nested `codeformat` element. See the code formatting documentation in Section 2.4.1, “Code Formatting” for a list of code formatting attributes.

Example 14.5. Using the <codeformat> Ant Tag

    <reversemappingtool package="com.xyz.jdo" directory="${basedir}/src">
      <codeformat tabSpaces="4" spaceBeforeParen="true" braceOnSameLine="false"/>
    </reversemappingtool>

Kodo's Ant tasks all utilize BEA licensing system and expect to find `license.bea` available in the classpath. Be sure that this file is avaialble to every task. For futher details, see Section 2.2, “License Configuration”.

### 14.1.2. Enhancer Ant Task

The enhancer task allows you to invoke the Kodo enhancer directly from within the Ant build process. The task's parameters correspond exactly to the long versions of the command-line arguments to `kodoc`.

The enhancer task accepts a nested `fileset` tag to specify the files that should be processed. You can specify `.java`, `.jdo`, or `.class` files. If you do not specify any files, the task will run on the classes listed in your `kodo.MetaDataFactory` property.

Following is an example of using the enhancer task in a `build.xml` file:

Example 14.6. Invoking the Enhancer from Ant

    <target name="enhance">
      <!-- define the kodoc task; this can be done at the top of the    -->
      <!-- build.xml file, so it will be available for all targets      -->
      <taskdef name="kodoc" classname="kodo.ant.PCEnhancerTask"/>

      <!-- invoke enhancer on all .jdo files below the current directory -->
      <kodoc>
        <fileset dir=".">
          <include name="**/model/*.java" />
        </fileset>
      </kodoc>
    </target>

### 14.1.3. Application Identity Tool Ant Task

The application identity tool task allows you to invoke the application identity tool directly from within the Ant build process. The task's parameters correspond exactly to the long versions of the command-line arguments to `appidtool`.

The application identity tool task accepts a nested `fileset` tag to specify the files that should be processed. You can specify `.java`, `.jdo`, or `.class` files. If you do not specify any files, the task will run on the classes listed in your `kodo.MetaDataFactory` property.

Following is an example of using the application identity tool task in a `build.xml` file:

Example 14.7. Invoking the Application Identity Tool from Ant

    <target name="appids">
      <!-- define the appidtool task; this can be done at the top of     -->
      <!-- the build.xml file, so it will be available for all targets   -->
      <taskdef name="appidtool" classname="kodo.ant.ApplicationIdToolTask"/>

      <!-- invoke tool on all .jdo files below the current directory     -->
      <appidtool>
        <fileset dir=".">
          <include name="**/model/*.java" />
        </fileset>
        <codeformat spaceBeforeParen="true" braceOnSameLine="false"/>
      </appidtool>
    </target>

### 14.1.4. Mapping Tool Ant Task

The mapping tool task allows you to directly invoke the mapping tool from within the Ant build process. It is useful for making sure that the database schema and object-relational mapping data is always synchronized with your persistent class definitions, without needing to remember to invoke the mapping tool manually. The task's parameters correspond exactly to the long versions of the command-line arguments to the `mappingtool`.

The mapping tool task accepts a nested `fileset` tag to specify the files that should be processed. You can specify `.java`, `.jdo`, or `.class` files. If you do not specify any files, the task will run on the classes listed in your `kodo.MetaDataFactory` property.

Following is an example of a `build.xml` target that invokes the mapping tool:

Example 14.8. Invoking the Mapping Tool from Ant

    <target name="refresh">
      <!-- define the mappingtool task; this can be done at the top of -->
      <!-- the build.xml file, so it will be available for all targets -->
      <taskdef name="mappingtool" classname="kodo.jdbc.ant.MappingToolTask"/>

      <!-- add the schema components for all .jdo files below the      -->
      <!-- current directory                                           -->
      <mappingtool action="buildSchema">
        <fileset dir=".">
          <include name="**/*.jdo" />
        </fileset>
      </mappingtool>
    </target>

### 14.1.5. Reverse Mapping Tool Ant Task

The reverse mapping tool task allows you to directly invoke the reverse mapping tool from within Ant. While many users will only run the reverse mapping process once, others will make it part of their build process. The task's parameters correspond exactly to the long versions of the command-line arguments to the `reversemappingtool`.

Following is an example of a `build.xml` target that invokes the reverse mapping tool:

Example 14.9. Invoking the Reverse Mapping Tool from Ant

    <target name="reversemap">
      <!-- define the reversemappingtool task; this can be done at the top of -->
      <!-- the build.xml file, so it will be available for all targets        -->
      <taskdef name="reversemappingtool"
        classname="kodo.jdbc.ant.ReverseMappingToolTask"/>

      <!-- reverse map the entire database -->
      <reversemappingtool package="com.xyz.model" directory="${basedir}/src"
        customizerProperties="${basedir}/conf/reverse.properties">
        <codeformat tabSpaces="4" spaceBeforeParen="true" braceOnSameLine="false"/>
      </reversemappingtool>
    </target>

### 14.1.6. Schema Tool Ant Task

The schema tool task allows you to directly invoke the schema tool from within the Ant build process. The task's parameters correspond exactly to the long versions of the command-line arguments to the `schematool`.

Following is an example of a `build.xml` target that invokes the schema tool:

Example 14.10. Invoking the Schema Tool from Ant

    <target name="schema">
      <!-- define the schematool task; this can be done at the top of  -->
      <!-- the build.xml file, so it will be available for all targets -->
      <taskdef name="schematool" classname="kodo.jdbc.ant.SchemaToolTask"/>

      <!-- add the schema components for all .schema files below the   -->
      <!-- current directory                                           -->
      <schematool action="add">
        <fileset dir=".">
          <include name="**/*.schema" />
        </fileset>
      </schematool>
    </target>

Prev | Up | Next
13.3. Controlling How the Profiler Obtains Context Information | Home | 14.2. Maven