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

    Licensed to the Apache Software Foundation (ASF) under one or more
    contributor license agreements.  See the NOTICE file distributed with
    this work for additional information regarding copyright ownership.
    The ASF licenses this file to You 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.apache.camel.quarkus</groupId>
        <artifactId>camel-quarkus-build-parent-it</artifactId>
        <version>1.0.0-CR3</version>
        <relativePath>../../../poms/build-parent-it/pom.xml</relativePath>
    </parent>

    <artifactId>camel-quarkus-grpc-integration-test</artifactId>
    <name>Camel Quarkus :: gRPC :: Integration Test</name>
    <description>Integration tests for Camel Quarkus gRPC extension</description>

    <properties>
        <!-- mvnd, a.k.a. Maven Daemon: https://github.com/gnodet/mvnd -->
        <!-- The following rule tells mvnd to build the listed deployment modules before this module. -->
        <!-- This is important because mvnd builds modules in parallel by default. The deployment modules are not -->
        <!-- explicit dependencies of this module in the Maven sense, although they are required by the Quarkus Maven plugin. -->
        <!-- Please update rule whenever you change the dependencies of this module by running -->
        <!--     mvn process-resources -Pformat    from the root directory -->
        <mvnd.builder.rule>camel-quarkus-grpc-deployment,camel-quarkus-support-policy-deployment</mvnd.builder.rule>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.apache.camel.quarkus</groupId>
            <artifactId>camel-quarkus-grpc</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.camel.quarkus</groupId>
            <artifactId>camel-quarkus-direct</artifactId>
        </dependency>
        <dependency>
            <groupId>io.quarkus</groupId>
            <artifactId>quarkus-resteasy</artifactId>
        </dependency>

        <!-- test dependencies -->
        <dependency>
            <groupId>io.quarkus</groupId>
            <artifactId>quarkus-junit5</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>io.rest-assured</groupId>
            <artifactId>rest-assured</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.camel.quarkus</groupId>
            <artifactId>camel-quarkus-integration-test-support</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>kr.motd.maven</groupId>
                <artifactId>os-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <phase>initialize</phase>
                        <goals>
                            <goal>detect</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.codehaus.gmaven</groupId>
                <artifactId>groovy-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <!-- gRPC is managed in Quarkus BOM but we still need ${grpc.version} for the protobuf-maven-plugin bellow -->
                        <!-- To solve that we parse the Quarkus BOM POM and set the grpc.version property dynamically -->
                        <!-- instead of hardcoding it -->
                        <id>set-grpc-version-property</id>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>execute</goal>
                        </goals>
                        <configuration>
                            <properties>
                                <localRepository>${settings.localRepository}</localRepository>
                                <quarkusVersion>${quarkus.version}</quarkusVersion>
                            </properties>
                            <source>
                                import java.nio.file.Path
                                import java.nio.file.Paths
                                import java.nio.file.Files
                                final Path localMavenRepoPath = Paths.get(properties['localRepository'])
                                final Path quarkusBomPath = localMavenRepoPath.resolve('io/quarkus/quarkus-bom/' + properties['quarkusVersion'] + '/quarkus-bom-' + properties['quarkusVersion'] + '.pom')
                                if (!Files.exists(quarkusBomPath)) {
                                    throw new IllegalStateException(quarkusBomPath + ' should exist')
                                }
                                def pomProject = new XmlParser().parseText(quarkusBomPath.getText('UTF-8'))
                                final String grpcVersion = pomProject.properties.'grpc.version'.text()
                                println 'setting grpc.version = ' + grpcVersion + ' as found in Quarkus BOM'
                                project.properties['grpc.version'] = grpcVersion
                            </source>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.xolstice.maven.plugins</groupId>
                <artifactId>protobuf-maven-plugin</artifactId>
                <extensions>true</extensions>
                <executions>
                    <execution>
                        <goals>
                            <goal>compile</goal>
                            <goal>compile-custom</goal>
                        </goals>
                        <phase>generate-sources</phase>
                        <configuration>
                            <protocArtifact>com.google.protobuf:protoc:${protobuf.version}:exe:${os.detected.classifier}</protocArtifact>
                            <pluginId>grpc-java</pluginId>
                            <pluginArtifact>io.grpc:protoc-gen-grpc-java:${grpc.version}:exe:${os.detected.classifier}</pluginArtifact>
                            <checkStaleness>true</checkStaleness>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>io.quarkus</groupId>
                <artifactId>quarkus-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <goals>
                            <goal>build</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>
