<?xml version="1.0" encoding="UTF-8"?>
<!--
  ~ Copyright 2020-Present Okta, 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.
  -->
<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.okta.cli</groupId>
        <artifactId>okta-cli-tools</artifactId>
        <version>0.10.0</version>
    </parent>

    <artifactId>okta-cli</artifactId>
    <name>Okta CLI</name>

    <properties>
        <maven.compiler.source>11</maven.compiler.source>
        <maven.compiler.target>11</maven.compiler.target>

        <picocli.version>4.6.3</picocli.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>com.okta.sdk</groupId>
            <artifactId>okta-sdk-api</artifactId>
            <version>${okta.sdk.version}</version>
        </dependency>
        <dependency>
            <groupId>com.okta.sdk</groupId>
            <artifactId>okta-sdk-impl</artifactId>
            <version>${okta.sdk.version}</version>
            <!-- Uses APIs that are not exposed in the api project-->
            <!-- <scope>runtime</scope>-->
        </dependency>
        <dependency>
            <groupId>com.okta.sdk</groupId>
            <artifactId>okta-sdk-httpclient</artifactId>
            <version>${okta.sdk.version}</version>
            <scope>runtime</scope>
        </dependency>

        <dependency>
            <groupId>com.okta.cli</groupId>
            <artifactId>okta-cli-common</artifactId>
        </dependency>

        <dependency>
            <groupId>info.picocli</groupId>
            <artifactId>picocli</artifactId>
            <version>${picocli.version}</version>
        </dependency>

        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>${slf4j.version}</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-jdk14</artifactId>
            <version>${slf4j.version}</version>
        </dependency>

        <dependency>
            <groupId>org.graalvm.nativeimage</groupId>
            <artifactId>svm</artifactId>
            <version>22.0.0.2</version>
        </dependency>

        <dependency>
            <groupId>com.google.auto.service</groupId>
            <artifactId>auto-service</artifactId>
            <version>1.0.1</version>
            <optional>true</optional>
        </dependency>

        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-core</artifactId>
            <version>4.3.1</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.hamcrest</groupId>
            <artifactId>hamcrest</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <resources>
            <resource>
                <directory>${project.basedir}/src/main/resources</directory>
            </resource>
            <resource>
                <directory>${project.basedir}/src/main/resources-filtered</directory>
                <filtering>true</filtering>
            </resource>
        </resources>
        <plugins>
<!--            <plugin>-->
<!--                <groupId>org.codehaus.mojo</groupId>-->
<!--                <artifactId>exec-maven-plugin</artifactId>-->
<!--                <version>1.6.0</version>-->
<!--                <configuration>-->
<!--                    <executable>java</executable>-->
<!--                    <arguments>-->
<!--                        <argument>-Xmx1000m</argument>-->
<!--                        <argument>-agentlib:native-image-agent=config-output-dir=target/foobar</argument>-->
<!--                        <argument>-classpath</argument>-->
<!--                        <classpath />-->
<!--                        <argument>com.okta.cli.OktaCli</argument>-->
<!--                        <argument>register</argument>-->
<!--                    </arguments>-->
<!--                </configuration>-->
<!--            </plugin>-->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.10.0</version>
                <configuration>
                    <verbose>true</verbose>
                    <annotationProcessorPaths>
                        <path>
                            <groupId>info.picocli</groupId>
                            <artifactId>picocli-codegen</artifactId>
                            <version>${picocli.version}</version>
                        </path>
                    </annotationProcessorPaths>
                </configuration>
            </plugin>
            <plugin>
                <groupId>pl.project13.maven</groupId>
                <artifactId>git-commit-id-plugin</artifactId>
                <version>4.9.10</version>
                <executions>
                    <execution>
                        <id>get-the-git-infos</id>
                        <goals>
                            <goal>revision</goal>
                        </goals>
                        <phase>initialize</phase>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.graalvm.nativeimage</groupId>
                <artifactId>native-image-maven-plugin</artifactId>
                <version>21.2.0</version>
                <configuration>
                    <mainClass>com.okta.cli.OktaCli</mainClass>
                    <skip>false</skip>
                    <imageName>okta</imageName>
                    <buildArgs>
                        <arg>--no-fallback</arg>
                        <arg>--no-server</arg>
                        <arg>--enable-url-protocols=http,https</arg>
                        <arg>-H:ResourceConfigurationFiles=../src/main/graalvm/resource-config.json</arg>
                        <arg>-H:ReflectionConfigurationFiles=../src/main/graalvm/reflect-config.json,../src/main/graalvm/okta-sdk-reflect-config.json</arg>
                        <arg>-H:+ReportExceptionStackTraces</arg>
                    </buildArgs>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>native-image</goal>
                        </goals>
                        <phase>package</phase>
                    </execution>
                </executions>
            </plugin>

<!--            &lt;!&ndash; the GraalVM native-image maven plugin is broken on windows, so just execute `native-image` directly &ndash;&gt;-->
<!--            <plugin>-->
<!--                <groupId>org.codehaus.mojo</groupId>-->
<!--                <artifactId>exec-maven-plugin</artifactId>-->
<!--                <version>1.6.0</version>-->
<!--                <executions>-->
<!--                    <execution>-->
<!--                        <phase>package</phase>-->
<!--                        <goals>-->
<!--                            <goal>exec</goal>-->
<!--                        </goals>-->
<!--                    </execution>-->
<!--                </executions>-->
<!--                <configuration>-->
<!--                    <executable>native-image</executable>-->
<!--                    <arguments>-->
<!--                        <argument>&#45;&#45;no-fallback</argument>-->
<!--                        <argument>&#45;&#45;no-server</argument>-->
<!--                        <argument>&#45;&#45;enable-url-protocols=http,https</argument>-->
<!--                        <argument>-H:ResourceConfigurationFiles=src/main/graalvm/resource-config.json</argument>-->
<!--                        <argument>-H:ReflectionConfigurationFiles=src/main/graalvm/reflect-config.json,src/main/graalvm/okta-sdk-reflect-config.json</argument>-->
<!--                        <argument>-H:+TraceClassInitialization</argument>-->
<!--                        <argument>-H:+ReportExceptionStackTraces</argument>-->
<!--                        <argument>-H:Class=com.okta.cli.OktaCli</argument>-->
<!--                        <argument>-H:Name=target/okta</argument>-->
<!--                        <argument>-cp</argument>-->
<!--                        <classpath />-->
<!--                    </arguments>-->
<!--                </configuration>-->
<!--            </plugin>-->

            <plugin>
                <artifactId>maven-jar-plugin</artifactId>
                <configuration>
                    <archive>
                        <manifestEntries>
                            <!-- Setting this fixes an issue when running javadoc -->
                            <!-- https://bugs.openjdk.java.net/browse/JDK-8212233 -->
                            <Automatic-Module-Name>com.okta.cli</Automatic-Module-Name>
                        </manifestEntries>
                    </archive>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>build-helper-maven-plugin</artifactId>
                <version>3.3.0</version>
                <executions>
                    <execution>
                        <id>attach-artifacts</id>
                        <phase>package</phase>
                        <goals>
                            <goal>attach-artifact</goal>
                        </goals>
                        <configuration>
                            <artifacts>
                                <artifact>
                                    <file>${project.build.directory}/okta${binary.ext}</file>
                                    <type>${binary.type}</type>
                                    <classifier>${binary.classifier}</classifier>
                                </artifact>
                            </artifacts>
                            <!-- TODO: it's difficult to attach artifacts from a multi platform build
                                 For now we will just upload the binaries to github releases -->
                            <skipAttach>true</skipAttach>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <version>2.6.4</version>
                <configuration>
                    <mainClass>com.okta.cli.OktaCli</mainClass>
                </configuration>
                <executions>
                    <execution>
                        <!-- force to after package phase -->
                        <phase>pre-integration-test</phase>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

    <profiles>
        <profile>
            <id>mac</id>
            <activation>
                <os>
                    <family>mac</family>
                </os>
            </activation>
            <properties>
                <binary.classifier>mac-${os.arch}</binary.classifier>
                <binary.type>bin</binary.type>
                <binary.ext />
            </properties>
        </profile>
        <profile>
            <id>windows</id>
            <activation>
                <os>
                    <family>windows</family>
                </os>
            </activation>
            <properties>
                <binary.classifier>windows-${os.arch}</binary.classifier>
                <binary.type>exe</binary.type>
                <binary.ext>.exe</binary.ext>
            </properties>
        </profile>
        <profile>
            <id>linux</id>
            <activation>
                <os>
                    <name>linux</name>
                </os>
            </activation>
            <properties>
                <binary.classifier>linux-${os.arch}</binary.classifier>
                <binary.type>bin</binary.type>
                <binary.ext />
            </properties>
        </profile>
    </profiles>
</project>