<?xml version="1.0" encoding="UTF-8"?>
<!--

    Copyright 2014-2015 Red Hat, Inc. and/or its affiliates
    and other contributors as indicated by the @author tags.

    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>
    <artifactId>rhq-metrics-parent</artifactId>
    <groupId>org.rhq.metrics</groupId>
    <version>0.2.7</version>
  </parent>
  <artifactId>rest-servlet</artifactId>
  <packaging>war</packaging>

  <name>RHQ Metrics REST-api</name>
  <description>The REST-api of RHQ-Metrics implemented as a Web archive</description>

  <properties>
    <swagger-annotations.version>1.2.3</swagger-annotations.version>
    <rest-docs-generator.version>4.11.0</rest-docs-generator.version>
  </properties>

  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>org.wildfly.bom</groupId>
        <artifactId>jboss-javaee-7.0-with-resteasy</artifactId>
        <version>${version.wildfly}</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>
    </dependencies>
  </dependencyManagement>

  <dependencies>

    <dependency>
      <groupId>org.antlr</groupId>
      <artifactId>antlr4-runtime</artifactId>
    </dependency>
    <dependency>
      <groupId>org.rhq.metrics</groupId>
      <artifactId>rhq-metrics-core</artifactId>
      <version>${project.version}</version>
    </dependency>

    <!-- Wildfly provided -->
    <dependency>
      <groupId>org.jboss.resteasy</groupId>
      <artifactId>resteasy-jaxrs</artifactId>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>org.jboss.resteasy</groupId>
      <artifactId>resteasy-jackson2-provider</artifactId>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>org.jboss.spec.javax.servlet</groupId>
      <artifactId>jboss-servlet-api_3.1_spec</artifactId>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>javax.enterprise</groupId>
      <artifactId>cdi-api</artifactId>
      <scope>provided</scope>
    </dependency>

    <!-- documentation -->
    <dependency>
      <groupId>com.wordnik</groupId>
      <artifactId>swagger-annotations_2.9.1</artifactId>
      <version>${swagger-annotations.version}</version>
      <scope>provided</scope>
    </dependency>

    <!-- test -->
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
    </dependency>
    <dependency>
      <groupId>org.assertj</groupId>
      <artifactId>assertj-core</artifactId>
    </dependency>
    <dependency>
      <groupId>org.mockito</groupId>
      <artifactId>mockito-core</artifactId>
    </dependency>
  </dependencies>

  <build>
    <finalName>rhq-metric-rest</finalName>
    <plugins>

      <plugin>
        <groupId>org.antlr</groupId>
        <artifactId>antlr4-maven-plugin</artifactId>
        <executions>
          <execution>
            <id>antlr4</id>
            <goals>
              <goal>antlr4</goal>
            </goals>
            <phase>generate-sources</phase>
            <configuration>
              <listener>true</listener>
              <visitor>true</visitor>
            </configuration>
          </execution>
        </executions>
      </plugin>

      <plugin>
        <artifactId>maven-war-plugin</artifactId>
        <configuration>
          <archive>
            <manifest>
              <addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
              <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
            </manifest>
            <!-- <manifestEntries> <Build-Number>${buildNumber}</Build-Number>
              </manifestEntries> -->
          </archive>
          <webResources>
            <resource>
              <filtering>false</filtering>
              <directory>${basedir}/src/main/webapp</directory>
            </resource>
          </webResources>
        </configuration>
      </plugin>

      <plugin>
        <groupId>org.wildfly.plugins</groupId>
        <artifactId>wildfly-maven-plugin</artifactId>
        <configuration>
          <jvmArgs>-Drhq-metrics.backend=em_cass -Xdebug
            -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8787</jvmArgs>
        </configuration>
      </plugin>

    </plugins>
  </build>

  <profiles>
    <profile>
      <id>REST doc generation</id>
      <activation>
        <property>
          <name>docgen</name>
        </property>
      </activation>

      <dependencies>
        <dependency>
          <groupId>org.rhq.helpers</groupId>
          <artifactId>rest-docs-generator</artifactId>
          <version>${rest-docs-generator.version}</version>
          <scope>provided</scope>
        </dependency>
      </dependencies>

      <build>
        <!-- Document generation from the Annotations on the REST-API. -->
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
              <annotationProcessors>
                <processor>org.rhq.helpers.rest_docs_generator.ClassLevelProcessor</processor>
              </annotationProcessors>
              <proc>only</proc>
              <compilerArguments>
                <AtargetDirectory>${project.build.directory}/docs/xml</AtargetDirectory>
                <AmodelPkg>org.rhq.metrics.restServlet</AmodelPkg>
                <!--<AskipPkg>org.rhq.enterprise.server.rest.reporting</AskipPkg> -->
                <!-- enable the next line to have the output of the processor
                  shown on console -->
                <!--<Averbose>true</Averbose> -->
              </compilerArguments>
              <!-- set the next to true to enable verbose output of the compiler
                plugin; default from the evn is true, but this is too noisy -->
              <verbose>false</verbose>
            </configuration>
            <executions>
              <execution>
                <id>create-rest-api-reports</id>
                <phase>process-classes</phase>
                <goals>
                  <!-- We want to process the classes in src/ -->
                  <goal>compile</goal>
                </goals>
              </execution>
            </executions>
          </plugin>

          <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>xml-maven-plugin</artifactId>
            <executions>
              <execution>
                <phase>process-classes</phase>
                <goals>
                  <goal>transform</goal>
                </goals>
              </execution>
            </executions>
            <configuration>
              <transformationSets>
                <transformationSet>
                  <!-- Generate a html rendering -->
                  <!-- org.rhq.helpers.rest_docs_generator.test plugin wrote
                    to target/docs/xml (see -AtargetDirectory above) -->
                  <dir>target/docs/xml</dir>
                  <includes>
                    <include>rest-api-out.xml</include>
                  </includes>
                  <stylesheet>src/main/xsl/apiout2html.xsl</stylesheet>
                  <parameters>
                    <parameter>
                      <name>basePath</name>
                      <value>http://localhost:8080/rhq-metrics</value>
                    </parameter>
                  </parameters>
                  <outputDir>${project.build.directory}/docs/html</outputDir>
                  <fileMappers>
                    <fileMapper
                      implementation="org.codehaus.plexus.components.io.filemappers.FileExtensionMapper">
                      <targetExtension>.html</targetExtension>
                    </fileMapper>
                  </fileMappers>
                </transformationSet>
                <transformationSet>
                  <!-- Generate a html rendering of a short form -->
                  <!-- org.rhq.helpers.rest_docs_generator.test plugin wrote
                    to target/docs/xml (see -AtargetDirectory above) -->
                  <dir>target/docs/xml</dir>
                  <includes>
                    <include>rest-api-out.xml</include>
                  </includes>
                  <stylesheet>src/main/xsl/apiout2html_overview.xsl</stylesheet>
                  <parameters>
                    <parameter>
                      <name>basePath</name>
                      <value>http://localhost:8080/rhq-metrics</value>
                    </parameter>
                  </parameters>
                  <outputDir>${project.build.directory}/docs/html</outputDir>
                  <fileMappers>
                    <fileMapper
                      implementation="org.codehaus.plexus.components.io.filemappers.MergeFileMapper">
                      <targetName>rest-api-overview</targetName>
                    </fileMapper>
                    <fileMapper
                      implementation="org.codehaus.plexus.components.io.filemappers.FileExtensionMapper">
                      <targetExtension>.html</targetExtension>
                    </fileMapper>
                  </fileMappers>
                </transformationSet>
                <transformationSet>
                  <!-- Generate a docbook file as input to fop -->
                  <!-- org.rhq.helpers.rest_docs_generator.test plugin wrote
                    to target/docs/xml (see -AtargetDirectory above) -->
                  <dir>target/docs/xml</dir>
                  <includes>
                    <include>rest-api-out.xml</include>
                  </includes>
                  <stylesheet>src/main/xsl/apiout2docbook.xsl</stylesheet>
                  <parameters>
                    <parameter>
                      <name>basePath</name>
                      <value>http://localhost:8080/rhq-metrics</value>
                    </parameter>
                  </parameters>
                  <outputDir>${project.build.directory}/docs/xml</outputDir>
                  <fileMappers>
                    <fileMapper
                      implementation="org.codehaus.plexus.components.io.filemappers.FileExtensionMapper">
                      <targetExtension>.dbx.xml</targetExtension>
                    </fileMapper>
                  </fileMappers>
                </transformationSet>
              </transformationSets>
            </configuration>
          </plugin>

          <plugin>
            <groupId>com.agilejava.docbkx</groupId>
            <artifactId>docbkx-maven-plugin</artifactId>
            <version>2.0.14</version>
            <executions>
              <execution>
                <phase>process-classes</phase>
                <goals>
                  <goal>generate-pdf</goal>
                  <goal>generate-html</goal>
                </goals>
              </execution>
            </executions>
            <configuration>
              <sourceDirectory>target/docs/xml</sourceDirectory> <!-- from previous plugin, 2nd transformation set -->
              <includes>rest-api-out.dbx.xml</includes>
              <hyphenate>true</hyphenate>
              <generateToc>true</generateToc>
            </configuration>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>
</project>

