<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/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.rackspace.cloud.api</groupId>
  <artifactId>rackbook</artifactId>
  <version>1.5</version>
  <packaging>jar</packaging>

  <name>rackspace-oXygen</name>
  <url>http://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <!-- This is the rax-oxygen-rel-plugin project version to be included as the releasenotes-plugin -->
    <rackspace.releasenotes.version>0.0.9</rackspace.releasenotes.version>
  </properties>

  <repositories>
    <repository>
      <id>public.maven.research.rackspace.com</id>
      <name>Rackspace Research</name>
      <url>http://maven.research.rackspacecloud.com/content/groups/aggregate</url>
    </repository>
    
    <repository>
      <id>releases.maven.research.rackspace.com</id>
      <name>Rackspace Research Releases</name>
      <url>http://maven.research.rackspacecloud.com/content/repositories/releases</url>
    </repository>
    
    <repository>
      <id>trancecode.org</id>
      <name>Trance Code Release Repo</name>
      <url>http://maven.trancecode.org/releases/</url>
    </repository>
    
    <repository>
      <id>snapshots.trancecode.org</id>
      <name>Trance Code Snapshot Repo</name>
      <url>http://maven.trancecode.org/snapshots/</url>
    </repository>
  </repositories>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>ro.sync.ecss</groupId>
      <artifactId>dita</artifactId>
      <version>1.0</version>
      <scope>system</scope>
      <systemPath>${project.basedir}/lib/oxygen.jar</systemPath>
    </dependency>
    <dependency>
      <groupId>log4j</groupId>
      <artifactId>log4j</artifactId>
      <version>1.2.15</version>
      <exclusions>
        <exclusion>
          <groupId>com.sun.jmx</groupId>
          <artifactId>jmxri</artifactId>
        </exclusion>
        <exclusion>
          <groupId>com.sun.jdmk</groupId>
          <artifactId>jmxtools</artifactId>
        </exclusion>
        <exclusion>
          <groupId>javax.jms</groupId>
          <artifactId>jms</artifactId>
        </exclusion>
      </exclusions>
    </dependency>
    <dependency>
      <groupId>org.eclipse</groupId>
      <artifactId>jface</artifactId>
      <version>3.2.1-M20060908-1000</version>
    </dependency>
    <dependency>
      <groupId>commons-logging</groupId>
      <artifactId>commons-logging</artifactId>
      <version>1.1.1</version>
    </dependency>
    

    
    
    <!-- SWT dependencies -->
    <dependency>
      <groupId>org.eclipse</groupId>
      <artifactId>swt-gtk-linux-x86</artifactId>
      <version>3.7.1</version>
      <scope>system</scope>
      <systemPath>${project.basedir}/lib/swt/swt-linux32-3.7.1.jar</systemPath>
    </dependency>   
    <dependency>
      <groupId>org.eclipse</groupId>
      <artifactId>swt-gtk-linux-x86_64</artifactId>
      <version>3.7.1</version>
      <scope>system</scope>
      <systemPath>${project.basedir}/lib/swt/swt-linux64-3.7.1.jar</systemPath>
    </dependency>   
    <dependency>
      <groupId>org.eclipse</groupId>
      <artifactId>swt-win32</artifactId>
      <version>3.7.1</version>
      <scope>system</scope>
      <systemPath>${project.basedir}/lib/swt/swt-win32-3.7.1.jar</systemPath>       
    </dependency>
    <dependency>
      <groupId>org.eclipse</groupId>
      <artifactId>swt-win32_64</artifactId>
      <version>3.7.1</version>
      <scope>system</scope>
      <systemPath>${project.basedir}/lib/swt/swt-win64-3.7.1.jar</systemPath>       
    </dependency>   
    <dependency>
      <groupId>org.eclipse</groupId>
      <artifactId>macosx-swt32</artifactId>
      <version>3.7.1</version>
      <scope>system</scope>
      <systemPath>${project.basedir}/lib/swt/swt-mac32-3.7.1.jar</systemPath>      
    </dependency> 
    <dependency>
      <groupId>org.eclipse</groupId>
      <artifactId>macosx-swt32_64</artifactId>
      <version>3.7.1</version>
      <scope>system</scope>
      <systemPath>${project.basedir}/lib/swt/swt-mac64-3.7.1.jar</systemPath>      
    </dependency> 

    <dependency>
      <groupId>com.rackspace.cloud.api</groupId>
      <artifactId>wadl-tools</artifactId>
      <version>1.0.2</version>
      <scope>provided</scope>
    </dependency> 

    <dependency>
      <groupId>com.rackspace.cloud</groupId>
      <artifactId>rax-oxygen-rel-plugin</artifactId>
      <type>zip</type>
      <classifier>bin</classifier>
      <version>${rackspace.releasenotes.version}</version>
    </dependency> 
    
    <dependency>
      <groupId>org.bluestemsoftware.open.maven.tparty</groupId>
      <artifactId>xerces-impl</artifactId>
      <version>2.9.0</version>
    </dependency>
 
  </dependencies>
  
  <scm>
    <connection>scm:git:ssh://git@git-n01.rcloudtech.rackspacecloud.com/rackspace-oxygen.git</connection>
  </scm>
  
  <distributionManagement>
    <repository>
      <id>releases.maven.research.rackspacecloud.com</id>
      
      <name>Rackspace Cloud Research Releases</name>
      <url>http://maven.research.rackspacecloud.com/content/repositories/releases/</url>
    </repository>
    
    <snapshotRepository>
      <id>snapshots.maven.research.rackspacecloud.com</id>
      
      <name>Rackspace Cloud Research Snapshots</name>
      <url>http://maven.research.rackspacecloud.com/content/repositories/snapshots/</url>
    </snapshotRepository>
  </distributionManagement>
   
  
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-antrun-plugin</artifactId>
        <version>1.7</version>
        <executions>
          <execution>
            <phase>generate-sources</phase>
            <configuration>
              <target>
                
                <property name="compile_classpath" refid="maven.compile.classpath" />
                <property name="runtime_classpath" refid="maven.runtime.classpath" />
                <property name="test_classpath" refid="maven.test.classpath" />
                <property name="plugin_classpath" refid="maven.plugin.classpath" />

                <!--
                  Place any Ant task here. You can add anything
                  you can add between <target> and </target> in a
                  build.xml.
                -->

                <property file="build.properties" />
                <!-- Create the target/oxygen folder and target/ and the target/author folder-->
                <mkdir dir="${oxygen.expand.dir}" />
                <mkdir dir="${author.expand.dir}" />
                
                <!-- 
                  oxygen.tar.gz and oxygenAuthor.tar.gz comes from the latest oxygen  
                  download which at the time of the writing of this scriptcan be found  
                  at: http://www.oxygenxml.com/InstData/Editor/All/oxygen.tar.gz  
                -->
                <gunzip src="${oxygen.dir}/oxygen.tar.gz" dest="${oxygen.dir}/oxygen.tar" />
                <untar src="${oxygen.dir}/oxygen.tar" dest="${oxygen.expand.dir}" />
                
                <gunzip src="${author.dir}/oxygenAuthor.tar.gz" dest="${author.dir}/oxygenAuthor.tar" />
                <untar src="${author.dir}/oxygenAuthor.tar" dest="${author.expand.dir}" />                  

                <!-- 
                  Create rackspace-oxygen.jar which has deployer.jar, deployerUtils.jar and serializer.jar classes.
                  These jar files come from oxygen. We have to do this because invoking oxygen's build.xml from 
                  maven results in java classpath issues. This is a bit of a hack, if we can find a way to configure
                  the build.xml we can skip this part
                -->
                <mkdir dir="${temp.dir}" />
                <mkdir dir="${temp.dir}/wadl-tools" />
                <mkdir dir="${temp.author.dir}" />
                <mkdir dir="${temp.deployer.dir}" />
                <mkdir dir="${temp.deployer.author.dir}" />
                <mkdir dir="${temp.deployerutils.dir}" />
                <mkdir dir="${temp.deployerutils.author.dir}" />
                <mkdir dir="${temp.serializer.dir}" />
                <mkdir dir="${temp.serializer.author.dir}" />
                <mkdir dir="${temp.log4j.dir}" />
                <mkdir dir="${temp.log4j.author.dir}" />

                <!-- 
                  Edit the oxygen.jnlp file and add the 
                  <property name="com.oxygenxml.default.options" value="http://host/path/to/default-options.xml" />
                -->

                <xslt in="${oxygen.jnlp.dir}/oxygen.jnlp" out="${temp.dir}/oxygenAuthorBeta0.jnlp" style="${rackspace.dir}/changeoxygenjnlp.xslt">
                  <param name="oxygenversion" expression="${oxygen.version}" />
                  <param name="rackbookversion" expression="${project.version}" />
                </xslt>

                <!-- 
                  Edit the author.jnlp file and add the 
                  <property name="com.oxygenxml.default.options" value="http://host/path/to/default-options.xml" />
                -->
                <xslt in="${author.jnlp.dir}/author.jnlp" out="${temp.dir}/author0.jnlp" style="${rackspace.dir}/changeauthorjnlp.xslt">
                  <param name="oxygenversion" expression="${oxygen.version}" />
                  <param name="rackbookversion" expression="${project.version}" />
                </xslt>
                
                <!--
                  Edit the oxygen packager.properties file is used by oxygen's ant script:
                  target/oxygen/oxygen/tools/jwsPackager/ant which invokes target/oxyge/oxyge/tools/ant/ant
                -->
                <copy file="${oxygen.dir}/packager.properties" tofile="${keystore.copy.dir}/packager.properties" overwrite="true" />
                <copy file="${author.dir}/packager.properties" tofile="${keystore.copy.author.dir}/packager.properties" overwrite="true" />
                
                <echo>copying file: ${oxygen.dir}/build.xml to: ${keystore.copy.dir}/build.xml</echo>
                <!-- 
                  the oxygen/build.xml was modified from the oxygen install oxygen/tools/jwsPackager folder.
                  It had to be modified because invocation of ant via maven resulted in messed up java classpath
                -->
                <copy file="${oxygen.dir}/build.xml" tofile="${keystore.copy.dir}/build.xml" overwrite="true" />
                <copy file="${author.dir}/build.xml" tofile="${keystore.copy.author.dir}/build.xml" overwrite="true" />
                <mkdir dir="${oxygen.expand.dir}/oxygen/frameworks/rackbook" />
                <mkdir dir="${oxygen.expand.dir}/oxygen/frameworks/wadl-tools" />
                <mkdir dir="${author.expand.dir}/oxygenAuthor/frameworks/rackbook" />
                <mkdir dir="${author.expand.dir}/oxygenAuthor/frameworks/wadl-tools" />
                              
                <!-- 
                    Copy the entire contents of rackbook to target/oxygen/oxygen/frameworks
                    and target/author/oxygenAuthor/frameworks
                -->
                <copy todir="${oxygen.expand.dir}/oxygen/frameworks/rackbook">
                  <fileset dir="rackbook" includes="**/*" />
                </copy>
                <copy todir="${author.expand.dir}/oxygenAuthor/frameworks/rackbook">
                  <fileset dir="rackbook" includes="**/*" />
                </copy>

                <copy file="${rackspace.dir}/defaults.xpr" tofile="${oxygen.expand.dir}/oxygen/preferences/defaults.xpr" />
		<copy file="${rackspace.dir}/defaults.xpr" tofile="${author.expand.dir}/oxygenAuthor/preferences/defaults.xpr" />

                <!--
                    We need to get the contents of the wadl-tools dependency folder  
                -->
                <unjar src="${maven.dependency.com.rackspace.cloud.api.wadl-tools.jar.path}" dest="${temp.dir}/wadl-tools" />
                <copy todir="${oxygen.expand.dir}/oxygen/frameworks/wadl-tools">
                  <fileset dir="${temp.dir}/wadl-tools" includes="oxygen/**/*" />
                  <fileset dir="${temp.dir}/wadl-tools" includes="xsd/**/*" />
                  <fileset dir="${temp.dir}/wadl-tools" includes="xsl/**/*" />
                  <fileset dir="${temp.dir}/wadl-tools" includes="*.xsl" />
                  <fileset dir="${temp.dir}/wadl-tools" includes="*.xsd" />
                  <fileset dir="${temp.dir}/wadl-tools" includes="*.sch" />
                  <fileset dir="${temp.dir}/wadl-tools" includes="*." />
                  <fileset dir="${temp.dir}/wadl-tools" includes="wadl.framework" />
                </copy>
                <copy todir="${author.expand.dir}/oxygenAuthor/frameworks/wadl-tools">
                  <fileset dir="${temp.dir}/wadl-tools" includes="oxygen/**/*" />
                  <fileset dir="${temp.dir}/wadl-tools" includes="xsd/**/*" />
                  <fileset dir="${temp.dir}/wadl-tools" includes="xsl/**/*" />
                  <fileset dir="${temp.dir}/wadl-tools" includes="*.xsl" />
                  <fileset dir="${temp.dir}/wadl-tools" includes="*.xsd" />
                  <fileset dir="${temp.dir}/wadl-tools" includes="*.sch" />
                  <fileset dir="${temp.dir}/wadl-tools" includes="*." />
                  <fileset dir="${temp.dir}/wadl-tools" includes="wadl.framework" />
                </copy>
                
		<!-- Copy the release notes plugin to the plugins dir -->
,		<unzip dest="${oxygen.expand.dir}/oxygen/plugins" src="${com.rackspace.cloud:rax-oxygen-rel-plugin:zip:bin}" />
		<unzip dest="${author.expand.dir}/oxygenAuthor/plugins" src="${com.rackspace.cloud:rax-oxygen-rel-plugin:zip:bin}" />
        
		<!-- The plugin directory should be called rackspacereleasenotes  -->
		<move todir="${oxygen.expand.dir}/oxygen/plugins/rackspacereleasenotes">
		  <fileset dir="${oxygen.expand.dir}/oxygen/plugins/rax-oxygen-rel-plugin-${rackspace.releasenotes.version}">
		    <include name="**/*" />
		  </fileset>
		</move>
		<move todir="${author.expand.dir}/oxygenAuthor/plugins/rackspacereleasenotes">
		  <fileset dir="${author.expand.dir}/oxygenAuthor/plugins/rax-oxygen-rel-plugin-${rackspace.releasenotes.version}">
		    <include name="**/*" />
		  </fileset>
		</move>
		<delete dir="${oxygen.expand.dir}/oxygen/plugins/rax-oxygen-rel-plugin-${rackspace.releasenotes.version}" />
		<delete dir="${author.expand.dir}/oxygenAuthor/plugins/rax-oxygen-rel-plugin-${rackspace.releasenotes.version}" />

                <!-- 
                  Copy deployer.jar, deployerUtils.jar, and serializer.jar which are oxygen .jar files and expand
                  the contents to the temp directory
                -->
                <copy file="${keystore.copy.dir}/lib/deployer.jar" tofile="${temp.dir}/deployer.zip" />
                <copy file="${keystore.copy.author.dir}/lib/deployer.jar" tofile="${temp.author.dir}/deployer.zip" />
                
                <copy file="${keystore.copy.dir}/lib/deployerUtils.jar" tofile="${temp.dir}/deployerUtils.zip" />
                <copy file="${keystore.copy.author.dir}/lib/deployerUtils.jar" tofile="${temp.author.dir}/deployerUtils.zip" />
                
                <copy file="${keystore.copy.dir}/lib/serializer.jar" tofile="${temp.dir}/serializer.zip" />
                <copy file="${keystore.copy.author.dir}/lib/serializer.jar" tofile="${temp.author.dir}/serializer.zip" />
                
                <copy file="${keystore.copy.dir}/lib/log4j.jar" tofile="${temp.dir}/log4j.zip" />
                <copy file="${keystore.copy.author.dir}/lib/log4j.jar" tofile="${temp.author.dir}/log4j.zip" />
                
                <unzip src="${temp.dir}/deployer.zip" dest="${temp.deployer.dir}" />
                <unzip src="${temp.author.dir}/deployer.zip" dest="${temp.deployer.author.dir}" />
                
                <unzip src="${temp.dir}/deployerUtils.zip" dest="${temp.deployerutils.dir}" />
                <unzip src="${temp.author.dir}/deployerUtils.zip" dest="${temp.deployerutils.author.dir}" />
                
                <unzip src="${temp.dir}/serializer.zip" dest="${temp.serializer.dir}" />
                <unzip src="${temp.author.dir}/serializer.zip" dest="${temp.serializer.author.dir}" />
                
                <unzip src="${temp.dir}/log4j.zip" dest="${temp.log4j.dir}" />
                <unzip src="${temp.author.dir}/log4j.zip" dest="${temp.log4j.author.dir}" />
                
                <!-- 
                  Copy all the classes in deployerUtils.jar into the expanded deployer folder
                -->
                <copy todir="${temp.deployer.copyto.dir}">
                  <fileset dir="${temp.deployerutils.copy.dir1}" />                
                </copy>
                <copy todir="${temp.deployer.copyto.author.dir}">
                  <fileset dir="${temp.deployerutils.copy.author.dir1}" />                
                </copy>                
                <!-- 
                  Copy all the classes in serializer.jar into the expanded deployer folder
                -->
                <copy todir="${temp.deployer.copyto.base.dir}">
                  <fileset dir="${temp.serializer.copy.dir}" />
                </copy>
                <copy todir="${temp.deployer.copyto.base.author.dir}">
                  <fileset dir="${temp.serializer.copy.author.dir}" />
                </copy>                
                
                <!-- 
                  Copy all the classes in log4j.jar into the expanded deployer folder
                -->
                <copy todir="${temp.log4j.copyto.dir}">
                  <fileset dir="${temp.log4j.copy.dir}" />
                </copy>                
                <copy todir="${temp.log4j.copyto.author.dir}">
                  <fileset dir="${temp.log4j.copy.author.dir}" />
                </copy>                   
                <!-- 
                  Jar up the entire deployer folder and include the MANIFEST.MF which point to the class that 
                  contains the main method via the entry:
                  Main-Class: ro.sync.jws.JwsPackager
                -->
                <echo>Creating jar in: ${temp.dir}/rackspace-oxygen.jar</echo>
                <jar destfile="${temp.dir}/rackspace-oxygen.jar" manifest="${manifest.dir}/${manifest.file}">
                  <fileset dir="${temp.deployer.dir}" />
                </jar>

                <echo>Creating jar in: ${temp.author.dir}/rackspace-author.jar</echo>
                <jar destfile="${temp.author.dir}/rackspace-author.jar" manifest="${manifest.dir}/${manifest.file}">
                  <fileset dir="${temp.deployer.author.dir}" />
                </jar>
                <!--
                  Make a copy of the rackspace-oxygen.jar, target/oxygen/oxygen/tools/jwsPackager/build.xml refers to this .jar  
                -->
                <copy file="${temp.dir}/rackspace-oxygen.jar" tofile="${keystore.copy.dir}/lib/rackspace-oxygen.jar" /> 
                <copy file="${temp.author.dir}/rackspace-author.jar" tofile="${keystore.copy.author.dir}/lib/rackspace-author.jar" />
                
                <echo>copying ${oxygen.dir}/ant to: ${keystore.copy.dir}/ant</echo>
                <copy file="${oxygen.dir}/ant" tofile="${keystore.copy.dir}/ant" overwrite="true" />
                <chmod file="${keystore.copy.dir}/ant" perm="ugo+x" />

                <echo>copying ${oxygen.author.dir}/antAuthor to: ${keystore.copy.author.dir}/antAuthor</echo>
                <copy file="${author.dir}/antAuthor" tofile="${keystore.copy.author.dir}/antAuthor" overwrite="true" />
                <chmod file="${keystore.copy.author.dir}/antAuthor" perm="ugo+x" />
                <!-- 
                  Replace the oxygen.jnlp file with the new version with the inserted property
                -->
                <copy file="${temp.dir}/oxygen.jnlp" tofile="${oxygen.jnlp.dir}/oxygen.jnlp" overwrite="true" />
                <copy file="${temp.author.dir}/author.jnlp" tofile="${author.jnlp.dir}/author.jnlp" overwrite="true" />
               
                <!--
                  the ant shell script is from oxygen. The original shell script sets the environment variable via:
                  export ANT_EXEC=..\ant\bin\ant
                  If the shell script is invoked directly from a unix shell then there are no problems, but when invoking
                  it via maven, as we do below, the value of ANT_EXEC becomes:
                  antbinant
                  Therefore I changed this to:
                  export ANT_EXEC=target/oxygen/oxygen/tools/ant/bin/ant
                  Also, the original invocation of the ant build was:
                  sh $ANT_EXEC $@ 
                  Once again, direct invocation from a unix shell works fine, but when invoked from maven, I had to indicate 
                  the build.xml location via:
                  sh $ANT_EXEC $@ -buildfile target/oxygen/oxygen/tools/jwsPackager/build.xml
                -->
                <exec executable="${keystore.copy.dir}/ant" />
                
                <exec executable="${keystore.copy.author.dir}/antAuthor" />
                <!--
                  oxygenJWS.zip contains all the needed files for java web start
                -->
                <copy file="${keystore.copy.dir}/dist/InstData/oxygenJWS.zip" tofile="${oxygen.expand.dir}/oxygenJWS.zip" />
                <copy file="${keystore.copy.author.dir}/dist-author/InstData/authorJWS.zip" tofile="${author.expand.dir}/authorJWS.zip" />
                
                <!-- 
                  clean up the build by deleting the temp folder and oxygen.tar folder
           
                  <delete dir="${temp.dir}" />
                  <delete dir="${oxygen.expand.dir}/oxygenAuthor" />
                  <delete dir="${author.expand.dir}/oxygen" />
                -->
                
                <delete file="${oxygen.dir}/oxygen.tar" />
                <delete file="${author.dir}/oxygenAuthor.tar" />
                <delete dir="${temp.dir}/wadl-tools" />
                <delete dir="target/antrun" />
                <delete dir="target/classes" />
                <delete file="${temp.dir}/author0.jnlp" /> 
                <delete file="${temp.dir}/oxygenAuthorBeta0.jnlp" />                
 
              </target>
            </configuration>
            <goals>
              <goal>run</goal>
            </goals>
          </execution>         
        </executions>
      </plugin>
      
      
    </plugins> 
    <resources>
      <resource>
        <directory>target/oxygen</directory>
        <includes>
          <include>oxygenJWS.zip</include>
        </includes>
      </resource>

      <resource>
        <directory>target/author</directory>
        <includes>
          <include>authorJWS.zip</include>
        </includes>
      </resource>
    </resources>
  </build>
  
</project>
