From 206f4e4511439e86ddf08fd639968888609f49a8 Mon Sep 17 00:00:00 2001 From: Ikhun Um Date: Fri, 28 Jun 2024 10:27:21 +0900 Subject: [PATCH] Synchronize HttpHeaderNames with Guava (#5789) Motivation: `HttpHeaderNamesTest` failed locally because we omitted three headers when upgrading the Guava version to 33.2.0. We can't detect the problem from our CI builds since all fields of Guava `HttpHeaders` are removed by the `trimShadedJar` task on which the `build` task depends. The fields are actually used for testing. Modifications: - Keep `HttpHeaders` and `MediaType` of Guava from trimming to avoid unexpected test results. - Add `-PpreferShadedTests=` option to run unshaded tests along with shaded tests - This option is disabled by default to avoid running the same tests twice. - Add missing headers to `HttpHeaderNames` Result: New headers from Guava have been added to `HttpHeaderNames`. --- .github/workflows/actions_build.yml | 4 ++- core/build.gradle | 3 +++ .../armeria/common/HttpHeaderNames.java | 27 ++++++++++++++----- gradle/scripts/README.md | 3 +++ gradle/scripts/lib/java-shade.gradle | 7 ++++- 5 files changed, 36 insertions(+), 8 deletions(-) diff --git a/.github/workflows/actions_build.yml b/.github/workflows/actions_build.yml index ed00fe1787b..f072a34d976 100644 --- a/.github/workflows/actions_build.yml +++ b/.github/workflows/actions_build.yml @@ -140,7 +140,9 @@ jobs: -PbuildJdkVersion=${{ env.BUILD_JDK_VERSION }} \ -PtestJavaVersion=${{ matrix.java }} \ ${{ matrix.min-java && format('-PminimumJavaVersion={0}', matrix.min-java) || '' }} \ - -Porg.gradle.java.installations.paths=${{ steps.setup-build-jdk.outputs.path }},${{ steps.setup-jdk.outputs.path }} + -Porg.gradle.java.installations.paths=${{ steps.setup-build-jdk.outputs.path }},${{ steps.setup-jdk.outputs.path }} \ + -PpreferShadedTests=${{ github.ref_name != 'main' }} + # Unshaded tests are skipped for PRs to avoid running the same tests twice. shell: bash env: COMMIT_SHA: ${{ github.event.pull_request.head.sha }} diff --git a/core/build.gradle b/core/build.gradle index 3b4eed35289..c01d1a9c3d2 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -227,6 +227,9 @@ if (tasks.findByName('trimShadedJar')) { keep "class com.linecorp.armeria.internal.shaded.bouncycastle.jcajce.provider.asymmetric.ec.** { *; }" keep "class com.linecorp.armeria.internal.shaded.bouncycastle.jcajce.provider.asymmetric.rsa.** { *; }" keep "class com.linecorp.armeria.internal.shaded.bouncycastle.jcajce.provider.asymmetric.x509.** { *; }" + // Keep the Guava classes accessed during testing. + keep "class com.linecorp.armeria.internal.shaded.guava.net.HttpHeaders { *; }" + keep "class com.linecorp.armeria.internal.shaded.guava.net.MediaType { *; }" dontnote } } diff --git a/core/src/main/java/com/linecorp/armeria/common/HttpHeaderNames.java b/core/src/main/java/com/linecorp/armeria/common/HttpHeaderNames.java index a454fbee744..42892439e15 100644 --- a/core/src/main/java/com/linecorp/armeria/common/HttpHeaderNames.java +++ b/core/src/main/java/com/linecorp/armeria/common/HttpHeaderNames.java @@ -745,6 +745,12 @@ public final class HttpHeaderNames { * header field name. */ public static final AsciiString PERMISSIONS_POLICY = create("Permissions-Policy"); + /** + * The HTTP {@code + * Permissions-Policy-Report-Only} header field name. + */ + public static final AsciiString PERMISSIONS_POLICY_REPORT_ONLY = create("Permissions-Policy-Report-Only"); /** * The HTTP {@code @@ -904,24 +910,33 @@ public final class HttpHeaderNames { * Observe-Browsing-Topics} header field name. */ public static final AsciiString OBSERVE_BROWSING_TOPICS = create("Observe-Browsing-Topics"); - /** - * The HTTP {@code CDN-Loop} header field name. - */ - public static final AsciiString CDN_LOOP = create("CDN-Loop"); - /** * The HTTP {@code * Sec-Ad-Auction-Fetch} header field name. */ public static final AsciiString SEC_AD_AUCTION_FETCH = create("Sec-Ad-Auction-Fetch"); - + /** + * The HTTP {@code + * Sec-GPC} header field name. + */ + public static final AsciiString SEC_GPC = create("Sec-GPC"); /** * The HTTP {@code * Ad-Auction-Signals} header field name. */ public static final AsciiString AD_AUCTION_SIGNALS = create("Ad-Auction-Signals"); + /** + * The HTTP {@code + * Ad-Auction-Allowed} header field name. + */ + public static final AsciiString AD_AUCTION_ALLOWED = create("Ad-Auction-Allowed"); + /** + * The HTTP {@code CDN-Loop} header field name. + */ + public static final AsciiString CDN_LOOP = create("CDN-Loop"); private static final Map map; private static final Map inverseMap; diff --git a/gradle/scripts/README.md b/gradle/scripts/README.md index 5bbdde12d82..29bc8c81f0b 100644 --- a/gradle/scripts/README.md +++ b/gradle/scripts/README.md @@ -573,6 +573,9 @@ relocations [ { from: "com.google.common", to: "com.doe.john.myproject.shaded.gu { from: "com.google.thirdparty.publicsuffix", to: "com.doe.john.myproject.shaded.publicsuffix" } ] ``` +Unshaded tests are disabled by default when a shading task is configured. If you want to run unshaded tests, +you can specify `-PpreferShadedTests=false` option. + ### Trimming a shaded JAR with `trim` flag If you shade many dependencies, your JAR will grow huge, even if you only use diff --git a/gradle/scripts/lib/java-shade.gradle b/gradle/scripts/lib/java-shade.gradle index ca96daee01d..061b1304470 100644 --- a/gradle/scripts/lib/java-shade.gradle +++ b/gradle/scripts/lib/java-shade.gradle @@ -254,8 +254,13 @@ configure(relocatedProjects) { gradle.taskGraph.whenReady { // Skip unshaded tests if shaded tests will run. + // To enable, set the property 'preferShadedTests' to 'false'. + boolean runUnshadedTests = false + if (rootProject.hasProperty('preferShadedTests') && "false" == rootProject.property('preferShadedTests')) { + runUnshadedTests = true + } if (gradle.taskGraph.hasTask(tasks.shadedTest)) { - tasks.test.onlyIf { false } + tasks.test.onlyIf { runUnshadedTests } } } }