<?xml version="1.0"?>
<!--
  ~ Copyright (c) 2011-2014 The original author or authors
  ~
  ~  All rights reserved. This program and the accompanying materials
  ~  are made available under the terms of the Eclipse Public License v1.0
  ~  and Apache License v2.0 which accompanies this distribution.
  ~
  ~      The Eclipse Public License is available at
  ~      http://www.eclipse.org/legal/epl-v10.html
  ~
  ~      The Apache License v2.0 is available at
  ~      http://www.opensource.org/licenses/apache2.0.php
  ~
  ~  You may elect to redistribute this code under either of these licenses.
  -->

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

  <artifactId>vertx-ext-parent</artifactId>
  <version>14</version>
  <packaging>pom</packaging>

  <name>Vert.x Ext Parent</name>

  <properties>
    <asciidoc.dir>${project.basedir}/src/main/asciidoc</asciidoc.dir>

    <!--
      Configure plugins that skip building documentation that otherwise would fail without
      the documentation bits. This is useful in pom aggregators that don't have documentation
      to build, they change this property to true.
    -->
    <doc.skip>false</doc.skip>

    <!-- We skip sources jar generation as we do it with the assembly plugin to have greater
         control over the content -->
    <source.skip>true</source.skip>
  </properties>

  <build>
    <pluginManagement>
      <plugins>
        <plugin>
          <artifactId>maven-clean-plugin</artifactId>
          <executions>
            <execution>
              <id>default-clean</id>
              <configuration>
                <filesets>
                  <fileset>
                    <directory>src/main/asciidoc</directory>
                  </fileset>
                  <fileset>
                    <directory>${asciidoc.dir}</directory>
                  </fileset>
                </filesets>
              </configuration>
            </execution>
          </executions>
        </plugin>
        <plugin>
          <artifactId>maven-compiler-plugin</artifactId>
          <executions>
            <execution>
              <id>default-compile</id>
              <configuration>
                <annotationProcessors>
                  <annotationProcessor>io.vertx.codegen.CodeGenProcessor</annotationProcessor>
                  <annotationProcessor>io.vertx.docgen.JavaDocGenProcessor</annotationProcessor>
                  <annotationProcessor>io.vertx.docgen.DocGenProcessor</annotationProcessor>
                </annotationProcessors>
                <generatedSourcesDirectory>${project.basedir}/src/main/generated</generatedSourcesDirectory>
                <compilerArgs>
                  <arg>-AoutputDirectory=${project.basedir}/src/main</arg>
                  <!-- $lang is replaced by the docgen processor to the target lang -->
                  <arg>-Adocgen.output=${asciidoc.dir}/$lang</arg>
                </compilerArgs>
              </configuration>
            </execution>
          </executions>
        </plugin>
        <plugin>
          <groupId>org.codehaus.mojo</groupId>
          <artifactId>build-helper-maven-plugin</artifactId>
          <version>1.9.1</version>
        </plugin>
        <plugin>
          <groupId>org.codehaus.gmavenplus</groupId>
          <artifactId>gmavenplus-plugin</artifactId>
          <version>1.2</version>
        </plugin>
        <plugin>
          <groupId>org.asciidoctor</groupId>
          <artifactId>asciidoctor-maven-plugin</artifactId>
          <version>1.5.2.1</version>
        </plugin>
        <plugin>
          <groupId>com.bluetrainsoftware.maven</groupId>
          <artifactId>groovydoc-maven-plugin</artifactId>
          <version>1.3</version>
        </plugin>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-javadoc-plugin</artifactId>
          <configuration>
            <sourcepath>${basedir}/src/main/java;${basedir}/src/main/generated</sourcepath>
          </configuration>
        </plugin>
        <plugin>
          <artifactId>maven-assembly-plugin</artifactId>
          <version>2.5.3</version>
        </plugin>
      </plugins>

    </pluginManagement>
    <plugins>

      <!-- Compile Groovy -->
      <plugin>
        <groupId>org.codehaus.gmavenplus</groupId>
        <artifactId>gmavenplus-plugin</artifactId>
        <executions>
          <execution>
            <goals>
              <goal>compile</goal>
            </goals>
          </execution>
        </executions>
      </plugin>

      <!-- Have .groovy files in sources-jar -->
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>build-helper-maven-plugin</artifactId>
        <executions>
          <execution>
            <id>add-groovy-source</id>
            <phase>prepare-package</phase>
            <goals>
              <goal>add-source</goal>
            </goals>
            <configuration>
              <sources>
                <source>${basedir}/src/main/groovy</source>
              </sources>
            </configuration>
          </execution>
        </executions>
      </plugin>

      <!-- Package sources -->
      <plugin>
        <artifactId>maven-assembly-plugin</artifactId>
        <dependencies>
          <dependency>
            <groupId>io.vertx</groupId>
            <artifactId>vertx-ext-resources</artifactId>
            <version>14</version>
          </dependency>
        </dependencies>
        <executions>
          <execution>
            <id>package-sources</id>
            <phase>package</phase>
            <goals>
              <goal>single</goal>
            </goals>
            <configuration>
              <attach>true</attach>
              <archive>
                <!-- Need a manifest to avoid empty archive -->
                <manifest>
                </manifest>
              </archive>
              <descriptorRefs>
                <descriptorRef>sources</descriptorRef>
              </descriptorRefs>
            </configuration>
          </execution>
        </executions>
      </plugin>

    </plugins>
  </build>

  <profiles>

    <!-- Documentation generation : use -DskipDocs to skip documentation generation -->
    <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>
      <repositories>
        <repository>
          <id>rubygems-releases</id>
          <url>http://rubygems-proxy.torquebox.org/releases</url>
        </repository>
      </repositories>
      <dependencies>
        <dependency>
          <groupId>rubygems</groupId>
          <artifactId>yard</artifactId>
          <version>0.8.7.6</version>
          <type>gem</type>
          <scope>provided</scope>
        </dependency>
      </dependencies>
      <build>
        <plugins>
          <plugin>
            <groupId>org.asciidoctor</groupId>
            <artifactId>asciidoctor-maven-plugin</artifactId>
            <executions>
              <execution>
                <id>asciidoctor</id>
                <goals>
                  <goal>process-asciidoc</goal>
                </goals>
                <configuration>
                  <sourceDirectory>${asciidoc.dir}</sourceDirectory>
                  <outputDirectory>${project.build.directory}/docs/${project.artifactId}</outputDirectory>
                  <sourceHighlighter>coderay</sourceHighlighter>
                  <preserveDirectories>true</preserveDirectories>
                  <relativeBaseDir>true</relativeBaseDir>
                  <skip>${doc.skip}</skip>
                  <backend>html</backend>
                  <doctype>book</doctype>
                </configuration>
                <phase>prepare-package</phase>
              </execution>
            </executions>
          </plugin>

          <plugin>
            <artifactId>maven-javadoc-plugin</artifactId>
            <executions>
              <execution>
                <phase>prepare-package</phase>
                <configuration>
                  <skip>${doc.skip}</skip>
                  <reportOutputDirectory>${project.build.directory}/docs</reportOutputDirectory>
                </configuration>
                <goals>
                  <goal>javadoc</goal>
                </goals>
              </execution>
            </executions>
          </plugin>
          <plugin>
            <groupId>com.phasebash.jsdoc</groupId>
            <artifactId>jsdoc3-maven-plugin</artifactId>
            <version>1.1.0</version>
            <executions>
              <execution>
                <phase>prepare-package</phase>
                <goals>
                  <goal>jsdoc3</goal>
                </goals>
                <configuration>
                  <recursive>true</recursive>
                  <skip>${doc.skip}</skip>
                  <directoryRoots>
                    <directoryRoot>${basedir}/src/main/resources</directoryRoot>
                  </directoryRoots>
                  <outputDirectory>${project.build.directory}/docs/${project.artifactId}/js/jsdoc</outputDirectory>
                </configuration>
              </execution>
            </executions>
          </plugin>
          <plugin>
            <groupId>com.bluetrainsoftware.maven</groupId>
            <artifactId>groovydoc-maven-plugin</artifactId>
            <executions>
              <execution>
                <phase>prepare-package</phase>
                <goals>
                  <goal>generate</goal>
                </goals>
                <configuration>
                  <destinationDirectory>${project.build.directory}/docs/${project.artifactId}/groovy/groovydoc</destinationDirectory>
                  <scope>public</scope>
                  <skipJavadoc>true</skipJavadoc>
                  <extensions>.groovy</extensions>
                </configuration>
              </execution>
            </executions>
          </plugin>
          <plugin>
            <groupId>de.saumya.mojo</groupId>
            <artifactId>gem-maven-plugin</artifactId>
            <version>1.0.9</version>
            <executions>
              <execution>
                <goals>
                  <goal>exec</goal>
                </goals>
                <phase>prepare-package</phase>
                <configuration>
                  <execArgs>${project.build.directory}/rubygems/bin/yardoc --no-private -m html -o ${project.build.directory}/docs/${project.artifactId}/ruby/yardoc ${project.basedir}/src/main/resources/**/*.rb</execArgs>
                </configuration>
              </execution>
            </executions>
            <dependencies>
              <dependency>
                <groupId>rubygems</groupId>
                <artifactId>yard</artifactId>
                <version>0.8.7.6</version>
                <type>gem</type>
              </dependency>
              <dependency>
                <groupId>rubygems</groupId>
                <artifactId>asciidoctor</artifactId>
                <version>1.5.2</version>
                <type>gem</type>
              </dependency>
            </dependencies>
          </plugin>
          <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <dependencies>
              <dependency>
                <groupId>io.vertx</groupId>
                <artifactId>vertx-ext-resources</artifactId>
                <version>14</version>
              </dependency>
            </dependencies>
            <executions>
              <execution>
                <id>package-docs</id>
                <phase>package</phase>
                <goals>
                  <goal>single</goal>
                </goals>
                <configuration>
                  <skipAssembly>${doc.skip}</skipAssembly>
                  <attach>true</attach>
                  <descriptorRefs>
                    <descriptorRef>docs</descriptorRef>
                  </descriptorRefs>
                </configuration>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>

  <reporting>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-project-info-reports-plugin</artifactId>
        <version>2.7</version>
        <reportSets>
          <reportSet>
            <reports>
            </reports>
          </reportSet>
        </reportSets>
      </plugin>
    </plugins>
  </reporting>

</project>
