OpenOffice Plugin

From JQuantLib

Jump to: navigation, search

Contents

Background

The OpenOffice Plugin was contributed by Praneet Tiwari. The intention is to provide a free alternative to the MS Excel Plugin of Quantlib and to demonstrate the functionality provided by JQuantlib. Praneet also documented his great work on his blog:

At the moment, we are sloooowly moving the development environment from NetBeans to Eclipse. Ideally (as usual), it will be possible to build this plugin automagically from the command line, which will allow us to integrate this build in our continuous integration server.


Difficult First Steps

The first difficulty is understand which resources you need to get started. It should not be difficult but, as usual, little details can imply of a lot of time wasted. You need resources for a certain version of OpenOfice, namely:

  1. An OpenOffice installation;
  2. OpenOffice SDK installation;
  3. JARs which should be part of the SDK, but they are not.

Being able to find all resources for a certain version for your platform is determinant for going ahead. If something is missing you certainly will have troubles when you try to build JQuantLib OpenOffice Plugin.


Downloading Resources

At the time of this writing, I was able to find all resources we need for version 3.1.0, which is not the most recent stable version at the moment. Anyway, it is the most recent complete environment I was able to find.

  1. OpenOffice installation
  2. OpenOffice SDK installation
  3. JARs which should be part of the SDK which can be found at central Maven Repository
    <dependencies>
        <dependency>
            <groupId>org.openoffice</groupId>
            <artifactId>unoil</artifactId>
            <version>3.1.0</version>
        </dependency>
        <dependency>
            <groupId>org.openoffice</groupId>
            <artifactId>juh</artifactId>
            <version>3.1.0</version>
        </dependency>
        <dependency>
            <groupId>org.openoffice</groupId>
            <artifactId>ridl</artifactId>
            <version>3.1.0</version>
        </dependency>
        <dependency>
            <groupId>org.openoffice</groupId>
            <artifactId>jurt</artifactId>
            <version>3.1.0</version>
        </dependency>
    </dependencies>


Installation

You can (or at least 'should be able to') install OpenOffice distribution and the corresponding OpenOffice SDK wherever it is more convenient for you. Beware that the installation of these resources can eventually collide with your currently installed version of OpenOffice, which you are happy using for your mundane daily tasks. You have to try yourself to see if you are able to install the resources mentioned here in a separate directory. This can eventually vary depending on the resources you were actually able to find. In my box I preferred to uninstall OpenOffice 3.1.1, making sure everything was uninstalled and I installed OpenOffice 3.1.0 stuff from scratch.


Clean Up Before Start

Just in case, it's a good practice to clean up everything before installing OpenOffice SDK. This is intended to guarantee that eventually mistaken configurations promote a mess of different versions which can imply on errors or instabilities very difficult to identify. In this step we will uninstall any pre-existing version of OpenOffice.

apt-get remove ure -V --simulate
<pre>
It says that the following packages will be removed:
<pre>
The following packages will be REMOVED
   openoffice.org (3.1.1-11~bpo50+1)
   openoffice.org-base (3.1.1-11~bpo50+1)
   openoffice.org-base-core (3.1.1-11~bpo50+1)
   openoffice.org-calc (3.1.1-11~bpo50+1)
   openoffice.org-common (3.1.1-11~bpo50+1)
   openoffice.org-core (3.1.1-11~bpo50+1)
   openoffice.org-draw (3.1.1-11~bpo50+1)
   openoffice.org-emailmerge (3.1.1-11~bpo50+1)
   openoffice.org-filter-binfilter (3.1.1-11~bpo50+1)
   openoffice.org-filter-mobiledev (3.1.1-11~bpo50+1)
   openoffice.org-help-en-gb (3.1.1-11~bpo50+1)
   openoffice.org-help-pt-br (3.1.1-11~bpo50+1)
   openoffice.org-impress (3.1.1-11~bpo50+1)
   openoffice.org-java-common (3.1.1-11~bpo50+1)
   openoffice.org-math (3.1.1-11~bpo50+1)
   openoffice.org-officebean (3.1.1-11~bpo50+1)
   openoffice.org-report-builder-bin (3.1.1-11~bpo50+1)
   openoffice.org-writer (3.1.1-11~bpo50+1)
   python-uno (3.1.1-11~bpo50+1)
   ure (1.5.1+OOo3.1.1-11~bpo50+1)

Now let's go ahead and remove them:

apt-get remove ure -y

Now let's purge all resources still eventually remaining on disk relative to uninstalled packages:

for pkg in `dpkg --list | grep -E '^rc' | awk '{ print $2 }' ` ;do
  dpkg --purge $pkg
done

Are there any remaining OpenOffice stuff remaining?

dpkg --list | fgrep openoffice
ii  openoffice.org-l10n-en-gb
ii  openoffice.org-l10n-pt-br
ii  openoffice.org-style-galaxy

Now let's uninstall these and purge them:

apt-get remove openoffice.org-l10n-en-gb openoffice.org-l10n-pt-br openoffice.org-style-galaxy -y
for pkg in `dpkg --list | grep -E '^rc' | awk '{ print $2 }' ` ;do
  dpkg --purge $pkg
done

Now everything is over! :)


Installing OpenOffice SDK

I've downloaded these 2 files in my box:

  • OOo_3.1.0_LinuxX86-64_install_en-US_deb.tar.gz : OpenOffice 3.1.0
  • OOo-SDK_3.1.0_LinuxX86-64_install_en-US_deb.sh : OpenOffice 3.1.0 SDK

I have installed all this stuff into my /opt/openoffice.org3 directory. First step is the installation of OpenOffice 3.1.0 from the huge .tar.gz file:

tar xzf OOo_3.1.0_LinuxX86-64_install_en-US_deb.tar.gz
dpkg -i OOO310_m11_native_packed-3_en-US.9399/DEBS/*.deb

Second step is installation of OpenOffice SDK:

chmod 755 OOo-SDK_3.1.0_LinuxX86-64_install_en-US_deb.sh
# you have to choose a destination directory
./OOo-SDK_3.1.0_LinuxX86-64_install_en-US_deb.sh
# now install OpenOffice SDK
dpkg -i ~/tmp/ooo/DEBS/ooobasis3.1-sdk_3.1.0-11_amd64.deb

Now make sure your non-privileged use has access to it:

ls -al /opt/openoffice.org/basis3.1/sdk


Environment Configuration

Now you need to perform the following 3 steps:

  1. first time configuration
  2. add a line to your ~/.bashrc file
  3. validate your environment


First time configuration

$ /opt/openoffice.org/basis3.1/sdk/setsdkenv_unix --force-configure

 Enter the Office installation directory [/opt/openoffice.org3]:
 Enter GNU make (3.79.1 or higher) tools directory [/usr/bin]:
 Enter zip (2.3 or higher) tool directory [/usr/bin]:
 C++ compilers where for example a language binding exist:
  - Solaris, Sun WorkShop 6 update 1 C++ 5.2 2000/09/11 or higher
  - Linux, GNU C++ compiler, gcc version 3.0.1 or higher
  - MacOS, GNU C++ compiler, gcc version 4.0.1 or higher
 Enter the directory of the C++ compiler, the directory
 where the compiler is located (optional) [/usr/bin]:
 Enter Java SDK (1.4.1_01 or higher) installation directory  (optional) [/home/rgomes/tmp/.setpath]: $JAVA_HOME
 Default output directory is in your HOME directory.
 Enter an existent directory if you prefer a different output directory (optional) [/home/rgomes]: $HOME/tmp
 Automatic deployment of UNO components (YES/NO) [YES]:

 ************************************************************************
 * ... your SDK environment has been prepared.
 * For each time you want to use this configured SDK environment, you
 * have to run the "setsdkenv_unix" script file!
 * Alternatively can you source one of the scripts
 *   "/home/rgomes/openoffice.org3.1_sdk/terra/setsdkenv_unix.sh"
 *   "/home/rgomes/openoffice.org3.1_sdk/terra/setsdkenv_unix.csh"
 * to get an environment without starting a new shell.
 ************************************************************************


 ************************************************************************
 *
 * SDK environment is prepared for Linux
 *
 * SDK = /opt/openoffice.org/basis3.1/sdk
 * Office = /opt/openoffice.org3
 * Office Base = /opt/openoffice.org/basis3.1
 * URE = /opt/openoffice.org/ure
 * Make = /usr/bin
 * Zip = /usr/bin
 * C++ Compiler = /usr/bin
 * Java = /opt/JavaIDE/jdk1.6.0_17-linux-x64
 * SDK Output directory = /home/rgomes/tmp/openoffice.org3.1_sdk
 * Auto deployment = YES
 *
 ************************************************************************

It will ask you questions which mostly present the correct defaults. You are also asked to provide locations for certain programs, like GNU make, etc. Make sure you have all this stuff installed and make sure you enter these locations properly when asked. if something fails later, it will be your and only your fault, obviously.

$ dpkg --list | fgrep make
ii  make                                 3.81-5                        The GNU version of the "make" utility.
ii  makedev                              2.3.1-88                      creates device files in /dev
ii  module-assistant                     0.10.11.0                     tool to make module package creation easier

$ which make
make: /usr/bin/make

$ dpkg --list | fgrep zip | fgrep -v bzip | fgrep -v gzip | fgrep -v 7zip
ii  unzip                                5.52-12                       De-archiver for .zip files
ii  zip                                  2.32-1                        Archiver for .zip files

$ which zip
zip: /usr/bin/zip


Change your ~/.bashrc

You need to add the following lines in the end of your ~/.bashrc:

# Load OpenOffice SDK, if any
HOSTNAME=`hostname`
if [ -f $HOME/openoffice.org3.1_sdk/$HOSTNAME/setsdkenv_unix.sh ] ;then
    source $HOME/openoffice.org3.1_sdk/$HOSTNAME/setsdkenv_unix.sh
fi


Validate your environment

See if you can call properly IDLC, the IDL compiler:

$ bash
 ************************************************************************
 *
 * SDK environment is prepared for Linux
 *
 * SDK = /opt/openoffice.org/basis3.1/sdk
 * Office = /opt/openoffice.org3
 * Office Base = /opt/openoffice.org/basis3.1
 * URE = /opt/openoffice.org/ure
 * Make = /usr/bin
 * Zip = /usr/bin
 * C++ Compiler = /usr/bin
 * Java = /opt/JavaIDE/jdk1.6.0_17-linux-x64
 * SDK Output directory = /home/rgomes/openoffice.org3.1_sdk
 * Auto deployment = YES
 *
 ************************************************************************

$ idlc -h

using: idlc [-options] <file_1> ... <file_n> | @<filename> | -stdin
    <file_n>    = file_n specifies one or more idl files.
                  Only files with the extension '.idl' are valid.
    @<filename> = filename specifies the name of a command file.
    -stdin      = read idl file from standard input.
  Options:
    -O<path>    = path specifies the output directory.
                  The generated output is a registry file with
                  the same name as the idl input file (or 'stdin'
                  for -stdin).
    -I<path>    = path specifies a directory where include
                  files will be searched by the preprocessor.
                  Multiple directories can be combined with ';'.
    -D<name>    = name defines a macro for the preprocessor.
    -C          = generate complete type information, including
                  documentation.
    -cid        = check if identifiers fulfill the UNO naming
                  requirements.
    -w          = display warning messages.
    -we         = treat warnings as errors.
    -h|-?       = print this help message and exit.

Sun Microsystems (R) idlc Version 1.1

This is good sign but not enough: I've tried to build our JQuantLib OpenOffice plugin (further steps how to build are further below) and the build failed. :(

There's an error (see stack trace below) which I couldn't figure out the reason in less than 10 minutes, So I decided to start a session of black magic. I've downloaded the source code of maven-ooo-plugin, the OpenOffice Maven Integration plugin, added some System.out commands, built it and tried again. Now I have some additional information which helps me figure out why on earth maven-ooo-plugin is not finding idlc:

$ mvn clean verify -X
...
[INFO] [ooo:build-idl {execution: default}]
[INFO] OpenOffice.org used: /opt/openoffice.org/basis3.1
[INFO] OpenOffice.org SDK used: /opt/openoffice.org/basis3.1/sdk
[INFO] IDL folder used: /home/rgomes/workspace/jquantlib-ooplugin/src/main/resources/idl
[INFO] Building IDL files
[info] Building file: /home/rgomes/workspace/jquantlib-ooplugin/src/main/resources/idl/org/jquantlib/XJQAddIn.idl
PATH=/opt/openoffice.org/basis3.1/sdk/linux/bin
LD_LIBRARY_PATH=/opt/openoffice.org/basis3.1/program
sh
-c
idlc -O "/home/rgomes/workspace/jquantlib-ooplugin/target/urd/org/jquantlib" -I "/opt/openoffice.org/basis3.1/sdk/idl" -I "/home/rgomes/workspace/jquantlib-ooplugin/src/main/resources/idl" /home/rgomes/workspace/jquantlib-ooplugin/src/main/resources/idl/org/jquantlib/XJQAddIn.idl
[ERROR] Error during idl-build
java.lang.Exception: sh: idlc: command not found

        at org.openoffice.maven.utils.ErrorReader.readErrors(ErrorReader.java:76)
        at org.openoffice.maven.types.IdlcVisitor.runIdlcOnFile(IdlcVisitor.java:121)
        at org.openoffice.maven.types.IdlcVisitor.visit(IdlcVisitor.java:83)
        at org.openoffice.maven.utils.VisitableFile.accept(VisitableFile.java:104)
        at org.openoffice.maven.utils.VisitableFile.accept(VisitableFile.java:111)
        at org.openoffice.maven.utils.VisitableFile.accept(VisitableFile.java:111)
        at org.openoffice.maven.utils.VisitableFile.accept(VisitableFile.java:111)
        at org.openoffice.maven.types.IdlBuilderMojo.execute(IdlBuilderMojo.java:160)
        at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:490)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:694)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalWithLifecycle(DefaultLifecycleExecutor.java:556)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:535)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:387)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:348)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:180)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:328)
        at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:138)
        at org.apache.maven.cli.MavenCli.main(MavenCli.java:362)
        at org.apache.maven.cli.compat.CompatibleMain.main(CompatibleMain.java:60)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
        at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
        at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)
        at org.codehaus.classworlds.Launcher.main(Launcher.java:375)

It basically means that maven-ooo-plugin is trying to find idlc on /opt/openoffice.org/sdk/linux/bin. Well, I don't have any linux folder there. So, let's circumvent this difficulty with a very dirty trick:

cd /opt/openoffice.org/sdk
ln -s ../sdk linux

Now the our build finally pass :)


Building from command line

WARNING:: THIS IS WORK IN PROGRESS AT THE TIME OF THIS WRITING OUR CODE WAS NOT CHECKED INTO OUR SVN REPOSITORY. BELOW YOU CAN SEE OUR pom.xml FOR YOUR REFERENCE IN THE TIME BEING.

<?xml version="1.0" encoding="UTF-8"?>
<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>


<!--
    Copyright (C) 2008 Richard Gomes

    This source code is release under the BSD License.

    This file is part of JQuantLib, a free-software/open-source library
    for financial quantitative analysts and developers - http://jquantlib.org/

    JQuantLib is free software: you can redistribute it and/or modify it
    under the terms of the JQuantLib license.  You should have received a
    copy of the license along with this program; if not, please email
    <jquant-devel@lists.sourceforge.net>. The license is also available online at
    <http://www.jquantlib.org/index.php/LICENSE.TXT>.

    This program is distributed in the hope that it will be useful, but WITHOUT
    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    FOR A PARTICULAR PURPOSE.  See the license for more details.

    JQuantLib is based on QuantLib. http://quantlib.org/
-->

    <parent>
        <groupId>org.jquantlib</groupId>
        <artifactId>jquantlib-all</artifactId>
        <version>0.1.3-SNAPSHOT</version>
        <relativePath>../jquantlib-all/pom.xml</relativePath>
    </parent>

    <groupId>${project.parent.groupId}</groupId>
    <artifactId>jquantlib-ooplugin</artifactId>
    <version>${project.parent.version}</version>
    <packaging>jar</packaging>

    <name>${project.artifactId}</name>
    <url>http://www.jquantlib.org/sites/${project.artifactId}/</url>

     <!--
     **** This project assumes that you have OpenOffice installed at:
     ****
     **** /opt/openoffice.org/basis3.1      :: application installation files
     **** /opt/openoffice.org/basis3.1/sdk  :: OpenOffice SDK installation files
     ****
     **** In case you need to change these settings, please add a section
     **** in your settings.xml similar to this:
     ****
     ****   <profile>
     ****     <id>ooffice</id>
     ****     <properties>
     ****       <settings.ooffice.app>/somewhere/openoffice</settings.ooffice.app>
     ****       <settings.ooffice.sdk>/somewhere/openoffice/sdk</settings.ooffice.sdk>
     ****       <settings.ooffice.version>some-version</settings.ooffice.version>
     ****     </properties>
     ****   </profile>
     -->

    <distributionManagement>
        <!-- NOTE: <site> entry cannot be inherited.
          **       It means to say that you need to copy/paste this text as it is to all projects.
          **       See comments in the parent POM for more information.
          -->
        <site>
            <id>site</id>
            <name>${project.project.artifactId} site generated by Maven</name>
            <url>${props.site.deploy.url}/${project.artifactId}</url>
        </site>
    </distributionManagement>

    <dependencies>
        <!-- dependencies from OpenOffice -->
        <dependency>
            <groupId>org.openoffice</groupId>
            <artifactId>juh</artifactId>
            <version>${ooffice.version}</version>
        </dependency>
        <dependency>
            <groupId>org.openoffice</groupId>
            <artifactId>jurt</artifactId>
            <version>${ooffice.version}</version>
        </dependency>
        <dependency>
            <groupId>org.openoffice</groupId>
            <artifactId>ridl</artifactId>
            <version>${ooffice.version}</version>
        </dependency>
        <dependency>
            <groupId>org.openoffice</groupId>
            <artifactId>unoil</artifactId>
            <version>${ooffice.version}</version>
        </dependency>

        <dependency>
            <groupId>org.jquantlib</groupId>
            <artifactId>jquantlib</artifactId>
            <version>${project.parent.version}</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.openoffice.dev</groupId>
                <artifactId>maven-ooo-plugin</artifactId>
                <version>1.0</version>
                <configuration>
                    <ooo>${ooffice.app}</ooo>
                    <sdk>${ooffice.sdk}</sdk>
                </configuration>
                <executions>
                    <execution>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>build-idl</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <descriptor>src/main/assembly/dep.xml</descriptor>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <configuration>
                    <archive>
                        <manifestEntries>
                            <RegistrationClassName>org.jquantlib.CentralRegistrationClass</RegistrationClassName>
                        </manifestEntries>
                        <manifestSections>
                            <manifestSection>
                                <name>org/jquantlib/CentralRegistrationHandler.class</name>
                                <manifestEntries>
                                    <!-- //FIXME:: this is probably wrong -->
                                    <RegistrationClasses>org.jquantlib.ooimpl</RegistrationClasses>
                                </manifestEntries>
                            </manifestSection>
                        </manifestSections>
                    </archive>
                </configuration>
            </plugin>
        </plugins>
    </build>

     <properties>
         <ooffice.version>3.1.0</ooffice.version>
         <ooffice.app>/opt/openoffice.org/basis3.1</ooffice.app>
         <ooffice.sdk>/opt/openoffice.org/basis3.1/sdk</ooffice.sdk>
     </properties>

     <profiles>
         <profile>
             <!-- activate this profile and you will be obtaining properties from your settings.xml -->
             <id>settings-ooffice</id>
             <properties>
                 <ooffice.app>${settings.ooffice.app}</ooffice.app>
                 <ooffice.sdk>${settings.ooffice.sdk}</ooffice.sdk>
                 <ooffice.version>${settings.ooffice.version}</ooffice.version>
             </properties>
         </profile>
     </profiles>

</project>


Old Stuff

This are old instructions, still for Netbeans. They are kept here for historical reasons, whilst we move our development environment to Eclipse.


Setting up the Dev-Environment

  1. Get OpenOffice 3.0 or above from here: http://download.openoffice.org/other.html and install it.
  2. Get the OpenOffice SDK 3.0 or above from here: http://download.openoffice.org/3.0.0/sdk.html and install it.
  3. Get Netbeans 6.5 or above from here: http://www.netbeans.org/downloads/ and install it. The "Java SE Version" is sufficient.
  4. Start Netbeans. Under Tools --> Plugins --> Tab: Available Plugins you should find the "OpenOffice.org API Plugin". Install it.
  5. Under Tools --> Options --> Miscellaneous --> OOo Plugin Api you can ensure that the Plugin points to your OpenOffice SDK installation.


Building and Running the Plugin

This are old instructions, still for Netbeans. They are kept here for historical reasons, whilst we move our development environment to Eclipse.

  1. Check out the JQuantlib and the JQAddIn project as described here using your favorite svn client.
  2. Import the JQAddIn project: File --> Import Project ...
  3. Open the JQuantlib project as Maven Project: File --> New Project ... --> Maven --> Maven Project with existing POM file (if there's no Maven entry there, install the Maven plugin the same way you installed the OpenOffice API Plugin).
  4. Right-Click the JQuantlib project --> Build...
  5. Right-Click the JQAddIn project --> Properties ... --> Libraries --> Add Jar/Folder --> Select the "jquantlib-0.1.3-SNAPSHOT-ubber.jar" you built before.

Now everything should be ready and compile. Right click the JQAddIn project and select "Debug and Run Extension in OpenOffice..."


TODOs

  • Linking the JQuantlib Jar to the JQAddIn project is inconvenient since you can't set break points in the JQuantlib code while debugging the AddIn. Unfortunately i don't know how to link projects in Netbeans the "Eclipse way". Please edit the instructions if you know how to do this.
  • We have to agree on package naming and repository location for this project. It's not in the repository yet.


Resources