<?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>
  <parent>
    <groupId>org.squashtest.tm</groupId>
    <artifactId>squash-tm-plugins</artifactId>
    <version>14.0.0-loadtest.IT2</version>
  </parent>

  <artifactId>plugin.testautomation.jenkins</artifactId>
  <name>${project.groupId}.${project.artifactId}</name>
  <description>Squash TM Connector for Squash TA on Jenkins</description>

  <properties>
    <maven-antrun-plugin.version>3.1.0</maven-antrun-plugin.version>
    <skipITs>false</skipITs>

    <!-- The default web port will be reserved and set by build-helper:reserve-network-port (see below) -->
    <!--stubTaServer.webapp.port>9000</stubTaServer.webapp.port-->
    <sonar.sources>src/main</sonar.sources>
    <squash.dependencies.version>${project.version}</squash.dependencies.version>
    <stubTaServer.webapp.path>target/${project.artifactId}-${project.version}</stubTaServer.webapp.path>
  </properties>

  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>org.squashtest.tm</groupId>
        <artifactId>squash-tm-bom</artifactId>
        <version>${project.version}</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>
    </dependencies>
  </dependencyManagement>

  <dependencies>

    <dependency>
      <groupId>org.squashtest.tm</groupId>
      <artifactId>core.testautomation.api</artifactId>
      <version>${project.version}</version>
    </dependency>

    <dependency>
      <groupId>org.apache.httpcomponents.client5</groupId>
      <artifactId>httpclient5</artifactId>
    </dependency>

    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <dependency>
      <groupId>org.squashtest.tm</groupId>
      <artifactId>tm.domain</artifactId>
      <version>${project.version}</version>
    </dependency>

    <dependency>
      <groupId>org.squashtest.tm</groupId>
      <artifactId>tm.service</artifactId>
      <version>${project.version}</version>
    </dependency>

    <dependency>
      <groupId>${project.groupId}</groupId>
      <artifactId>spock-test-dependencies</artifactId>
      <version>${project.version}</version>
      <type>pom</type>
      <scope>test</scope>
    </dependency>
  </dependencies>

  <build>

    <testSourceDirectory>src/test/groovy</testSourceDirectory>
    <resources>
      <resource>
        <directory>${project.basedir}/src/main/resources</directory>
      </resource>
    </resources>

    <plugins>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>build-helper-maven-plugin</artifactId>
        <executions>
          <execution>
            <id>add-integration-test-source</id>
            <goals>
              <goal>add-test-source</goal>
            </goals>
            <configuration>
              <sources>
                <source>src/it/groovy</source>
              </sources>
            </configuration>
          </execution>

          <execution>
            <id>add-integration-test-resource</id>
            <goals>
              <goal>add-test-resource</goal>
            </goals>
            <phase>generate-test-resources</phase>
            <configuration>
              <resources>
                <resource>
                  <directory>src/it/resources</directory>
                </resource>
              </resources>
            </configuration>
          </execution>

          <execution>
            <id>reserve-stub-port</id>
            <goals>
              <goal>reserve-network-port</goal>
            </goals>
            <phase>pre-integration-test</phase>
            <configuration>
              <portNames>
                <portName>stubTaServer.webapp.port</portName>
              </portNames>
              <minPortNumber>9000</minPortNumber>
              <maxPortNumber>11000</maxPortNumber>
            </configuration>
          </execution>

        </executions>
      </plugin>

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <executions>
          <execution>
            <id>compile-integration-test</id>
            <goals>
              <goal>testCompile</goal>
            </goals>
            <phase>pre-integration-test</phase>
          </execution>
        </executions>
      </plugin>

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-failsafe-plugin</artifactId>
        <configuration>
          <!-- We can run ITs and skip unit tests with -DskipTests=true -->
          <skipTests>${skipITs}</skipTests>
        </configuration>

        <executions>
          <execution>
            <id>integration-tests</id>
            <goals>
              <goal>integration-test</goal>
              <goal>verify</goal>
            </goals>
            <phase>integration-test</phase>
            <configuration>
              <systemPropertyVariables>
                <stubTaServer.webapp.port>${stubTaServer.webapp.port}</stubTaServer.webapp.port>
              </systemPropertyVariables>
            </configuration>
          </execution>
        </executions>
      </plugin>

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-antrun-plugin</artifactId>
        <version>${maven-antrun-plugin.version}</version>
        <executions>
          <execution>
            <goals>
              <goal>run</goal>
            </goals>
            <phase>pre-integration-test</phase>
            <configuration>
              <target>
                <echo message="Create document base for IT's tomcat"/>
                <mkdir dir="${stubTaServer.webapp.path}"/>
              </target>
            </configuration>
          </execution>
        </executions>
      </plugin>

      <!-- Does not work after java 17 migration, part of solution is to use cargo-maven3-plugin with tomcat9
       but still have issues in tests, and all this configuration for only 3 tests, I really think it is not worth... -->
      <!-- <plugin>
         <groupId>org.apache.tomcat.maven</groupId>
         <artifactId>tomcat7-maven-plugin</artifactId>
         <version>2.2</version>
         <executions>
           <execution>
             <id>start-stub-ta</id>
             &lt;!&ndash; start stub ta server before ITs &ndash;&gt;
             <goals>
               <goal>run-war-only</goal>
             </goals>
             <phase>pre-integration-test</phase>
             <configuration>
               <skip>${skipITs}</skip>
               <ignorePackaging>true</ignorePackaging>
               <path>/foo</path>
               <warDirectory>${stubTaServer.webapp.path}</warDirectory>
               <port>${stubTaServer.webapp.port}</port>
               <fork>true</fork>
               <webapps>
                 <webapp>
                   <groupId>org.squashtest.ta.test</groupId>
                   <artifactId>stub-ta-server</artifactId>
                   <version>1.0.1</version>
                   <type>war</type>
                   <asWebapp>true</asWebapp>
                 </webapp>
               </webapps>
             </configuration>
           </execution>

           <execution>
             <id>shutdown-stub-ta</id>
             &lt;!&ndash; kills stub ta server after ITs &ndash;&gt;
             <goals>
               <goal>shutdown</goal>
             </goals>
             <phase>post-integration-test</phase>
             <configuration>
               <skip>${skipITs}</skip>
               <path>/foo</path>
             </configuration>
           </execution>
         </executions>
       </plugin>-->
      <!-- ====== /INTEGRATION TESTS ====== -->
    </plugins>
  </build>
  <repositories>
    <repository>
      <id>squashtest-release</id>
      <name>SquashTest release repository</name>
      <url>https://repo.squashtest.org/maven2/releases</url>
    </repository>
  </repositories>
</project>
