<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.10.1</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.10.1</tag>
    </scm>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <version.kotlin>2.1.0</version.kotlin>
        <version.kotlin-dokka>1.9.20</version.kotlin-dokka>
        <version.jdk>11</version.jdk>
        <version.jackson>2.18.2</version.jackson>
        <version.surefire>3.5.2</version.surefire>

        <jvm.args.debug /> <!-- Used by the -Pdebug profile. -->
        <mainClass>Crunch</mainClass>
        <fatJarAssemblyId>fatjar</fatJarAssemblyId>
        <testRunCmd>${jvm.args.debug} -jar ${project.build.directory}/${project.build.finalName}-${fatJarAssemblyId}.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.4.2</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>
                        <id>testData-unzip</id>
                        <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>
                    <execution>
                        <id>distZip-unzip-before-e2e-test</id><phase>pre-integration-test</phase><goals><goal>run</goal></goals>
                        <configuration>
                            <target><unzip src="${project.build.directory}/${project.build.finalName}-dist.zip" dest="${project.build.directory}/dist-zip/" /></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>
                    <workingDirectory>${project.build.directory}/workdir</workingDirectory>

                    <systemPropertyVariables>
                        <target.dir>${project.build.directory}</target.dir>
                        <test.data.dir>${project.build.testSourceDirectory}/../data</test.data.dir>
                        <test.output.dir>${project.build.directory}/testOutput</test.output.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>
                        <target.dir>${project.build.directory}</target.dir>
                        <test.cruncher.runCmd>${testRunCmd}</test.cruncher.runCmd>
                        <test.data.dir>${project.build.testSourceDirectory}/../data</test.data.dir>
                        <test.output.dir>${project.build.directory}/testOutput</test.output.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>

            <!-- Assemblies - fat jar, dist zip. -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId><artifactId>maven-assembly-plugin</artifactId><version>3.7.1</version>
                <executions>

                    <!-- Disabled, because it does not include resources. Possibly a bug? -->
                    <execution>
                        <id>single-DISABLED</id> <!-- Was before MJAR-233: assembleDistJar -->
                        <goals><goal>single</goal></goals>
                        <phase>none</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>
                            <appendAssemblyId>true</appendAssemblyId>
                        </configuration>
                    </execution>

                    <!-- Shaded jar. Used primarily for testing. Users would rather use ...-dist.zip . -->
                    <execution>
                        <id>single</id>
                        <goals><goal>single</goal></goals>
                        <phase>package</phase>
                        <configuration>
                            <archive>
                                <manifest>
                                    <mainClass>${mainClass}</mainClass>
                                    <addClasspath>false</addClasspath> <!-- false for jar-with-dependencies -->
                                    <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
                                    <addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
                                </manifest>
                                <manifestEntries>
                                    <Release-Version>${project.version}</Release-Version>
                                </manifestEntries>
                            </archive>
                            <descriptors>
                                <descriptor>src/main/assembly-${fatJarAssemblyId}.xml</descriptor>
                            </descriptors>
                            <appendAssemblyId>true</appendAssemblyId>
                        </configuration>
                    </execution>

                    <execution>
                        <id>dist</id> <!-- assembleDistZip -->
                        <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>
                            <appendAssemblyId>false</appendAssemblyId>
                        </configuration>
                    </execution>

                </executions>
            </plugin>

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


            <!-- One real execution of the tool from outside JUnit. -->
            <plugin>
                <groupId>org.codehaus.mojo</groupId><artifactId>exec-maven-plugin</artifactId><version>3.5.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>

                    <!-- Run CsvCruncher from the -dist.zip (extracted above) through the script. -->
                    <execution>
                        <id>testCrunch-dist</id><phase>verify</phase><goals><goal>exec</goal></goals>
                        <configuration>
                            <skip>${skipE2E}</skip>
                            <executable>sh</executable>
                            <commandlineArgs>
                                ${project.build.directory}/dist-zip/${project.build.finalName}-dist/crunch
                                --json=entries
                                --rowNumbers
                                --logLevel=INFO
                                -in src/test/data/eapBuilds.csv
                                -out ${project.build.directory}/results/distZipCrunchResult.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.4.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>
                            <excludeDefaultDirectories>true</excludeDefaultDirectories>
                            <filesets> <fileset> <directory>hsqldb/</directory> <useDefaultExcludes>false</useDefaultExcludes> </fileset> </filesets>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId><artifactId>maven-enforcer-plugin</artifactId><version>3.5.0</version>
                <executions>
                    <execution>
                        <id>enforce-maven</id>
                        <goals><goal>enforce</goal></goals>
                        <configuration>
                            <rules>
                                <requireMavenVersion><version>3.8.7</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.13.0</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>
            <!-- Saxon 9 not found in maven repos. -->
            <dependency><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.4</version></dependency>

        <dependency><groupId>org.apache.commons</groupId><artifactId>commons-lang3</artifactId><version>3.17.0</version></dependency>
        <dependency><groupId>commons-io</groupId><artifactId>commons-io</artifactId><version>2.18.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.16</version></dependency>
        <dependency><groupId>ch.qos.logback</groupId><artifactId>logback-classic</artifactId><version>1.5.12</version></dependency>
        <dependency><groupId>ch.qos.logback</groupId><artifactId>logback-core</artifactId><version>1.5.12</version></dependency>

        <!-- Test deps -->
        <dependency><groupId>org.junit.jupiter</groupId><artifactId>junit-jupiter</artifactId><version>5.11.3</version><scope>test</scope></dependency>
        <dependency><groupId>org.junit.jupiter</groupId><artifactId>junit-jupiter-params</artifactId><version>5.11.3</version><scope>test</scope></dependency>
        <dependency><groupId>org.assertj</groupId><artifactId>assertj-core</artifactId><version>3.26.3</version><scope>test</scope></dependency>
        <dependency><groupId>org.apache.commons</groupId><artifactId>commons-csv</artifactId><version>1.12.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>
    <repositories>
        <repository>
            <id>central</id>
            <url>https://repo.maven.apache.org/maven2/</url>
        </repository>
    </repositories>

    <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.1</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.11.1</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.1.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.7.0</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. -->
                    <!-- Remember to run this before Maven build: export GPG_TTY=$(tty) -->
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId><artifactId>maven-gpg-plugin</artifactId><version>3.2.7</version>
                        <executions>
                            <execution>
                                <id>sign-artifacts</id>
                                <phase>verify</phase>
                                <goals><goal>sign</goal></goals>
                                <configuration>
                                    <keyname>73BA361CA92D829800730DE207838E30786B5257</keyname>
                                    <passphrase>${gpg.passphrase}</passphrase>
                                    <executable>${gpg.executable}</executable>
                                </configuration>
                            </execution>
                            <execution>
                                <!-- The current setup does not sign the base jar, so the Staged release fails on OSSRH checks. Not sure if this works, leaving as WIP. -->
                                <id>sign-main-jar-hack</id>
                                <phase>none</phase> <!-- DISABLED - did not work -->
                                <goals><goal>sign-and-deploy-file</goal></goals>
                                <configuration>
                                    <file>${project.build.directory}/${project.build.finalName}.jar</file>
                                    <url>https://${ossrh.host}/</url>
                                    <repositoryId>ossrh</repositoryId>

                                    <groupId>${project.groupId}</groupId>
                                    <artifactId>${project.artifactId}</artifactId>
                                    <version>${project.version}</version>

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