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

<!--
  Codehaus Cargo, copyright 2004-2011 Vincent Massol, 2012-2022 Ali Tokmen.

  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/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <groupId>org.codehaus.cargo</groupId>
    <artifactId>cargo-extensions-daemon</artifactId>
    <version>1.9.10</version>
  </parent>
  <artifactId>cargo-daemon-itests</artifactId>
  <name>Cargo Daemon Integration Tests</name>
  <packaging>pom</packaging>
  <description>Cargo Daemon Integration Tests</description>
  <modules>
    <module>browser</module>
    <module>client</module>
    <module>deployable-on-jetty</module>
    <module>deployable-on-tomcat</module>
  </modules>

  <profiles>
    <profile>
      <id>run-its</id>
      <activation>
        <property>
          <name>skipTests</name>
          <value>!true</value>
        </property>
      </activation>
      <build>
        <plugins>
          <!--
            Make sure tests always use randomly assigned and available ports
          -->
          <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>build-helper-maven-plugin</artifactId>
            <executions>
              <execution>
                <id>generate-port-numbers</id>
                <phase>generate-test-sources</phase>
                <goals>
                  <goal>reserve-network-port</goal>
                </goals>
                <configuration>
                  <portNames>
                    <portName>cargo.daemon.itests.daemon.port</portName>
                    <portName>cargo.daemon.itests.daemon.ajp.port</portName>
                    <portName>cargo.daemon.itests.daemon.rmi.port</portName>
                    <portName>cargo.daemon.itests.servlet.port</portName>
                    <portName>cargo.daemon.itests.rmi.port</portName>
                  </portNames>
                </configuration>
              </execution>
            </executions>
          </plugin>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <executions>
              <execution>
                <id>copy-jetty-distributable</id>
                <phase>generate-test-resources</phase>
                <goals>
                  <goal>copy</goal>
                </goals>
                <configuration>
                  <artifactItems>
                    <artifactItem>
                      <groupId>org.eclipse.jetty</groupId>
                      <artifactId>jetty-distribution</artifactId>
                      <type>zip</type>
                      <destFileName>jetty9x.zip</destFileName>
                    </artifactItem>
                    <artifactItem>
                      <groupId>org.codehaus.cargo</groupId>
                      <artifactId>cargo-daemon-webapp</artifactId>
                      <type>war</type>
                      <destFileName>cargo-daemon-webapp.jar</destFileName>
                    </artifactItem>
                    <artifactItem>
                      <groupId>org.codehaus.cargo</groupId>
                      <artifactId>simple-war</artifactId>
                      <type>war</type>
                      <destFileName>simple-war.war</destFileName>
                    </artifactItem>
                    <artifactItem>
                      <groupId>org.codehaus.cargo</groupId>
                      <artifactId>systemproperty-war</artifactId>
                      <type>war</type>
                      <destFileName>systemproperty-war.war</destFileName>
                    </artifactItem>
                  </artifactItems>
                  <outputDirectory>${project.build.directory}/test-artifacts</outputDirectory>
                </configuration>
              </execution>
            </executions>
          </plugin>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-antrun-plugin</artifactId>
            <executions>
              <execution>
                <phase>pre-integration-test</phase>
                <goals>
                  <goal>run</goal>
                </goals>
                <configuration>
                  <target>
                    <delete dir="${project.build.directory}/daemon-cargo-home" />
                    <delete dir="${project.build.directory}/daemon-home" />
                    <delete dir="${project.build.directory}/daemon-test-configurations-home" />
                  </target>
                </configuration>
              </execution>
            </executions>
          </plugin>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <executions>
              <execution>
                <id>surefire-it</id>
                <phase>integration-test</phase>
                <goals>
                  <goal>test</goal>
                </goals>
                <configuration>
                  <skip>false</skip>
                  <systemProperties>
                    <property>
                      <name>cargo.home</name>
                      <value>${project.build.directory}/daemon-cargo-home</value>
                    </property>
                    <property>
                      <name>daemon.home</name>
                      <value>${project.build.directory}/daemon-home</value>
                    </property>
                    <property>
                      <name>daemon.port</name>
                      <value>${cargo.daemon.itests.daemon.port}</value>
                    </property>
                    <property>
                      <name>daemon.test-configurations.home</name>
                      <value>${project.build.directory}/daemon-test-configurations-home</value>
                    </property>
                    <property>
                      <name>servlet.port</name>
                      <value>${cargo.daemon.itests.servlet.port}</value>
                    </property>
                    <property>
                      <name>rmi.port</name>
                      <value>${cargo.daemon.itests.rmi.port}</value>
                    </property>
                    <property>
                      <name>artifacts.dir</name>
                      <value>${project.build.directory}/test-artifacts</value>
                    </property>
                  </systemProperties>
                </configuration>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>
  </profiles>

  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <configuration>
          <skip>true</skip>
        </configuration>
      </plugin>
    </plugins>
  </build>

  <dependencies>
    <dependency>
      <groupId>org.codehaus.cargo</groupId>
      <artifactId>cargo-sample-java</artifactId>
      <scope>test</scope>
    </dependency>
  </dependencies>

  <dependencyManagement>
    <dependencies>
      <!--
       We need to use Jetty 9.2.x as all previous versions use the Jasper compiler in a way to try
       generate Java 5 compatible bytecode, while all successor versions require Java 8 and above.
       Attempting to generate Java 5 compatible bytecode generates a JasperException PWC6033
       (error in Javac compilation for JSP) with cause PWC6199 (generated servlet error:
       Target option 1.5 is no longer supported. Use 1.6 or later) in JDK 11.
       -->
      <dependency>
        <groupId>org.eclipse.jetty</groupId>
        <artifactId>jetty-distribution</artifactId>
        <version>9.2.29.v20191105</version>
      </dependency>
    </dependencies>
  </dependencyManagement>
</project>
