From 6b2309890037b1568d33d8e7a4b30cde7c17e69a Mon Sep 17 00:00:00 2001 From: Ben Manes Date: Sat, 2 Nov 2024 10:41:19 -0700 Subject: [PATCH] dependency updates --- .github/workflows/dependency-review.yml | 2 +- .github/workflows/qodana.yml | 2 +- .github/workflows/spelling.yml | 2 +- .../cache/LocalCacheFactoryGenerator.java | 9 ++++++--- .../caffeine/cache/NodeFactoryGenerator.java | 9 ++++++--- .../gradle/wrapper/gradle-wrapper.properties | 2 +- .../gradle/wrapper/gradle-wrapper.properties | 2 +- .../gradle/wrapper/gradle-wrapper.properties | 2 +- .../gradle/wrapper/gradle-wrapper.properties | 2 +- .../gradle/wrapper/gradle-wrapper.properties | 2 +- .../gradle/wrapper/gradle-wrapper.properties | 2 +- gradle/libs.versions.toml | 18 +++++++++--------- .../lifecycle/java-library.caffeine.gradle.kts | 11 +++++++---- .../lifecycle/testing.caffeine.gradle.kts | 4 +--- .../quality/errorprone.caffeine.gradle.kts | 1 + gradle/wrapper/gradle-wrapper.properties | 2 +- .../simulator/parser/AbstractTraceReader.java | 4 ++-- .../cache/simulator/policy/Registry.java | 4 +++- .../policy/sampled/SampledPolicy.java | 14 ++++++-------- 19 files changed, 51 insertions(+), 43 deletions(-) diff --git a/.github/workflows/dependency-review.yml b/.github/workflows/dependency-review.yml index 720e66d9d0..8e46de5740 100644 --- a/.github/workflows/dependency-review.yml +++ b/.github/workflows/dependency-review.yml @@ -21,7 +21,7 @@ jobs: - name: Checkout Repository uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - name: Dependency Review - uses: actions/dependency-review-action@a6993e2c61fd5dc440b409aa1d6904921c5e1894 # v4.3.5 + uses: actions/dependency-review-action@4081bf99e2866ebe428fc0477b69eb4fcda7220a # v4.4.0 with: license-check: false comment-summary-in-pr: on-failure diff --git a/.github/workflows/qodana.yml b/.github/workflows/qodana.yml index 9cd2ef193d..c0f231b090 100644 --- a/.github/workflows/qodana.yml +++ b/.github/workflows/qodana.yml @@ -63,7 +63,7 @@ jobs: cache-encryption-key: ${{ secrets.GRADLE_ENCRYPTION_KEY }} arguments: check -x test - name: Qodana - Code Inspection - uses: JetBrains/qodana-action@4f04143e8d52028fee27c2a219c8856035094962 # v2024.2.5 + uses: JetBrains/qodana-action@31d6f3309b31c566758e1314a3d9ef0dff75ecbd # v2024.2.6 env: QODANA_TOKEN: ${{ secrets.QODANA_TOKEN }} with: diff --git a/.github/workflows/spelling.yml b/.github/workflows/spelling.yml index ff6a506952..4222ba5b60 100644 --- a/.github/workflows/spelling.yml +++ b/.github/workflows/spelling.yml @@ -34,4 +34,4 @@ jobs: objects.githubusercontent.com:443 - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - name: Typos - uses: crate-ci/typos@0d9e0c2c1bd7f770f6eb90f87780848ca02fc12c # v1.26.8 + uses: crate-ci/typos@d01f29c66d1bf1a08730750f61d86c210b0d039d # v1.27.0 diff --git a/caffeine/src/javaPoet/java/com/github/benmanes/caffeine/cache/LocalCacheFactoryGenerator.java b/caffeine/src/javaPoet/java/com/github/benmanes/caffeine/cache/LocalCacheFactoryGenerator.java index c81e2061f3..d61f60c99e 100644 --- a/caffeine/src/javaPoet/java/com/github/benmanes/caffeine/cache/LocalCacheFactoryGenerator.java +++ b/caffeine/src/javaPoet/java/com/github/benmanes/caffeine/cache/LocalCacheFactoryGenerator.java @@ -25,7 +25,6 @@ import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; -import java.nio.file.Paths; import java.time.Year; import java.time.ZoneId; import java.util.ArrayList; @@ -144,6 +143,7 @@ private NavigableMap> getClassNameToFeatures() { return classNameToFeatures; } + @SuppressWarnings("SetsImmutableEnumSetIterable") private ImmutableSet getFeatures(List combination) { var features = new LinkedHashSet(); features.add(((Boolean) combination.get(0)) ? Feature.STRONG_KEYS : Feature.WEAK_KEYS); @@ -156,6 +156,7 @@ private ImmutableSet getFeatures(List combination) { if (features.contains(Feature.MAXIMUM_WEIGHT)) { features.remove(Feature.MAXIMUM_SIZE); } + // In featureByIndex order for class naming return ImmutableSet.copyOf(features); } @@ -164,6 +165,7 @@ private Set> combinations() { return Sets.cartesianProduct(sets); } + @SuppressWarnings("SetsImmutableEnumSetIterable") private TypeSpec makeLocalCacheSpec(String className, boolean isFinal, ImmutableSet features) { TypeName superClass; @@ -174,8 +176,9 @@ private TypeSpec makeLocalCacheSpec(String className, generateFeatures = features; superClass = BOUNDED_LOCAL_CACHE; } else { + // Requires that parentFeatures is in featureByIndex order for super class naming parentFeatures = ImmutableSet.copyOf(Iterables.limit(features, features.size() - 1)); - generateFeatures = ImmutableSet.of(features.asList().get(features.size() - 1)); + generateFeatures = Sets.immutableEnumSet(features.asList().get(features.size() - 1)); superClass = ParameterizedTypeName.get(ClassName.bestGuess( encode(Feature.makeClassName(parentFeatures))), kTypeVar, vTypeVar); } @@ -208,6 +211,6 @@ private static String encode(String className) { } public static void main(String[] args) throws FormatterException, IOException { - new LocalCacheFactoryGenerator(Paths.get(args[0])).generate(); + new LocalCacheFactoryGenerator(Path.of(args[0])).generate(); } } diff --git a/caffeine/src/javaPoet/java/com/github/benmanes/caffeine/cache/NodeFactoryGenerator.java b/caffeine/src/javaPoet/java/com/github/benmanes/caffeine/cache/NodeFactoryGenerator.java index 85df35469f..ae4889c348 100644 --- a/caffeine/src/javaPoet/java/com/github/benmanes/caffeine/cache/NodeFactoryGenerator.java +++ b/caffeine/src/javaPoet/java/com/github/benmanes/caffeine/cache/NodeFactoryGenerator.java @@ -25,7 +25,6 @@ import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; -import java.nio.file.Paths; import java.time.Year; import java.time.ZoneId; import java.util.ArrayList; @@ -146,6 +145,7 @@ private NavigableMap> getClassNameToFeatures() { return classNameToFeatures; } + @SuppressWarnings("SetsImmutableEnumSetIterable") private ImmutableSet getFeatures(List combination) { var features = new LinkedHashSet(); features.add((Feature) combination.get(0)); @@ -158,9 +158,11 @@ private ImmutableSet getFeatures(List combination) { if (features.contains(Feature.MAXIMUM_WEIGHT)) { features.remove(Feature.MAXIMUM_SIZE); } + // In featureByIndex order for class naming return ImmutableSet.copyOf(features); } + @SuppressWarnings("SetsImmutableEnumSetIterable") private TypeSpec makeNodeSpec(String className, boolean isFinal, ImmutableSet features) { TypeName superClass; ImmutableSet parentFeatures; @@ -170,8 +172,9 @@ private TypeSpec makeNodeSpec(String className, boolean isFinal, ImmutableSet().configureEach { javaCompiler = javaToolchains.compilerFor { // jdk 17+ is required by compiler plugins, e.g. error-prone - languageVersion = maxOf(javaVersion, JavaLanguageVersion.of(21)) + languageVersion = maxOf(javaVersion, javaLtsVersion) } options.compilerArgs.addAll(listOf("-Xlint:all", "-Xlint:-auxiliaryclass", "-Xlint:-classfile", @@ -88,9 +89,8 @@ tasks.withType().configureEach { use() quiet() noTimestamp() - if (javaVersion.canCompileOrRun(18)) { - addStringOption("-link-modularity-mismatch", "info") - } + addStringOption("-release", javaVersion.toString()) + addStringOption("-link-modularity-mismatch", "info") links( "https://checkerframework.org/api/", "https://errorprone.info/api/latest/", @@ -104,4 +104,7 @@ tasks.withType().configureEach { dependsOn(":caffeine:javadoc") } } + javadocTool.set(javaToolchains.javadocToolFor({ + languageVersion = maxOf(javaVersion, javaLtsVersion) + })) } diff --git a/gradle/plugins/src/main/kotlin/lifecycle/testing.caffeine.gradle.kts b/gradle/plugins/src/main/kotlin/lifecycle/testing.caffeine.gradle.kts index 4aeac33486..06214870cc 100644 --- a/gradle/plugins/src/main/kotlin/lifecycle/testing.caffeine.gradle.kts +++ b/gradle/plugins/src/main/kotlin/lifecycle/testing.caffeine.gradle.kts @@ -30,10 +30,8 @@ dependencies { tasks.withType().configureEach { inputs.property("javaVendor", java.toolchain.vendor.get().toString()) + // Use --debug-jvm to remotely attach to the test task jvmArgs("-XX:SoftRefLRUPolicyMSPerMB=0", "-XX:+EnableDynamicAgentLoading", "-Xshare:off") - if ("debug" in systemProperties) { - jvmArgs("-Xdebug", "-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005") - } jvmArgs(defaultJvmArgs()) if (isCI()) { reports.junitXml.includeSystemOutLog = false diff --git a/gradle/plugins/src/main/kotlin/quality/errorprone.caffeine.gradle.kts b/gradle/plugins/src/main/kotlin/quality/errorprone.caffeine.gradle.kts index 7245ed8ec4..c1e6a9da2a 100644 --- a/gradle/plugins/src/main/kotlin/quality/errorprone.caffeine.gradle.kts +++ b/gradle/plugins/src/main/kotlin/quality/errorprone.caffeine.gradle.kts @@ -81,6 +81,7 @@ fun errorChecks() = listOf( fun disabledChecks() = listOf( "AvoidObjectArrays", "AndroidJdkLibsChecker", + "ConstantNaming", "IsInstanceLambdaUsage", "Java7ApiChecker", "Java8ApiChecker", diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 8b6a1cac83..e7da39c493 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,4 +1,4 @@ -distributionUrl=https\://services.gradle.org/distributions/gradle-8.11-rc-1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.11-rc-2-bin.zip distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME diff --git a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/parser/AbstractTraceReader.java b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/parser/AbstractTraceReader.java index 90a8ce37a5..24fb97216c 100644 --- a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/parser/AbstractTraceReader.java +++ b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/parser/AbstractTraceReader.java @@ -24,7 +24,7 @@ import java.io.SequenceInputStream; import java.io.UncheckedIOException; import java.nio.file.Files; -import java.nio.file.Paths; +import java.nio.file.Path; import java.util.Iterator; import java.util.List; import java.util.function.UnaryOperator; @@ -138,7 +138,7 @@ protected BufferedInputStream readInput(InputStream input) { /** Returns the input stream for the raw file. */ private InputStream openFile() throws IOException { - var file = Paths.get(filePath); + var file = Path.of(filePath); if (Files.exists(file)) { return Files.newInputStream(file); } diff --git a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/Registry.java b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/Registry.java index 04777407e7..0287e6f97c 100644 --- a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/Registry.java +++ b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/Registry.java @@ -21,6 +21,7 @@ import static java.util.Locale.US; import static org.apache.commons.lang3.StringUtils.isNotBlank; +import java.util.Arrays; import java.util.HashMap; import java.util.Map; import java.util.Set; @@ -77,6 +78,7 @@ import com.github.benmanes.caffeine.cache.simulator.policy.two_queue.TwoQueuePolicy; import com.google.auto.value.AutoValue; import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Sets; import com.typesafe.config.Config; /** @@ -242,7 +244,7 @@ Set characteristics() { var policySpec = policyClass().getAnnotation(PolicySpec.class); return (policySpec == null) ? ImmutableSet.of() - : ImmutableSet.copyOf(policySpec.characteristics()); + : Sets.immutableEnumSet(Arrays.asList(policySpec.characteristics())); } static Factory of(Class policyClass, Function> creator) { diff --git a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sampled/SampledPolicy.java b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sampled/SampledPolicy.java index f3018d1ab3..ccc2bf4bfe 100644 --- a/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sampled/SampledPolicy.java +++ b/simulator/src/main/java/com/github/benmanes/caffeine/cache/simulator/policy/sampled/SampledPolicy.java @@ -201,22 +201,21 @@ public enum EvictionPolicy { /** Evicts entries based on insertion order. */ FIFO { @Override Node select(List sample, Random random, long tick) { - return sample.stream().min(Comparator.comparingLong( - node -> node.insertionTime)).orElseThrow(); + return Collections.min(sample, Comparator.comparingLong(node -> node.insertionTime)); } }, /** Evicts entries based on how recently they are used, with the least recent evicted first. */ LRU { @Override Node select(List sample, Random random, long tick) { - return sample.stream().min(Comparator.comparingLong(node -> node.accessTime)).orElseThrow(); + return Collections.min(sample, Comparator.comparingLong(node -> node.accessTime)); } }, /** Evicts entries based on how recently they are used, with the least recent evicted first. */ MRU { @Override Node select(List sample, Random random, long tick) { - return sample.stream().max(Comparator.comparingLong(node -> node.accessTime)).orElseThrow(); + return Collections.max(sample, Comparator.comparingLong(node -> node.accessTime)); } }, @@ -225,7 +224,7 @@ public enum EvictionPolicy { */ LFU { @Override Node select(List sample, Random random, long tick) { - return sample.stream().min(Comparator.comparingInt(node -> node.frequency)).orElseThrow(); + return Collections.min(sample, Comparator.comparingInt(node -> node.frequency)); } }, @@ -234,7 +233,7 @@ public enum EvictionPolicy { */ MFU { @Override Node select(List sample, Random random, long tick) { - return sample.stream().max(Comparator.comparingInt(node -> node.frequency)).orElseThrow(); + return Collections.max(sample, Comparator.comparingInt(node -> node.frequency)); } }, @@ -249,8 +248,7 @@ public enum EvictionPolicy { /** Evicts entries based on how frequently they are used divided by their age. */ HYPERBOLIC { @Override Node select(List sample, Random random, long tick) { - return sample.stream().min(Comparator.comparingDouble( - node -> hyperbolic(node, tick))).orElseThrow(); + return Collections.min(sample, Comparator.comparingDouble(node -> hyperbolic(node, tick))); } double hyperbolic(Node node, long tick) { return node.frequency / (double) (tick - node.insertionTime);