<?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>
    <groupId>io.vertx</groupId>
    <artifactId>vertx-parent</artifactId>
    <version>9</version>
  </parent>

  <modelVersion>4.0.0</modelVersion>

  <artifactId>vertx-lang-ruby</artifactId>
  <version>3.3.2</version>

  <properties>
    <asciidoc.dir>${project.basedir}/src/main/asciidoc</asciidoc.dir>
    <tools.jar>${java.home}/../lib/tools.jar</tools.jar>
    <stack.version>3.3.2</stack.version>
  </properties>

  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>io.vertx</groupId>
        <artifactId>vertx-dependencies</artifactId>
        <version>${stack.version}</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>
    </dependencies>
  </dependencyManagement>

  <dependencies>

    <dependency>
      <groupId>io.vertx</groupId>
      <artifactId>vertx-codegen</artifactId>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>io.vertx</groupId>
      <artifactId>vertx-codegen</artifactId>
      <classifier>sources</classifier>
      <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-core</artifactId>
    </dependency>
    <dependency>
      <groupId>io.vertx</groupId>
      <artifactId>vertx-core</artifactId>
      <classifier>sources</classifier>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>org.jruby</groupId>
      <artifactId>jruby-complete</artifactId>
      <version>9.0.5.0</version>
    </dependency>
    <dependency>
      <groupId>org.mvel</groupId>
      <artifactId>mvel2</artifactId>
      <version>2.2.8.Final</version>
      <scope>provided</scope>
    </dependency>

    <!-- Test 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>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.12</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>io.vertx</groupId>
      <artifactId>vertx-core</artifactId>
      <type>test-jar</type>
      <scope>test</scope>
    </dependency>

  </dependencies>

  <build>

    <pluginManagement>
      <plugins>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-surefire-plugin</artifactId>
          <configuration>
            <systemPropertyVariables>
              <java.util.logging.SimpleFormatter.format>%4$s: %3$s - %5$s %6$s%n</java.util.logging.SimpleFormatter.format>
              <gems.path>${project.build.directory}/gems</gems.path>
            </systemPropertyVariables>
            <additionalClasspathElements>
              <additionalClasspathElement>${project.build.testSourceDirectory}</additionalClasspathElement>
              <additionalClasspathElement>${project.basedir}/src/main/resources</additionalClasspathElement>
            </additionalClasspathElements>
          </configuration>
        </plugin>
        <plugin>
          <artifactId>maven-clean-plugin</artifactId>
          <executions>
            <execution>
              <id>default-clean</id>
              <configuration>
                <filesets>
                  <fileset>
                    <directory>${asciidoc.dir}</directory>
                  </fileset>
                </filesets>
              </configuration>
            </execution>
          </executions>
        </plugin>
      </plugins>
    </pluginManagement>
    <plugins>
      <plugin>
        <artifactId>maven-dependency-plugin</artifactId>
        <executions>
          <!-- Unpack vertx-core source code to target/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 target/sources/codegen -->
          <execution>
            <id>unpack-codegen</id>
            <phase>generate-test-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/codegen</outputDirectory>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.bsc.maven</groupId>
        <artifactId>maven-processor-plugin</artifactId>
        <version>3.1.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 ruby 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>
                <outputDirectory>${project.basedir}/src/main</outputDirectory>
              </optionMap>
              <sourceDirectory>${project.build.directory}/sources/vertx-core</sourceDirectory>
            </configuration>
          </execution>
          <!-- Run the annotation processor on vertx-core and generate the ruby API -->
          <execution>
            <id>generate-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}/ruby</docgen.output>
              </optionMap>
              <sourceDirectory>${project.build.directory}/sources/vertx-core</sourceDirectory>
            </configuration>
          </execution>
          <!-- We have to run the annotation processor again to process doc overrides -->
          <execution>
            <id>generate-docoverride</id>
            <goals>
              <goal>process</goal>
            </goals>
            <phase>prepare-package</phase>
            <configuration>
              <processors>
                <processor>io.vertx.docgen.DocGenProcessor</processor>
              </processors>
              <optionMap>
                <docgen.output>${asciidoc.dir}/ruby</docgen.output>

                <maven.groupId>${project.groupId}</maven.groupId>
                <maven.artifactId>${project.artifactId}</maven.artifactId>
                <maven.version>${project.version}</maven.version>
              </optionMap>
              <sourceDirectory>src/main/docoverride</sourceDirectory>
            </configuration>
          </execution>
          <!-- Run the annotation processor on codegen and generate the ruby codegen -->
          <execution>
            <id>generate-codegen</id>
            <goals>
              <goal>process</goal>
            </goals>
            <phase>generate-test-sources</phase>
            <configuration>
              <processors>
                <processor>io.vertx.codegen.CodeGenProcessor</processor>
              </processors>
              <optionMap>
                <outputDirectory>${project.basedir}/src/test</outputDirectory>
              </optionMap>
              <sourceDirectory>${project.build.directory}/sources/codegen</sourceDirectory>
              <excludes>
                <exclude>io/vertx/test/lang/ruby/**</exclude>
              </excludes>
              <additionalSourceDirectories>
                <additionalSourceDirectory>${project.basedir}/src/test/java</additionalSourceDirectory>
              </additionalSourceDirectories>
            </configuration>
          </execution>
        </executions>
        <dependencies>
          <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.11</version>
          </dependency>
        </dependencies>
      </plugin>

      <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-assembly-plugin</artifactId>
        <executions>
          <execution>
            <id>assemble</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>
    <profile>
      <id>docs</id>
      <activation>
        <property>
          <name>!skipDocs</name>
        </property>
      </activation>
      <pluginRepositories>
        <pluginRepository>
          <id>rubygems-releases</id>
          <url>http://rubygems-proxy.torquebox.org/releases</url>
        </pluginRepository>
      </pluginRepositories>
      <build>
        <plugins>
          <plugin>
            <groupId>de.saumya.mojo</groupId>
            <artifactId>gem-maven-plugin</artifactId>
            <version>1.1.4</version>
            <executions>
              <execution>
                <goals>
                  <goal>exec</goal>
                </goals>
                <phase>prepare-package</phase>
                <configuration>
                  <execArgs>${project.build.directory}/rubygems/bin/yardoc --no-private -m html --main ${project.basedir}/src/main/resources/vertx/index.md -o ${project.build.directory}/docs/yardoc ${project.basedir}/src/main/resources/vertx/*.rb</execArgs>
                </configuration>
              </execution>
            </executions>
            <dependencies>
              <dependency>
                <groupId>rubygems</groupId>
                <artifactId>yard</artifactId>
                <version>0.8.7.6</version>
                <type>gem</type>
              </dependency>
            </dependencies>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>

</project>
