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

    Copyright 2015-2016 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>hawkular-datamining-parent</artifactId>
    <groupId>org.hawkular.datamining</groupId>
    <version>0.2.0.Final</version>
  </parent>

  <artifactId>hawkular-datamining-rest</artifactId>
  <packaging>war</packaging>

  <dependencies>
    <dependency>
      <groupId>org.hawkular.datamining</groupId>
      <artifactId>hawkular-datamining-cdi</artifactId>
      <version>${project.version}</version>
    </dependency>

    <!-- Servlet Filter -->
    <dependency>
      <groupId>org.jboss.spec.javax.servlet</groupId>
      <artifactId>jboss-servlet-api_3.1_spec</artifactId>
      <scope>provided</scope>
    </dependency>

    <!-- Rest -->
    <dependency>
      <groupId>org.jboss.resteasy</groupId>
      <artifactId>resteasy-jaxrs</artifactId>
      <scope>provided</scope>
    </dependency>
    <!-- JSON -->
    <dependency>
      <groupId>org.jboss.resteasy</groupId>
      <artifactId>resteasy-jackson2-provider</artifactId>
      <scope>provided</scope>
    </dependency>

    <dependency>
      <groupId>javax.enterprise</groupId>
      <artifactId>cdi-api</artifactId>
      <scope>provided</scope>
    </dependency>

    <!-- DOC -->
    <dependency>
      <groupId>io.swagger</groupId>
      <artifactId>swagger-annotations</artifactId>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>io.swagger</groupId>
      <artifactId>swagger-core</artifactId>
      <scope>provided</scope>
    </dependency>
  </dependencies>

  <profiles>
    <profile>
      <id>dev</id>
      <build>
        <plugins>
          <!-- Download wildfly and copy dist war there -->
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <executions>
              <execution>
                <id>unpack-wildfly</id>
                <phase>prepare-package</phase>
                <goals>
                  <goal>unpack</goal>
                </goals>
                <configuration>
                  <artifactItems>
                    <artifactItem>
                      <groupId>org.wildfly</groupId>
                      <artifactId>wildfly-dist</artifactId>
                      <version>${version.org.wildfly}</version>
                      <type>zip</type>
                      <outputDirectory>${project.build.directory}</outputDirectory>
                    </artifactItem>
                  </artifactItems>
                </configuration>
              </execution>
              <execution>
                <id>copy</id>
                <phase>package</phase>
                <goals>
                  <goal>copy</goal>
                </goals>
                <configuration>
                  <artifactItems>
                    <artifactItem>
                      <groupId>org.hawkular.datamining</groupId>
                      <artifactId>hawkular-datamining-rest</artifactId>
                      <version>${project.version}</version>
                      <type>war</type>
                      <overWrite>false</overWrite>
                      <outputDirectory>${project.build.directory}/wildfly-${version.org.wildfly}/standalone/deployments</outputDirectory>
                    </artifactItem>
                  </artifactItems>
                  <outputDirectory>${project.build.directory}/wars</outputDirectory>
                  <overWriteReleases>false</overWriteReleases>
                  <overWriteSnapshots>true</overWriteSnapshots>
                </configuration>
              </execution>
            </executions>
          </plugin>

          <!-- further customize standalone.xml -->
          <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>xml-maven-plugin</artifactId>
            <version>${version.org.codehaus.mojo.xml-maven-plugin}</version>
            <executions>
              <execution>
                <id>transform-standalone-xml</id>
                <phase>install</phase>
                <goals>
                  <goal>transform</goal>
                </goals>
                <configuration>
                  <transformationSets>
                     standalone.xml
                    <transformationSet>
                      <dir>${project.build.directory}/wildfly-${version.org.wildfly}/standalone/configuration</dir>
                      <stylesheet>jboss-standalone.xsl</stylesheet>
                      <includes>
                        <include>standalone.xml</include>
                      </includes>
                      <outputDir>${project.build.directory}/wildfly-${version.org.wildfly}/standalone/configuration</outputDir>
                    </transformationSet>
                  </transformationSets>
                </configuration>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>

    <profile>
      <id>docgen</id>
      <properties>
        <restDocDirectory>${project.basedir}/src/main/rest-doc</restDocDirectory>
        <swaggerDirectory>${project.build.directory}/generated/swagger-ui</swaggerDirectory>
      </properties>
      <build>
        <!-- Document generation from the Swagger annotations on the REST-API. -->
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <executions>
              <execution>
                <id>unpack</id>
                <phase>process-resources</phase>
                <goals>
                  <goal>unpack</goal>
                </goals>
                <configuration>
                  <artifactItems>
                    <artifactItem>
                      <groupId>org.hawkular</groupId>
                      <artifactId>hawkular-build-tools</artifactId>
                      <version>${version.org.hawkular.hawkular-build-tools}</version>
                      <type>jar</type>
                      <includes>**/*.groovy</includes>
                    </artifactItem>
                  </artifactItems>
                </configuration>
              </execution>
            </executions>
          </plugin>
          <plugin>
            <groupId>com.github.kongchen</groupId>
            <artifactId>swagger-maven-plugin</artifactId>
            <configuration>
              <apiSources>
                <apiSource>
                  <springmvc>false</springmvc>
                  <locations>org.hawkular.datamining.rest</locations>
                  <basePath>/hawkular/datamining/</basePath>
                  <info>
                    <title>Hawkular Data Mining</title>
                    <version>${project.version}</version>
                  </info>
                  <swaggerDirectory>${swaggerDirectory}</swaggerDirectory>
                </apiSource>
              </apiSources>
            </configuration>
            <executions>
              <execution>
                <phase>compile</phase>
                <goals>
                  <goal>generate</goal>
                </goals>
              </execution>
            </executions>
          </plugin>
          <plugin>
            <groupId>org.codehaus.gmavenplus</groupId>
            <artifactId>gmavenplus-plugin</artifactId>
            <dependencies>
              <dependency>
                <groupId>org.codehaus.groovy</groupId>
                <artifactId>groovy-all</artifactId>
                <version>${version.org.codehaus.groovy}</version>
              </dependency>
            </dependencies>
            <configuration>
              <properties>
                <baseFile>${restDocDirectory}/base.adoc</baseFile>
                <swaggerFile>${swaggerDirectory}/swagger.json</swaggerFile>
                <outputFile>${project.build.directory}/generated/rest-datamining.adoc</outputFile>
              </properties>
              <scripts>
                <script>file:///${project.build.directory}/dependency/hawkular-documentation/apidoc.groovy</script>
              </scripts>
            </configuration>
            <executions>
              <execution>
                <id>generate-api-doc</id>
                <phase>compile</phase>
                <goals>
                  <goal>execute</goal>
                </goals>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>
</project>
