<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.metricshub</groupId>
		<artifactId>metricshub-community</artifactId>
		<version>3.9.07</version>
	</parent>

	<artifactId>metricshub-jmx-extension</artifactId>

	<name>MetricsHub JMX Extension</name>
	<description>
		MetricsHub JMX Extension implementation providing a set of
		functionalities used to process JMX criteria and sources.
	</description>

	<dependencies>
		<dependency>
			<groupId>org.metricshub</groupId>
			<artifactId>metricshub-engine</artifactId>
		</dependency>
		<dependency>
			<groupId>org.projectlombok</groupId>
			<artifactId>lombok</artifactId>
			<scope>compile</scope>
			<optional>true</optional>
		</dependency>
		<dependency>
			<groupId>org.slf4j</groupId>
			<artifactId>slf4j-api</artifactId>
		</dependency>
		<dependency>
			<groupId>io.opentelemetry.instrumentation</groupId>
			<artifactId>opentelemetry-instrumentation-annotations</artifactId>
		</dependency>
		<dependency>
			<groupId>com.fasterxml.jackson.core</groupId>
			<artifactId>jackson-databind</artifactId>
		</dependency>
		<dependency>
			<groupId>com.fasterxml.jackson.core</groupId>
			<artifactId>jackson-core</artifactId>
		</dependency>
		<dependency>
			<groupId>com.fasterxml.jackson.dataformat</groupId>
			<artifactId>jackson-dataformat-yaml</artifactId>
		</dependency>
		<dependency>
			<groupId>org.junit.jupiter</groupId>
			<artifactId>junit-jupiter-engine</artifactId>
			<scope>test</scope>
		</dependency>
		<dependency>
			<groupId>org.junit.jupiter</groupId>
			<artifactId>junit-jupiter-params</artifactId>
			<scope>test</scope>
		</dependency>
		<dependency>
			<groupId>org.mockito</groupId>
			<artifactId>mockito-core</artifactId>
			<scope>test</scope>
		</dependency>
		<dependency>
			<groupId>org.mockito</groupId>
			<artifactId>mockito-junit-jupiter</artifactId>
			<scope>test</scope>
		</dependency>
		<dependency>
			<groupId>org.slf4j</groupId>
			<artifactId>slf4j-simple</artifactId>
			<scope>test</scope>
		</dependency>
	</dependencies>

	<build>
		<resources>
			<resource>
				<directory>src/main/resources</directory>
				<filtering>true</filtering>
			</resource>
		</resources>

		<plugins>

			<!-- surefire -->
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-surefire-plugin</artifactId>
				<configuration>
					<systemPropertyVariables>
						<jacoco-agent.destfile>target/jacoco.exec</jacoco-agent.destfile>
					</systemPropertyVariables>
					<classpathDependencyExcludes>
						<classpathDependencyExclude>org.apache.logging.log4j:log4j-slf4j-impl</classpathDependencyExclude>
					</classpathDependencyExcludes>
					<argLine>@{argLine} -javaagent:"${org.mockito:mockito-core:jar}"</argLine>
				</configuration>
			</plugin>

			<!-- build-helper-maven-plugin -->
			<plugin>
				<groupId>org.codehaus.mojo</groupId>
				<artifactId>build-helper-maven-plugin</artifactId>
				<executions>
					<execution>
						<id>add-test-source</id>
						<phase>generate-test-sources</phase>
						<goals>
							<goal>add-test-source</goal>
						</goals>
						<configuration>
							<sources>
								<source>src/it/java</source>
							</sources>
						</configuration>
					</execution>
				</executions>
			</plugin>

			<!-- Failsafe for integration tests -->
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-failsafe-plugin</artifactId>
				<executions>
					<execution>
						<id>integration-test</id>
						<goals>
							<goal>integration-test</goal>
							<goal>verify</goal>
						</goals>
					</execution>
				</executions>
				<configuration>
					<argLine>${failsafe.argLine}</argLine>
					<forkCount>1</forkCount>
					<reuseForks>false</reuseForks>
					<classesDirectory>${project.build.outputDirectory}</classesDirectory>
					<trimStackTrace>false</trimStackTrace>
					<includes>
						<include>**/*IT.java</include>
					</includes>
				</configuration>
			</plugin>

			<!-- JaCoCo for code coverage -->
			<plugin>
				<groupId>org.jacoco</groupId>
				<artifactId>jacoco-maven-plugin</artifactId>
				<executions>
					<!-- Attach JaCoCo agent for unit tests -->
					<execution>
						<id>prepare-agent</id>
						<goals>
							<goal>prepare-agent</goal>
						</goals>
					</execution>

					<!-- Attach JaCoCo agent for integration tests -->
					<execution>
						<id>prepare-agent-integration</id>
						<goals>
							<goal>prepare-agent-integration</goal>
						</goals>
						<configuration>
							<propertyName>failsafe.argLine</propertyName>
							<destFile>${project.build.directory}/jacoco-it.exec</destFile>
						</configuration>
						<phase>pre-integration-test</phase>
					</execution>

					<!-- Merge unit + integration exec files -->
					<execution>
						<id>merge-results</id>
						<phase>verify</phase>
						<goals>
							<goal>merge</goal>
						</goals>
						<configuration>
							<fileSets>
								<fileSet>
									<directory>${project.build.directory}</directory>
									<includes>
										<include>jacoco.exec</include>
										<include>jacoco-it.exec</include>
									</includes>
								</fileSet>
							</fileSets>
							<destFile>${project.build.directory}/jacoco-merged.exec</destFile>
						</configuration>
					</execution>

					<!-- Generate the final report -->
					<execution>
						<id>report</id>
						<phase>verify</phase>
						<goals>
							<goal>report</goal>
						</goals>
						<configuration>
							<dataFile>${project.build.directory}/jacoco-merged.exec</dataFile>
							<outputDirectory>${project.reporting.outputDirectory}/jacoco</outputDirectory>
						</configuration>
					</execution>

					<!-- Coverage Rules -->
					<execution>
						<id>check</id>
						<goals>
							<goal>check</goal>
						</goals>
						<configuration>
							<dataFile>${project.build.directory}/jacoco-merged.exec</dataFile>
							<rules>
								<rule>
									<element>BUNDLE</element>
									<limits>
										<limit>
											<counter>COMPLEXITY</counter>
											<value>COVEREDRATIO</value>
											<minimum>0.70</minimum>
										</limit>
									</limits>
								</rule>
							</rules>
						</configuration>
					</execution>
				</executions>
				<configuration>
					<excludes>
						<exclude>org/metricshub/extension/jmx/*JmxConfigurationBuilder*</exclude>
					</excludes>
				</configuration>
			</plugin>

			<!-- Maven Shade Plugin-->
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-shade-plugin</artifactId>
				<executions>
					<execution>
						<phase>package</phase>
						<goals>
							<goal>shade</goal>
						</goals>
						<configuration>
							<artifactSet>
								<includes>
									<include>org.metricshub:metricshub-jmx-extension</include>
								</includes>
							</artifactSet>
							<transformers>
								<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
									<manifestEntries>
										<Multi-Release>true</Multi-Release>
										<MetricsHub-Extension-Id>${project.artifactId}</MetricsHub-Extension-Id>
									</manifestEntries>
								</transformer>
							</transformers>
							<minimizeJar>false</minimizeJar>
						</configuration>
					</execution>
				</executions>
			</plugin>
		</plugins>
	</build>
</project>
