<?xml version="1.0" encoding="UTF-8"?>
<!--
  ~ Copyright 2015, Stratio.
  ~
  ~ Licensed to STRATIO (C) under one or more contributor license agreements.
  ~ See the NOTICE file distributed with this work for additional information
  ~ regarding copyright ownership.  The STRATIO (C) licenses this file
  ~ to you under the Apache License, Version 2.0 (the
  ~ "License"); you may not use this file except in compliance
  ~ with the License.  You may obtain a copy of the License at
  ~
  ~   http://www.apache.org/licenses/LICENSE-2.0
  ~
  ~ Unless required by applicable law or agreed to in writing,
  ~ software distributed under the License is distributed on an
  ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  ~ KIND, either express or implied.  See the License for the
  ~ specific language governing permissions and limitations
  ~ under the License.
  -->
<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>

    <parent>
        <groupId>com.instaclustr</groupId>
        <artifactId>cassandra-lucene-index-parent</artifactId>
        <version>4.0.0-1.0.0</version>
        <relativePath>../pom.xml</relativePath>
    </parent>

    <artifactId>cassandra-lucene-index-plugin</artifactId>
    <name>Cassandra Lucene Index plugin</name>
    <description>Cassandra Lucene Index plugin</description>

    <packaging>jar</packaging>

    <properties>
        <version.snowball-stemmer>1.3.0.581.1</version.snowball-stemmer>
        <version.findbugs>3.0.1</version.findbugs>
        <version.jdeb>1.8</version.jdeb>
        <version.rpm>1.5.0</version.rpm>
        <version.scala.maven.plugin>4.4.0</version.scala.maven.plugin>
        <version.scala>2.13.1</version.scala>
        <outputDirectory>${project.build.directory}</outputDirectory>
        <maintainer>smiklosovic at apache dot org</maintainer>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.scala-lang</groupId>
            <artifactId>scala-library</artifactId>
            <version>${scala.version}</version>
        </dependency>
        <dependency>
            <groupId>com.typesafe.scala-logging</groupId>
            <artifactId>scala-logging_${scala.binary.version}</artifactId>
            <version>${scala.logging.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.cassandra</groupId>
            <artifactId>cassandra-all</artifactId>
            <version>${cassandra.version}</version>
        </dependency>
        <dependency>
            <groupId>com.github.rholder</groupId>
            <artifactId>snowball-stemmer</artifactId>
            <version>${version.snowball-stemmer}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.lucene</groupId>
            <artifactId>lucene-core</artifactId>
            <version>${lucene.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.lucene</groupId>
            <artifactId>lucene-analyzers-common</artifactId>
            <version>${lucene.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.lucene</groupId>
            <artifactId>lucene-spatial</artifactId>
            <version>${lucene.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.lucene</groupId>
            <artifactId>lucene-queryparser</artifactId>
            <version>${lucene.version}</version>
        </dependency>
        <dependency>
            <groupId>com.vividsolutions</groupId>
            <artifactId>jts-core</artifactId>
            <version>${jts.version}</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-core</artifactId>
            <version>${jackson.core.version}</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>${jackson.databind.version}</version>
        </dependency>
        <dependency>
            <groupId>javax.validation</groupId>
            <artifactId>validation-api</artifactId>
            <version>${validation.version}</version>
        </dependency>
        <dependency>
            <groupId>com.google.code.findbugs</groupId>
            <artifactId>jsr305</artifactId>
            <version>${version.findbugs}</version>
        </dependency>
        <!-- test -->
        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-all</artifactId>
            <version>${mockito.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>${junit.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.scalatest</groupId>
            <artifactId>scalatest_${scala.binary.version}</artifactId>
            <version>${scalatest.version}</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>net.alchim31.maven</groupId>
                <artifactId>scala-maven-plugin</artifactId>
                <version>${version.scala.maven.plugin}</version>
                <configuration>
                    <args>
                        <arg>-nowarn</arg>
                    </args>
                    <scalaVersion>${version.scala}</scalaVersion>
                </configuration>
                <executions>
                    <execution>
                        <id>scala-compile-first</id>
                        <phase>process-resources</phase>
                        <goals>
                            <goal>add-source</goal>
                            <goal>compile</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>scala-test-compile</id>
                        <phase>process-test-resources</phase>
                        <goals>
                            <goal>add-source</goal>
                            <goal>testCompile</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>${maven.shade.plugin.version}</version>
                <configuration>
                    <artifactSet>
                        <includes>
                            <include>org.scala-lang:*</include>
                            <include>com.typesafe.scala-logging:*</include>
                            <include>org.apache.lucene:*</include>
                            <include>com.spatial4j:*</include>
                            <include>com.github.rholder:*</include>
                            <include>com.fasterxml.jackson.core:*</include>
                        </includes>
                    </artifactSet>
                    <createDependencyReducedPom>false</createDependencyReducedPom>
                </configuration>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>${maven.jar.plugin.version}</version>
                <configuration>
                    <outputDirectory>${outputDirectory}</outputDirectory>
                    <archive>
                        <manifest>
                            <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
                            <addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
        </plugins>
    </build>
    <profiles>
        <profile>
            <id>deb</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.vafer</groupId>
                        <artifactId>jdeb</artifactId>
                        <version>${version.jdeb}</version>
                        <executions>
                            <execution>
                                <phase>package</phase>
                                <goals>
                                    <goal>jdeb</goal>
                                </goals>
                                <configuration>
                                    <name>${project.artifactId}</name>
                                    <deb>${outputDirectory}/[[name]]_${project.version}.deb</deb>
                                    <dataSet>
                                        <data>
                                            <src>${outputDirectory}/${project.build.finalName}.jar</src>
                                            <type>file</type>
                                            <mapper>
                                                <type>perm</type>
                                                <prefix>/usr/share/cassandra/lib</prefix>
                                            </mapper>
                                        </data>
                                    </dataSet>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <profile>
            <id>rpm</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>de.dentrassi.maven</groupId>
                        <artifactId>rpm</artifactId>
                        <version>${version.rpm}</version>
                        <executions>
                            <execution>
                                <phase>package</phase>
                                <goals>
                                    <goal>rpm</goal>
                                </goals>
                                <configuration>
                                    <packageName>${project.artifactId}</packageName>
                                    <group>Applications/Databases</group>
                                    <packager>${maintainer}</packager>
                                    <skipSigning>true</skipSigning>
                                    <entries>
                                        <entry>
                                            <name>/usr/share/cassandra/lib/${project.build.finalName}.jar</name>
                                            <file>${outputDirectory}/${project.build.finalName}.jar</file>
                                        </entry>
                                    </entries>
                                    <targetDir>${outputDirectory}</targetDir>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <profile>
            <id>patch</id>
            <properties>
                <cassandra_home>${project.build.directory}/apache-cassandra-${cassandra.version}</cassandra_home>
            </properties>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-antrun-plugin</artifactId>
                        <version>1.7</version>
                        <executions>
                            <execution>
                                <phase>package</phase>
                                <configuration>
                                    <target>
                                        <delete verbose="true">
                                            <fileset dir="${cassandra_home}/lib" includes="${project.artifactId}*.jar"/>
                                        </delete>
                                        <copy file="${project.build.directory}/${project.build.finalName}.jar"
                                              toFile="${cassandra_home}/lib/${project.build.finalName}.jar"/>

                                    </target>
                                </configuration>
                                <goals>
                                    <goal>run</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <profile>
            <id>download_and_patch</id>
            <properties>
                <cassandra_home>${project.build.directory}/apache-cassandra-${cassandra.version}</cassandra_home>
            </properties>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-antrun-plugin</artifactId>
                        <version>1.7</version>
                        <executions>
                            <execution>
                                <phase>package</phase>
                                <configuration>
                                    <target>
                                        <echo message="Downloading Apache Cassandra"/>
                                        <get src="http://www.us.apache.org/dist/cassandra/${cassandra.version}/apache-cassandra-${cassandra.version}-bin.tar.gz"
                                             dest="${project.build.directory}/apache-cassandra-${cassandra.version}-bin.tar.gz"/>
                                        <echo message="Uncompressing Apache Cassandra"/>
                                        <gunzip src="${project.build.directory}/apache-cassandra-${cassandra.version}-bin.tar.gz"
                                                dest="${project.build.directory}/apache-cassandra-${cassandra.version}-bin.tar"/>
                                        <delete file="${project.build.directory}/apache-cassandra-${cassandra.version}-bin.tar.gz"/>
                                        <untar src="${project.build.directory}/apache-cassandra-${cassandra.version}-bin.tar"
                                               dest="${project.build.directory}"/>
                                        <delete file="${project.build.directory}/apache-cassandra-${cassandra.version}-bin.tar"/>
                                        <echo message="Patching Apache Cassandra"/>
                                        <copy file="${project.build.directory}/${project.build.finalName}.jar"
                                              toFile="${project.build.directory}/apache-cassandra-${cassandra.version}/lib/${project.build.finalName}.jar"/>
                                        <echo message="Moving Apache Cassandra to ${cassandra_home}"/>
                                        <move file="${project.build.directory}/apache-cassandra-${cassandra.version}"
                                              toFile="${cassandra_home}"/>
                                    </target>
                                </configuration>
                                <goals>
                                    <goal>run</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
</project>
