<?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>be.orbinson.osgi</groupId>
        <artifactId>opentelemetry-osgi-wrappers</artifactId>
        <version>1.0.2</version>
        <relativePath>../pom.xml</relativePath>
    </parent>

    <artifactId>integration-tests</artifactId>
    <name>Integration Tests</name>

    <dependencies>
        <!-- OSGi -->
        <dependency>
            <groupId>org.osgi</groupId>
            <artifactId>osgi.core</artifactId>
            <version>7.0.0</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.osgi</groupId>
            <artifactId>osgi.cmpn</artifactId>
            <version>7.0.0</version>
            <scope>provided</scope>
        </dependency>

        <!-- OpenTelemetry -->
        <dependency>
            <groupId>io.opentelemetry</groupId>
            <artifactId>opentelemetry-api</artifactId>
            <version>1.43.0</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>io.opentelemetry</groupId>
            <artifactId>opentelemetry-sdk</artifactId>
            <version>1.43.0</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>io.opentelemetry</groupId>
            <artifactId>opentelemetry-sdk-testing</artifactId>
            <version>1.43.0</version>
        </dependency>

        <!-- Testing -->
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter</artifactId>
            <version>5.10.2</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.jayway.jsonpath</groupId>
            <artifactId>json-path</artifactId>
            <version>2.9.0</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>biz.aQute.bnd</groupId>
                <artifactId>bnd-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>bnd-process</id>
                        <goals>
                            <goal>bnd-process</goal>
                        </goals>
                        <configuration>
                            <bnd><![CDATA[
                        Export-Package: be.orbinson.osgi.opentelemetry
                        Import-Package: *;resolution:=optional

                        -includeresource: @opentelemetry-sdk-testing-1.43.0.jar;lib:=true
                   ]]></bnd>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <!-- We have to install the main and test jar to local repo so that the feature plugin can use it in the feature model -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-install-plugin</artifactId>
                <version>3.1.2</version>
                <executions>
                    <execution>
                        <id>install-to-local-repo</id>
                        <goals>
                            <goal>install</goal>
                        </goals>
                        <phase>pre-integration-test</phase>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>build-helper-maven-plugin</artifactId>
                <version>3.2.0</version>
                <executions>
                    <execution>
                        <id>reserve-network-port</id>
                        <goals>
                            <goal>reserve-network-port</goal>
                        </goals>
                        <phase>process-resources</phase>
                        <configuration>
                            <portNames>
                                <portName>http.port</portName>
                            </portNames>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.sling</groupId>
                <artifactId>slingfeature-maven-plugin</artifactId>
                <version>1.8.4</version>
                <extensions>true</extensions>
                <executions>
                    <execution>
                        <id>aggregate</id>
                        <phase>package</phase>
                        <goals>
                            <goal>aggregate-features</goal>
                        </goals>
                        <configuration>
                            <aggregates>
                                <aggregate>
                                    <classifier>main</classifier>
                                    <filesInclude>*.json</filesInclude>
                                </aggregate>
                            </aggregates>
                        </configuration>
                    </execution>
                    <execution>
                        <id>attach</id>
                        <phase>package</phase>
                        <goals>
                            <goal>attach-features</goal>
                        </goals>
                        <configuration>
                            <replacePropertyVariables>opentelemetry.java.version,opentelemetry.java.instrumentation.version,opentelemetry.semconv.version</replacePropertyVariables>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.sling</groupId>
                <artifactId>feature-launcher-maven-plugin</artifactId>
                <version>0.1.6</version>
                <configuration>
                    <launches>
                        <launch>
                            <id>model</id>
                            <skip>${skipTests}</skip>
                            <feature>
                                <groupId>${project.groupId}</groupId>
                                <artifactId>${project.artifactId}</artifactId>
                                <version>${project.version}</version>
                                <classifier>main</classifier>
                                <type>slingosgifeature</type>
                            </feature>
                            <launcherArguments>
                                <frameworkProperties>
                                    <org.osgi.service.http.port>${http.port}</org.osgi.service.http.port>
                                </frameworkProperties>
                                <!-- Uncomment to enable debugging of IT tests
                                <vmOptions>
                                <value>-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5000</value>
                                </vmOptions>
                                -->
                            </launcherArguments>
                            <startTimeoutSeconds>180</startTimeoutSeconds>
                        </launch>
                    </launches>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>start</goal>
                            <goal>stop</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-failsafe-plugin</artifactId>
                <version>3.3.1</version>
                <configuration>
                    <systemPropertyVariables>
                        <HTTP_PORT>${http.port}</HTTP_PORT>
                        <build.log.file>${project.build.directory}/../build.log</build.log.file>
                    </systemPropertyVariables>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>integration-test</goal>
                            <goal>verify</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>
