<?xml version="1.0" encoding="UTF-8"?>
<!--
  ~ Copyright 2017-2019 Crown Copyright
  ~
  ~ Licensed 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>uk.gov.gchq.gaffer</groupId>
        <artifactId>gaffer-tools</artifactId>
        <version>1.21.2</version>
    </parent>

    <artifactId>slider</artifactId>

    <properties>
        <addon.pkg.name>Gaffer</addon.pkg.name>
        <addon.pkg.file>gaffer-slider-${project.version}</addon.pkg.file>

        <!-- Overriding parent hadoop.version as slider-funtest requires 2.7.1+ otherwise NoSuchMethodError: org.apache.hadoop.tracing.SpanReceiverHost -->
        <hadoop.version>2.7.1</hadoop.version>

        <!-- Dependency Versions -->
        <slider.version>0.92.0-incubating</slider.version>
        <slider.accumulo.version>0.80.0-incubating</slider.accumulo.version>
        <slider.accumulo.branch>branches/branch-0.92</slider.accumulo.branch>

        <!-- Testing Properties -->
        <test.cluster.type>docker_cloudera_quickstart</test.cluster.type>

        <!-- Output Locations -->
        <gaffer.output.directory>${project.build.directory}/gaffer</gaffer.output.directory>
        <slider.output.directory>${project.build.directory}/slider</slider.output.directory>
        <slider.accumulo.output.directory>${project.build.directory}/accumulo-pkg</slider.accumulo.output.directory>
        <cluster.config.output.directory>${project.build.directory}/clusters</cluster.config.output.directory>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.apache.slider</groupId>
            <artifactId>slider-core</artifactId>
            <version>${slider.version}</version>
        </dependency>

        <dependency>
            <groupId>org.apache.slider</groupId>
            <artifactId>slider-funtest</artifactId>
            <version>${slider.version}</version>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>junit</groupId>
                    <artifactId>junit</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <dependency>
            <groupId>org.apache.slider.packages</groupId>
            <artifactId>slider-accumulo-app-package</artifactId>
            <version>${slider.accumulo.version}</version>
            <scope>test</scope>
            <!-- The pom for 0.80.0-incubating depends on Accumulo 1.7.0-SNAPSHOT :( -->
            <exclusions>
                <exclusion>
                    <groupId>org.apache.accumulo</groupId>
                    <artifactId>accumulo-server-base</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.apache.accumulo</groupId>
                    <artifactId>accumulo-core</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <dependency>
            <groupId>uk.gov.gchq.gaffer</groupId>
            <artifactId>common-util</artifactId>
            <version>${gaffer.version}</version>
            <type>test-jar</type>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>uk.gov.gchq.gaffer</groupId>
            <artifactId>integration-test</artifactId>
            <type>test-jar</type>
            <version>${gaffer.version}</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>uk.gov.gchq.gaffer</groupId>
            <artifactId>accumulo-store</artifactId>
            <version>${gaffer.version}</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>uk.gov.gchq.gaffer</groupId>
            <artifactId>accumulo-store</artifactId>
            <type>test-jar</type>
            <version>${gaffer.version}</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.apache.hadoop</groupId>
            <artifactId>hadoop-client</artifactId>
            <version>${hadoop.version}</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
            </resource>
            <resource>
                <directory>scripts</directory>
                <filtering>true</filtering>
                <targetPath>${project.build.directory}/scripts</targetPath>
            </resource>
        </resources>

        <testResources>
            <testResource>
                <directory>src/test/resources</directory>
            </testResource>
            <testResource>
                <directory>src/test/clusters</directory>
                <filtering>true</filtering>
                <targetPath>${cluster.config.output.directory}</targetPath>
            </testResource>
        </testResources>

        <plugins>
            <plugin>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>${dependency.plugin.version}</version>
                <configuration>
                    <overWriteIfNewer>true</overWriteIfNewer>
                    <overWriteReleases>true</overWriteReleases>
                    <overWriteSnapshots>true</overWriteSnapshots>
                </configuration>

                <executions>
                    <execution>
                        <id>get-gaffer-iterators</id>
                        <phase>generate-resources</phase>
                        <goals>
                            <goal>copy</goal>
                        </goals>
                        <configuration>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>uk.gov.gchq.gaffer</groupId>
                                    <artifactId>accumulo-store</artifactId>
                                    <classifier>iterators</classifier>
                                    <version>${gaffer.version}</version>
                                </artifactItem>
                            </artifactItems>
                            <outputDirectory>${gaffer.output.directory}</outputDirectory>
                        </configuration>
                    </execution>

                    <execution>
                        <id>get-slider-distribution</id>
                        <phase>generate-resources</phase>
                        <goals>
                            <goal>unpack</goal>
                        </goals>
                        <configuration>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>org.apache.slider</groupId>
                                    <artifactId>slider-assembly</artifactId>
                                    <classifier>all</classifier>
                                    <type>zip</type>
                                    <version>${slider.version}</version>
                                </artifactItem>
                            </artifactItems>
                            <outputDirectory>${slider.output.directory}</outputDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>1.5.0</version>
                <executions>
                    <execution>
                        <id>build-accumulo-package</id>
                        <phase>generate-resources</phase>
                        <goals>
                            <goal>exec</goal>
                        </goals>
                        <configuration>
                            <executable>scripts/build_accumulo_package.sh</executable>
                            <arguments>
                                <argument>${slider.accumulo.branch}</argument>
                                <argument>${accumulo.version}</argument>
                                <argument>${slider.accumulo.output.directory}</argument>
                                <argument>--build-native</argument>
                            </arguments>
                        </configuration>
                    </execution>

                    <execution>
                        <id>shade-accumulo-iterator-jar</id>
                        <phase>generate-resources</phase>
                        <goals>
                            <goal>exec</goal>
                        </goals>
                        <configuration>
                            <executable>${project.basedir}/../jar-shader/shade.sh</executable>
                            <arguments>
                                <argument>${gaffer.output.directory}/accumulo-store-${gaffer.version}-iterators.jar</argument>
                            </arguments>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>2.6</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                        <configuration>
                            <descriptor>src/assembly/package.xml</descriptor>
                            <appendAssemblyId>false</appendAssemblyId>
                            <finalName>${addon.pkg.file}</finalName>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

    <profiles>
        <profile>
            <id>accumulo-funtest</id>
            <build>
                <plugins>
                    <plugin>
                        <artifactId>maven-failsafe-plugin</artifactId>
                        <configuration>
                            <includes>
                                <include>**/*FunctionalTest.java</include>
                                <include>**/*FunctionalTests.java</include>
                                <include>**/*FT.java</include>
                                <include>**/*FTs.java</include>
                            </includes>
                            <systemPropertyVariables>
                                <!-- Location of the Slider distribution and config to use -->
                                <slider.conf.dir>${cluster.config.output.directory}/${test.cluster.type}/slider</slider.conf.dir>
                                <slider.bin.dir>${slider.output.directory}/slider-${slider.version}</slider.bin.dir>
                                <!-- Location of the Accumulo slider app package to use -->
                                <test.app.pkg.dir>${slider.accumulo.output.directory}</test.app.pkg.dir>
                                <test.app.pkg.file>slider-accumulo-app-package-${accumulo.version}.zip</test.app.pkg.file>
                                <test.app.pkg.name>ACCUMULO</test.app.pkg.name>
                                <!-- Location of the Gaffer addon package to use -->
                                <test.addon.pkg.dir>${project.build.directory}</test.addon.pkg.dir>
                                <test.addon.pkg.file>${addon.pkg.file}.zip</test.addon.pkg.file>
                                <test.addon.pkg.name>${addon.pkg.name}</test.addon.pkg.name>
                                <!-- Location of the cluster specific configuration to use -->
                                <test.app.resources.dir>${cluster.config.output.directory}/${test.cluster.type}/accumulo</test.app.resources.dir>
                            </systemPropertyVariables>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>

</project>
