<?xml version="1.0" encoding="UTF-8"?>

<!--
 * See the NOTICE file distributed with this work for additional
 * information regarding copyright ownership.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * 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
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see http://www.gnu.org/licenses/
-->

<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>
  <parent>
    <groupId>org.phenomecentral</groupId>
    <artifactId>phenomecentral-parent</artifactId>
    <version>1.0-rc-2</version>
  </parent>
  <artifactId>database-zip</artifactId>
  <name>PhenomeCentral - HSQLDB Database</name>
  <packaging>pom</packaging>
  <description>ZIP packaging of PhenomeCentral, stored as an HSQLDB database dump.</description>
  <properties>
    <xwiki.db.connection.url>jdbc:hsqldb:file:${project.build.directory}/data/database/xwiki_db;shutdown=true</xwiki.db.connection.url>
  </properties>
  <!-- Required for the exec:exec plugin execution below. Doesn't seem to work as an exec plugin
       dependency -->
  <dependencies>
    <dependency>
      <groupId>org.hsqldb</groupId>
      <artifactId>hsqldb</artifactId>
      <version>2.3.3</version>
    </dependency>
    <dependency>
      <groupId>${project.groupId}</groupId>
      <artifactId>phenomecentral-ui</artifactId>
      <version>${project.version}</version>
      <type>xar</type>
      <scope>provided</scope>
    </dependency>
  </dependencies>
  <build>
    <plugins>
      <!-- Step 1: Copy and filter the Hibernate config file which will be used by the packager
           plugin -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-remote-resources-plugin</artifactId>
        <executions>
          <execution>
            <id>xwiki-platform-tool-configuration-resources</id>
            <phase>process-resources</phase>
            <goals>
              <goal>process</goal>
            </goals>
            <configuration>
              <resourceBundles>
                <resourceBundle>org.xwiki.platform:xwiki-platform-tool-configuration-resources:${xwiki.version}</resourceBundle>
              </resourceBundles>
              <properties>
                <xwikiDbConnectionUrl>jdbc:hsqldb:file:${project.build.directory}/data/database/xwiki_db;shutdown=true;hsqldb.cache_size=50000;hsqldb.script_format=3;hsqldb.nio_max_size=512;hsqldb.lob_file_scale=16;hsqldb.default_table_type=cached;hsqldb.tx=mvcc</xwikiDbConnectionUrl>
                <xwikiDbConnectionUsername>sa</xwikiDbConnectionUsername>
                <xwikiDbConnectionPassword />
                <xwikiDbConnectionDriverClass>org.hsqldb.jdbcDriver</xwikiDbConnectionDriverClass>
                <xwikiDbDialect>org.hibernate.dialect.HSQLDialect</xwikiDbDialect>
                <xwikiDbHbmXwiki>xwiki.hbm.xml</xwikiDbHbmXwiki>
                <xwikiDbHbmFeeds>feeds.hbm.xml</xwikiDbHbmFeeds>
                <xwikiDbHbmCommonExtraMappings>activitystream.hbm.xml</xwikiDbHbmCommonExtraMappings>
                <xwikiCfgVirtual>0</xwikiCfgVirtual>
                <xwikiCfgVirtualUsepath>0</xwikiCfgVirtualUsepath>
                <xwikiCfgEditCommentMandatory>0</xwikiCfgEditCommentMandatory>
                <xwikiCfgDefaultSkin>colibri</xwikiCfgDefaultSkin>
                <xwikiCfgDefaultBaseSkin>colibri</xwikiCfgDefaultBaseSkin>
                <xwikiCfgEncoding>UTF-8</xwikiCfgEncoding>
                <xwikiCfgAdditionalProperties>
xwiki.plugin.watchlist.automaticwatch=none
xwiki.authentication.group.allgroupimplicit=1
xwiki.backlinks=0
xwiki.monitor=0
xwiki.store.attachment.hint=file
xwiki.store.attachment.versioning.hint=file
xwiki.store.attachment.recyclebin.hint=file
                </xwikiCfgAdditionalProperties>
              </properties>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <!-- Step 2: Expand the XAR file -->
      <plugin>
        <groupId>org.xwiki.commons</groupId>
        <artifactId>xwiki-commons-tool-xar-plugin</artifactId>
      </plugin>
      <!-- Step 3: Import the XAR content into the Database -->
      <plugin>
        <groupId>org.phenotips</groupId>
        <artifactId>phenotips-packager-maven-plugin</artifactId>
        <configuration>
          <hibernateConfig>
            ${project.build.directory}/maven-shared-archive-resources/hibernate.cfg.xml
          </hibernateConfig>
          <xwikiConfig>
            ${project.build.directory}/maven-shared-archive-resources/xwiki.cfg
          </xwikiConfig>
        </configuration>
        <dependencies>
          <dependency>
            <groupId>org.hsqldb</groupId>
            <artifactId>hsqldb</artifactId>
            <version>2.3.3</version>
          </dependency>
          <!-- Filesystem attachment storage -->
          <dependency>
            <groupId>org.xwiki.platform</groupId>
            <artifactId>xwiki-platform-store-filesystem-attachments</artifactId>
            <version>${xwiki.version}</version>
            <scope>runtime</scope>
          </dependency>
          <!-- Bump the version of some dependencies used by the plugin-->
          <dependency>
            <groupId>org.xwiki.commons</groupId>
            <artifactId>xwiki-commons-extension-api</artifactId>
            <version>${xwiki.version}</version>
            <scope>runtime</scope>
          </dependency>
          <dependency>
            <groupId>org.xwiki.platform</groupId>
            <artifactId>xwiki-platform-oldcore</artifactId>
            <version>${xwiki.version}</version>
            <scope>runtime</scope>
          </dependency>
          <!-- Add dependencies that have their own set of migrators, so that a new database doesn't trigger migrators. -->
          <dependency>
            <groupId>org.xwiki.platform</groupId>
            <artifactId>xwiki-platform-activitystream-api</artifactId>
            <version>${xwiki.version}</version>
          </dependency>
          <dependency>
            <groupId>org.phenotips</groupId>
            <artifactId>application-configuration-migrations</artifactId>
            <version>${phenotips.version}</version>
          </dependency>
          <dependency>
            <groupId>org.phenotips</groupId>
            <artifactId>patient-data-migrations</artifactId>
            <version>${phenotips.version}</version>
          </dependency>
          <dependency>
            <groupId>org.phenotips</groupId>
            <artifactId>patient-access-rules-migrations</artifactId>
            <version>${phenotips.version}</version>
          </dependency>
          <dependency>
            <groupId>org.phenotips</groupId>
            <artifactId>patient-measurements-migrations</artifactId>
            <version>${phenotips.version}</version>
          </dependency>
          <dependency>
            <groupId>org.phenotips</groupId>
            <artifactId>patient-data-default-impl</artifactId>
            <version>${phenotips.version}</version>
            <exclusions>
              <exclusion>
                <groupId>org.xwiki.platform</groupId>
                <artifactId>xwiki-platform-search-solr-query</artifactId>
              </exclusion>
            </exclusions>
          </dependency>
          <!-- WikiMacro classes are automatically generated. -->
          <dependency>
            <groupId>org.xwiki.platform</groupId>
            <artifactId>xwiki-platform-rendering-wikimacro-store</artifactId>
            <version>${xwiki.version}</version>
          </dependency>
          <!-- Needed by the distribution manager, which doesn't declare it as a dependency -->
          <dependency>
            <groupId>org.xwiki.platform</groupId>
            <artifactId>xwiki-platform-wiki-default</artifactId>
            <version>${xwiki.version}</version>
          </dependency>
          <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>3.0.1</version>
          </dependency>
        </dependencies>
        <executions>
          <execution>
            <phase>prepare-package</phase>
            <goals>
              <goal>import</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      <!-- Step 4: Zip the generated database -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-assembly-plugin</artifactId>
        <configuration>
          <appendAssemblyId>false</appendAssemblyId>
          <descriptors>
            <descriptor>${basedir}/src/assemble/data.xml</descriptor>
          </descriptors>
        </configuration>
        <executions>
          <execution>
            <phase>package</phase>
            <goals>
              <goal>single</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</project>
