<?xml version="1.0" encoding="UTF-8"?>
<!--
  ~ JBoss, Home of Professional Open Source.
  ~
  ~ Copyright 2023 Red Hat, Inc., and individual contributors
  ~ as indicated by the @author tags.
  ~
  ~ 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/xsd/maven-4.0.0.xsd">

    <modelVersion>4.0.0</modelVersion>

    <parent>
        <groupId>org.jberet</groupId>
        <artifactId>jberet-parent</artifactId>
        <version>2.2.1.Final</version>
    </parent>

    <artifactId>test-deployment</artifactId>
    <packaging>war</packaging>

    <properties>
        <jboss.home>${project.build.directory}${file.separator}wildfly</jboss.home>
        <version.org.wildfly>30.0.1.Final</version.org.wildfly>
        <galleon.fork.embedded>true</galleon.fork.embedded>
    </properties>

    <dependencies>
        <dependency>
            <groupId>jakarta.ws.rs</groupId>
            <artifactId>jakarta.ws.rs-api</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>io.rest-assured</groupId>
            <artifactId>rest-assured</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <profiles>
        <profile>
            <id>release</id>
            <build>
                <plugins>
                    <!-- It conflicts with `maven-wildfly-plugin` -->
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-source-plugin</artifactId>
                        <configuration>
                            <skipSource>true</skipSource>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>


    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <configuration>
                    <warName>test-deployment</warName>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.wildfly.plugins</groupId>
                <artifactId>wildfly-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>server-provisioning</id>
                        <phase>generate-test-resources</phase>
                        <goals>
                            <goal>provision</goal>
                        </goals>
                        <configuration>
                            <provisioning-dir>${jboss.home}</provisioning-dir>
                            <galleon-options>
                                <jboss-fork-embedded>${galleon.fork.embedded}</jboss-fork-embedded>
                            </galleon-options>
                            <feature-packs>
                                <feature-pack>
                                    <groupId>org.wildfly</groupId>
                                    <artifactId>wildfly-ee-galleon-pack</artifactId>
                                    <version>${version.org.wildfly}</version>
                                    <inherit-configs>false</inherit-configs>
                                    <included-configs>
                                        <config>
                                            <model>standalone</model>
                                            <name>standalone-full.xml</name>
                                        </config>
                                        <config>
                                            <model>standalone</model>
                                            <name>standalone.xml</name>
                                        </config>
                                    </included-configs>
                                    <excluded-packages>
                                        <name>docs.schema</name>
                                        <name>appclient</name>
                                        <name>domain</name>
                                    </excluded-packages>
                                </feature-pack>
                            </feature-packs>
                            <channels>
                                <channel>
                                    <manifest>
                                        <groupId>org.jberet</groupId>
                                        <artifactId>jberet-channel-manifest</artifactId>
                                        <version>${project.version}</version>
                                    </manifest>
                                </channel>
                            </channels>
                        </configuration>
                    </execution>
                    <execution>
                        <id>wildfly-start</id>
                        <phase>pre-integration-test</phase>
                        <goals>
                            <goal>start</goal>
                            <goal>deploy</goal>
                        </goals>
                        <configuration>
                            <filename>test-deployment.war</filename>
                        </configuration>
                    </execution>
                    <execution>
                        <phase>post-integration-test</phase>
                        <id>wildfly-stop</id>
                        <goals>
                            <goal>shutdown</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <excludes>
                        <exclude>**/*ITest*</exclude>
                    </excludes>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-failsafe-plugin</artifactId>
                <configuration>
                    <testClassesDirectory>${project.build.testOutputDirectory}</testClassesDirectory>
                    <includes>
                        <include>**/*ITest*</include>
                    </includes>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>integration-test</goal>
                            <goal>verify</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

</project>
