<?xml version="1.0" encoding="UTF-8"?>
<!--
  ~ Copyright The ClusterBench Authors
  ~ SPDX-License-Identifier: Apache-2.0
  -->

<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>clusterbench</artifactId>
        <groupId>org.jboss.test</groupId>
        <version>7.0.0.Final</version>
    </parent>

    <artifactId>clusterbench-ee10-ear</artifactId>
    <version>7.0.0.Final</version>
    <packaging>ear</packaging>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <wildfly.skip>false</wildfly.skip>
    </properties>

    <build>
        <finalName>clusterbench-ee10</finalName>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <!-- Define executions since 'ear' packaging skips test compilation -->
                <executions>
                    <execution>
                        <id>testCompile</id>
                        <goals>
                            <goal>testCompile</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-ear-plugin</artifactId>
                <configuration>
                    <version>8</version>
                    <defaultLibBundleDir>lib</defaultLibBundleDir>
                    <modules>
                        <ejbModule>
                            <groupId>${project.groupId}</groupId>
                            <artifactId>clusterbench-ee10-ejb</artifactId>
                            <bundleFileName>clusterbench-ee10-ejb.jar</bundleFileName>
                        </ejbModule>
                        <webModule>
                            <groupId>${project.groupId}</groupId>
                            <artifactId>clusterbench-ee10-web</artifactId>
                            <classifier>default</classifier>
                            <contextRoot>/clusterbench</contextRoot>
                            <bundleFileName>clusterbench-ee10-web.war</bundleFileName>
                        </webModule>
                        <webModule>
                            <groupId>${project.groupId}</groupId>
                            <artifactId>clusterbench-ee10-web</artifactId>
                            <classifier>passivating</classifier>
                            <contextRoot>/clusterbench-passivating</contextRoot>
                            <bundleFileName>clusterbench-ee10-web-passivating.war</bundleFileName>
                        </webModule>
                        <webModule>
                            <groupId>${project.groupId}</groupId>
                            <artifactId>clusterbench-ee10-web</artifactId>
                            <classifier>granular</classifier>
                            <contextRoot>/clusterbench-granular</contextRoot>
                            <bundleFileName>clusterbench-ee10-web-granular.war</bundleFileName>
                        </webModule>
                    </modules>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-failsafe-plugin</artifactId>
                <executions>
                    <execution>
                        <id>failsafe-integration-test</id>
                        <phase>integration-test</phase>
                        <goals>
                            <goal>integration-test</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>failsafe-verify</id>
                        <phase>verify</phase>
                        <goals>
                            <goal>verify</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

    <dependencies>
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>clusterbench-ee10-ejb</artifactId>
            <version>${project.version}</version>
            <type>ejb</type>
        </dependency>
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>clusterbench-ee10-web</artifactId>
            <version>${project.version}</version>
            <classifier>default</classifier>
            <type>war</type>
        </dependency>
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>clusterbench-ee10-web</artifactId>
            <version>${project.version}</version>
            <classifier>passivating</classifier>
            <type>war</type>
        </dependency>
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>clusterbench-ee10-web</artifactId>
            <version>${project.version}</version>
            <classifier>granular</classifier>
            <type>war</type>
        </dependency>
        <!-- Test dependencies -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <profiles>
        <profile>
            <id>integration</id>
            <activation>
                <property>
                    <name>!skipTests</name>
                </property>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.wildfly.plugins</groupId>
                        <artifactId>wildfly-maven-plugin</artifactId>
                        <configuration>
                            <server-args>
                                <!--
                                FIXME workaround for FD_SOCK2 failing on resource service restart on Windows platform - switch to ha profile from full-ha which starts the channel on demand

                                2023-07-25T08:21:28.7711991Z Caused by: java.lang.IllegalStateException: clusterbench-1: failed to find an available port in ports [54200, 54201, 54202, 54203]
                                ...
                                2023-07-25T08:21:29.3791333Z [INFO] [standalone@embedded /] batch
                                2023-07-25T08:21:30.0202882Z [INFO] [standalone@embedded / #] /subsystem=jgroups/stack=udp/protocol=FD_SOCK2:write-attribute(name=properties,value={port_range=100})
                                2023-07-25T08:21:30.0266081Z [INFO] [standalone@embedded / #] run-batch &#45;&#45;headers={allow-resource-service-restart=true}
                                ...
                                2023-07-25T08:21:31.1781113Z Caused by: java.lang.Exception: failed to open a port in range 55200-55200 (last exception: java.net.BindException: Address already in use: Cannot bind)
                                -->
                                <!-- <server-arg>&#45;&#45;server-config=standalone-full-ha.xml</server-arg>-->
                                <server-arg>--server-config=standalone-ha.xml</server-arg>
                                <server-arg>-Djboss.node.name=clusterbench-1</server-arg>
                            </server-args>
                        </configuration>
                        <executions>
                            <execution>
                                <id>integration-test-wildfly-deploy</id>
                                <phase>pre-integration-test</phase>
                                <goals>
                                    <goal>start</goal>
                                    <goal>execute-commands</goal>
                                    <goal>deploy</goal>
                                </goals>
                                <configuration>
                                    <scripts>
                                        <script>jgroups.cli</script>
                                        <script>remote-cache-container.cli</script>
                                    </scripts>
                                    <version>${version.org.wildfly}</version>
                                </configuration>
                            </execution>
                            <execution>
                                <id>integration-test-wildfly-undeploy</id>
                                <phase>post-integration-test</phase>
                                <goals>
                                    <goal>undeploy</goal>
                                    <goal>shutdown</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <profile>
            <id>integration-quickly</id>
            <activation>
                <property>
                    <name>quickly</name>
                </property>
            </activation>
            <properties>
                <wildfly.skip>true</wildfly.skip>
            </properties>
        </profile>
        <profile>
            <!-- OpenShift will run the following with extra properties: "mvn -e -Popenshift -DskipTests -B package" -->
            <!-- See https://github.com/wildfly/wildfly-charts/blob/main/charts/wildfly/README.md -->
            <id>openshift</id>
            <build>
                <finalName>ROOT</finalName>
                <directory>../target</directory>
                <plugins>
                    <plugin>
                        <groupId>org.wildfly.plugins</groupId>
                        <artifactId>wildfly-maven-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>openshift-build</id>
                                <goals>
                                    <goal>package</goal>
                                </goals>
                                <configuration>
                                    <skip>false</skip>
                                    <feature-packs>
                                        <feature-pack>
                                            <location>org.wildfly:wildfly-galleon-pack:${version.org.wildfly}</location>
                                        </feature-pack>
                                        <feature-pack>
                                            <location>org.wildfly.cloud:wildfly-cloud-galleon-pack:${version.org.wildfly.cloud-feature-pack}</location>
                                        </feature-pack>
                                    </feature-packs>
                                    <layers>
                                        <layer>cloud-server</layer>
                                        <layer>jsf</layer>
                                        <layer>ejb</layer>
                                        <layer>web-clustering</layer>
                                    </layers>
                                    <filename>ROOT.ear</filename>
                                </configuration>
                            </execution>
                            <execution>
                                <id>integration-test-wildfly-deploy</id>
                                <phase>none</phase>
                            </execution>
                            <execution>
                                <id>integration-test-wildfly-undeploy</id>
                                <phase>none</phase>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-failsafe-plugin</artifactId>
                        <executions>
                            <execution>
                                <phase>none</phase>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <profile>
            <!-- shortens name of bundled JARs and WARs -->
            <!-- mvn clean install -P short-names -->
            <id>short-names</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-ear-plugin</artifactId>
                        <configuration>
                            <version>8</version>
                            <defaultLibBundleDir>lib</defaultLibBundleDir>
                            <modules>
                                <ejbModule>
                                    <groupId>${project.groupId}</groupId>
                                    <artifactId>clusterbench-ee10-ejb</artifactId>
                                    <bundleFileName>clusterbench-ejb.jar</bundleFileName>
                                </ejbModule>
                                <webModule>
                                    <groupId>${project.groupId}</groupId>
                                    <artifactId>clusterbench-ee10-web</artifactId>
                                    <classifier>default</classifier>
                                    <contextRoot>/clusterbench</contextRoot>
                                    <bundleFileName>a.war</bundleFileName>
                                </webModule>
                                <webModule>
                                    <groupId>${project.groupId}</groupId>
                                    <artifactId>clusterbench-ee10-web</artifactId>
                                    <classifier>passivating</classifier>
                                    <contextRoot>/clusterbench-passivating</contextRoot>
                                    <bundleFileName>b.war</bundleFileName>
                                </webModule>
                                <webModule>
                                    <groupId>${project.groupId}</groupId>
                                    <artifactId>clusterbench-ee10-web</artifactId>
                                    <classifier>granular</classifier>
                                    <contextRoot>/clusterbench-granular</contextRoot>
                                    <bundleFileName>c.war</bundleFileName>
                                </webModule>
                            </modules>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <profile>
            <!-- mvn clean install -P singleton-deployment-specific-descriptor -->
            <id>singleton-deployment-specific-descriptor</id>
            <build>
                <finalName>clusterbench-ee10</finalName>
                <plugins>
                    <plugin>
                        <artifactId>maven-resources-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>copy-resources</id>
                                <phase>validate</phase>
                                <goals>
                                    <goal>copy-resources</goal>
                                </goals>
                                <configuration>
                                    <outputDirectory>${basedir}/target/${project.build.finalName}/META-INF</outputDirectory>
                                    <resources>
                                        <resource>
                                            <directory>src/main/singleton-deployment-specific-descriptor/META-INF</directory>
                                            <filtering>true</filtering>
                                        </resource>
                                    </resources>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <profile>
            <!-- mvn clean install -P singleton-deployment-jboss-all -->
            <id>singleton-deployment-jboss-all</id>
            <build>
                <finalName>clusterbench-ee10</finalName>
                <plugins>
                    <plugin>
                        <artifactId>maven-resources-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>copy-resources</id>
                                <phase>validate</phase>
                                <goals>
                                    <goal>copy-resources</goal>
                                </goals>
                                <configuration>
                                    <outputDirectory>${basedir}/target/${project.build.finalName}/META-INF</outputDirectory>
                                    <resources>
                                        <resource>
                                            <directory>src/main/singleton-deployment-jboss-all/META-INF</directory>
                                            <filtering>true</filtering>
                                        </resource>
                                    </resources>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <profile>
            <!-- mvn clean install -P shared-sessions -->
            <id>shared-sessions</id>
            <build>
                <finalName>clusterbench-ee10</finalName>
                <plugins>
                    <plugin>
                        <artifactId>maven-resources-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>copy-resources</id>
                                <phase>validate</phase>
                                <goals>
                                    <goal>copy-resources</goal>
                                </goals>
                                <configuration>
                                    <outputDirectory>${basedir}/target/${project.build.finalName}/META-INF</outputDirectory>
                                    <resources>
                                        <resource>
                                            <directory>src/main/shared-sessions/META-INF</directory>
                                            <filtering>true</filtering>
                                        </resource>
                                    </resources>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-ear-plugin</artifactId>
                        <configuration>
                            <version>8</version>
                            <defaultLibBundleDir>lib</defaultLibBundleDir>
                            <modules>
                                <ejbModule>
                                    <groupId>${project.groupId}</groupId>
                                    <artifactId>clusterbench-ee10-ejb</artifactId>
                                </ejbModule>
                                <webModule>
                                    <groupId>${project.groupId}</groupId>
                                    <artifactId>clusterbench-ee10-web</artifactId>
                                    <classifier>default</classifier>
                                    <bundleFileName>clusterbench-ee10-web-default.war</bundleFileName>
                                    <contextRoot>/clusterbench</contextRoot>
                                </webModule>
                                <webModule>
                                    <groupId>${project.groupId}</groupId>
                                    <artifactId>clusterbench-ee10-web</artifactId>
                                    <classifier>default</classifier>
                                    <bundleFileName>clusterbench-ee10-web-default-1.war</bundleFileName>
                                    <contextRoot>/clusterbench-shared-sessions-1</contextRoot>
                                </webModule>
                                <webModule>
                                    <groupId>${project.groupId}</groupId>
                                    <artifactId>clusterbench-ee10-web</artifactId>
                                    <classifier>default</classifier>
                                    <bundleFileName>clusterbench-ee10-web-default-2.war</bundleFileName>
                                    <contextRoot>/clusterbench-shared-sessions-2</contextRoot>
                                </webModule>
                                <webModule>
                                    <groupId>${project.groupId}</groupId>
                                    <artifactId>clusterbench-ee10-web</artifactId>
                                    <classifier>passivating</classifier>
                                    <contextRoot>/clusterbench-passivating</contextRoot>
                                </webModule>
                                <webModule>
                                    <groupId>${project.groupId}</groupId>
                                    <artifactId>clusterbench-ee10-web</artifactId>
                                    <classifier>granular</classifier>
                                    <contextRoot>/clusterbench-granular</contextRoot>
                                </webModule>
                            </modules>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <profile>
            <!-- mvn clean install -P sso-form -->
            <id>sso-form</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-ear-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>clusterbench-sso-1</id>
                                <phase>package</phase>
                                <goals>
                                    <goal>generate-application-xml</goal>
                                    <goal>ear</goal>
                                </goals>
                                <configuration>
                                    <finalName>${project.build.finalName}-1</finalName>
                                    <workDirectory>${project.build.directory}/${project.build.finalName}-1</workDirectory>
                                    <generatedDescriptorLocation>${project.build.directory}/${project.build.finalName}-1-tmp</generatedDescriptorLocation>
                                    <version>8</version>
                                    <defaultLibBundleDir>lib</defaultLibBundleDir>
                                    <modules>
                                        <ejbModule>
                                            <groupId>${project.groupId}</groupId>
                                            <artifactId>clusterbench-ee10-ejb</artifactId>
                                        </ejbModule>
                                        <webModule>
                                            <groupId>${project.groupId}</groupId>
                                            <artifactId>clusterbench-ee10-web</artifactId>
                                            <classifier>default</classifier>
                                            <contextRoot>/clusterbench-sso-1</contextRoot>
                                        </webModule>
                                        <webModule>
                                            <groupId>${project.groupId}</groupId>
                                            <artifactId>clusterbench-ee10-web</artifactId>
                                            <classifier>passivating</classifier>
                                            <contextRoot>/clusterbench-passivating1</contextRoot>
                                        </webModule>
                                        <webModule>
                                            <groupId>${project.groupId}</groupId>
                                            <artifactId>clusterbench-ee10-web</artifactId>
                                            <classifier>granular</classifier>
                                            <contextRoot>/clusterbench-granular1</contextRoot>
                                        </webModule>
                                    </modules>
                                </configuration>
                            </execution>
                            <execution>
                                <id>clusterbench-sso-2</id>
                                <phase>package</phase>
                                <goals>
                                    <goal>generate-application-xml</goal>
                                    <goal>ear</goal>
                                </goals>
                                <configuration>
                                    <finalName>${project.build.finalName}-2</finalName>
                                    <workDirectory>${project.build.directory}/${project.build.finalName}-2</workDirectory>
                                    <generatedDescriptorLocation>${project.build.directory}/${project.build.finalName}-2-tmp</generatedDescriptorLocation>
                                    <version>8</version>
                                    <defaultLibBundleDir>lib</defaultLibBundleDir>
                                    <modules>
                                        <ejbModule>
                                            <groupId>${project.groupId}</groupId>
                                            <artifactId>clusterbench-ee10-ejb</artifactId>
                                        </ejbModule>
                                        <webModule>
                                            <groupId>${project.groupId}</groupId>
                                            <artifactId>clusterbench-ee10-web</artifactId>
                                            <classifier>default</classifier>
                                            <contextRoot>/clusterbench-sso-2</contextRoot>
                                        </webModule>
                                        <webModule>
                                            <groupId>${project.groupId}</groupId>
                                            <artifactId>clusterbench-ee10-web</artifactId>
                                            <classifier>passivating</classifier>
                                            <contextRoot>/clusterbench-passivating2</contextRoot>
                                        </webModule>
                                        <webModule>
                                            <groupId>${project.groupId}</groupId>
                                            <artifactId>clusterbench-ee10-web</artifactId>
                                            <classifier>granular</classifier>
                                            <contextRoot>/clusterbench-granular2</contextRoot>
                                        </webModule>
                                    </modules>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <profile>
            <!-- just contains the interfaces for acting as an EJB client -->
            <id>2clusters</id>
            <build>
                <plugins>
                    <plugin>
                        <artifactId>maven-resources-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>copy-resources</id>
                                <phase>validate</phase>
                                <goals>
                                    <goal>copy-resources</goal>
                                </goals>
                                <configuration>
                                    <outputDirectory>${basedir}/target/${project.build.finalName}/META-INF</outputDirectory>
                                    <resources>
                                        <resource>
                                            <directory>src/main/2clusters/META-INF</directory>
                                            <filtering>true</filtering>
                                        </resource>
                                    </resources>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <profile>
            <!-- mvn clean install -P core -->
            <id>core</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-ear-plugin</artifactId>
                        <configuration>
                            <version>8</version>
                            <defaultLibBundleDir>lib</defaultLibBundleDir>
                            <modules>
                                <ejbModule>
                                    <groupId>${project.groupId}</groupId>
                                    <artifactId>clusterbench-ee10-ejb</artifactId>
                                    <bundleFileName>clusterbench-ee10-ejb.jar</bundleFileName>
                                </ejbModule>
                                <webModule>
                                    <groupId>${project.groupId}</groupId>
                                    <artifactId>clusterbench-ee10-web</artifactId>
                                    <classifier>default</classifier>
                                    <contextRoot>/clusterbench</contextRoot>
                                    <bundleFileName>clusterbench-ee10-web.war</bundleFileName>
                                </webModule>
                                <webModule>
                                    <groupId>${project.groupId}</groupId>
                                    <artifactId>clusterbench-ee10-web</artifactId>
                                    <classifier>passivating</classifier>
                                    <excluded>true</excluded>
                                </webModule>
                                <webModule>
                                    <groupId>${project.groupId}</groupId>
                                    <artifactId>clusterbench-ee10-web</artifactId>
                                    <classifier>granular</classifier>
                                    <excluded>true</excluded>
                                </webModule>
                            </modules>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>

</project>
