<?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>rhq-metrics-parent</artifactId>
    <groupId>org.rhq.metrics</groupId>
    <version>0.2.5</version>
  </parent>
  <modelVersion>4.0.0</modelVersion>

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

  <artifactId>rest-servlet</artifactId>
  <packaging>war</packaging>

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

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

    <dependency>
      <groupId>org.jboss.resteasy</groupId>
      <artifactId>jaxrs-api</artifactId>
      <version>${resteasy.version}</version>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>org.jboss.resteasy</groupId>
      <artifactId>resteasy-jaxrs</artifactId>
      <version>${resteasy.version}</version>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>org.jboss.resteasy</groupId>
      <artifactId>resteasy-jackson2-provider</artifactId>
      <version>${resteasy.version}</version>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>org.jboss.resteasy</groupId>
      <artifactId>resteasy-jaxb-provider</artifactId>
      <version>${resteasy.version}</version>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>org.jboss.resteasy</groupId>
      <artifactId>resteasy-servlet-initializer</artifactId>
      <version>${resteasy.version}</version>
      <scope>provided</scope>
    </dependency>

    <dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>javax.servlet-api</artifactId>
      <version>3.0.1</version>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>javax.ws.rs</groupId>
      <artifactId>javax.ws.rs-api</artifactId>
      <version>2.0-m03</version>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>javax</groupId>
      <artifactId>javaee-web-api</artifactId>
      <version>6.0</version>
      <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>
  </dependencies>

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

      <plugins>

         <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>
          <version>1.0.2.Final</version>
          <configuration>
            <jvmArgs>-Drhq-metrics.backend=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>
