<?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">
  <parent>
    <artifactId>vertx-lang-kotlin-parent</artifactId>
    <groupId>io.vertx</groupId>
    <version>3.5.1</version>
  </parent>
  <modelVersion>4.0.0</modelVersion>

  <artifactId>vertx-lang-kotlin</artifactId>

  <dependencies>

    <dependency>
      <groupId>io.vertx</groupId>
      <artifactId>vertx-codegen</artifactId>
      <classifier>tck-sources</classifier>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>io.vertx</groupId>
      <artifactId>vertx-codegen</artifactId>
      <classifier>tck</classifier>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>io.vertx</groupId>
      <artifactId>vertx-core</artifactId>
      <type>test-jar</type>
      <scope>test</scope>
    </dependency>

    <dependency>
      <groupId>io.vertx</groupId>
      <artifactId>vertx-codegen</artifactId>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>io.vertx</groupId>
      <artifactId>vertx-docgen</artifactId>
      <optional>true</optional>
    </dependency>
    <dependency>
      <groupId>io.vertx</groupId>
      <artifactId>vertx-codetrans</artifactId>
      <optional>true</optional>
    </dependency>
    <dependency>
      <groupId>io.vertx</groupId>
      <artifactId>vertx-codegen</artifactId>
      <scope>provided</scope>
      <classifier>sources</classifier>
    </dependency>
    <dependency>
      <groupId>io.vertx</groupId>
      <artifactId>vertx-core</artifactId>
      <scope>provided</scope>
      <classifier>sources</classifier>
    </dependency>
  </dependencies>

  <build>
    <testSourceDirectory>src/test/kotlin</testSourceDirectory>
    <plugins>
      <plugin>
        <groupId>org.jetbrains.kotlin</groupId>
        <artifactId>kotlin-maven-plugin</artifactId>
        <executions>
          <execution>
            <id>compile</id>
            <goals>
              <goal>compile</goal>
            </goals>
            <phase>compile</phase>
            <configuration>
              <sourceDirs>
                <sourceDir>src/main/java</sourceDir>
                <sourceDir>target/generated-sources/kotlin</sourceDir>
              </sourceDirs>
            </configuration>
          </execution>
          <execution>
            <id>>test-compile</id>
            <goals>
              <goal>test-compile</goal>
            </goals>
            <phase>test-compile</phase>
            <configuration>
              <sourceDirs>
                <sourceDir>src/test/kotlin</sourceDir>
                <sourceDir>target/generated-test-sources/kotlin</sourceDir>
              </sourceDirs>
            </configuration>
          </execution>
        </executions>
      </plugin>

      <plugin>
        <artifactId>maven-dependency-plugin</artifactId>
        <executions>
          <!-- Unpack vertx-core source code to target/sources/vertx-core -->
          <execution>
            <id>unpack-vertx-core</id>
            <phase>generate-sources</phase>
            <goals>
              <goal>unpack-dependencies</goal>
            </goals>
            <configuration>
              <includeGroupIds>io.vertx</includeGroupIds>
              <includeArtifactIds>vertx-core</includeArtifactIds>
              <includeTypes>jar</includeTypes>
              <includeClassifiers>sources</includeClassifiers>
              <includes>io/vertx/core/**/*.java,examples/**/*.java</includes>
              <excludes>**/impl/**/*.java,**/logging/**/*.java</excludes>
              <outputDirectory>${project.build.directory}/sources/vertx-core</outputDirectory>
            </configuration>
          </execution>
          <!-- Unpack codegen source code to sources/test/java -->
          <execution>
            <id>unpack-tck</id>
            <phase>generate-sources</phase>
            <goals>
              <goal>unpack-dependencies</goal>
            </goals>
            <configuration>
              <includeGroupIds>io.vertx</includeGroupIds>
              <includeArtifactIds>vertx-codegen</includeArtifactIds>
              <includeTypes>jar</includeTypes>
              <includeClassifiers>tck-sources</includeClassifiers>
              <outputDirectory>${project.build.directory}/sources/vertx-codegen</outputDirectory>
            </configuration>
          </execution>
        </executions>
      </plugin>

      <plugin>
        <groupId>org.bsc.maven</groupId>
        <artifactId>maven-processor-plugin</artifactId>
        <version>3.2.0</version>
        <configuration>
          <systemProperties>
            <java.util.logging.SimpleFormatter.format>%4$s: %3$s - %5$s %6$s%n</java.util.logging.SimpleFormatter.format>
          </systemProperties>
        </configuration>
        <executions>
          <!-- Run the annotation processor on vertx-core and generate the Kotlin API -->
          <execution>
            <id>generate-api</id>
            <goals>
              <goal>process</goal>
            </goals>
            <phase>generate-sources</phase>
            <configuration>
              <processors>
                <processor>io.vertx.codegen.CodeGenProcessor</processor>
              </processors>
              <optionMap>
                <codegen.output>${project.build.directory}/generated-sources</codegen.output>
                <codegen.generators>Kotlin</codegen.generators>
              </optionMap>
              <sourceDirectory>${project.build.directory}/sources/vertx-core</sourceDirectory>
            </configuration>
          </execution>
          <!-- We have to run the annotation processor again to process docs -->
          <execution>
            <id>docgen-docs</id>
            <goals>
              <goal>process</goal>
            </goals>
            <phase>prepare-package</phase>
            <configuration>
              <processors>
                <processor>io.vertx.docgen.DocGenProcessor</processor>
              </processors>
              <optionMap>
                <docgen.output>${asciidoc.dir}/kotlin</docgen.output>
                <maven.groupId>${project.groupId}</maven.groupId>
                <maven.artifactId>${project.artifactId}</maven.artifactId>
                <maven.version>${project.version}</maven.version>
              </optionMap>
              <sourceDirectory>${project.build.directory}/sources/vertx-core</sourceDirectory>
            </configuration>
          </execution>
          <!-- Run the annotation processor on vertx-codegen TCK and generate the Kotlin API -->
          <execution>
            <id>generate-tck</id>
            <goals>
              <goal>process-test</goal>
            </goals>
            <phase>generate-test-sources</phase>
            <configuration>
              <processors>
                <processor>io.vertx.codegen.CodeGenProcessor</processor>
              </processors>
              <optionMap>
                <codegen.output>${project.build.directory}/generated-test-sources</codegen.output>
                <codegen.generators>Kotlin</codegen.generators>
              </optionMap>
              <sourceDirectory>${project.build.directory}/sources/vertx-codegen</sourceDirectory>
              <defaultOutputDirectory>${project.build.directory}/generated-test-sources/apt</defaultOutputDirectory>
            </configuration>
          </execution>
        </executions>
        <dependencies>
          <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>${junit.version}</version>
          </dependency>
        </dependencies>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-source-plugin</artifactId>
        <executions>
          <execution>
            <id>attach-sources</id>
            <goals>
              <goal>jar-no-fork</goal>
              <goal>test-jar-no-fork</goal>
            </goals>
            <phase>package</phase>
            <configuration>
              <includes>
                <include>**/*.kt</include>
                <include>**/*.json</include>
                <include>**/*.templ</include>
              </includes>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <artifactId>maven-assembly-plugin</artifactId>
        <executions>
          <execution>
            <id>assemble-docs</id>
            <phase>package</phase>
            <goals>
              <goal>single</goal>
            </goals>
            <configuration>
              <attach>true</attach>
              <descriptors>
                <descriptor>src/main/assembly/docs.xml</descriptor>
              </descriptors>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>

  <profiles>
    <!-- Use -Pdocs -->
    <profile>
      <id>docs</id>
      <build>
        <plugins>
          <plugin>
            <groupId>org.asciidoctor</groupId>
            <artifactId>asciidoctor-maven-plugin</artifactId>
            <executions>
              <execution>
                <goals>
                  <goal>process-asciidoc</goal>
                </goals>
                <phase>prepare-package</phase>
              </execution>
            </executions>
          </plugin>
          <plugin>
            <artifactId>maven-javadoc-plugin</artifactId>
            <executions>
              <execution>
                <configuration>
                  <sourcepath>${project.build.directory}/sources/vertx-core/</sourcepath>
                  <reportOutputDirectory>${project.build.directory}/docs</reportOutputDirectory>
                </configuration>
                <phase>package</phase>
                <goals>
                  <goal>javadoc</goal>
                </goals>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>

</project>
