<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>

    <groupId>com.kinetica</groupId>
    <artifactId>kinetica-jdbc</artifactId>
    <version>7.2.3.10</version>
    <packaging>jar</packaging>

    <properties>
        <!-- Build System Replaceable -->
        <kinetica.dep-jar-suffix>jar-with-dependencies</kinetica.dep-jar-suffix>
        <kinetica.sql>kisql</kinetica.sql>

        <!-- Dependency Versions -->
        <gpudb-api.version>7.2.3.10</gpudb-api.version>
        <slf4j.version>1.7.12</slf4j.version>
        <jsap.version>2.1</jsap.version>
        <commons-configuration.version>1.9</commons-configuration.version>

        <!-- Maven Plug-In Versions -->
        <maven-assembly-plugin.version>3.3.0</maven-assembly-plugin.version>
        <maven-compiler-plugin.version>3.8.1</maven-compiler-plugin.version>
        <maven-surefire-plugin.version>2.22.2</maven-surefire-plugin.version>
        <maven-jar-plugin.version>2.6</maven-jar-plugin.version>
        <maven-shade-plugin.version>3.5.1</maven-shade-plugin.version>
        <launch4j-maven-plugin.version>2.1.2</launch4j-maven-plugin.version>

        <maven.compiler.source>11</maven.compiler.source>
        <maven.compiler.target>11</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

        <launch4jPhase>none</launch4jPhase> <!-- skips launch4j building MSW exe on non-x86 -->
        <target.build.dir>target</target.build.dir> <!-- override on cmd-line -->
    </properties>

    <name>kinetica-jdbc-driver</name>
    <description>JDBC driver for connecting to and managing a Kinetica database</description>
    <url>https://github.com/kineticadb/kinetica-connector-jdbc</url>
    <licenses>
        <license>
            <name>MIT License</name>
            <url>https://opensource.org/license/mit</url>
        </license>
    </licenses>
    <developers>
        <developer>
            <name>Andy Jacobs</name>
            <email>ajacobs@kinetica.com</email>
            <organization>Kinetica DB Inc.</organization>
            <organizationUrl>https://www.kinetica.com/</organizationUrl>
        </developer>
    </developers>
    <scm>
        <connection>scm:git:https://github.com/kineticadb/kinetica-client-jdbc.git</connection>
        <developerConnection>scm:git:https://github.com/kineticadb/kinetica-client-jdbc.git</developerConnection>
        <url>https://github.com/kineticadb/kinetica-client-jdbc</url>
    </scm>

    <profiles>
        <profile>
            <id>ConfigureTargetBuildDir</id>
            <activation>
                <property>
                    <name>target.build.dir</name>
                </property>
            </activation>
            <build>
                <directory>${target.build.dir}</directory>
            </build>
        </profile>
        <profile>
            <id>profile-x86</id> <!-- $ mvn help:active-profiles shows current profile -->
            <activation>
                <os>
                    <arch>amd64</arch> <!-- $ mvn enforcer:display-info shows arch; 'amd64' not 'x86_84' or 'x64' -->
                </os>
            </activation>
            <properties>
                <launch4jPhase>package</launch4jPhase> <!-- build it -->
            </properties>
        </profile>
        <profile>
            <id>compile-java9andup-bytecode-compatibility-java8</id>
            <activation>
                <jdk>[9,)</jdk>
            </activation>
            <properties>
                <maven.compiler.source>11</maven.compiler.source>
                <maven.compiler.target>11</maven.compiler.target>
            </properties>
        </profile>
    </profiles>

    <build>
        <resources>
            <resource>
                <directory>${basedir}/src/main/java</directory>
                <includes>
                    <include>**/messages.properties</include>
                </includes>
            </resource>
            <resource>
                <directory>${basedir}/src/main/resources</directory>
                <includes>
                    <include>**/*</include>
                </includes>
                <excludes>
                    <exclude>logback.fullshaded.xml</exclude>
                </excludes>
            </resource>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
                <includes>
                    <include>**/kinetica-jdbc-build.properties</include>
                </includes>
            </resource>
            <resource>
                <directory>src/main/resources</directory>
            </resource>
        </resources>

        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>${maven-compiler-plugin.version}</version>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>${maven-surefire-plugin.version}</version>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>${maven-jar-plugin.version}</version>
                <configuration>
                    <archive>
                        <index>true</index>
                        <manifest>
                            <addClasspath>true</addClasspath>
                            <addExtensions>false</addExtensions>
                        </manifest>
                    </archive>
                    <forceCreation>true</forceCreation>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>${maven-assembly-plugin.version}</version>
                <configuration>
                    <descriptorRefs>
                        <descriptorRef>${kinetica.dep-jar-suffix}</descriptorRef>
                    </descriptorRefs>
                </configuration>
                <executions>
                    <execution>
                        <id>make-assembly</id>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                        <configuration>
                            <archive>
                                <manifest>
                                    <addClasspath>true</addClasspath>
                                    <mainClass>com.kinetica.kisql</mainClass>
                                </manifest>
                            </archive>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>${maven-shade-plugin.version}</version>
                <executions>
                    <execution>
                        <id>sources</id>
                        <phase>deploy</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <createDependencyReducedPom>false</createDependencyReducedPom>
                            <filters>
                                <filter>
                                    <artifact>*:*</artifact>
                                    <includes>
                                        <include>sources.txt</include>
                                    </includes>
                                </filter>
                            </filters>
                            <shadedArtifactAttached>true</shadedArtifactAttached>
                            <shadedClassifierName>sources</shadedClassifierName>
                        </configuration>
                    </execution>
                    <execution>
                        <id>javadoc</id>
                        <phase>deploy</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <createDependencyReducedPom>false</createDependencyReducedPom>
                            <filters>
                                <filter>
                                    <artifact>*:*</artifact>
                                    <includes>
                                        <include>javadoc.txt</include>
                                    </includes>
                                </filter>
                            </filters>
                            <shadedArtifactAttached>true</shadedArtifactAttached>
                            <shadedClassifierName>javadoc</shadedClassifierName>
                        </configuration>
                    </execution>
                    <execution>
                        <id>shaded</id>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <createDependencyReducedPom>false</createDependencyReducedPom>
                            <transformers>
                                <transformer implementation="org.apache.maven.plugins.shade.resource.DontIncludeResourceTransformer">
                                    <resource>logback.fullshaded.xml</resource>
                                </transformer>
                            </transformers>
                            <filters>
                                <filter>
                                    <artifact>*:*</artifact>
                                    <excludes>
                                        <exclude>module-info.class</exclude> <!-- Silence warning from avro: "Discovered module-info.class. Shading will break its strong encapsulation" -->
                                        <exclude>META-INF/*.SF</exclude>
                                        <exclude>META-INF/*.DSA</exclude>
                                        <exclude>META-INF/*.RSA</exclude>
                                        <exclude>sources.txt</exclude>
                                        <exclude>javadoc.txt</exclude>
                                    </excludes>
                                </filter>
                            </filters>
                            <relocations>
                                <relocation>
                                    <pattern>com.fasterxml</pattern>
                                    <shadedPattern>com.gpudb.fasterxml</shadedPattern>
                                </relocation>
                                <relocation>
                                    <pattern>org.apache</pattern>
                                    <shadedPattern>com.gpudb.apache</shadedPattern>
                                </relocation>
                                <relocation>
                                    <pattern>org.threeten</pattern>
                                    <shadedPattern>com.gpudb.threeten</shadedPattern>
                                </relocation>
                                <relocation>
                                    <pattern>org.jline</pattern>
                                    <shadedPattern>com.gpudb.jline</shadedPattern>
                                </relocation>
                            </relocations>
                            <shadedArtifactAttached>true</shadedArtifactAttached>
                            <shadedClassifierName>shaded</shadedClassifierName>
                        </configuration>
                    </execution>
                    <execution>
                        <!--
                            To use the fullshaded JAR as a dependency, exclude all transitive dependencies:
                            
                            <dependency>
                                <groupId>com.kinetica</groupId>
                                <artifactId>kinetica-jdbc</artifactId>
                                <version>[7.1.8.0,7.2.0.0-SNAPSHOT)</version>
                                <classifier>fullshaded</classifier>
                                <exclusions>
                                    <exclusion>
                                        <groupId>*</groupId>
                                        <artifactId>*</artifactId>
                                    </exclusion>
                                </exclusions>
                            </dependency>
                         -->
                        <id>fullshaded</id>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <createDependencyReducedPom>false</createDependencyReducedPom>
                            <artifactSet>
                                <excludes>
                                    <exclude>org.xerial.snappy:snappy-java</exclude>
                                </excludes>
                            </artifactSet>
                            <transformers>
                                <transformer implementation="org.apache.maven.plugins.shade.resource.DontIncludeResourceTransformer">
                                    <resource>logback.xml</resource>
                                </transformer>
                                <transformer implementation="org.apache.maven.plugins.shade.resource.IncludeResourceTransformer">
                                    <resource>logback.xml</resource>
                                    <file>logback.fullshaded.xml</file>
                                </transformer>
                            </transformers>
                            <filters>
                                <filter>
                                    <artifact>*:*</artifact>
                                    <excludes>
                                        <exclude>META-INF/*.SF</exclude>
                                        <exclude>META-INF/*.DSA</exclude>
                                        <exclude>META-INF/*.RSA</exclude>
                                        <exclude>sources.txt</exclude>
                                        <exclude>javadoc.txt</exclude>
                                    </excludes>
                                </filter>
                            </filters>
                            <relocations>
                                <relocation>
                                    <pattern>ch.qos.logback</pattern>
                                    <shadedPattern>com.gpudb.logback</shadedPattern>
                                </relocation>
                                <relocation>
                                    <pattern>com.fasterxml</pattern>
                                    <shadedPattern>com.gpudb.fasterxml</shadedPattern>
                                </relocation>
                                <relocation>
                                    <pattern>org.apache</pattern>
                                    <shadedPattern>com.gpudb.apache</shadedPattern>
                                </relocation>
                                <relocation>
                                    <pattern>org.threeten</pattern>
                                    <shadedPattern>com.gpudb.threeten</shadedPattern>
                                </relocation>
                                <relocation>
                                    <pattern>org.jline</pattern>
                                    <shadedPattern>com.gpudb.jline</shadedPattern>
                                </relocation>
                                <relocation>
                                    <pattern>org.slf4j</pattern>
                                    <shadedPattern>com.gpudb.slf4j</shadedPattern>
                                </relocation>
                            </relocations>
                            <shadedArtifactAttached>true</shadedArtifactAttached>
                            <shadedClassifierName>fullshaded</shadedClassifierName>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>com.code54.mojo</groupId>
                <artifactId>buildversion-plugin</artifactId>
                <version>1.0.3</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>set-properties</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>com.akathist.maven.plugins.launch4j</groupId>
                <artifactId>launch4j-maven-plugin</artifactId>
                <version>${launch4j-maven-plugin.version}</version>
                <executions>
                    <execution>
                        <id>l4j-${kinetica.sql}</id>
                        <phase>${launch4jPhase}</phase> <!-- Do not build MSWin package on non-x86, see profile above -->
                        <goals><goal>launch4j</goal></goals>
                        <configuration>
                            <headerType>console</headerType>
                            <outfile>${target.build.dir}/${kinetica.sql}.exe</outfile>
                            <jar>${target.build.dir}/${project.artifactId}-${project.version}-${kinetica.dep-jar-suffix}.jar</jar>
                            <errTitle>${kinetica.sql}</errTitle>
                            <classPath>
                                <mainClass>com.kinetica.kisql</mainClass>
                            </classPath>
                            <jre>
                                <minVersion>1.7</minVersion>
                            </jre>
                            <versionInfo>
                                <fileVersion>${project.version}</fileVersion>
                                <txtFileVersion>${project.version}</txtFileVersion>
                                <fileDescription>Simple client for running SQL on any Kinetica database</fileDescription>
                                <copyright>Kinetica DB, Inc.</copyright>
                                <productVersion>${project.version}</productVersion>
                                <txtProductVersion>${project.version}</txtProductVersion>
                                <productName>Kinetica SQL Client</productName>
                                <internalName>${kinetica.sql}</internalName>
                                <originalFilename>${kinetica.sql}.exe</originalFilename>
                            </versionInfo>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-gpg-plugin</artifactId>
                <version>3.2.4</version>
                <executions>
                    <execution>
                        <id>sign-artifacts</id>
                        <phase>deploy</phase>
                        <goals>
                            <goal>sign</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>org.sonatype.central</groupId>
                <artifactId>central-publishing-maven-plugin</artifactId>
                <version>0.5.0</version>
                <extensions>true</extensions>
                <configuration>
                    <publishingServerId>central</publishingServerId>
                </configuration>
            </plugin>

        </plugins>
    </build>

    <repositories>
        <repository>
            <id>thirdparty</id>
            <name>ThirdParty</name>
            <url>https://nexus.kinetica.com/repository/thirdparty</url>
        </repository>
    </repositories>

    <dependencies>
        <!-- JUnit Jupiter API and Engine -->
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter</artifactId>
            <version>5.8.2</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.jetbrains</groupId>
            <artifactId>annotations</artifactId>
            <version>24.0.1</version> <!-- or the latest -->
        </dependency>
        <dependency>
            <groupId>com.gpudb</groupId>
            <artifactId>gpudb-api</artifactId>
            <version>${gpudb-api.version}</version>
        </dependency>

        <dependency>
            <groupId>org.jline</groupId>
            <artifactId>jline</artifactId>
            <version>3.25.0</version>
        </dependency>
    </dependencies>
</project>
