<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
         xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>dev.resteasy.grpc</groupId>
        <artifactId>resteasy-grpc-testsuite</artifactId>
        <version>1.0.0.Alpha2</version>
        <relativePath>../pom.xml</relativePath>
    </parent>
    <properties>
        <maven.compiler.parameters>true</maven.compiler.parameters>
        <module.jar.path>${jboss.home}${file.separator}modules${file.separator}system${file.separator}layers${file.separator}base</module.jar.path>
        <!-- Provisioning properties -->
        <jboss.home>${project.build.directory}${file.separator}wildfly</jboss.home>

        <!-- RESTEasy properties -->
        <resteasy.test.feature.pack.groupId>org.jboss.resteasy</resteasy.test.feature.pack.groupId>
        <resteasy.test.feature.pack.artifactId>galleon-feature-pack</resteasy.test.feature.pack.artifactId>
        <resteasy.test.feature.pack.version>${version.org.jboss.resteasy}</resteasy.test.feature.pack.version>

        <!-- Server properties -->
        <server.test.feature.pack.groupId>org.wildfly</server.test.feature.pack.groupId>
        <server.test.feature.pack.artifactId>wildfly-ee-galleon-pack</server.test.feature.pack.artifactId>
        <server.test.feature.pack.version>${version.org.wildfly}</server.test.feature.pack.version>
        <!-- For grpc-bridge test -->
        <wildfly.grpc.test.feature.pack.groupId>org.wildfly.extras.grpc</wildfly.grpc.test.feature.pack.groupId>
        <wildfly.grpc.test.feature.pack.artifactId>wildfly-grpc-feature-pack</wildfly.grpc.test.feature.pack.artifactId>
        <wildfly.grpc.test.feature.pack.version>0.1.0.Final</wildfly.grpc.test.feature.pack.version>

        <!-- For compiling the test project -->
        <root.class>CC1</root.class>
        <servlet.name>GrpcServlet</servlet.name>
    </properties>
    <artifactId>grpc-tests</artifactId>
    <name>RESTEasy Main testsuite: gRPC tests</name>
    <profiles>
        <!--
        Name:  download
        Descr: Download WildFly
        -->
        <profile>
            <id>download</id>
            <activation>
                <property>
                    <name>!server.home</name>
                </property>
            </activation>
            <properties>
                <jboss.home>${project.build.directory}${file.separator}wildfly</jboss.home>
            </properties>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.wildfly.plugins</groupId>
                        <artifactId>wildfly-maven-plugin</artifactId>
                        <version>4.1.0.Final</version>
                        <executions>
                            <execution>
                                <id>server-provisioning</id>
                                <phase>process-test-resources</phase>
                                <goals>
                                    <goal>provision</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <profile>
            <id>provision-preview</id>
            <activation>
                <property>
                    <name>provision.preview</name>
                </property>
            </activation>
            <properties>
                <resteasy.test.feature.pack.groupId>org.jboss.resteasy</resteasy.test.feature.pack.groupId>
                <resteasy.test.feature.pack.artifactId>galleon-preview-feature-pack</resteasy.test.feature.pack.artifactId>
                <resteasy.test.feature.pack.version>${version.org.jboss.resteasy}</resteasy.test.feature.pack.version>
                <server.test.feature.pack.groupId>org.wildfly</server.test.feature.pack.groupId>
                <server.test.feature.pack.artifactId>wildfly-preview-feature-pack</server.test.feature.pack.artifactId>
                <server.test.feature.pack.version>${version.org.wildfly}</server.test.feature.pack.version>
            </properties>
        </profile>
        <profile>
            <id>skip.tracing.tests</id>
            <activation>
                <property>
                    <name>skip.tracing.tests</name>
                </property>
            </activation>
            <properties>
                <additional.surefire.exclude.tracing.tests>,org.jboss.resteasy.category.TracingRequired</additional.surefire.exclude.tracing.tests>
            </properties>
        </profile>
    </profiles>
    <dependencies>
        <!-- This is only required because a generator adds the @javax.annotation.Generated on generated source which
             no longer exists in Java 9+. It was migrated to javax.annotation.processing.Generated.
          -->
        <dependency>
            <groupId>javax.annotation</groupId>
            <artifactId>javax.annotation-api</artifactId>
            <version>1.3.2</version>
            <scope>provided</scope>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>jakarta.enterprise</groupId>
            <artifactId>jakarta.enterprise.cdi-api</artifactId>
        </dependency>
        <dependency>
            <groupId>jakarta.ws.rs</groupId>
            <artifactId>jakarta.ws.rs-api</artifactId>
        </dependency>
        <dependency>
            <groupId>jakarta.servlet</groupId>
            <artifactId>jakarta.servlet-api</artifactId>
        </dependency>
        <dependency>
            <groupId>dev.resteasy.grpc</groupId>
            <artifactId>grpc-bridge</artifactId>
        </dependency>
        <dependency>
            <groupId>dev.resteasy.grpc</groupId>
            <artifactId>grpc-bridge-runtime</artifactId>
        </dependency>
        <dependency>
            <groupId>org.jboss.resteasy</groupId>
            <artifactId>resteasy-core</artifactId>
        </dependency>
        <dependency>
            <groupId>io.grpc</groupId>
            <artifactId>protoc-gen-grpc-java</artifactId>
            <version>1.54.1</version>
            <type>pom</type>
        </dependency>
        <dependency>
            <groupId>io.grpc</groupId>
            <artifactId>grpc-protobuf</artifactId>
        </dependency>
        <dependency>
            <groupId>io.grpc</groupId>
            <artifactId>grpc-stub</artifactId>
        </dependency>
        <dependency>
            <groupId>com.google.protobuf</groupId>
            <artifactId>protobuf-java</artifactId>
        </dependency>

        <!-- Test Dependencies -->
        <dependency>
            <groupId>io.grpc</groupId>
            <artifactId>grpc-netty-shaded</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.jboss.resteasy</groupId>
            <artifactId>arquillian-utils</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.jboss.resteasy</groupId>
            <artifactId>resteasy-client</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.jboss.resteasy</groupId>
            <artifactId>resteasy-client-utils</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.jboss.resteasy</groupId>
            <artifactId>resteasy-json-p-provider</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.jboss.resteasy</groupId>
            <artifactId>resteasy-json-binding-provider</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.jboss.arquillian.junit</groupId>
            <artifactId>arquillian-junit-container</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.wildfly.arquillian</groupId>
            <artifactId>wildfly-arquillian-container-managed</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>
    <build>
        <extensions>
            <extension>
                <groupId>kr.motd.maven</groupId>
                <artifactId>os-maven-plugin</artifactId>
                <version>1.7.0</version>
            </extension>
        </extensions>

        <testResources>
            <testResource>
                <directory>src/test/resources</directory>
                <filtering>true</filtering>
                <includes>
                    <include>arquillian.xml</include>
                </includes>
            </testResource>
            <testResource>
                <directory>src/test/resources</directory>
                <excludes>
                    <exclude>arquillian.xml</exclude>
                </excludes>
            </testResource>
        </testResources>
        <plugins>
            <plugin>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <systemPropertyVariables>
                        <server.config.dir>${jboss.home}/standalone/configuration</server.config.dir>
                    </systemPropertyVariables>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.wildfly.plugins</groupId>
                <artifactId>wildfly-maven-plugin</artifactId>
                <version>4.1.0.Final</version>
                <configuration>
                    <jboss-home>${jboss.home}</jboss-home>
                    <provisioning-dir>${jboss.home}</provisioning-dir>
                    <feature-packs>
                        <feature-pack>
                            <groupId>${server.test.feature.pack.groupId}</groupId>
                            <artifactId>${server.test.feature.pack.artifactId}</artifactId>
                            <version>${server.test.feature.pack.version}</version>
                        </feature-pack>
                        <feature-pack>
                            <groupId>${resteasy.test.feature.pack.groupId}</groupId>
                            <artifactId>${resteasy.test.feature.pack.artifactId}</artifactId>
                            <version>${resteasy.test.feature.pack.version}</version>
                            <inherit-configs>false</inherit-configs>
                        </feature-pack>
                        <feature-pack>
                            <groupId>${wildfly.grpc.test.feature.pack.groupId}</groupId>
                            <artifactId>${wildfly.grpc.test.feature.pack.artifactId}</artifactId>
                            <version>${wildfly.grpc.test.feature.pack.version}</version>
                        </feature-pack>
                    </feature-packs>
                    <layers>
                        <layer>jaxrs-server</layer>
                        <layer>cdi</layer>
                        <layer>grpc</layer>
                        <layer>undertow</layer>
                    </layers>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>build-helper-maven-plugin</artifactId>
                <version>3.2.0</version>
                <executions>
                    <execution>
                        <id>proto</id>
                        <phase>initialize</phase>
                        <goals>
                            <goal>add-source</goal>
                        </goals>
                        <configuration>
                            <sources>
                                <source>src/main/proto</source>
                            </sources>
                        </configuration>
                    </execution>
                    <execution>
                        <id>java-generated</id>
                        <phase>process-sources</phase>
                        <goals>
                            <goal>add-source</goal>
                        </goals>
                        <configuration>
                            <sources>
                                <source>${project.basedir}/target/generated-sources/protobuf/java/</source>
                                <source>${project.basedir}/target/generated-sources/protobuf/grpc-java/</source>
                            </sources>
                        </configuration>
                    </execution>
                    <execution>
                        <id>java-test-generated</id>
                        <phase>process-sources</phase>
                        <goals>
                            <goal>add-test-source</goal>
                        </goals>
                        <configuration>
                            <sources>
                                <source>${project.basedir}/target/generated-sources/protobuf/java/</source>
                                <source>${project.basedir}/target/generated-sources/protobuf/grpc-java/</source>
                                <source>${project.basedir}/src/test/java</source>
                            </sources>
                        </configuration>
                    </execution>
                    <execution>
                        <id>add-test-source</id>
                        <phase>process-sources</phase>
                        <goals>
                            <goal>add-test-source</goal>
                        </goals>
                        <configuration>
                            <sources>
                                <source>${project.basedir}/target/generated-sources/protobuf/grpc-java/</source>
                                <!--source>${project.basedir}/target/generatedSources/</source-->
                            </sources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>3.0.0</version>
                <executions>
                    <execution>
                        <id>genproto</id>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>java</goal>
                        </goals>
                        <configuration>
                            <mainClass>dev.resteasy.grpc.bridge.generator.protobuf.JavaToProtobufGenerator</mainClass>
                            <cleanupDaemonThreads>false</cleanupDaemonThreads>
                            <arguments>
                                <argument>${project.basedir}</argument>
                                <argument>dev.resteasy.grpc.example</argument>
                                <argument>dev.resteasy.grpc.example</argument>
                                <argument>${root.class}</argument>
                            </arguments>
                            <systemProperties>
                                <systemProperty>
                                    <key>exec.cleanupDaemonThreads</key>
                                    <value>false</value>
                                </systemProperty>
                            </systemProperties>
                        </configuration>
                    </execution>
                    <execution>
                        <id>genprotobuf</id>
                        <phase>process-classes</phase>
                        <goals>
                            <goal>java</goal>
                        </goals>
                        <configuration>
                            <mainClass>dev.resteasy.grpc.bridge.generator.protobuf.JavabufTranslatorGenerator</mainClass>
                            <cleanupDaemonThreads>false</cleanupDaemonThreads>
                            <arguments>
                                <argument>${project.basedir}/target/generated-sources/protobuf/java</argument>
                                <argument>dev.resteasy.grpc.example.${root.class}</argument>
                            </arguments>
                            <systemProperties>
                                <systemProperty>
                                    <key>exec.cleanupDaemonThreads</key>
                                    <value>false</value>
                                </systemProperty>
                            </systemProperties>
                        </configuration>
                    </execution>
                    <execution>
                        <id>reader-writer</id>
                        <phase>process-classes</phase>
                        <goals>
                            <goal>java</goal>
                        </goals>
                        <configuration>
                            <mainClass>dev.resteasy.grpc.bridge.generator.protobuf.ReaderWriterGenerator</mainClass>
                            <cleanupDaemonThreads>false</cleanupDaemonThreads>
                            <arguments>
                                <argument>${project.build.directory}/generated-sources/protobuf/grpc-java</argument>
                                <argument>dev.resteasy.grpc.example.${root.class}_proto</argument>
                                <argument>${root.class}</argument>
                            </arguments>
                            <systemProperties>
                                <systemProperty>
                                    <key>exec.cleanupDaemonThreads</key>
                                    <value>false</value>
                                </systemProperty>
                            </systemProperties>
                        </configuration>
                    </execution>
                    <execution>
                        <id>genGRPC</id>
                        <phase>process-classes</phase>
                        <goals>
                            <goal>java</goal>
                        </goals>
                        <configuration>
                            <mainClass>dev.resteasy.grpc.bridge.generator.ServiceGrpcExtender</mainClass>
                            <cleanupDaemonThreads>false</cleanupDaemonThreads>
                            <arguments>
                                <argument>${root.class}</argument>
                                <argument>${servlet.name}</argument>
                                <argument>dev.resteasy.grpc.example</argument>
                                <argument>${project.basedir}/src/main/proto</argument>
                                <argument>${project.build.directory}/generated-sources/protobuf/grpc-java</argument>
                            </arguments>
                            <systemProperties>
                                <systemProperty>
                                    <key>exec.cleanupDaemonThreads</key>
                                    <value>false</value>
                                </systemProperty>
                            </systemProperties>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>org.xolstice.maven.plugins</groupId>
                <artifactId>protobuf-maven-plugin</artifactId>
                <version>0.6.1</version>
                <configuration>
                    <protocArtifact>com.google.protobuf:protoc:3.21.7:exe:${os.detected.classifier}</protocArtifact>
                    <pluginId>grpc-java</pluginId>
                    <pluginArtifact>io.grpc:protoc-gen-grpc-java:1.54.1:exe:${os.detected.classifier}</pluginArtifact>
                    <clearOutputDirectory>true</clearOutputDirectory>
                </configuration>
                <executions>
                    <execution>
                        <id>compile_proto</id>
                        <phase>process-sources</phase>
                        <goals>
                            <goal>compile</goal>
                            <goal>compile-custom</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>
