<?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">
    <modelVersion>4.0.0</modelVersion>

    <parent>
        <groupId>org.infinispan.protostream</groupId>
        <artifactId>parent</artifactId>
        <version>1.0.2.Final</version>
        <relativePath>../parent/pom.xml</relativePath>
    </parent>

    <artifactId>sample-domain-definition</artifactId>
    <packaging>bundle</packaging>

    <name>Sample domain model definitions in proto file</name>
    <description>
        Defines entities in a protobuf file which is then compiled into a binary descriptor and both proto and
        its binary counterpart are packaged into a jar to be used by other projects.
    </description>

    <build>
        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <includes>
                    <include>**/*.proto</include>
                </includes>
            </resource>
            <resource>
                <directory>${project.build.directory}/protobuf-descriptors</directory>
                <includes>
                    <include>**/*.protobin</include>
                </includes>
            </resource>
        </resources>

        <plugins>
            <!-- Execute protoc to parse our proto definitions and generate the serialized descriptor set. -->
            <!-- Ideally, we should use a dedicated maven plugin for this but none of the 3-4 available plugins actually work for us. -->
            <plugin>
                <artifactId>maven-antrun-plugin</artifactId>
                <executions>
                    <execution>
                        <id>compile-protoc</id>
                        <phase>generate-resources</phase>
                        <configuration>
                            <target>
                                <mkdir dir="${project.build.directory}/protobuf-descriptors/sample_bank_account"/>
                                <exec executable="protoc" failonerror="true">
                                    <arg value="--proto_path=${project.basedir}/src/main/resources"/>
                                    <arg value="--include_imports"/>
                                    <arg value="--descriptor_set_out=${project.build.directory}/protobuf-descriptors/sample_bank_account/bank.protobin"/>
                                    <arg value="${project.basedir}/src/main/resources/sample_bank_account/bank.proto"/>
                                </exec>
                            </target>
                        </configuration>
                        <goals>
                            <goal>run</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.felix</groupId>
                <artifactId>maven-bundle-plugin</artifactId>
                <extensions>true</extensions>
                <configuration>
                    <instructions>
                        <Export-Package>
                            sample_bank_account.*;version=${project.version};-split-package:=error
                        </Export-Package>
                    </instructions>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>
