<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>
    <groupId>ch.zizka.csvcruncher</groupId>
    <artifactId>csv-cruncher</artifactId>
    <version>2.7.0</version>

    <name>CsvCruncher</name>
    <description>Treats CSV or JSON files as SQL tables, and exports SQL SELECTs back to CSV or JSON.</description>
    <url>https://github.com/OndraZizka/csv-cruncher</url>
    <licenses><license><name>The Apache Software License, Version 2.0</name><url>http://www.apache.org/licenses/LICENSE-2.0.txt</url><distribution>repo</distribution></license></licenses>
    <developers><developer><name>Ondrej Zizka</name><email>zizka@seznam.cz</email></developer></developers>
    <issueManagement><system>GitHub Issues</system><url>https://github.com/OndraZizka/csv-cruncher/issues</url></issueManagement>
    <scm>
        <url>https://github.com/OndraZizka/csv-cruncher</url>
        <developerConnection>scm:git:git@github.com:OndraZizka/csv-cruncher.git</developerConnection>
      <tag>csv-cruncher-2.7.0</tag>
  </scm>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <version.kotlin>1.8.21</version.kotlin>
        <version.kotlin-dokka>1.8.20</version.kotlin-dokka>
        <version.jdk>11</version.jdk>
        <version.jackson>2.14.1</version.jackson>
        <version.surefire>3.1.2</version.surefire>

        <jvm.args.debug /> <!-- Used by the -Pdebug profile. -->
        <mainClass>Crunch</mainClass>
        <testRunCmd>${jvm.args.debug} -jar ${project.build.directory}/${project.build.finalName}-single.jar</testRunCmd>
        <skipE2E>false</skipE2E>
        <ossrh.host>oss.sonatype.org</ossrh.host>
        <kotlin.compiler.incremental>true</kotlin.compiler.incremental>
        <surefire.printSummary>false</surefire.printSummary><!-- Suppress the WARNING about skipped tests (except the final one). -->
    </properties>

    <build>
        <sourceDirectory>src/main/kotlin</sourceDirectory>
        <resources>
            <!--
            <resource> <directory>src/main/kotlin</directory> <excludes><exclude>*.java</exclude><exclude>*.kt</exclude></excludes> </resource>
            -->
            <resource><directory>src/main/resources</directory></resource>
            <resource><directory>./</directory><includes><include>README.md</include></includes></resource>
        </resources>
        <testResources>
            <testResource><directory>src/test/kotlin</directory><excludes><exclude>*.java</exclude><exclude>*.kt</exclude></excludes></testResource>
        </testResources>
        <testSourceDirectory>src/test/kotlin</testSourceDirectory>

        <plugins>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId><artifactId>maven-jar-plugin</artifactId><version>3.3.0</version>
                <configuration><includes><include>**/*.class</include><exclude>**/*.kt</exclude></includes></configuration>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId><artifactId>maven-antrun-plugin</artifactId><version>3.1.0</version>
                <executions>
                    <execution>
                        <phase>generate-test-resources</phase>
                        <goals><goal>run</goal></goals>
                        <configuration><target><unzip src="src/test/data/json/github_data.zip" dest="target/testData/json/" /></target></configuration>
                    </execution>
                </executions>
            </plugin>


            <plugin>
                <groupId>org.apache.maven.plugins</groupId><artifactId>maven-surefire-plugin</artifactId><version>${version.surefire}</version>
                <configuration>
                    <trimStackTrace>false</trimStackTrace>

                    <systemPropertyVariables>
                        <test.data.dir>${project.build.testSourceDirectory}/../data</test.data.dir>
                        <target.dir>${project.build.directory}</target.dir>
                        <textdb.allow_full_path>true</textdb.allow_full_path>
                    </systemPropertyVariables>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId><artifactId>maven-failsafe-plugin</artifactId><version>${version.surefire}</version>
                <configuration>
                    <trimStackTrace>false</trimStackTrace>
                    <systemPropertyVariables>
                        <test.cruncher.runCmd>${testRunCmd}</test.cruncher.runCmd>
                        <test.data.dir>${project.build.testSourceDirectory}/../data</test.data.dir>
                        <target.dir>${project.build.directory}</target.dir>
                        <textdb.allow_full_path>true</textdb.allow_full_path>
                    </systemPropertyVariables>
                </configuration>
                <executions>
                    <execution><id>it</id><goals><goal>integration-test</goal></goals></execution>
                    <execution><id>ve</id><goals><goal>verify</goal></goals></execution>
                </executions>
            </plugin>

            <!-- Better - uses the Assembly plugin with built-in jar-with-dependencies descriptor.
                   mvn install assembly:assembly
            -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId><artifactId>maven-assembly-plugin</artifactId><version>3.4.2</version>
                <executions>
                    <execution>
                        <id>assembleDistJar</id>
                        <goals><goal>single</goal></goals>
                        <phase>package</phase>
                        <configuration>
                            <finalName>${project.artifactId}-${project.version}-single</finalName>
                            <archive>
                                <manifest>
                                    <mainClass>${mainClass}</mainClass>
                                    <addClasspath>false</addClasspath> <!-- false for jar-with-dependencies -->
                                    <classpathPrefix>lib/</classpathPrefix>
                                    <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
                                    <addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
                                </manifest>
                                <manifestEntries>
                                    <Release-Version>${project.version}</Release-Version>
                                </manifestEntries>
                            </archive>
                            <descriptorRefs>
                                <descriptorRef>jar-with-dependencies</descriptorRef>
                            </descriptorRefs>
                        </configuration>
                    </execution>
                    <execution>
                        <id>assembleDistZip</id>
                        <goals><goal>single</goal></goals>
                        <phase>package</phase>
                        <configuration>
                            <finalName>${project.artifactId}-${project.version}-dist</finalName>
                            <archive>
                                <manifest>
                                    <mainClass>${mainClass}</mainClass>
                                    <addClasspath>false</addClasspath>
                                    <classpathPrefix>lib/</classpathPrefix>
                                </manifest>
                            </archive>
                            <descriptors>
                                <descriptor>src/main/assembly-dist.xml</descriptor>
                            </descriptors>
                        </configuration>
                    </execution>
                </executions>
                <configuration>
                    <appendAssemblyId>false</appendAssemblyId>
                </configuration>
            </plugin>

            <plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-dependency-plugin</artifactId><version>3.5.0</version></plugin>


            <!-- One real execution of the tool from outside JUnit. -->
            <plugin>
                <groupId>org.codehaus.mojo</groupId><artifactId>exec-maven-plugin</artifactId><version>3.1.0</version>
                <executions>
                    <execution>
                        <id>testCrunch-simple</id><phase>integration-test</phase><goals><goal>exec</goal></goals>
                        <configuration>
                            <skip>${skipE2E}</skip>
                            <executable>java</executable>
                            <commandlineArgs>
                                ${testRunCmd}
                                --json=entries
                                --rowNumbers
                                --logLevel=INFO
                                -in src/test/data/eapBuilds.csv
                                -out target/results/result.csv
                                -sql 'SELECT jobName, buildNumber, config, ar, arFile, deployDur, warmupDur, scale,
                                CAST(warmupDur AS DOUBLE) / CAST(deployDur AS DOUBLE) AS warmupSlower
                                FROM eapBuilds ORDER BY deployDur'
                            </commandlineArgs>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId><artifactId>maven-clean-plugin</artifactId><version>3.2.0</version>
                <!-- Delete the pre-existing DB -->
                <executions>
                    <execution><id>clean-hsqldb-data</id><phase>pre-integration-test</phase><goals><goal>clean</goal></goals>
                        <configuration><directory>hsqldb/</directory></configuration>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId><artifactId>maven-enforcer-plugin</artifactId><version>3.1.0</version>
                <executions>
                    <execution>
                        <id>enforce-maven</id>
                        <goals><goal>enforce</goal></goals>
                        <configuration>
                            <rules>
                                <requireMavenVersion><version>3.8.1</version></requireMavenVersion>
                            </rules>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>org.jetbrains.kotlin</groupId>
                <artifactId>kotlin-maven-plugin</artifactId>
                <version>${version.kotlin}</version>
                <executions>
                    <execution>
                        <id>compile</id><phase>compile</phase><goals><goal>compile</goal></goals>
                        <configuration>
                            <jvmTarget>${version.jdk}</jvmTarget>
                            <sourceDirs><sourceDir>src/main/kotlin</sourceDir></sourceDirs>
                        </configuration>
                    </execution>
                    <execution><id>test-compile</id><phase>test-compile</phase><goals><goal>test-compile</goal></goals></execution>
                </executions>
            </plugin>

            <!-- Maven Compiler plugin -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.10.1</version>
                <executions>
                    <!-- Short-circuit the special treatment of default-compile executions. See https://kotlinlang.org/docs/reference/using-maven.html -->
                    <execution><id>default-compile</id><phase>none</phase></execution>
                    <execution><id>default-testCompile</id><phase>none</phase></execution>
                </executions>
                <inherited>true</inherited>
                <configuration>
                    <source>${version.jdk}</source>
                    <target>${version.jdk}</target>
                    <optimize>true</optimize>
                    <debug>true</debug>
                    <encoding>utf-8</encoding>
                </configuration>
            </plugin>

        </plugins>
    </build>


    <dependencyManagement>
        <dependencies>
            <dependency>
                <!-- Saxon 9 not found in maven repos. -->
                <groupId>net.sf.saxon</groupId>
                <artifactId>saxon</artifactId>
                <version>8.7</version>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <dependencies>

        <dependency><groupId>org.jetbrains.kotlin</groupId><artifactId>kotlin-stdlib-jdk8</artifactId><version>${version.kotlin}</version></dependency>
        <dependency><groupId>org.jetbrains.kotlin</groupId><artifactId>kotlin-reflect</artifactId><version>${version.kotlin}</version></dependency>

        <dependency><groupId>org.hsqldb</groupId><artifactId>hsqldb</artifactId><version>2.7.2</version></dependency>

        <dependency><groupId>org.apache.commons</groupId><artifactId>commons-lang3</artifactId><version>3.12.0</version></dependency>
        <dependency><groupId>commons-io</groupId><artifactId>commons-io</artifactId><version>2.11.0</version></dependency>

        <!-- Just for the JSON encoding. 355 kB.
        <dependency> <groupId>commons-codec</groupId> <artifactId>commons-codec</artifactId> <version>1.11</version> </dependency>
         -->

        <!-- Just for the JSON encoding. 16 kB. -->
        <!-- Not used now, as we use javax.json, see below.
        <dependency> <groupId>com.googlecode.json-simple</groupId> <artifactId>json-simple</artifactId> <version>1.1</version> </dependency>
        -->

        <dependency><groupId>javax.json</groupId><artifactId>javax.json-api</artifactId><version>1.1.4</version></dependency>
        <dependency><groupId>org.glassfish</groupId><artifactId>javax.json</artifactId><version>1.1.4</version></dependency>

        <dependency><groupId>com.fasterxml.jackson.core</groupId><artifactId>jackson-core</artifactId><version>${version.jackson}</version></dependency>
        <dependency><groupId>com.fasterxml.jackson.core</groupId><artifactId>jackson-databind</artifactId><version>${version.jackson}</version></dependency>
        <dependency><groupId>com.fasterxml.jackson.core</groupId><artifactId>jackson-annotations</artifactId><version>${version.jackson}</version></dependency>
        <dependency><groupId>com.fasterxml.jackson.module</groupId><artifactId>jackson-module-kotlin</artifactId><version>${version.jackson}</version></dependency>
        <dependency><groupId>com.fasterxml.jackson.dataformat</groupId><artifactId>jackson-dataformat-cbor</artifactId><version>${version.jackson}</version></dependency>

        <!-- Logging -->
        <dependency><groupId>org.slf4j</groupId><artifactId>slf4j-api</artifactId><version>2.0.6</version></dependency>
        <dependency><groupId>ch.qos.logback</groupId><artifactId>logback-classic</artifactId><version>1.4.5</version></dependency>
        <dependency><groupId>ch.qos.logback</groupId><artifactId>logback-core</artifactId><version>1.4.5</version></dependency>

        <!-- Test deps -->
        <dependency><groupId>org.junit.jupiter</groupId><artifactId>junit-jupiter</artifactId><version>5.9.1</version><scope>test</scope></dependency>
        <dependency><groupId>org.assertj</groupId><artifactId>assertj-core</artifactId><version>3.23.1</version><scope>test</scope></dependency>
        <dependency><groupId>org.apache.commons</groupId><artifactId>commons-csv</artifactId><version>1.9.0</version><scope>test</scope></dependency>
        <dependency><groupId>org.jetbrains.kotlin</groupId><artifactId>kotlin-test</artifactId><version>${version.kotlin}</version><scope>test</scope></dependency>

    </dependencies>

    <profiles>
        <profile>
            <id>debug</id>
            <properties>
                <jvm.args.debug>-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5050</jvm.args.debug>
            </properties>
        </profile>

        <!-- Releasing to Maven Central -->
        <profile>
            <id>release</id><!-- Was named "ossrh", but then this happened:
                The requested profile "release" could not be activated because it does not exist.
                Failed to execute goal org.sonatype.plugins:nexus-staging-maven-plugin:1.6.8:deploy (injected-nexus-deploy) on project csv-cruncher: Remote staging failed: Staging rules failure!
             -->
            <activation>
                <property><name>release</name></property>
            </activation>
            <build>
                <plugins>

                    <!-- Generate a JavaDoc and source jars -->
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId><artifactId>maven-source-plugin</artifactId><version>3.3.0</version>
                        <configuration><includes>**/*.kt</includes></configuration>
                        <executions><execution><id>attach-sources</id><goals><goal>jar</goal></goals></execution></executions>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId><artifactId>maven-javadoc-plugin</artifactId><version>3.5.0</version>
                        <executions><execution><id>attach-javadocs</id><goals><goal>jar</goal></goals></execution></executions>
                    </plugin>
                    <!-- <plugin> <groupId>org.jetbrains.kotlin</groupId> <artifactId>kdoc-maven-plugin</artifactId> <version>${version.kotlin}</version> </plugin> -->
                    <plugin>
                        <groupId>org.jetbrains.dokka</groupId><artifactId>dokka-maven-plugin</artifactId><version>${version.kotlin-dokka}</version>
                        <executions>
                            <execution><id>dokka-site</id><phase>pre-site</phase><goals><goal>dokka</goal></goals></execution>
                            <execution><id>dokka-jar</id><phase>package</phase><goals><goal>javadocJar</goal></goals></execution>
                        </executions>
                        <configuration><dokkaPlugins><plugin><groupId>org.jetbrains.dokka</groupId><artifactId>kotlin-as-java-plugin</artifactId><version>${version.kotlin-dokka}</version></plugin></dokkaPlugins></configuration>
                    </plugin>

                    <!-- Release plugin -->
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId><artifactId>maven-release-plugin</artifactId><version>3.0.1</version>
                        <configuration>
                            <autoVersionSubmodules>true</autoVersionSubmodules>
                            <useReleaseProfile>false</useReleaseProfile>
                            <releaseProfiles>release</releaseProfiles>
                            <goals>deploy</goals>
                        </configuration>
                    </plugin>

                    <plugin>
                        <groupId>org.sonatype.plugins</groupId><artifactId>nexus-staging-maven-plugin</artifactId><version>1.6.13</version>
                        <extensions>true</extensions>
                        <configuration>
                            <serverId>ossrh</serverId>
                            <nexusUrl>https://${ossrh.host}/</nexusUrl>
                            <autoReleaseAfterClose>true</autoReleaseAfterClose>
                            <keepStagingRepositoryOnFailure>true</keepStagingRepositoryOnFailure>
                            <keepStagingRepositoryOnCloseRuleFailure>true</keepStagingRepositoryOnCloseRuleFailure>
                            <skipStagingRepositoryClose>true</skipStagingRepositoryClose>
                        </configuration>
                    </plugin>

                    <!-- This relies on the gpg command being installed and the GPG credentials being available e.g. from settings.xml. -->
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId><artifactId>maven-gpg-plugin</artifactId><version>3.1.0</version>
                        <executions>
                            <execution>
                                <id>sign-artifacts</id>
                                <phase>verify</phase>
                                <goals><goal>sign</goal></goals>
                                <configuration>
                                    <!-- Remember to run this before Maven build: export GPG_TTY=$(tty) -->
                                    <keyname>73BA361CA92D829800730DE207838E30786B5257</keyname>
                                    <passphrase>${gpg.passphrase}</passphrase>
                                    <executable>${gpg.executable}</executable>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>

    <!-- Releasing to OSSRH, the alternative way. The other way is to use the 'release' profile, using -Drelease. -->
    <distributionManagement>
        <snapshotRepository>
            <id>ossrh</id>
            <name>ossrh</name>
            <url>https://${ossrh.host}/content/repositories/snapshots</url>
        </snapshotRepository>
        <repository>
            <id>ossrh</id>
            <name>ossrh</name>
            <url>https://${ossrh.host}/service/local/staging/deploy/maven2/</url>
        </repository>
    </distributionManagement>
</project>
