<?xml version="1.0" encoding="UTF-8"?>
<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>com.github.nbbrd.sdmx-dl</groupId>
        <artifactId>sdmx-dl-parent</artifactId>
        <version>3.1.1</version>
    </parent>

    <artifactId>sdmx-dl-cli</artifactId>
    <packaging>jar</packaging>

    <name>sdmx-dl-cli</name>
    <description>Easily download official statistics - CLI</description>
    <url>https://github.com/nbbrd/sdmx-dl</url>

    <properties>
        <project.x.mainClass>sdmxdl.cli.MainCommand</project.x.mainClass>
    </properties>

    <dependencies>
        <!-- compile only -->
        <dependency>
            <groupId>org.jspecify</groupId>
            <artifactId>jspecify</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>info.picocli</groupId>
            <artifactId>picocli-codegen</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.github.nbbrd.java-design-util</groupId>
            <artifactId>java-design-processor</artifactId>
            <scope>provided</scope>
        </dependency>

        <!-- compile and runtime -->
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>sdmx-dl-api</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>sdmx-dl-provider-base</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>sdmx-dl-provider-ri</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>sdmx-dl-provider-dialects</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>sdmx-dl-provider-px</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>sdmx-dl-format-xml</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>sdmx-dl-format-csv</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>sdmx-dl-format-protobuf</artifactId>
            <version>${project.version}</version>
            <exclusions>
                <exclusion>
                    <groupId>com.google.code.gson</groupId>
                    <artifactId>gson</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>info.picocli</groupId>
            <artifactId>picocli</artifactId>
        </dependency>
        <dependency>
            <groupId>info.picocli</groupId>
            <artifactId>picocli-jansi-graalvm</artifactId>
            <version>1.2.0</version>
        </dependency>
        <dependency>
            <groupId>com.github.nbbrd.java-console-properties</groupId>
            <artifactId>java-console-properties</artifactId>
            <version>1.4.1</version>
        </dependency>
        <dependency>
            <groupId>dev.failsafe</groupId>
            <artifactId>failsafe</artifactId>
        </dependency>

        <!-- runtime only -->
        <dependency>
            <groupId>com.github.nbbrd.java-io-util</groupId>
            <artifactId>java-io-win</artifactId>
            <scope>runtime</scope>
        </dependency>

        <!-- test only -->
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>sdmx-dl-api</artifactId>
            <version>${project.version}</version>
            <classifier>tests</classifier>
            <type>test-jar</type>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>sdmx-dl-format-xml</artifactId>
            <version>${project.version}</version>
            <classifier>tests</classifier>
            <type>test-jar</type>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.assertj</groupId>
            <artifactId>assertj-core</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.junit-pioneer</groupId>
            <artifactId>junit-pioneer</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <properties combine.self="append">
                        <!-- Disable parallel JUnit execution due to shared system property handling -->
                        <configurationParameters>
                            junit.jupiter.execution.parallel.enabled=false
                        </configurationParameters>
                    </properties>
                </configuration>
            </plugin>

            <!-- Generate configuration files and documentation for picocli-based applications -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <annotationProcessorPaths >
                        <path>
                            <groupId>info.picocli</groupId>
                            <artifactId>picocli-codegen</artifactId>
                            <version>${picocli.version}</version>
                        </path>
                    </annotationProcessorPaths>
                    <compilerArgs >
                        <!-- picocli-codegen option -->
                        <arg>-Aproject=${project.groupId}/${project.artifactId}</arg>
                    </compilerArgs>
                </configuration>
            </plugin>

            <plugin>
                <groupId>io.github.ascopes</groupId>
                <artifactId>protobuf-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <protoc>${protobuf.version}</protoc>
                    <embedSourcesInClassOutputs>true</embedSourcesInClassOutputs>
                    <failOnMissingSources>false</failOnMissingSources>
                </configuration>
            </plugin>

            <!-- Generates a all-in-one executable jar -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <filters>
                        <filter>
                            <artifact>*:*</artifact>
                            <excludes>
                                <exclude>**/module-info.class</exclude>
                                <exclude>META-INF/MANIFEST.MF</exclude>
                                <exclude>META-INF/NOTICE</exclude>
                                <exclude>META-INF/LICENSE</exclude>
                                <exclude>META-INF/LICENSE.txt</exclude>
                                <exclude>META-INF/MSFTSIG*</exclude>
                            </excludes>
                        </filter>
                    </filters>
                    <transformers>
                        <transformer
                                implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
                        <transformer
                                implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                            <mainClass>${project.x.mainClass}</mainClass>
                            <manifestEntries>
                                <Enable-Native-Access>ALL-UNNAMED</Enable-Native-Access>
                            </manifestEntries>
                        </transformer>
                    </transformers>
                    <shadedArtifactAttached>true</shadedArtifactAttached>
                    <shadedClassifierName>bin</shadedClassifierName>
                    <createDependencyReducedPom>false</createDependencyReducedPom>
                </configuration>
            </plugin>

            <plugin>
                <!-- Generates data files for documentation -->
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>3.6.3</version>
                <executions>
                    <execution>
                        <id>generate-csv-sources</id>
                        <phase>package</phase>
                        <goals>
                            <goal>exec</goal>
                        </goals>
                        <configuration>
                            <executable>java</executable>
                            <arguments>
                                <argument>-classpath</argument>
                                <classpath/>
                                <argument>${project.x.mainClass}</argument>
                                <argument>list</argument>
                                <argument>sources</argument>
                                <argument>-o</argument>
                                <argument>${project.parent.basedir}/docs/assets/sources.csv</argument>
                                <argument>--no-config</argument>
                            </arguments>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

    <profiles>
        <profile>
            <id>native</id>
            <properties>
                <graalvm.version>21.2.0</graalvm.version>
            </properties>
            <dependencies>
                <dependency>
                    <groupId>org.graalvm.sdk</groupId>
                    <artifactId>graal-sdk</artifactId>
                    <version>${graalvm.version}</version>
                    <scope>provided</scope>
                </dependency>
            </dependencies>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.graalvm.nativeimage</groupId>
                        <artifactId>native-image-maven-plugin</artifactId>
                        <version>${graalvm.version}</version>
                        <executions>
                            <execution>
                                <goals>
                                    <goal>native-image</goal>
                                </goals>
                                <phase>package</phase>
                            </execution>
                        </executions>
                        <configuration>
                            <imageName>${project.artifactId}-${project.version}</imageName>
                            <!-- FIX: kryo: report-unsupported-elements-at-runtime -->
                            <!-- FIX: sdmx-dl: xml resources such as Checks.xml -->
                            <!-- FIX: sdmx-dl: ps1 resources such as WinPasswordVault.ps1 -->
                            <!-- FIX: sdmx-dl: csv resources such as api.json -->
                            <!-- FIX: sdmx-dl: csv resources such as websites.csv -->
                            <!-- FIX: sdmx-dl: some Windows charsets are not included by default -->
                            <buildArgs>
                                --no-fallback
                                --enable-http
                                --enable-https
                                --report-unsupported-elements-at-runtime
                                -H:IncludeResources=.*\.(xml|ps1|json|csv)$
                                -H:+AddAllCharsets
                                -H:+TraceSecurityServices
                            </buildArgs>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
</project>