diff --git a/.editorconfig b/.editorconfig index 8628b45bd..52cac2bc7 100644 --- a/.editorconfig +++ b/.editorconfig @@ -11,7 +11,7 @@ max_line_length = 200 max_line_length = 300 [pom.xml] -max_line_length = 110 +max_line_length = 120 [*.py] # checked by black diff --git a/.github/workflows/multi-version-test.yml b/.github/workflows/multi-version-test.yml new file mode 100644 index 000000000..130153442 --- /dev/null +++ b/.github/workflows/multi-version-test.yml @@ -0,0 +1,45 @@ +--- +name: Java-Version Compatibility Tests + +on: [pull_request] + +permissions: {} + +jobs: + compatibility-test: + name: Test on Java ${{ matrix.java }} + runs-on: ubuntu-24.04 + strategy: + fail-fast: false + matrix: + java: [17, 21, 25] + steps: + - name: Check out + uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6 + with: + persist-credentials: false + + - name: Set up Java ${{ matrix.java }} + id: setup-java + uses: actions/setup-java@v4 + with: + distribution: "temurin" + java-version: ${{ matrix.java }} + + - name: Cache local Maven repository + uses: actions/cache@8b402f58fbc84540c8b491a91e594a4576fec3d7 # v5.0.2 + with: + path: ~/.m2/repository + key: ${{ runner.os }}-maven-java${{ matrix.java }}-${{ hashFiles('**/pom.xml') }} + restore-keys: | + ${{ runner.os }}-maven-java${{ matrix.java }}- + ${{ runner.os }}-maven- + + - name: Build and test on Java ${{ matrix.java }} + run: >- + ./mvnw clean install + -Dtest.java.version=${{ matrix.java }} + -Dspotless.skip=true + -Dcheckstyle.skip=true + -Dwarnings=-nowarn + -Dcoverage.skip=true diff --git a/.mise/tasks/build-release.sh b/.mise/tasks/build-release.sh index a29b0d22f..64ce4ad4b 100755 --- a/.mise/tasks/build-release.sh +++ b/.mise/tasks/build-release.sh @@ -9,4 +9,4 @@ set -euo pipefail VERSION=${usage_tag#v} mise run set-version "$VERSION" -mvn -B package -P 'release,!default' -Dmaven.test.skip=true +mvn -B install -P 'release,!default' -Dmaven.test.skip=true -Dgpg.skip=true diff --git a/benchmarks/pom.xml b/benchmarks/pom.xml index b2fad5766..b484e4754 100644 --- a/benchmarks/pom.xml +++ b/benchmarks/pom.xml @@ -85,8 +85,8 @@ 1.8 1.8 - - + + -parameters diff --git a/integration-tests/it-spring-boot-smoke-test/pom.xml b/integration-tests/it-spring-boot-smoke-test/pom.xml index 35663055f..4d7f79c8d 100644 --- a/integration-tests/it-spring-boot-smoke-test/pom.xml +++ b/integration-tests/it-spring-boot-smoke-test/pom.xml @@ -89,95 +89,108 @@ - - org.graalvm.buildtools - native-maven-plugin - - - - - --initialize-at-build-time=org.junit.jupiter.api.DisplayNameGenerator$IndicativeSentences - - - --initialize-at-build-time=org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor$ClassInfo - - - --initialize-at-build-time=org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor$LifecycleMethods - - - --initialize-at-build-time=org.junit.jupiter.engine.descriptor.ClassTemplateInvocationTestDescriptor - - - --initialize-at-build-time=org.junit.jupiter.engine.descriptor.ClassTemplateTestDescriptor - - - --initialize-at-build-time=org.junit.jupiter.engine.descriptor.DynamicDescendantFilter$Mode - - - --initialize-at-build-time=org.junit.jupiter.engine.descriptor.ExclusiveResourceCollector$1 - - - --initialize-at-build-time=org.junit.jupiter.engine.descriptor.MethodBasedTestDescriptor$MethodInfo - - - --initialize-at-build-time=org.junit.jupiter.engine.discovery.ClassSelectorResolver$DummyClassTemplateInvocationContext - - - --initialize-at-build-time=org.junit.platform.engine.support.store.NamespacedHierarchicalStore$EvaluatedValue - - --initialize-at-build-time=org.junit.platform.launcher.core.DiscoveryIssueNotifier - - - --initialize-at-build-time=org.junit.platform.launcher.core.HierarchicalOutputDirectoryProvider - - - --initialize-at-build-time=org.junit.platform.launcher.core.LauncherDiscoveryResult$EngineResultInfo - - - --initialize-at-build-time=org.junit.platform.suite.engine.SuiteTestDescriptor$LifecycleMethods - - - --initialize-at-build-time=org.junit.platform.commons.logging.LoggerFactory$DelegatingLogger - - - --initialize-at-build-time=org.junit.jupiter.engine.execution.ConditionEvaluator - - - --initialize-at-build-time=org.junit.jupiter.engine.execution.InterceptingExecutableInvoker - - - --initialize-at-build-time=org.junit.jupiter.api.extension.ConditionEvaluationResult - - - --initialize-at-build-time=org.junit.jupiter.engine.execution.InvocationInterceptorChain - - - - - org.springframework.boot spring-boot-maven-plugin - - com.diffplug.spotless - spotless-maven-plugin - 3.1.0 - - - - - - - - verify - - check - - - - + + + java17-plus + + [17,) + + + + + org.graalvm.buildtools + native-maven-plugin + + + + + --initialize-at-build-time=org.junit.jupiter.api.DisplayNameGenerator$IndicativeSentences + + + --initialize-at-build-time=org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor$ClassInfo + + + --initialize-at-build-time=org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor$LifecycleMethods + + + --initialize-at-build-time=org.junit.jupiter.engine.descriptor.ClassTemplateInvocationTestDescriptor + + + --initialize-at-build-time=org.junit.jupiter.engine.descriptor.ClassTemplateTestDescriptor + + + --initialize-at-build-time=org.junit.jupiter.engine.descriptor.DynamicDescendantFilter$Mode + + + --initialize-at-build-time=org.junit.jupiter.engine.descriptor.ExclusiveResourceCollector$1 + + + --initialize-at-build-time=org.junit.jupiter.engine.descriptor.MethodBasedTestDescriptor$MethodInfo + + + --initialize-at-build-time=org.junit.jupiter.engine.discovery.ClassSelectorResolver$DummyClassTemplateInvocationContext + + + --initialize-at-build-time=org.junit.platform.engine.support.store.NamespacedHierarchicalStore$EvaluatedValue + + --initialize-at-build-time=org.junit.platform.launcher.core.DiscoveryIssueNotifier + + + --initialize-at-build-time=org.junit.platform.launcher.core.HierarchicalOutputDirectoryProvider + + + --initialize-at-build-time=org.junit.platform.launcher.core.LauncherDiscoveryResult$EngineResultInfo + + + --initialize-at-build-time=org.junit.platform.suite.engine.SuiteTestDescriptor$LifecycleMethods + + + --initialize-at-build-time=org.junit.platform.commons.logging.LoggerFactory$DelegatingLogger + + + --initialize-at-build-time=org.junit.jupiter.engine.execution.ConditionEvaluator + + + --initialize-at-build-time=org.junit.jupiter.engine.execution.InterceptingExecutableInvoker + + + --initialize-at-build-time=org.junit.jupiter.api.extension.ConditionEvaluationResult + + + --initialize-at-build-time=org.junit.jupiter.engine.execution.InvocationInterceptorChain + + + + + + + com.diffplug.spotless + spotless-maven-plugin + 3.1.0 + + + + + + + + verify + + check + + + + + + + + + diff --git a/pom.xml b/pom.xml index 6f3d5282a..8e121f2a3 100644 --- a/pom.xml +++ b/pom.xml @@ -28,6 +28,7 @@ 6.0.2 2.16.0-alpha 8 + 25 0.70 false false @@ -69,6 +70,67 @@ 3.0.2 provided + + + org.junit.jupiter + junit-jupiter + ${junit-jupiter.version} + test + + + org.junit.jupiter + junit-jupiter-params + ${junit-jupiter.version} + test + + + org.mockito + mockito-core + 5.21.0 + test + + + org.assertj + assertj-core + 3.27.6 + test + + + com.google.guava + guava + ${guava.version} + test + + + org.slf4j + slf4j-simple + 2.0.17 + test + + + org.junit-pioneer + junit-pioneer + 2.3.0 + test + + + org.awaitility + awaitility + 4.3.0 + test + + + org.wiremock + wiremock + 3.13.2 + test + + + org.hamcrest + hamcrest-core + + + @@ -252,42 +314,16 @@ ${java.version} ${java.version} ${java.version} - 25 - 25 - 25 + ${test.java.version} + ${test.java.version} + ${test.java.version} true -Xlint:all,-serial,-processing,-options ${warnings} --should-stop=ifError=FLOW -XDcompilePolicy=simple - - -Xplugin:ErrorProne - -Xep:AlmostJavadoc:OFF - -Xep:MissingSummary:OFF - -Xep:LongDoubleConversion:OFF - -Xep:StringSplitter:OFF - -XepExcludedPaths:(.*/generated/.*|.*/src/test/java/.*|.*/examples/.*|.*/integration-tests/.*) - -XepOpt:NullAway:AnnotatedPackages=io.prometheus.metrics - - - - com.google.errorprone - error_prone_core - 2.46.0 - - - com.uber.nullaway - nullaway - 0.13.0 - - - @@ -301,6 +337,31 @@ + + + + org.junit + junit-bom + ${junit-jupiter.version} + pom + import + + + io.opentelemetry.instrumentation + opentelemetry-instrumentation-bom-alpha + ${otel.instrumentation.version} + pom + import + + + io.opentelemetry + opentelemetry-proto + 1.7.1-alpha + test + + + + @@ -331,102 +392,15 @@ - default + examples-and-integration-tests - true + [25,) examples benchmarks integration-tests - - - - org.junit - junit-bom - ${junit-jupiter.version} - pom - import - - - io.opentelemetry.instrumentation - opentelemetry-instrumentation-bom-alpha - ${otel.instrumentation.version} - pom - import - - - io.opentelemetry - opentelemetry-proto - 1.7.1-alpha - test - - - - - - - org.junit.jupiter - junit-jupiter - ${junit-jupiter.version} - test - - - org.junit.jupiter - junit-jupiter-params - ${junit-jupiter.version} - test - - - org.mockito - mockito-core - 5.21.0 - test - - - org.assertj - assertj-core - 3.27.6 - test - - - com.google.guava - guava - ${guava.version} - test - - - org.slf4j - slf4j-simple - 2.0.17 - test - - - org.junit-pioneer - junit-pioneer - 2.3.0 - test - - - org.awaitility - awaitility - 4.3.0 - test - - - org.wiremock - wiremock - 3.13.2 - test - - - org.hamcrest - hamcrest-core - - - - javadoc @@ -448,6 +422,45 @@ + + errorprone + + [21,) + + + + + maven-compiler-plugin + + + -XDaddTypeAnnotationsToSymbol=true + + -Xplugin:ErrorProne + -Xep:AlmostJavadoc:OFF + -Xep:MissingSummary:OFF + -Xep:LongDoubleConversion:OFF + -Xep:StringSplitter:OFF + -XepExcludedPaths:(.*/generated/.*|.*/src/test/java/.*|.*/examples/.*|.*/integration-tests/.*) + -XepOpt:NullAway:AnnotatedPackages=io.prometheus.metrics + + + + + com.google.errorprone + error_prone_core + 2.46.0 + + + com.uber.nullaway + nullaway + 0.13.0 + + + + + + + release diff --git a/prometheus-metrics-exporter-httpserver/src/test/java/io/prometheus/metrics/exporter/httpserver/HTTPServerTest.java b/prometheus-metrics-exporter-httpserver/src/test/java/io/prometheus/metrics/exporter/httpserver/HTTPServerTest.java index 9b7f658de..5959c5c91 100644 --- a/prometheus-metrics-exporter-httpserver/src/test/java/io/prometheus/metrics/exporter/httpserver/HTTPServerTest.java +++ b/prometheus-metrics-exporter-httpserver/src/test/java/io/prometheus/metrics/exporter/httpserver/HTTPServerTest.java @@ -12,6 +12,7 @@ import io.prometheus.metrics.model.registry.PrometheusScrapeRequest; import io.prometheus.metrics.model.snapshots.MetricSnapshots; import java.io.IOException; +import java.lang.reflect.Method; import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.Socket; @@ -45,7 +46,7 @@ public Result authenticate(HttpExchange exchange) { HttpHandler handler = exchange -> { boolean found = false; - Subject current = Subject.current(); + Subject current = getCurrentSubject(); for (Principal p : current.getPrincipals()) { if (user.equals(p.getName())) { found = true; @@ -186,4 +187,27 @@ void healthDisabled() throws IOException { "204", "/-/healthy"); } + + /** + * Get current Subject using reflection to support both Java 17 and Java 18+. + * + *

Java 18+ has Subject.current(), but Java 17 and earlier require + * Subject.getSubject(AccessController.getContext()). + */ + @SuppressWarnings({"removal"}) + private static Subject getCurrentSubject() { + try { + Method currentMethod = Subject.class.getMethod("current"); + return (Subject) currentMethod.invoke(null); + } catch (NoSuchMethodException e) { + // Fall back to pre-Java 18 API + try { + return Subject.getSubject(java.security.AccessController.getContext()); + } catch (Exception ex) { + throw new RuntimeException("Failed to get current Subject", ex); + } + } catch (Exception e) { + throw new RuntimeException("Failed to invoke Subject.current()", e); + } + } } diff --git a/prometheus-metrics-parent/pom.xml b/prometheus-metrics-parent/pom.xml index 075eaf782..c5b521b1a 100644 --- a/prometheus-metrics-parent/pom.xml +++ b/prometheus-metrics-parent/pom.xml @@ -68,29 +68,39 @@ - - com.diffplug.spotless - spotless-maven-plugin - 3.1.0 - - - - - ${spotless.skip} - - - - verify - - check - - - - + + java17-plus + + [17,) + + + + + com.diffplug.spotless + spotless-maven-plugin + 3.1.0 + + + + + ${spotless.skip} + + + + verify + + check + + + + + + + release