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

<!--
 * See the NOTICE file distributed with this work for additional
 * information regarding copyright ownership.
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This software 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-->

<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.xwiki.platform</groupId>
    <artifactId>xwiki-platform-distribution-debian-solr</artifactId>
    <version>16.9.0</version>
  </parent>
  <artifactId>xwiki-platform-distribution-debian-solr-cores</artifactId>
  <packaging>pom</packaging>
  <name>XWiki Platform - Distribution - Debian - Solr - Cores</name>
  <description>Install a Solr core for ${debian.solr.core} in the right location (based on Solr default setup)</description>
  <properties>
    <data.path>${project.build.directory}/data</data.path>

    <debian.description>
 XWiki is a free wiki software platform written in Java with a design emphasis
 on extensibility.
 .
 This package contains a pre configured Solr core for XWiki ${debian.solr.core} to be used in a standalone Solr setup.
    </debian.description>

    <debian.package.core>${debian.xwiki.core}</debian.package.core>
    <debian.package>xwiki-solr${solr.major.version}-${debian.package.core}</debian.package>

    <debian.solr.package>xwiki-platform-search-solr-server-core-minimal</debian.solr.package>

    <debian.solr.core>xwiki_${debian.xwiki.core}_${solr.major.version}</debian.solr.core>

    <debian.solr.var>/var/solr</debian.solr.var>
    <debian.solr.var.data>${debian.solr.var}/data</debian.solr.var.data>
    <debian.solr.var.data.core>${debian.solr.var.data}/${debian.solr.core}</debian.solr.var.data.core>

    <debian.solr.var.oldsolr8core>${debian.solr.var.data}/xwiki_${debian.xwiki.core}</debian.solr.var.oldsolr8core>
    <debian.xwiki.var.oldsolr8core>${debian.xwiki.var}/solr/${debian.xwiki.core}</debian.xwiki.var.oldsolr8core>
    <debian.xwiki.var.oldsolr9corecore>${debian.xwiki.var}/solr/${solr.major.version}/${debian.xwiki.core}</debian.xwiki.var.oldsolr9corecore>

    <debian.postinst>
#!/bin/sh

set -e
#set -x

# By default, Solr 9 is not allowed to access files outside of ${debian.solr.var} (even through links) which unfortunately was the case of the XWiki cores before 16.4.0.

# Move the core files stored at the Solr 8 location (XWiki &lt; 16.2.0)
if [ -d ${debian.xwiki.var.oldsolr8core} ]; then
  # Remove the link to the old location
  rm -f ${debian.solr.var.oldsolr8core}
  # And replace it with the actual core
  mv ${debian.xwiki.var.oldsolr8core} ${debian.solr.var.oldsolr8core}
fi

# Migrate the core files stored at the previous Solr 9 location (XWiki 16.2.0 and 16.3.0)
if [ -d ${debian.xwiki.var.oldsolr9corecore} ]; then
  # Move the data
  mv ${debian.xwiki.var.oldsolr9corecore}/data ${debian.solr.var.data.core}/
  # Replace the default schema with the previous one (so that it matches the data)
  mv -f ${debian.xwiki.var.oldsolr9corecore}/conf/managed-schema ${debian.solr.var.data.core}/conf/managed-schema
  # Delete what remains of the old core location
  rm -rf ${debian.xwiki.var.oldsolr9corecore}
fi

# Make the default solr user ("solr") owner of the core files
if id "solr" &gt;/dev/null 2&gt;&amp;1; then
  chown -R solr:solr ${debian.solr.var.data.core}
else
  echo "No system user with name 'solr' could be found. Please make the user which runs Solr is the owner of the folder ${debian.solr.var.data.core} and its content."
fi
    </debian.postinst>
    <debian.postrm>
#!/bin/sh

set -e
#set -x

if [ "$1" = "purge"  ]; then
    rm -rf ${debian.solr.var.data.core}
fi
    </debian.postrm>
  </properties>
  <modules>
    <module>xwiki-platform-distribution-debian-solr-core-events</module>
    <module>xwiki-platform-distribution-debian-solr-core-extension_index</module>
    <module>xwiki-platform-distribution-debian-solr-core-ratings</module>
    <module>xwiki-platform-distribution-debian-solr-core-search</module>
  </modules>
  <dependencies>
    <dependency>
      <groupId>org.xwiki.platform</groupId>
      <artifactId>${debian.solr.package}</artifactId>
      <version>16.9.0</version>
      <type>zip</type>
      <scope>provided</scope>
    </dependency>
  </dependencies>
  <build>
    <plugins>
      <!-- Unpack the data -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
        <executions>
            <execution>
              <id>unzip-application</id>
              <phase>process-resources</phase>
              <goals>
                <goal>unpack</goal>
              </goals>
              <configuration>
                <artifactItems>
                  <artifactItem>
                    <groupId>org.xwiki.platform</groupId>
                    <artifactId>${debian.solr.package}</artifactId>
                    <version>${platform.version}</version>
                    <type>zip</type>
                  </artifactItem>
                </artifactItems>
                <outputDirectory>${data.path}</outputDirectory>
              </configuration>
            </execution>
          </executions>
      </plugin>
      <!-- Prepare configuration -->
      <plugin>
        <groupId>org.xwiki.commons</groupId>
        <artifactId>xwiki-commons-tool-remote-resource-plugin</artifactId>
        <version>${commons.version}</version>
      </plugin>
    </plugins>
    <pluginManagement>
      <plugins>
        <!-- Produce deb package -->
        <plugin>
          <artifactId>jdeb</artifactId>
          <groupId>org.vafer</groupId>
          <configuration>
            <dataSet combine.children="append">
              <data>
                <src>${data.path}</src>
                <type>directory</type>
                <mapper>
                  <type>perm</type>
                  <prefix>${debian.solr.var.data.core}</prefix>
                </mapper>
                <conffile>true</conffile>
              </data>
            </dataSet>
          </configuration>
        </plugin>
      </plugins>
    </pluginManagement>
  </build>
</project>
