<?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-6</version>
  </parent>

  <artifactId>phenomecentral-rpm</artifactId>
  <packaging>rpm</packaging>
  <name>PhenomeCentral - RPM Distribution</name>
  <description>Distribution containing PhenomeCentral deployed under Tomcat, with mariadb for storage, as a RedHat (.rpm) package.</description>

  <properties>
    <pcwar.path>${project.build.directory}/pcwar</pcwar.path>
    <data.path>${project.build.directory}/phenotips</data.path>
    <db.path>${data.path}/data</db.path>
    <xwiki.properties.environment.permanentDirectory>/var/lib/phenotips/data</xwiki.properties.environment.permanentDirectory>
  </properties>

  <dependencies>
    <dependency>
      <groupId>${project.groupId}</groupId>
      <artifactId>phenomecentral-war</artifactId>
      <version>${project.version}</version>
      <type>war</type>
    </dependency>

    <dependency>
      <groupId>org.phenotips</groupId>
      <artifactId>solr-configuration</artifactId>
      <version>${phenotips.version}</version>
      <type>jar</type>
      <optional>true</optional>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <!-- Unpack the war -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
        <executions>
          <execution>
            <id>unzip-phenomecentral</id>
            <phase>process-resources</phase>
            <goals>
              <goal>unpack</goal>
            </goals>
            <configuration>
              <artifactItems>
                <artifactItem>
                  <groupId>${project.groupId}</groupId>
                  <artifactId>phenomecentral-war</artifactId>
                  <version>${project.version}</version>
                  <type>war</type>
                </artifactItem>
              </artifactItems>
              <excludes>**\/xwiki.cfg,**/xwiki.properties,**/hibernate.cfg.xml</excludes>
              <outputDirectory>${pcwar.path}</outputDirectory>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <!-- Prepare configuration -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-remote-resources-plugin</artifactId>
        <executions>
          <execution>
            <id>xwiki-configuration-resources</id>
          </execution>
          <execution>
            <id>xwiki-platform-tool-configuration-resources</id>
            <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:${environment.permanentDirectory}/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>instance.hbm.xml</xwikiDbHbmCommonExtraMappings>
                <xwikiCfgPlugins>\
  com.xpn.xwiki.monitor.api.MonitorPlugin,\
  com.xpn.xwiki.plugin.skinx.JsSkinExtensionPlugin,\
  com.xpn.xwiki.plugin.skinx.JsSkinFileExtensionPlugin,\
  com.xpn.xwiki.plugin.skinx.JsResourceSkinExtensionPlugin,\
  com.xpn.xwiki.plugin.skinx.CssSkinExtensionPlugin,\
  com.xpn.xwiki.plugin.skinx.CssSkinFileExtensionPlugin,\
  com.xpn.xwiki.plugin.skinx.CssResourceSkinExtensionPlugin,\
  com.xpn.xwiki.plugin.skinx.LinkExtensionPlugin,\
  com.xpn.xwiki.plugin.mail.MailPlugin,\
  com.xpn.xwiki.plugin.packaging.PackagePlugin,\
  com.xpn.xwiki.plugin.svg.SVGPlugin,\
  com.xpn.xwiki.plugin.fileupload.FileUploadPlugin,\
  com.xpn.xwiki.plugin.image.ImagePlugin,\
  com.xpn.xwiki.plugin.zipexplorer.ZipExplorerPlugin,\
  com.xpn.xwiki.plugin.diff.DiffPlugin,\
  com.xpn.xwiki.plugin.rightsmanager.RightsManagerPlugin,\
  com.xpn.xwiki.plugin.jodatime.JodaTimePlugin,\
  com.xpn.xwiki.plugin.mailsender.MailSenderPlugin</xwikiCfgPlugins>
                <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.authentication.rightsclass=org.phenotips.security.authorization.ModularRightServiceImpl
xwiki.section.edit=0
xwiki.backlinks=0
xwiki.showviewaction=0
xwiki.defaultweb=data
xwiki.usedefaultweb=1
xwiki.usedefaultaction=0
xwiki.monitor=0
xwiki.authentication.loginpage=/PhenomeCentral/login
xwiki.authentication.loginsubmitpage=/loginsubmit/PhenomeCentral/login
xwiki.store.attachment.hint=file
xwiki.store.attachment.versioning.hint=file
xwiki.store.attachment.recyclebin.hint=file
                </xwikiCfgAdditionalProperties>
                <xwikiPropertiesEnvironmentPermanentDirectory>/var/lib/phenotips/</xwikiPropertiesEnvironmentPermanentDirectory>
                <xwikiPropertiesAdditionalProperties>
model.reference.default.space=data
extension.repositories=maven-central:maven:https://nexus.phenotips.org/nexus/content/groups/public/
extension.repositories=maven-phenotips:maven:https://nexus.phenotips.org/nexus/content/repositories/releases/
extension.repositories=phenotips.org:xwiki:https://phenotips.org/rest/
rendering.transformations=macro
activeinstalls.pingURL=https://stats.phenotips.org
activeinstalls.ipFetchURL=https://phenotips.org/get/Stats/Id
                </xwikiPropertiesAdditionalProperties>
              </properties>
            </configuration>
          </execution>
        </executions>
      </plugin>

      <!-- Produce the RPM -->
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>rpm-maven-plugin</artifactId>
        <version>2.1.5</version>
        <extensions>true</extensions>
        <configuration>
          <name>phenomecentral</name>
          <summary>The PhenomeCentral server packaged for Tomcat and mariadb</summary>
          <description>PhenomeCentral is a repository for clinicians and scientists working in the rare disorder community. PhenomeCentral encourages global scientific collaboration while respecting the privacy of patients profiled in this centralized database. Once users enter their patients' data, they are connected to other patient profiles within PhenomeCentral that share similar phenotypes and genotypes.</description>
          <packager>Centre for Computational Medicine, Hospital for Sick Children (support@phenomecentral.org)</packager>
          <license>AGPL 3.0</license>
          <group>Applications/Science</group>
          <icon>src/main/resources/phenomecentral.gif</icon>
          <defaultDirmode>750</defaultDirmode>
          <defaultFilemode>644</defaultFilemode>
          <defaultUsername>tomcat</defaultUsername>
          <defaultGroupname>tomcat</defaultGroupname>
          <requires>
            <require>java &gt;= 0:1.8.0</require>
            <require>tomcat</require>
            <require>unzip</require>
            <require>bc</require>
            <require>wget</require>
            <require>mariadb-server</require>
          </requires>
          <mappings>
            <!-- Copy the main PhenomeCentral webapp -->
            <mapping>
              <directory>/var/lib/phenotips/webapp</directory>
              <sources>
                <source>
                  <location>${pcwar.path}</location>
                </source>
              </sources>
            </mapping>
            <!-- Copy the custom PhenomeCentral/PhenoTips/XWiki configuration files into the webapp -->
            <mapping>
              <directory>/var/lib/phenotips/webapp/WEB-INF</directory>
              <configuration>noreplace</configuration>
              <directoryIncluded>false</directoryIncluded>
              <sources>
                <source>
                  <location>${project.build.outputDirectory}/</location>
                  <includes>
                    <include>xwiki.cfg</include>
                    <include>xwiki.properties</include>
                    <include>hibernate.cfg.xml</include>
                  </includes>
                </source>
              </sources>
            </mapping>
            <!-- Copy the data dependencies into the "next" directory for optional unpacking when first installing this package -->
            <mapping>
              <directory>/var/lib/phenotips/next</directory>
              <dependency>
                <includes>
                  <include>org.phenotips:solr-configuration</include>
                </includes>
              </dependency>
            </mapping>
            <!-- Copy the webapp descriptor -->
            <mapping>
              <directory>/etc/tomcat/Catalina/localhost</directory>
              <directoryIncluded>false</directoryIncluded>
              <sources>
                <source>
                  <location>${project.build.outputDirectory}/context.xml</location>
                  <destination>ROOT.xml</destination>
                </source>
              </sources>
            </mapping>
            <!-- Copy the exomiser scripts -->
            <mapping>
              <directory>/var/lib/exomiser/scripts</directory>
              <directoryIncluded>false</directoryIncluded>
              <sources>
                <source>
                  <location>src/main/resources/exomiser_cron.sh</location>
                </source>
                <source>
                  <location>src/main/resources/exomiser_cron.py</location>
                </source>
                <source>
                  <location>src/main/resources/exomiser_settings.txt</location>
                </source>
              </sources>
            </mapping>
            <!-- Install the exomiser cron -->
            <mapping>
              <directory>/etc/cron.d</directory>
              <directoryIncluded>false</directoryIncluded>
              <sources>
                <source>
                  <location>src/main/resources/exomiser.cron</location>
                  <destination>exomiser</destination>
                </source>
              </sources>
            </mapping>
            <!-- Copy the exomiser configuration -->
            <mapping>
              <directory>/var/lib/exomiser/scripts</directory>
              <configuration>noreplace</configuration>
              <directoryIncluded>false</directoryIncluded>
              <sources>
                <source>
                  <location>src/main/resources/exomiser.credentials</location>
                </source>
              </sources>
            </mapping>
          </mappings>
          <preinstallScriptlet>
            <scriptFile>src/main/scripts/preinstall</scriptFile>
            <fileEncoding>utf-8</fileEncoding>
          </preinstallScriptlet>
          <postinstallScriptlet>
            <scriptFile>src/main/scripts/postinstall</scriptFile>
            <fileEncoding>utf-8</fileEncoding>
          </postinstallScriptlet>
          <postremoveScriptlet>
            <scriptFile>src/main/scripts/postremove</scriptFile>
            <fileEncoding>utf-8</fileEncoding>
          </postremoveScriptlet>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>
