<?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>3.11.8.1</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>
    </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.scalatest</groupId>
            <artifactId>scalatest_${scala.binary.version}</artifactId>
            <version>${scalatest.version}</version>
            <scope>test</scope>
        </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.version}</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>${jackson.version}</version>
        </dependency>
        <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>com.google.code.findbugs</groupId>
            <artifactId>jsr305</artifactId>
            <version>${version.findbugs}</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>net.alchim31.maven</groupId>
                <artifactId>scala-maven-plugin</artifactId>
                <configuration>
                    <args>
                        <arg>-nowarn</arg>
                    </args>
                </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>2.3</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>
        </plugins>
    </build>
    <profiles>
        <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>
