<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>org.janusgraph</groupId>
        <artifactId>janusgraph</artifactId>
        <version>0.3.1</version>
    </parent>

    <artifactId>janusgraph-cql</artifactId>
    <name>JanusGraph-CQL: Distributed Graph Database</name>
    <url>http://janusgraph.org</url>

    <properties>
        <vavr.version>0.9.0</vavr.version>
        <test.byteorderedpartitioner>byteorderedpartitioner</test.byteorderedpartitioner>
        <test.murmur>murmur</test.murmur>
        <test.murmur-ssl>murmur-ssl</test.murmur-ssl>
        <test.javaagent.opts>-javaagent:${com.github.jbellis:jamm:jar}</test.javaagent.opts>
        <test.extra.jvm.opts>${test.javaagent.opts}</test.extra.jvm.opts>
        <test.jvm.opts>-Xms256m -Xmx1280m -ea -XX:+HeapDumpOnOutOfMemoryError ${test.extra.jvm.opts}</test.jvm.opts>
        <test.excluded.groups>org.janusgraph.testcategory.MemoryTests,org.janusgraph.testcategory.PerformanceTests,org.janusgraph.testcategory.BrittleTests</test.excluded.groups>
        <top.level.basedir>${basedir}/..</top.level.basedir>
    </properties>

    <dependencies>
        <!-- Compile Dependencies -->
        <dependency>
            <groupId>org.janusgraph</groupId>
            <artifactId>janusgraph-core</artifactId>
            <version>${project.version}</version>
        </dependency>

        <dependency>
            <groupId>com.datastax.cassandra</groupId>
            <artifactId>cassandra-driver-core</artifactId>
            <version>${cassandra-driver.version}</version>
        </dependency>
        <dependency>
            <groupId>io.netty</groupId>
            <artifactId>netty-handler</artifactId>
        </dependency>
        <dependency>
            <groupId>com.google.guava</groupId>
            <artifactId>guava</artifactId>
        </dependency>
        <dependency>
            <groupId>io.vavr</groupId>
            <artifactId>vavr</artifactId>
            <version>${vavr.version}</version>
        </dependency>

        <!-- Test Dependencies -->
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.janusgraph</groupId>
            <artifactId>janusgraph-cassandra</artifactId>
            <version>${project.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.janusgraph</groupId>
            <artifactId>janusgraph-cassandra</artifactId>
            <version>${project.version}</version>
            <classifier>tests</classifier>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.janusgraph</groupId>
            <artifactId>janusgraph-test</artifactId>
            <version>${project.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-all</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <testResources>
            <testResource>
                <directory>src/test/resources</directory>
                <excludes>
                    <exclude>cassandra/</exclude>
                    <exclude>keystores/</exclude>
                    <exclude>properties/</exclude>
                </excludes>
                <filtering>true</filtering>
            </testResource>
        </testResources>
        <plugins>
            <plugin>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <execution>
                        <id>set-dependency-properties</id>
                        <phase>process-test-classes</phase>
                        <goals>
                            <goal>properties</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <artifactId>maven-resources-plugin</artifactId>
                <executions>
                    <execution>
                        <id>filter-${test.byteorderedpartitioner}</id>
                        <phase>process-test-resources</phase>
                        <goals>
                            <goal>copy-resources</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${project.build.directory}/cassandra/${test.byteorderedpartitioner}/conf</outputDirectory>
                            <filters>
                                <filter>${project.build.testResources[0].directory}/properties/${test.byteorderedpartitioner}.properties</filter>
                            </filters>
                            <resources>
                                <resource>
                                    <directory>${project.build.testResources[0].directory}/cassandra</directory>
                                    <filtering>true</filtering>
                                </resource>
                            </resources>
                        </configuration>
                    </execution>
                    <execution>
                        <id>filter-${test.murmur}</id>
                        <phase>process-test-resources</phase>
                        <goals>
                            <goal>copy-resources</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${project.build.directory}/cassandra/${test.murmur}/conf</outputDirectory>
                            <filters>
                                <filter>${project.build.testResources[0].directory}/properties/${test.murmur}.properties</filter>
                            </filters>
                            <resources>
                                <resource>
                                    <directory>${project.build.testResources[0].directory}/cassandra</directory>
                                    <filtering>true</filtering>
                                </resource>
                            </resources>
                        </configuration>
                    </execution>
                    <execution>
                        <id>filter-${test.murmur-ssl}</id>
                        <phase>process-test-resources</phase>
                        <goals>
                            <goal>copy-resources</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${project.build.directory}/cassandra/${test.murmur-ssl}/conf</outputDirectory>
                            <filters>
                                <filter>${project.build.testResources[0].directory}/properties/${test.murmur-ssl}.properties</filter>
                            </filters>
                            <resources>
                                <resource>
                                    <directory>${project.build.testResources[0].directory}/cassandra</directory>
                                    <filtering>true</filtering>
                                </resource>
                            </resources>
                        </configuration>
                    </execution>
                    <execution>
                        <id>filter-${test.murmur-ssl}-static</id>
                        <phase>process-test-resources</phase>
                        <goals>
                            <goal>copy-resources</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${project.build.directory}/cassandra/${test.murmur-ssl}/conf</outputDirectory>
                            <resources>
                                <resource>
                                    <directory>${project.build.testResources[0].directory}/keystores</directory>
                                    <filtering>false</filtering>
                                </resource>
                            </resources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <argLine>${test.jvm.opts}</argLine>
                    <forkCount>1</forkCount>
                    <reuseForks>false</reuseForks>
                    <parallel>none</parallel>
                    <perCoreThreadCount>false</perCoreThreadCount>
                    <threadCount>1</threadCount>
                    <systemPropertyVariables>
                        <log4j.configuration>file:${project.build.testOutputDirectory}/log4j.properties</log4j.configuration>
                    </systemPropertyVariables>
                </configuration>
                <executions>
                    <execution>
                        <id>default-test</id>
                        <phase>none</phase>
                    </execution>
                    <execution>
                        <id>${test.byteorderedpartitioner}-test</id>
                        <goals>
                            <goal>test</goal>
                        </goals>
                        <phase>test</phase>
                        <configuration>
                            <excludedGroups>${test.excluded.groups},org.janusgraph.testcategory.UnorderedKeyStoreTests,org.janusgraph.testcategory.SerialTests,org.janusgraph.testcategory.CassandraSSLTests</excludedGroups>
                            <groups />
                            <reportNameSuffix>${test.byteorderedpartitioner}</reportNameSuffix>
                            <systemProperties>
                                <property>
                                    <name>test.cassandra.confdir</name>
                                    <value>${project.build.directory}/cassandra/${test.byteorderedpartitioner}/conf</value>
                                </property>
                                <property>
                                    <name>test.cassandra.datadir</name>
                                    <value>${project.build.directory}/cassandra/${test.byteorderedpartitioner}/data</value>
                                </property>
                            </systemProperties>
                            <skip>${test.skip.byteorderedpartitioner}</skip>
                        </configuration>
                    </execution>
                    <execution>
                        <id>${test.murmur}-test</id>
                        <goals>
                            <goal>test</goal>
                        </goals>
                        <phase>test</phase>
                        <configuration>
                            <excludedGroups>${test.excluded.groups},org.janusgraph.testcategory.OrderedKeyStoreTests,org.janusgraph.testcategory.SerialTests,org.janusgraph.testcategory.CassandraSSLTests</excludedGroups>
                            <groups />
                            <reportNameSuffix>${test.murmur}</reportNameSuffix>
                            <systemProperties>
                                <property>
                                    <name>test.cassandra.confdir</name>
                                    <value>${project.build.directory}/cassandra/${test.murmur}/conf</value>
                                </property>
                                <property>
                                    <name>test.cassandra.datadir</name>
                                    <value>${project.build.directory}/cassandra/${test.murmur}/data</value>
                                </property>
                            </systemProperties>
                            <skip>${test.skip.murmur}</skip>
                        </configuration>
                    </execution>
                    <execution>
                        <id>${test.murmur}-serial-test</id>
                        <goals>
                            <goal>test</goal>
                        </goals>
                        <phase>test</phase>
                        <configuration>
                            <excludedGroups />
                            <groups>org.janusgraph.testcategory.SerialTests</groups>
                            <parallel>none</parallel>
                            <perCoreThreadCount>false</perCoreThreadCount>
                            <threadCount>1</threadCount>
                            <runOrder>alphabetical</runOrder>
                            <reportNameSuffix>${test.murmur}-serial</reportNameSuffix>
                            <systemProperties>
                                <property>
                                    <name>test.cassandra.confdir</name>
                                    <value>${project.build.directory}/cassandra/${test.murmur}/conf</value>
                                </property>
                                <property>
                                    <name>test.cassandra.datadir</name>
                                    <value>${project.build.directory}/cassandra/${test.murmur}/data</value>
                                </property>
                            </systemProperties>
                            <skip>${test.skip.murmur-serial}</skip>
                        </configuration>
                    </execution>
                    <execution>
                        <id>${test.murmur-ssl}-test</id>
                        <goals>
                            <goal>test</goal>
                        </goals>
                        <phase>test</phase>
                        <configuration>
                            <excludedGroups />
                            <groups>org.janusgraph.testcategory.CassandraSSLTests</groups>
                            <!-- The TP3 JUnit Suite/Runner ignores groups/@Category and I'm not sure why. Redundant excludes to keep TP3 tests from using non-SSL configs on SSL -->
                            <excludes>
                                <exclude>**/*ComputerTest.java</exclude>
                                <exclude>**/*StructureTest.java</exclude>
                                <exclude>**/*ProcessTest.java</exclude>
                            </excludes>
                            <threadCount>1</threadCount>
                            <reportNameSuffix>${test.murmur-ssl}</reportNameSuffix>
                            <systemProperties>
                                <property>
                                    <name>test.cassandra.confdir</name>
                                    <value>${project.build.directory}/cassandra/${test.murmur-ssl}/conf</value>
                                </property>
                                <property>
                                    <name>test.cassandra.datadir</name>
                                    <value>${project.build.directory}/cassandra/${test.murmur-ssl}/data</value>
                                </property>
                            </systemProperties>
                            <skip>${test.skip.murmur-ssl}</skip>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
    <profiles>
        <profile>
	          <id>coverage</id>
	          <activation>
	              <activeByDefault>false</activeByDefault>
	          </activation>
	          <properties>
	              <test.extra.jvm.opts>${jacoco.opts} ${test.javaagent.opts}</test.extra.jvm.opts>
	          </properties>
        </profile>

        <profile>
            <!-- Run Thrift tests with ScyllaDB (requires Docker) -->
            <id>scylladb-test</id>
            <properties>
                <!-- Tests are run under failsafe so skip them under surefire -->
                <test.skip.byteorderedpartitioner>true</test.skip.byteorderedpartitioner>
                <test.skip.murmur>true</test.skip.murmur>
                <test.skip.murmur-serial>true</test.skip.murmur-serial>
                <test.skip.murmur-ssl>true</test.skip.murmur-ssl>
            </properties>
            <build>
                <plugins>
                    <plugin>
                        <artifactId>maven-failsafe-plugin</artifactId>
                        <configuration>
                            <skipITs>false</skipITs>
                            <includes>
                                <include>**/org/janusgraph/diskstorage/cql/*.java</include>
                                <include>**/org/janusgraph/graphdb/cql/*.java</include>
                            </includes>
                            <!-- Exclude default (performance/memory) tests. Also exclude SSL tests (fail under Scylla) -->
                            <excludedGroups>${test.excluded.groups},org.janusgraph.testcategory.CassandraSSLTests</excludedGroups>
                            <systemProperties>
                                <!-- Run tests against the containerized Scylla test server -->
                                <property>
                                    <name>storage.hostname</name>
                                    <value>0.0.0.0</value>
                                </property>
                            </systemProperties>
                        </configuration>
                        <executions>
                            <execution>
                                <goals>
                                    <goal>integration-test</goal>
                                    <goal>verify</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <groupId>io.fabric8</groupId>
                        <artifactId>docker-maven-plugin</artifactId>
                        <version>0.18.1</version>
                        <configuration>
                            <images>
                                <image>
                                    <alias>scylladb</alias>
                                    <name>scylladb/scylla:${scylladb.version}</name>
                                    <run>
                                        <!-- Limit to two CPUs -->
                                        <cmd>--smp 2</cmd>
                                        <!-- Expose Thrift and CQL ports -->
                                        <ports>
                                            <port>9160:9160</port>
                                            <port>9042:9042</port>
                                        </ports>
                                        <wait>
                                            <tcp>
                                                <ports>
                                                    <port>9160</port>
                                                    <port>9042</port>
                                                </ports>
                                            </tcp>
                                            <time>60000</time>
                                        </wait>
                                    </run>
                                </image>
                            </images>
                        </configuration>
                        <executions>
                            <execution>
                                <id>docker-start</id>
                                <phase>pre-integration-test</phase>
                                <goals>
                                    <goal>start</goal>
                                </goals>
                            </execution>
                            <execution>
                                <id>docker-stop</id>
                                <phase>post-integration-test</phase>
                                <goals>
                                    <goal>stop</goal>
                                    <goal>remove</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
</project>
