<!--

    Copyright DataStax, Inc.

    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.

-->
<!--
    Copyright (C) 2021 ScyllaDB
    Modified by ScyllaDB
-->
<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>com.scylladb</groupId>
        <artifactId>scylla-driver-parent</artifactId>
        <version>3.11.5.2</version>
    </parent>

    <artifactId>scylla-driver-core</artifactId>
    <name>Java Driver for Scylla and Apache Cassandra - Core</name>
    <description>
        A driver for Scylla and Apache Cassandra 1.2+ that works exclusively with the Cassandra Query Language version 3
        (CQL3) and Cassandra's binary protocol.
    </description>

    <dependencies>

        <dependency>
            <groupId>io.netty</groupId>
            <artifactId>netty-handler</artifactId>
        </dependency>

        <dependency>
            <groupId>com.google.guava</groupId>
            <artifactId>guava</artifactId>
        </dependency>

        <dependency>
            <groupId>io.dropwizard.metrics</groupId>
            <artifactId>metrics-core</artifactId>
        </dependency>

        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
        </dependency>

        <dependency>
            <groupId>com.github.jnr</groupId>
            <artifactId>jnr-ffi</artifactId>
        </dependency>

        <dependency>
            <groupId>com.github.jnr</groupId>
            <artifactId>jnr-posix</artifactId>
        </dependency>

        <!-- Compression libraries for the protocol. -->
        <!-- Each of them is only a mandatory runtime dependency if you want to use the compression it offers -->

        <dependency>
            <groupId>org.xerial.snappy</groupId>
            <artifactId>snappy-java</artifactId>
            <optional>true</optional>
        </dependency>

        <dependency>
            <groupId>org.lz4</groupId>
            <artifactId>lz4-java</artifactId>
            <optional>true</optional>
        </dependency>

        <!-- End of compression libraries -->

        <dependency>
            <groupId>io.netty</groupId>
            <artifactId>netty-transport-native-epoll</artifactId>
            <optional>true</optional>
        </dependency>

        <dependency>
            <groupId>org.hdrhistogram</groupId>
            <artifactId>HdrHistogram</artifactId>
            <optional>true</optional>
        </dependency>

        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.assertj</groupId>
            <artifactId>assertj-core</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-all</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.scassandra</groupId>
            <artifactId>java-client</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-exec</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>io.netty</groupId>
            <artifactId>${netty-tcnative.artifact}</artifactId>
            <classifier>${os.detected.classifier}</classifier>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>com.github.tomakehurst</groupId>
            <artifactId>wiremock</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.jboss.byteman</groupId>
            <artifactId>byteman-bmunit</artifactId>
            <scope>test</scope>
            <version>${byteman.version}</version>
            <exclusions>
                <exclusion>
                    <groupId>org.testng</groupId>
                    <artifactId>testng</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-core</artifactId>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.dataformat</groupId>
            <artifactId>jackson-dataformat-yaml</artifactId>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.bouncycastle/bcprov-jdk15on -->
        <dependency>
            <groupId>org.bouncycastle</groupId>
            <artifactId>bcprov-jdk18on</artifactId>
            <version>1.76</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.bouncycastle/bcpkix-jdk15on -->
        <dependency>
            <groupId>org.bouncycastle</groupId>
            <artifactId>bcpkix-jdk18on</artifactId>
            <version>1.76</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.bouncycastle/bcutil-jdk15on -->
        <dependency>
            <groupId>org.bouncycastle</groupId>
            <artifactId>bcutil-jdk18on</artifactId>
            <version>1.76</version>
        </dependency>


    </dependencies>

    <build>

        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
            </resource>
        </resources>

        <plugins>

            <plugin>
                <artifactId>maven-jar-plugin</artifactId>
                <configuration>
                    <archive>
                        <manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
                    </archive>
                </configuration>
                <executions>
                    <execution>
                        <id>test-jar</id>
                        <goals>
                            <goal>test-jar</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

            <!--
            We avoid packaging bundle because it does not play nicely with the shade plugin, see
            https://stackoverflow.com/questions/31262032/maven-shade-plugin-and-custom-packaging-type
            -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-source-plugin</artifactId>
                <executions>
                    <execution>
                        <id>attach-test-sources</id>
                        <goals>
                            <goal>test-jar-no-fork</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.felix</groupId>
                <artifactId>maven-bundle-plugin</artifactId>
                <configuration>
                    <instructions>
                        <Bundle-SymbolicName>com.datastax.driver.core</Bundle-SymbolicName>
                    </instructions>
                    <!--
                    Prevent customized manifest entries from the project's maven-jar-plugin configuration from being read, see
                    http://apache-felix.18485.x6.nabble.com/how-lt-manifestLocation-gt-is-used-in-maven-bundle-plugin-td4835566.html
                    -->
                    <archive>
                        <forced>true</forced>
                    </archive>
                </configuration>
                <executions>
                    <!-- Default execution -->
                    <execution>
                        <id>bundle-manifest</id>
                        <phase>process-classes</phase>
                        <goals>
                            <goal>manifest</goal>
                        </goals>
                        <configuration>
                            <manifestLocation>${project.build.outputDirectory}/META-INF</manifestLocation>
                            <instructions>
                                <!-- JNR does not provide OSGi bundles, so exclude it; the driver can live without it -->
                                <Import-Package><![CDATA[com.google.common.*;version="16.0.1",!jnr.*,io.netty.channel.epoll,*]]></Import-Package>
                            </instructions>
                        </configuration>
                    </execution>
                    <!-- Alternate execution to generate the shaded JAR's manifest -->
                    <execution>
                        <id>bundle-manifest-shaded</id>
                        <phase>process-classes</phase>
                        <goals>
                            <goal>manifest</goal>
                        </goals>
                        <configuration>
                            <manifestLocation>${project.build.directory}/META-INF-shaded</manifestLocation>
                            <instructions>
                                <!--
                                JNR does not provide OSGi bundles, so exclude it; the driver can live without it
                                Explicitly import javax.security.cert because it's required by Netty, but Netty has been explicitly excluded
                                -->
                                <Import-Package><![CDATA[com.google.common.*;version="16.0.1",!jnr.*,!io.netty.*,!com.codahale.metrics,javax.security.cert,javax.management,*]]></Import-Package>
                                <Private-Package>com.datastax.shaded.*</Private-Package>
                                <Export-Package>com.datastax.shaded.metrics;*</Export-Package>
                            </instructions>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <artifactId>maven-shade-plugin</artifactId>
                <configuration>
                    <shadedArtifactAttached>true</shadedArtifactAttached>
                    <artifactSet>
                        <includes>
                            <include>io.netty:*</include>
                            <include>io.dropwizard.metrics:metrics-core</include>
                        </includes>
                        <excludes>
                            <exclude>io.netty:netty-transport-native-epoll</exclude>
                        </excludes>
                    </artifactSet>
                    <relocations>
                        <relocation>
                            <pattern>io.netty</pattern>
                            <shadedPattern>com.datastax.shaded.netty</shadedPattern>
                        </relocation>
                        <relocation>
                            <pattern>com.codahale.metrics</pattern>
                            <shadedPattern>com.datastax.shaded.metrics</shadedPattern>
                        </relocation>
                    </relocations>
                    <transformers>
                        <transformer implementation="org.apache.maven.plugins.shade.resource.DontIncludeResourceTransformer">
                            <resources>
                                <resource>META-INF/MANIFEST.MF</resource>
                                <resource>META-INF/io.netty.versions.properties</resource>
                                <resource>META-INF/maven/io.netty/netty-buffer/pom.properties</resource>
                                <resource>META-INF/maven/io.netty/netty-buffer/pom.xml</resource>
                                <resource>META-INF/maven/io.netty/netty-codec/pom.properties</resource>
                                <resource>META-INF/maven/io.netty/netty-codec/pom.xml</resource>
                                <resource>META-INF/maven/io.netty/netty-common/pom.properties</resource>
                                <resource>META-INF/maven/io.netty/netty-common/pom.xml</resource>
                                <resource>META-INF/maven/io.netty/netty-handler/pom.properties</resource>
                                <resource>META-INF/maven/io.netty/netty-handler/pom.xml</resource>
                                <resource>META-INF/maven/io.netty/netty-transport/pom.properties</resource>
                                <resource>META-INF/maven/io.netty/netty-transport/pom.xml</resource>
                                <resource>META-INF/maven/io.dropwizard.metrics/metrics-core/pom.properties</resource>
                                <resource>META-INF/maven/io.dropwizard.metrics/metrics-core/pom.xml</resource>
                            </resources>
                        </transformer>
                        <!-- Pick up the alternate manifest that was generated by the alternate execution of the bundle plugin -->
                        <transformer implementation="org.apache.maven.plugins.shade.resource.IncludeResourceTransformer">
                            <resource>META-INF/MANIFEST.MF</resource>
                            <file>${project.build.directory}/META-INF-shaded/MANIFEST.MF</file>
                        </transformer>
                    </transformers>
                </configuration>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

        </plugins>

    </build>

    <profiles>

        <profile>
            <id>isolated</id>
            <build>
                <plugins>
                    <plugin>
                        <artifactId>maven-surefire-plugin</artifactId>
                        <configuration>
                            <skip>false</skip>
                            <includes>
                                <include>**/SSL*Test.java</include>
                                <include>**/ControlConnectionTest.java</include>
                                <include>**/ExtendedPeerCheckDisabledTest.java</include>
                                <include>**/UUIDsPID*.java</include>
                                <include>**/FrameLengthTest.java</include>
                                <include>**/HeapCompressionTest.java</include>
                            </includes>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>

    </profiles>

</project>

