<?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.lancethomps</groupId>
    <artifactId>lancethomps-parent</artifactId>
    <version>1.7.0</version>
    <relativePath>../../pom.xml</relativePath>
  </parent>
  <artifactId>lancethomps-java-cli</artifactId>
  <version>1.7.0</version>
  <packaging>pom</packaging>
  <name>${project.groupId}:${project.artifactId}</name>
  <url>https://github.com/lancethomps/lancethomps-parent/modules/lancethomps-java-cli</url>
  <properties>
    <java.level>11</java.level>
  </properties>
  <dependencies>
    <dependency>
      <groupId>org.graalvm.nativeimage</groupId>
      <artifactId>svm</artifactId>
      <version>20.1.0</version>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>info.picocli</groupId>
      <artifactId>picocli</artifactId>
      <version>4.3.2</version>
    </dependency>
    <dependency>
      <groupId>info.picocli</groupId>
      <artifactId>picocli-jansi-graalvm</artifactId>
      <version>1.1.0</version>
    </dependency>
    <dependency>
      <groupId>org.fusesource.jansi</groupId>
      <artifactId>jansi</artifactId>
      <version>1.18</version>
    </dependency>
    <!-- Logging -->
    <dependency>
      <groupId>org.apache.logging.log4j</groupId>
      <artifactId>log4j-core</artifactId>
    </dependency>
    <!-- Guava + Apache Commons -->
    <dependency>
      <groupId>com.google.guava</groupId>
      <artifactId>guava</artifactId>
    </dependency>
    <dependency>
      <groupId>org.apache.commons</groupId>
      <artifactId>commons-text</artifactId>
    </dependency>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <scope>test</scope>
    </dependency>
  </dependencies>
  <build>
    <pluginManagement>
      <plugins>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-compiler-plugin</artifactId>
          <configuration>
            <annotationProcessorPaths>
              <path>
                <groupId>info.picocli</groupId>
                <artifactId>picocli-codegen</artifactId>
                <version>4.1.4</version>
              </path>
            </annotationProcessorPaths>
            <compilerArgs>
              <arg>-Xlint:classfile</arg>
              <arg>-Aproject=${project.groupId}/${project.artifactId}</arg>
            </compilerArgs>
          </configuration>
        </plugin>
        <plugin>
          <groupId>org.codehaus.gmaven</groupId>
          <artifactId>groovy-maven-plugin</artifactId>
          <version>2.1.1</version>
          <executions>
            <execution>
              <id>install-javacli</id>
              <phase>install</phase>
              <goals>
                <goal>execute</goal>
              </goals>
              <configuration>
                <classpathScope>runtime</classpathScope>
                <source>import org.apache.commons.io.FileUtils

                  import picocli.AutoComplete

                  String imageName = properties.get("javacli.imageName")
                  String mainClass = properties.get("javacli.mainClass")

                  File nativeImage = new File(new File(basedir as File, "target"), imageName)
                  File installedNativeImage = new File(new File(basedir as File, "dotfiles/bin"), imageName)
                  installedNativeImage.delete()
                  FileUtils.copyFile(nativeImage, installedNativeImage)
                  installedNativeImage.setExecutable(true, false)

                  File completionFile = new File(basedir as File, String.format("dotfiles/.bash_completion.d/%s-completion.sh", imageName))
                  completionFile.getParentFile().mkdirs()
                  AutoComplete.main(
                      "-n",
                      imageName,
                      "-o",
                      completionFile.getAbsolutePath(),
                      "--force",
                      mainClass
                  )</source>
              </configuration>
            </execution>
          </executions>
          <dependencies>
            <dependency>
              <groupId>org.codehaus.groovy</groupId>
              <artifactId>groovy-all</artifactId>
              <version>3.0.4</version>
              <type>pom</type>
              <exclusions>
                <exclusion>
                  <artifactId>groovy-testng</artifactId>
                  <groupId>org.codehaus.groovy</groupId>
                </exclusion>
              </exclusions>
            </dependency>
            <dependency>
              <groupId>${project.groupId}</groupId>
              <artifactId>${project.artifactId}</artifactId>
              <version>${project.version}</version>
            </dependency>
            <dependency>
              <groupId>info.picocli</groupId>
              <artifactId>picocli-codegen</artifactId>
              <version>4.3.2</version>
            </dependency>
            <dependency>
              <groupId>commons-io</groupId>
              <artifactId>commons-io</artifactId>
              <version>2.7</version>
            </dependency>
          </dependencies>
        </plugin>
        <plugin>
          <groupId>org.graalvm.nativeimage</groupId>
          <artifactId>native-image-maven-plugin</artifactId>
          <version>20.1.0</version>
          <executions>
            <execution>
              <phase>package</phase>
              <goals>
                <goal>native-image</goal>
              </goals>
              <configuration>
                <!--suppress UnresolvedMavenProperty -->
                <imageName>${javacli.imageName}</imageName>
                <!--suppress UnresolvedMavenProperty -->
                <mainClass>${javacli.mainClass}</mainClass>
                <buildArgs>-H:+ReportUnsupportedElementsAtRuntime
                  -H:+ReportExceptionStackTraces
                  --no-server</buildArgs>
              </configuration>
            </execution>
          </executions>
        </plugin>
      </plugins>
    </pluginManagement>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-checkstyle-plugin</artifactId>
      </plugin>
    </plugins>
  </build>
  <profiles>
    <profile>
      <!-- NB: turn on this profile in IntelliJ for IDE support when editing groovy-maven-plugin scripts -->
      <id>editor-groovy-maven-plugin</id>
      <dependencies>
        <dependency>
          <groupId>org.apache.maven</groupId>
          <artifactId>maven-core</artifactId>
          <version>3.6.3</version>
          <type>jar</type>
          <scope>provided</scope>
          <exclusions>
            <exclusion>
              <artifactId>*</artifactId>
              <groupId>*</groupId>
            </exclusion>
          </exclusions>
        </dependency>
        <dependency>
          <groupId>org.apache.maven</groupId>
          <artifactId>maven-settings</artifactId>
          <version>3.6.3</version>
          <type>jar</type>
          <scope>provided</scope>
          <exclusions>
            <exclusion>
              <artifactId>*</artifactId>
              <groupId>*</groupId>
            </exclusion>
          </exclusions>
        </dependency>
        <dependency>
          <groupId>org.codehaus.gmaven</groupId>
          <artifactId>groovy-maven-plugin</artifactId>
          <version>2.1.1</version>
          <type>jar</type>
          <scope>provided</scope>
          <exclusions>
            <exclusion>
              <artifactId>*</artifactId>
              <groupId>*</groupId>
            </exclusion>
          </exclusions>
        </dependency>
        <dependency>
          <groupId>org.codehaus.groovy</groupId>
          <artifactId>groovy-all</artifactId>
          <version>3.0.4</version>
          <type>pom</type>
          <scope>provided</scope>
          <exclusions>
            <exclusion>
              <artifactId>groovy-testng</artifactId>
              <groupId>org.codehaus.groovy</groupId>
            </exclusion>
          </exclusions>
        </dependency>
        <dependency>
          <groupId>info.picocli</groupId>
          <artifactId>picocli-codegen</artifactId>
          <version>4.3.2</version>
          <scope>provided</scope>
        </dependency>
        <dependency>
          <groupId>commons-io</groupId>
          <artifactId>commons-io</artifactId>
          <version>2.7</version>
          <scope>provided</scope>
        </dependency>
      </dependencies>
    </profile>
  </profiles>
</project>
