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

    JBoss, Home of Professional Open Source.
    Copyright 2014-2022 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>
    <artifactId>parent</artifactId>
    <groupId>org.jboss.pnc</groupId>
    <version>3.4.4</version>
  </parent>

  <artifactId>messaging</artifactId>
  <name>messaging</name>
  <packaging>jar</packaging>

  <dependencies>

    <dependency>
      <groupId>org.jboss.pnc</groupId>
      <artifactId>common</artifactId>
    </dependency>
    <dependency>
      <groupId>org.jboss.pnc</groupId>
      <artifactId>moduleconfig</artifactId>
    </dependency>

    <dependency>
      <groupId>org.projectlombok</groupId>
      <artifactId>lombok</artifactId>
    </dependency>

    <dependency>
      <groupId>jakarta.enterprise</groupId>
      <artifactId>jakarta.enterprise.cdi-api</artifactId>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>org.jboss.spec.javax.jms</groupId>
      <!--<artifactId>jboss-jms-api_2.0_spec</artifactId>-->
      <artifactId>jboss-jms-api_1.1_spec</artifactId>
    </dependency>
    <dependency>
      <groupId>org.jboss.spec.javax.ejb</groupId>
      <artifactId>jboss-ejb-api_3.2_spec</artifactId>
    </dependency>
    <dependency>
      <groupId>org.jboss.spec.javax.annotation</groupId>
      <artifactId>jboss-annotations-api_1.3_spec</artifactId>
      <scope>provided</scope>
    </dependency>

    <dependency>
      <groupId>org.jboss.pnc</groupId>
      <artifactId>test-common</artifactId>
    </dependency>
    <dependency>
      <groupId>org.jboss.arquillian.junit</groupId>
      <artifactId>arquillian-junit-container</artifactId>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>org.wildfly.arquillian</groupId>
      <artifactId>wildfly-arquillian-container-managed</artifactId>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>org.jboss.pnc</groupId>
      <artifactId>messaging-spi</artifactId>
    </dependency>

    <!-- OTEL Dependencies for Instrumentation -->
    <dependency>
      <groupId>io.opentelemetry</groupId>
      <artifactId>opentelemetry-context</artifactId>
    </dependency>

  </dependencies>


  <build>
    <plugins>
      <plugin>
        <artifactId>maven-ejb-plugin</artifactId>
        <configuration>
          <ejbVersion>3.1</ejbVersion>
        </configuration>
      </plugin>
    </plugins>
  </build>

  <profiles>
    <profile>
      <id>download-server</id>
      <activation>
        <property>
          <name>eap.zip.url</name>
        </property>
      </activation>
      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-antrun-plugin</artifactId>
            <executions>
              <execution>
                <id>download-and-extract-eap-server</id>
                <goals>
                  <goal>run</goal>
                </goals>
                <phase>pre-integration-test</phase>
                <configuration>
                  <target>
                    <!-- If JBOSS_HOME is set it causes obscure errors with CLI in -->
                    <!-- jboss-as-maven-plugin. -->
                    <property environment="env" />
                    <fail message="JBOSS_HOME must not be set" if="env.JBOSS_HOME" />

                    <echo>Preparing EAP application server</echo>
                    <echo>EAP URL ${eap.zip.url}</echo>
                    <fail message="Please specify EAP zip file URL via: -Deap.zip.url=" unless="eap.zip.url" />
                    <mkdir dir="${test.server.unpack.dir}" />
                    <get usetimestamp="true" src="${eap.zip.url}" skipexisting="true" dest="${test.server.unpack.dir}/${app.server}-${jboss.version}.zip" />
                    <unzip src="${test.server.unpack.dir}/${app.server}-${jboss.version}.zip" dest="${test.server.unpack.dir}/" overwrite="true" />

                  </target>
                </configuration>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>

    <profile>
      <id>configure-test-container</id>
      <activation>
        <property>
          <name>eap.zip.url</name>
        </property>
      </activation>
      <build>
        <plugins>
          <plugin>
            <groupId>org.wildfly.plugins</groupId>
            <artifactId>wildfly-maven-plugin</artifactId>
            <executions>
              <execution>
                <id>start-server</id>
                <phase>pre-integration-test</phase>
                <goals>
                  <goal>start</goal>
                </goals>
                <configuration>
                  <jbossHome>${test.server.build.dir}</jbossHome>
                  <java-opts>
                    <java-opt>--add-modules=java.se</java-opt>
                  </java-opts>
                </configuration>
              </execution>
                <execution>
                <id>configure-logging</id>
                <phase>pre-integration-test</phase>
                <goals>
                  <goal>execute-commands</goal>
                </goals>
                <configuration>
                  <execute-commands>
                    <batch>true</batch>
                    <commands>
                      <command>
                        /subsystem=logging/logger=org.jboss.pnc:add
                      </command>
                      <command>
                        /subsystem=logging/logger=org.jboss.pnc:change-log-level(level=DEBUG)
                      </command>
                      <command>
                        /subsystem=logging/logger=org:add(level=INFO)
                      </command>
                      <command>
                        /subsystem=logging/console-handler=CONSOLE:change-log-level(level=DEBUG)
                      </command>
                      <command>
                        /subsystem=logging/root-logger=ROOT:change-root-log-level(level=DEBUG)
                      </command>
                    </commands>
                  </execute-commands>
                </configuration>
              </execution>
              <execution>
                <id>configure-amq</id>
                <phase>pre-integration-test</phase>
                <goals>
                  <goal>execute-commands</goal>
                </goals>
                <configuration>
                  <execute-commands>
                    <batch>false</batch>
                    <commands>
                      <command>
                        /extension=org.wildfly.extension.messaging-activemq:add
                      </command>
                      <command>
                        /subsystem=messaging-activemq:add
                      </command>
                    </commands>
                  </execute-commands>
                </configuration>
              </execution>
              <execution>
                <id>restart-shutdown</id>
                <phase>pre-integration-test</phase>
                <goals>
                  <goal>shutdown</goal>
                </goals>
              </execution>
              <execution>
                <id>restart-start</id>
                <phase>pre-integration-test</phase>
                <goals>
                  <goal>start</goal>
                </goals>
                <configuration>
                  <jbossHome>${test.server.build.dir}</jbossHome>
                  <java-opts>
                    <java-opt>--add-modules=java.se</java-opt>
                    <java-opt>--add-opens=java.base/jdk.internal.misc=ALL-UNNAMED</java-opt>
                    <java-opt>-Dio.netty.tryReflectionSetAccessible=true</java-opt>
                  </java-opts>
                </configuration>
              </execution>
              <execution>
                <id>configure-amq-step02</id>
                <phase>pre-integration-test</phase>
                <goals>
                  <goal>execute-commands</goal>
                </goals>
                <configuration>
                  <execute-commands>
                    <batch>true</batch>
                    <commands>
                      <command>
                        /subsystem=messaging-activemq/server=default:add
                      </command>
                      <command>
                        /subsystem=messaging-activemq/server=default/in-vm-connector=in-vm:add(server-id="0")
                      </command>
                      <command>
                        /subsystem=messaging-activemq/server=default/in-vm-acceptor=in-vm:add(server-id="0")
                      </command>
                      <command>
                        /subsystem=messaging-activemq/server=default/connection-factory=InVmConnectionFactory:add(entries=[java:/ConnectionFactory],connectors=["in-vm"])
                      </command>
                      <command>
                        /subsystem=messaging-activemq/server=default/pooled-connection-factory=activemq-ra:add(transaction="xa", connectors=["in-vm"], entries=["java:/JmsXA", "java:jboss/DefaultJMSConnectionFactory"])
                      </command>
                      <command>
                        /subsystem=ee/service=default-bindings:write-attribute(name="jms-connection-factory", value="java:jboss/DefaultJMSConnectionFactory")
                      </command>
                      <command>
                        /subsystem=ejb3:write-attribute(name="default-resource-adapter-name", value="${ejb.resource-adapter-name:activemq-ra.rar}")
                      </command>
                    </commands>
                  </execute-commands>
                </configuration>
              </execution>
              <execution>
                <id>add-jms-topic</id>
                <phase>pre-integration-test</phase>
                <goals>
                  <goal>add-resource</goal>
                </goals>
                <configuration>
                  <resources>
                    <resource>
                      <address>subsystem=messaging-activemq,server=default,jms-topic=pncTopic</address>
                      <properties>
                        <durable>true</durable>
                        <entries>!!["java:/jms/queue/pncTopic"]</entries>
                      </properties>
                    </resource>
                  </resources>
                </configuration>
              </execution>
              <execution>
                <id>shutdown-server</id>
                <phase>pre-integration-test</phase>
                <goals>
                  <goal>shutdown</goal>
                </goals>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>

  </profiles>


</project>
