<?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>io.smallrye</groupId>
        <artifactId>smallrye-build-parent</artifactId>
        <version>39</version>
        <relativePath />
    </parent>

    <groupId>io.smallrye.opentelemetry.examples</groupId>
    <artifactId>library</artifactId>
    <version>2.4.0</version>
    <packaging>war</packaging>
    <name>SmallRye OpenTelemetry Examples: Library</name>

    <properties>
        <version.plugin.war>3.3.2</version.plugin.war>
        <version.plugin.dependency>3.5.0</version.plugin.dependency>
        <version.plugin.jetty>11.0.13</version.plugin.jetty>

        <version.weld.core>5.1.0.Final</version.weld.core>
        <version.resteasy>6.2.2.Final</version.resteasy>
        <version.smallrye.config>3.1.1</version.smallrye.config>

        <version.opentelemetry>1.23.0</version.opentelemetry>
        <version.opentelemetry.exporter>1.23.0</version.opentelemetry.exporter>
    </properties>

    <build>
        <finalName>${project.artifactId}</finalName>

        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-war-plugin</artifactId>
                    <version>${version.plugin.war}</version>
                    <configuration>
                        <failOnMissingWebXml>false</failOnMissingWebXml>
                        <archive>
                            <manifest>
                                <addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
                                <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
                            </manifest>
                            <manifestEntries>
                                <Date>${maven.build.timestamp}</Date>
                                <Specification-Title>${project.name}</Specification-Title>
                                <Specification-Version>${project.version}</Specification-Version>
                                <Implementation-Title>${project.name}</Implementation-Title>
                                <Implementation-Version>${project.version}</Implementation-Version>
                            </manifestEntries>
                        </archive>
                    </configuration>
                </plugin>

                <plugin>
                    <groupId>org.eclipse.jetty</groupId>
                    <artifactId>jetty-maven-plugin</artifactId>
                    <version>${version.plugin.jetty}</version>
                    <configuration>
                        <webApp>
                            <contextPath>/</contextPath>
                        </webApp>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.jboss.resteasy</groupId>
                <artifactId>resteasy-bom</artifactId>
                <version>${version.resteasy}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <dependencies>
        <dependency>
            <groupId>org.jboss.weld.servlet</groupId>
            <artifactId>weld-servlet-core</artifactId>
            <version>${version.weld.core}</version>
        </dependency>
        <dependency>
            <groupId>org.jboss.resteasy</groupId>
            <artifactId>resteasy-servlet-initializer</artifactId>
        </dependency>
        <dependency>
            <groupId>org.jboss.resteasy</groupId>
            <artifactId>resteasy-cdi</artifactId>
        </dependency>
        <dependency>
            <groupId>org.jboss.resteasy</groupId>
            <artifactId>resteasy-json-binding-provider</artifactId>
        </dependency>
        <dependency>
            <groupId>io.smallrye.config</groupId>
            <artifactId>smallrye-config</artifactId>
            <version>${version.smallrye.config}</version>
        </dependency>

        <!-- Open Telemetry -->
        <dependency>
            <groupId>io.opentelemetry</groupId>
            <artifactId>opentelemetry-exporter-otlp</artifactId>
            <version>${version.opentelemetry.exporter}</version>
        </dependency>
        <dependency>
            <groupId>io.smallrye.opentelemetry</groupId>
            <artifactId>smallrye-opentelemetry-config</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>io.smallrye.opentelemetry</groupId>
            <artifactId>smallrye-opentelemetry-cdi</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>io.smallrye.opentelemetry</groupId>
            <artifactId>smallrye-opentelemetry-rest</artifactId>
            <version>${project.version}</version>
        </dependency>
    </dependencies>

    <profiles>
        <profile>
            <id>agent</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-dependency-plugin</artifactId>
                        <version>${version.plugin.dependency}</version>
                        <executions>
                            <execution>
                                <id>copy-jetty-agent</id>
                                <phase>generate-resources</phase>
                                <goals>
                                    <goal>copy</goal>
                                </goals>
                                <configuration>
                                    <stripVersion>true</stripVersion>
                                    <artifactItems>
                                        <artifactItem>
                                            <groupId>io.opentelemetry.javaagent</groupId>
                                            <artifactId>opentelemetry-javaagent</artifactId>
                                            <version>${version.opentelemetry}</version>
                                            <type>jar</type>
                                            <overWrite>false</overWrite>
                                            <outputDirectory>${project.build.directory}/agent</outputDirectory>
                                        </artifactItem>
                                    </artifactItems>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>

                    <plugin>
                        <groupId>org.eclipse.jetty</groupId>
                        <artifactId>jetty-maven-plugin</artifactId>
                        <version>${version.plugin.jetty}</version>
                        <configuration>
                            <deployMode>FORK</deployMode>
                            <jvmArgs>-javaagent:target/agent/opentelemetry-javaagent.jar -Dotel.javaagent.configuration-file=target/classes/META-INF/microprofile-config.properties</jvmArgs>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>

  <scm>
    <tag>2.4.0</tag>
  </scm>
</project>
