<?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">
    <modelVersion>4.0.0</modelVersion>

    <groupId>{{groupId}}</groupId>
    <artifactId>{{artifactId}}</artifactId>
    <version>{{version}}</version>
    <packaging>war</packaging>

    <!-- contains default pluginManagement configuration for liberty-maven-plugin -->
    <parent>
        <groupId>net.wasdev.wlp.maven.parent</groupId>
        <artifactId>liberty-maven-app-parent</artifactId>
        <version>2.1.2</version>
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>

        <liberty.plugin.version>2.6.1</liberty.plugin.version>
        <app.name>{{appName}}</app.name>
        {{#each properties}}
        <{{this.name}}>{{this.value}}</{{this.name}}>
        {{/each}}
        {{#has platforms 'bluemix'}}
        <!-- Cloud Foundry/IBM Cloud properties -->
        <cf.context>mybluemix.net</cf.context>
        <cf.target>https://api.ng.bluemix.net</cf.target>
        <cf.space>dev</cf.space>
        <cf.context.root>${cf.host}.${cf.context}</cf.context.root>

        <!-- The Cloud Foundry or IBM Cloud organization, username and password can be
            entered here. -->
        <!-- <cf.org></cf.org> -->
        <!-- <cf.username></cf.username> -->
        <!-- <cf.password></cf.password> -->
        <!-- This is the host for your app in IBM Cloud and what it will be called in the dashboard. -->
        <cf.host>${app.name}</cf.host>
        {{/has}}
    </properties>

    <dependencies>
        {{#each dependencies}}
        <dependency>
            <groupId>{{this.groupId}}</groupId>
            <artifactId>{{this.artifactId}}</artifactId>
            <version>{{this.version}}</version>
            {{#if scope}}
            <scope>{{this.scope}}</scope>
            {{/if}}
            {{#if type}}
            <type>{{this.type}}</type>
            {{/if}}
            {{#if exclusions}}
            <exclusions>
              {{#each exclusions}}
              <exclusion>
                <groupId>{{this.groupId}}</groupId>
                <artifactId>{{this.artifactId}}</artifactId>
              </exclusion>
              {{/each}}
            </exclusions>
            {{/if}}
        </dependency>
        {{/each}}
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.6</version>
                <configuration>
                    <failOnMissingWebXml>false</failOnMissingWebXml>
                    <packagingExcludes>pom.xml</packagingExcludes>
                </configuration>
            </plugin>
            <!-- Plugin to run unit tests -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.18.1</version>
                <executions>
                    <execution>
                        <phase>test</phase>
                        <id>default-test</id>
                        <configuration>
                            <excludes>
                                <exclude>**/it/**</exclude>
                            </excludes>
                            <reportsDirectory>${project.build.directory}/test-reports/unit</reportsDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            {{#javametrics}}
            <!-- Configure javametrics monitoring -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>3.0.1</version>
                <executions>
                    <execution>
                        <id>copy-javametrics-dash</id>
                        <phase>package</phase>
                        <goals>
                            <goal>copy-dependencies</goal>
                        </goals>
                        <configuration>
                          <stripVersion>true</stripVersion>
                          <outputDirectory>${project.build.directory}/liberty/wlp/usr/servers/defaultServer/dropins</outputDirectory>
                          <includeArtifactIds>javametrics-dash</includeArtifactIds>
                      </configuration>
                    </execution>
                    <execution>
                        <id>copy-javametrics-rest</id>
                        <phase>package</phase>
                        <goals>
                            <goal>copy-dependencies</goal>
                        </goals>
                        <configuration>
                            <stripVersion>true</stripVersion>
                            <outputDirectory>${project.build.directory}/liberty/wlp/usr/servers/defaultServer/dropins</outputDirectory>
                            <includeArtifactIds>javametrics-rest</includeArtifactIds>
                      </configuration>
                    </execution>
                    <execution>
                        <id>copy-javametrics-agent</id>
                        <phase>package</phase>
                        <goals>
                            <goal>copy-dependencies</goal>
                        </goals>
                        <configuration>
                          <stripVersion>true</stripVersion>
                          <outputDirectory>${project.build.directory}/liberty/wlp/usr/servers/defaultServer/resources/</outputDirectory>
                          <includeArtifactIds>javametrics-agent</includeArtifactIds>
                      </configuration>
                    </execution>
                    <execution>
                        <id>copy-javametrics-asm</id>
                        <phase>package</phase>
                        <goals>
                            <goal>copy-dependencies</goal>
                        </goals>
                        <configuration>
                          <outputDirectory>${project.build.directory}/liberty/wlp/usr/servers/defaultServer/resources/asm</outputDirectory>
                          <includeGroupIds>org.ow2.asm</includeGroupIds>
                          <includeArtifactIds>asm,asm-commons</includeArtifactIds>
                      </configuration>
                    </execution>
                </executions>
            </plugin>
            {{/javametrics}}
            <!-- Enable liberty-maven plugin -->
            <plugin>
                <groupId>net.wasdev.wlp.maven.plugins</groupId>
                <artifactId>liberty-maven-plugin</artifactId>
                <version>${liberty.plugin.version}</version>
                <configuration>
                    {{#libertyBeta}}
                    <install>
                        <type>webProfile7</type>
                        <version>{{libertyVersion}}</version>
                    </install>
                    {{else}}
                    <assemblyArtifact>
                        <groupId>com.ibm.websphere.appserver.runtime</groupId>
                        <artifactId>wlp-webProfile7</artifactId>
                        <version>{{libertyVersion}}</version>
                        <type>zip</type>
                    </assemblyArtifact>
                    {{/libertyBeta}}
                    <configFile>${basedir}/src/main/liberty/config/server.xml</configFile>
                    <serverEnv>${basedir}/src/main/liberty/config/server.env</serverEnv>
                    <jvmOptionsFile>${basedir}/src/main/liberty/config/jvm.options</jvmOptionsFile>
                    <packageFile>${package.file}</packageFile>
                    <include>${packaging.type}</include>
                    <bootstrapProperties>
                        <app.location>${project.artifactId}-${project.version}.war</app.location>
                        <default.http.port>${testServerHttpPort}</default.http.port>
                        <default.https.port>${testServerHttpsPort}</default.https.port>
                    </bootstrapProperties>
                    <features>
                        <acceptLicense>true</acceptLicense>
                    </features>
                    <looseApplication>false</looseApplication>
                </configuration>
            </plugin>
            <!-- Plugin to run functional tests -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-failsafe-plugin</artifactId>
                <version>2.18.1</version>
                <executions>
                    <execution>
                        <phase>integration-test</phase>
                        <id>integration-test</id>
                        <goals>
                            <goal>integration-test</goal>
                        </goals>
                        <configuration>
                            <includes>
                                <include>**/it/**</include>
                            </includes>
                            <systemPropertyVariables>
                                <liberty.test.port>${testServerHttpPort}</liberty.test.port>
                                <war.context>${warContext}</war.context>
                            </systemPropertyVariables>
                        </configuration>
                    </execution>
                    <execution>
                        <id>verify-results</id>
                        <goals>
                            <goal>verify</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <summaryFile>${project.build.directory}/test-reports/it/failsafe-summary.xml</summaryFile>
                    <reportsDirectory>${project.build.directory}/test-reports/it</reportsDirectory>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <profiles>
        <profile>
            <id>runnable</id>
            <properties>
                <package.file>${project.build.directory}/${app.name}.jar</package.file>
                <packaging.type>runnable</packaging.type>
            </properties>
        </profile>
        <profile>
            <id>bx-dev-build</id>
            <build>
                <pluginManagement>
                    <plugins>
                        <plugin>
                            <groupId>net.wasdev.wlp.maven.plugins</groupId>
                            <artifactId>liberty-maven-plugin</artifactId>
                            <version>${liberty.plugin.version}</version>
                            <configuration>
                                <outputDirectory>/tmp/liberty</outputDirectory>
                            </configuration>
                            <executions>
                                <execution>
                                    <id>install-feature</id>
                                    <phase>prepare-package</phase>
                                    <goals>
                                        <goal>install-feature</goal>
                                    </goals>
                                    <configuration>
                                        <outputDirectory>/tmp/liberty</outputDirectory>
                                    </configuration>
                                </execution>
                                <execution>
                                    <id>package-server</id>
                                    <phase>package</phase>
                                    <goals>
                                        <goal>package-server</goal>
                                    </goals>
                                    <configuration>
                                        <outputDirectory>/tmp/liberty</outputDirectory>
                                    </configuration>
                                </execution>
                            </executions>
                        </plugin>
                    </plugins>
                </pluginManagement>
             </build>
        </profile>
        {{#has platforms 'bluemix'}}
        <profile>
          <id>bluemix</id>
          <build>
              <plugins>
                  <plugin>
                      <groupId>org.apache.maven.plugins</groupId>
                      <artifactId>maven-enforcer-plugin</artifactId>
                      <version>1.4.1</version>
                      <executions>
                          <execution>
                              <id>enforce-bluemix-credentials</id>
                              <phase>initialize</phase>
                              <goals>
                                  <goal>enforce</goal>
                              </goals>
                              <configuration>
                                  <rules>
                                      <requireProperty>
                                          <property>cf.org</property>
                                          <message>The cf.org property must be
                                              provided with the bluemix
                                              profile.</message>
                                      </requireProperty>
                                      <requireProperty>
                                          <property>cf.username</property>
                                          <message>The cf.username property
                                              must be provided with the
                                              bluemix profile.</message>
                                      </requireProperty>
                                      <requireProperty>
                                          <property>cf.password</property>
                                          <message>The cf.password property
                                              must be provided with the
                                              bluemix profile.</message>
                                      </requireProperty>
                                  </rules>
                              </configuration>
                          </execution>
                      </executions>
                  </plugin>
                  <plugin>
                      <groupId>org.cloudfoundry</groupId>
                      <artifactId>cf-maven-plugin</artifactId>
                      <version>1.1.3</version>
                      <configuration>
                          <target>${cf.target}</target>
                          <org>${cf.org}</org>
                          <space>${cf.space}</space>
                          <username>${cf.username}</username>
                          <password>${cf.password}</password>
                          <appname>${cf.host}</appname>
                          <memory>512</memory>
                      </configuration>
                      <executions>
                          <execution>
                              <id>push</id>
                              <phase>package</phase>
                              <goals>
                                  <goal>push</goal>
                              </goals>
                              <configuration>
                                  <path>${package.file}</path>
                              </configuration>
                          </execution>
                      </executions>
                  </plugin>
              </plugins>
          </build>
      </profile>
      {{/has}}
    </profiles>
</project>
