<?xml version="1.0" encoding="UTF-8"?>
<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">

  <parent>
    <groupId>io.vertx</groupId>
    <artifactId>vertx-codegen-parent</artifactId>
    <version>5.1.3</version>
  </parent>

  <modelVersion>4.0.0</modelVersion>

  <name>vertx-codegen-protobuf</name>
  <artifactId>vertx-codegen-protobuf</artifactId>

  <properties>
    <doc.skip>false</doc.skip>
    <asciidoc.dir>${project.basedir}/src/main/asciidoc</asciidoc.dir>
    <grpc.version>1.50.2</grpc.version>
    <protoc.version>3.21.12</protoc.version>
    <vertx.javadoc.legacyMode>true</vertx.javadoc.legacyMode>
  </properties>

  <dependencies>
    <dependency>
      <groupId>io.vertx</groupId>
      <artifactId>vertx-codegen-processor</artifactId>
    </dependency>
    <dependency>
      <groupId>com.google.protobuf</groupId>
      <artifactId>protobuf-java</artifactId>
      <version>${protoc.version}</version>
    </dependency>
    <dependency>
      <groupId>io.grpc</groupId>
      <artifactId>grpc-stub</artifactId>
      <version>${grpc.version}</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>io.grpc</groupId>
      <artifactId>grpc-protobuf</artifactId>
      <version>${grpc.version}</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.13.1</version>
      <scope>test</scope>
    </dependency>
  </dependencies>

  <build>
    <extensions>
      <extension>
        <groupId>kr.motd.maven</groupId>
        <artifactId>os-maven-plugin</artifactId>
        <version>1.4.1.Final</version>
      </extension>
    </extensions>
    <pluginManagement>
      <plugins>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-compiler-plugin</artifactId>
          <executions>
            <execution>
              <id>default-compile</id>
              <configuration>
                <annotationProcessorPaths>
                  <annotationProcessorPath>
                    <groupId>io.vertx</groupId>
                    <artifactId>vertx-docgen-processor</artifactId>
                    <classifier>processor</classifier>
                  </annotationProcessorPath>
                </annotationProcessorPaths>
                <showWarnings>true</showWarnings>
                <compilerArgs>
                  <arg>-Adocgen.source=${asciidoc.dir}</arg>
                  <arg>-Adocgen.output=${project.build.directory}/asciidoc/java</arg>
                </compilerArgs>
              </configuration>
            </execution>
            <execution>
              <id>generate-test-converters</id>
              <goals>
                <goal>testCompile</goal>
              </goals>
              <phase>generate-test-sources</phase>
              <configuration>
                <annotationProcessors>
                  <annotationProcessor>io.vertx.codegen.processor.Processor</annotationProcessor>
                </annotationProcessors>
                <compileSourceRoots>
                  <compileSourceRoot>${project.basedir}/src/converters/java</compileSourceRoot>
                </compileSourceRoots>
                <generatedTestSourcesDirectory>${project.basedir}/src/converters/generated</generatedTestSourcesDirectory>
              </configuration>
            </execution>
          </executions>
        </plugin>
        <plugin>
          <artifactId>maven-jar-plugin</artifactId>
          <executions>
            <execution>
              <id>default-jar</id>
              <configuration>
                <excludes>
                  <exclude>io/vertx/core/**</exclude>
                  <exclude>examples/**</exclude>
                </excludes>
              </configuration>
            </execution>
          </executions>
        </plugin>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-source-plugin</artifactId>
          <configuration>
            <excludes>
              <exclude>io/vertx/core/**</exclude>
              <exclude>examples/**</exclude>
            </excludes>
          </configuration>
        </plugin>
      </plugins>
    </pluginManagement>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
        <executions>
          <execution>
            <id>unpack</id>
            <phase>generate-test-sources</phase>
            <goals>
              <goal>unpack</goal>
            </goals>
            <configuration>
              <artifactItems>
                <artifactItem>
                  <groupId>io.vertx</groupId>
                  <artifactId>vertx-codegen-api</artifactId>
                  <type>jar</type>
                </artifactItem>
                <artifactItem>
                  <groupId>io.vertx</groupId>
                  <artifactId>vertx-codegen-processor</artifactId>
                  <type>jar</type>
                </artifactItem>
                <artifactItem>
                  <groupId>com.fasterxml.jackson.core</groupId>
                  <artifactId>jackson-core</artifactId>
                  <type>jar</type>
                </artifactItem>
                <artifactItem>
                  <groupId>com.google.protobuf</groupId>
                  <artifactId>protobuf-java</artifactId>
                  <type>jar</type>
                </artifactItem>
              </artifactItems>
              <outputDirectory>${project.build.directory}/test-classpath</outputDirectory>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>build-helper-maven-plugin</artifactId>
        <executions>
          <execution>
            <id>add-source</id>
            <goals>
              <goal>add-source</goal>
            </goals>
            <configuration>
              <sources>
                <source>${basedir}/src/stubs/java</source>
              </sources>
            </configuration>
          </execution>
          <execution>
            <id>add-test-source</id>
            <goals>
              <goal>add-test-source</goal>
            </goals>
            <configuration>
              <sources>
                <source>${basedir}/src/stubs/java</source>
              </sources>
            </configuration>
          </execution>
        </executions>
      </plugin>

      <!-- Copy proto files for Protoc Plugin -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-resources-plugin</artifactId>
        <version>3.2.0</version>
        <executions>
          <execution>
            <id>copy-standard-proto</id>
            <phase>process-sources</phase>
            <goals>
              <goal>copy-resources</goal>
            </goals>
            <configuration>
              <outputDirectory>${project.build.directory}/proto</outputDirectory>
              <resources>
                <resource>
                  <directory>${project.basedir}/src/main/resources/proto/</directory>
                  <includes>
                    <include>*.proto</include>
                  </includes>
                </resource>
              </resources>
            </configuration>
          </execution>
          <execution>
            <id>copy-generated-proto</id>
            <phase>process-test-sources</phase>
            <goals>
              <goal>copy-resources</goal>
            </goals>
            <configuration>
              <outputDirectory>${project.build.directory}/proto</outputDirectory>
              <resources>
                <resource>
                  <directory>${project.basedir}/src/converters/generated/</directory>
                  <includes>
                    <include>*.proto</include>
                  </includes>
                </resource>
              </resources>
            </configuration>
          </execution>
        </executions>
      </plugin>

      <!-- Protoc Plugin to test against dataModel Protocol Buffer converter -->
      <plugin>
        <groupId>org.xolstice.maven.plugins</groupId>
        <artifactId>protobuf-maven-plugin</artifactId>
        <version>0.6.1</version>
        <configuration>
          <protocArtifact>com.google.protobuf:protoc:${protoc.version}:exe:${os.detected.classifier}</protocArtifact>
          <pluginId>grpc-java</pluginId>
          <pluginArtifact>io.grpc:protoc-gen-grpc-java:${grpc.version}:exe:${os.detected.classifier}</pluginArtifact>
          <protoTestSourceRoot>${project.build.directory}/proto</protoTestSourceRoot>
        </configuration>
        <executions>
          <execution>
            <id>test-compile</id>
            <phase>process-test-sources</phase>
            <goals>
              <goal>test-compile</goal>
              <goal>test-compile-custom</goal>
            </goals>
          </execution>
        </executions>
      </plugin>

      <plugin>
        <artifactId>maven-assembly-plugin</artifactId>
        <executions>
          <execution>
            <id>package-docs</id>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</project>
