OpenOffice Maven2 Integration

From Apache OpenOffice Wiki
Revision as of 15:55, 6 November 2010 by Javatux (Talk | contribs)

Jump to: navigation, search

Overview

Maven is a well-know build framework for Java applications provided by the Apache foundation. It can be extended using plugins to perform custom actions. Maven manages the project dependencies which are fetched from remote or local repositories.

Some steps are missing in the Maven build to create and build OpenOffice.org extensions:

  • Generate Java classes from IDL files
  • Generate an OXT file to package the project
  • Create a simple OpenOffice.org extension project structure

Features

A Maven 2 plugin for OpenOffice.org extensions is currently under development. It already provides:

  • A goal to generate the Java classes from the IDL files
  • An archetytpe for the structure of an OpenOffice.org Extension project

Generating an Extension project

This will be done, by using a maven archetype for Uno projects. Here are the parameters to pass to maven execution to create an test-uno project.

[bash] mvn archetype:create \

 -DgroupId=org.openoffice.dev.tests            \
 -DartifactId=ooo-ext-test                     \
 -Dversion=1.0                                 \
 -DpackageName=org.openoffice.dev              \
 -DarchetypeGroupId=org.openoffice.dev         \
 -DarchetypeArtifactId=maven-ooo-plugin        \
 -DarchetypeVersion=1.1.1-SNAPSHOT

The started project will create the file and folder structure to place IDL folders and the Java sources. It will also add a generic UNO registration class like the one described by this blog post. The generated project pom.xml will contain dependencies to the OOo libraries and the needed basic configuration to run the goals provided by this maven2 plugin.

The generated project will be structured in order to fit the UNO extension packaging needs. This is not yet fully determined, but will need to be studied.

Building the IDL files

To build the IDL files, some additional configuration will be needed in the project pom.xml. The configuration will be like the following: [xml]

 <build>
   <plugins>
     <plugin>
       <groupId>org.openoffice.dev</groupId>
       <artifactId>maven-ooo-plugin</artifactId>
       <version>1.0</version>
       <configuration>
         <idlDir>${basedir}/src/main/idl</idlDir>
         <ooo>/path/to/an/ooo/installation</ooo>
         <sdk>/path/to/an/ooo/sdk/installation</sdk>
       </configuration>
       <executions>
         <execution>
           <phase>generate-sources</phase>
             <goals>
               <goal>build-idl</goal>
             </goals>
         </execution>
       </executions>       
     </plugin>
   </plugins>
 </build>

The configuration for idlDir can be ommitted if you use src/main/idl as default path (as in this example).

This Mojo configuration is not really clean, because it needs to define the path to an OpenOffice.org installation and the to OOo SDK. A solution would be to provide a default guess for the OOo installation path. This feature will be available in 1.1.1 but don't expect that it will work for all OS'es and installations.

Another solution is to use System Properties for the locations. System Properties can be set in the users Maven2 settings.xml (.m2/settings.xml) ie: [xml] <?xml version="1.0"?> <settings 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/xsd/settings-1.0.0.xsd">

 ...
 <profiles>
   <profile>
     <id>default</id>
     ...
     <properties>
       <ooo>/path/to/an/ooo/installation</ooo>
       <sdk>/path/to/an/ooo/sdk/installation</sdk>
     </properties>
     ...
   </profile>
 </profiles>
 <activeProfiles>
   <activeProfile>default</activeProfile>
 </activeProfiles>

</settings> Now, in the pom you can refer to the variables by ${ooo} and ${sdk} like this: [xml] ...

       <configuration>
         <ooo>${ooo}</ooo>
         <sdk>${sdk}</sdk>
       </configuration>

... I think this is the best solution which is available in Maven2. It allows you to use the same pom file for your buildserver and local development environment. Even it allows multiple OpenOffice versions if you give the properties other names.

Using this configuration the Java classes corresponding to the UNO types defined in the IDL files, are generated before the Java compilation phase. Using the standard maven build command is enough: [bash] mvn build

Creating a new UNO type implementation

This feature is not yet developed

Creating a new UNO type implementation is quite hard. The maven plugin will provide a goal to create a skeleton for the implementation of a UNO type, either of the extension project or an OpenOffice.org one. This goal will delegate the skeleton creation to the uno-skeletonmaker tool.

It could be invoked in the following way: [bash] mvn ooo:skeleton \

   -Dtype=the.type.to.implement        \
   -DimplementationName=the.class.name \
   -Djava.version=1.4

The java.version parameter would be optional and could be set to 1.4 or 1.5 to indicate which version of Java the implementation will support.

This Mojo will run the uno-skeletonmaker and add the new implementation to the implementations list of the project.

Getting started

In the past the sources were located on the API project CVS: http://api.openoffice.org/source/browse/api/maven2integration/. But these sources are out-of-date.

The actual sources are located now at http://github.com/fredericmorin/maven-ooo-plugin.

...

Explain how to get started with the development and how to use the plugin.

...

Repository

If you want to use the latest snapshot (1.1.1-SNAPSHOT) of the maven-ooo-plugin you can use the repository at http://labs.agentes.de/repository/ and add the following lines to your POM:

<repositories>
  ...
  <repository>
    <id>agentes</id>
    <name>agentes repository</name>
    <url>http://labs.agentes.de/repository/</url>
  </repository>
  ...
</repositories>


More Infos

Personal tools