<?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/maven-v4_0_0.xsd">

  <modelVersion>4.0.0</modelVersion>
  <parent>
    <groupId>org.optaweb.employeerostering</groupId>
    <artifactId>employee-rostering</artifactId>
    <version>7.26.0.Final</version>
  </parent>

  <artifactId>employee-rostering-webapp</artifactId>
  <packaging>war</packaging>

  <name>Employee Rostering as a Service Webapp</name>

  <properties>
    <!-- maven Cargo configuration -->
    <cargo.containers.dir>${project.build.directory}/containers</cargo.containers.dir>
    <cargo.configurations.dir>${project.build.directory}/configurations</cargo.configurations.dir>
    <cargo.container.profile.dir>${cargo.configurations.dir}/cargo-profile</cargo.container.profile.dir>
    <cargo.container.log.file>${cargo.container.profile.dir}/profile-log.txt</cargo.container.log.file>
    <cargo.container.port>8080</cargo.container.port>
    <cargo.container.id>to-be-specified-in-a-profile</cargo.container.id>
    <cargo.goal>start</cargo.goal>

    <application.url>http://localhost:${cargo.container.port}/</application.url>
  </properties>

  <dependencies>
    <dependency>
      <groupId>org.optaweb.employeerostering</groupId>
      <artifactId>employee-rostering-shared</artifactId>
    </dependency>
    <dependency>
      <groupId>org.optaweb.employeerostering</groupId>
      <artifactId>employee-rostering-server</artifactId>
    </dependency>
    <!-- The dependency employee-rostering-gwtui is added by the maven profile withGwt -->

    <!-- JEE -->
    <dependency>
      <groupId>javax.persistence</groupId>
      <artifactId>javax.persistence-api</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>
    <!-- Swagger -->
    <dependency>
      <groupId>io.swagger</groupId>
      <artifactId>swagger-jaxrs</artifactId>
      <exclusions>
        <!-- Provided by app server -->
        <exclusion>
          <groupId>javax.validation</groupId>
          <artifactId>validation-api</artifactId>
        </exclusion>
        <!-- Conflicts with jboss-jaxrs-api_2.1_spec -->
        <exclusion>
          <groupId>javax.ws.rs</groupId>
          <artifactId>jsr311-api</artifactId>
        </exclusion>
      </exclusions>
    </dependency>
    <!-- Logging -->
    <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-api</artifactId>
    </dependency>

    <!-- Testing -->
    <dependency>
      <groupId>org.optaweb.employeerostering</groupId>
      <artifactId>employee-rostering-restclient</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.jboss.spec.javax.ws.rs</groupId>
      <artifactId>jboss-jaxrs-api_2.1_spec</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.jboss.resteasy</groupId>
      <artifactId>resteasy-client</artifactId>
      <scope>test</scope>
      <exclusions>
        <exclusion>
          <groupId>commons-logging</groupId>
          <artifactId>commons-logging</artifactId>
        </exclusion>
      </exclusions>
    </dependency>
    <dependency>
      <groupId>org.assertj</groupId>
      <artifactId>assertj-core</artifactId>
      <scope>test</scope>
    </dependency>
  </dependencies>

  <build>
    <finalName>optaweb-employee-rostering-${project.version}</finalName>
    <testResources>
      <testResource>
        <directory>src/test/resources/filtered</directory>
        <filtering>true</filtering>
      </testResource>
      <testResource>
        <directory>src/test/resources</directory>
        <includes>
          <include>*.cli</include>
        </includes>
      </testResource>
    </testResources>
    <pluginManagement>
      <plugins>
        <plugin>
          <groupId>org.codehaus.cargo</groupId>
          <artifactId>cargo-maven2-plugin</artifactId>
          <configuration>
            <container>
              <containerId>${cargo.container.id}</containerId>
              <timeout>600000</timeout>
              <output>${cargo.container.log.file}</output>
            </container>
            <deployables>
              <deployable>
                <groupId>${project.groupId}</groupId>
                <artifactId>${project.artifactId}</artifactId>
                <type>war</type>
                <pingURL>${application.url}</pingURL>
                <pingTimeout>120000</pingTimeout>
              </deployable>
            </deployables>
            <configuration>
              <home>${cargo.container.profile.dir}</home>
              <properties>
                <cargo.servlet.port>${cargo.container.port}</cargo.servlet.port>
              </properties>
            </configuration>
          </configuration>
          <executions>
            <execution>
              <id>start-container</id>
              <phase>pre-integration-test</phase>
              <goals>
                <goal>${cargo.goal}</goal>
              </goals>
            </execution>
            <execution>
              <id>stop-container</id>
              <phase>post-integration-test</phase>
              <goals>
                <goal>stop</goal>
              </goals>
            </execution>
          </executions>
        </plugin>
      </plugins>
    </pluginManagement>
    <plugins>
      <plugin>
        <groupId>org.codehaus.cargo</groupId>
        <artifactId>cargo-maven2-plugin</artifactId>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-failsafe-plugin</artifactId>
        <executions>
          <execution>
            <goals>
              <goal>integration-test</goal>
              <goal>verify</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>

  <profiles>
    <profile>
      <id>withGwt</id>
      <activation>
        <property>
          <name>!withoutGwt</name>
        </property>
      </activation>
      <dependencies>
        <dependency>
          <groupId>org.optaweb.employeerostering</groupId>
          <artifactId>employee-rostering-gwtui</artifactId>
          <type>war</type>
          <scope>runtime</scope>
        </dependency>
      </dependencies>
    </profile>

    <profile>
      <!-- Use this profile for any OpenShift specific customization your app will need. -->
      <!-- By default that is to put the resulting archive into the 'deployments' folder. -->
      <id>openshift</id>
      <build>
        <finalName>optaweb-employee-rostering</finalName>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <configuration>
              <outputDirectory>target</outputDirectory>
              <warName>ROOT</warName>
            </configuration>
          </plugin>
        </plugins>
      </build>
    </profile>

    <!-- Skip entire Cargo execution and tests -->
    <profile>
      <id>skipCargo</id>
      <activation>
        <property>
          <name>skipTests</name>
          <value>true</value>
        </property>
      </activation>
      <properties>
        <cargo.maven.skip>true</cargo.maven.skip>
      </properties>
    </profile>

    <profile>
      <id>cargoWildfly14</id>
      <activation>
        <property>
          <name>!cargo.maven.skip</name>
        </property>
      </activation>
      <properties>
        <cargo.container.id>wildfly14x</cargo.container.id>
        <cargo.container.port>8080</cargo.container.port>
      </properties>
      <build>
        <pluginManagement>
          <plugins>
            <plugin>
              <groupId>org.codehaus.cargo</groupId>
              <artifactId>cargo-maven2-plugin</artifactId>
              <configuration>
                <container>
                  <type>installed</type>
                  <artifactInstaller>
                    <groupId>org.wildfly</groupId>
                    <artifactId>wildfly-dist</artifactId>
                    <version>${version.org.wildfly}</version>
                  </artifactInstaller>
                </container>
                <configuration>
                  <properties>
                    <cargo.jboss.configuration>standalone</cargo.jboss.configuration>
                    <cargo.jvmargs>-Xmx512m</cargo.jvmargs>
                  </properties>
                </configuration>
              </configuration>
            </plugin>
          </plugins>
        </pluginManagement>
      </build>
    </profile>

    <!-- Start the container and don't run tests -->
    <profile>
      <id>runCargo</id>
      <properties>
        <cargo.goal>run</cargo.goal>
      </properties>
    </profile>
  </profiles>
</project>
