diff --git a/.github/workflows/multi-version-test.yml b/.github/workflows/multi-version-test.yml new file mode 100644 index 000000000..4fc7e07a7 --- /dev/null +++ b/.github/workflows/multi-version-test.yml @@ -0,0 +1,39 @@ +--- +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@9255dc7a253b0ccc959486e2bca901246202afeb # v5 + 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 \ No newline at end of file diff --git a/integration-tests/it-spring-boot-smoke-test/pom.xml b/integration-tests/it-spring-boot-smoke-test/pom.xml index 35663055f..eb0d1c5d8 100644 --- a/integration-tests/it-spring-boot-smoke-test/pom.xml +++ b/integration-tests/it-spring-boot-smoke-test/pom.xml @@ -21,7 +21,7 @@ Spring Smoke Tests - 25 + ${test.java.version} 6.0.2 @@ -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 5a64862cf..f9b261c33 100644 --- a/pom.xml +++ b/pom.xml @@ -28,6 +28,7 @@ 6.0.2 2.16.0-alpha 8 + 25 0.70 false false @@ -252,42 +253,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.12.15 - - - @@ -301,6 +276,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 + + + + @@ -340,30 +340,6 @@ 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 - - - @@ -448,6 +424,44 @@ + + errorprone + + [21,) + + + + + maven-compiler-plugin + + + + -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.12.15 + + + + + + + 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