Skip to content

Commit c07e687

Browse files
authored
Server code on Java 21, client code on Java 11 (#106)
According to the discussion #100, this change enforces Java release 21 for server code and 11 for client consumable code. Using Java 11 requires some changes to `:polaris-core`. One new BSD-3-Clause licensed test dependency `org.threeten:threeten-extra` was added to provide a mutable clock to replace `java.time.InstantSource`.
1 parent 7ce0945 commit c07e687

20 files changed

+272
-211
lines changed

Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
# Base Image
1717
# Use a non-docker-io registry, because pulling images from docker.io is
1818
# subject to aggressive request rate limiting and bandwidth shaping.
19-
FROM registry.access.redhat.com/ubi9/openjdk-21-runtime as build
19+
FROM registry.access.redhat.com/ubi9/openjdk-21:1.20-2.1721752936 as build
2020

2121
# Copy the REST catalog into the container
2222
COPY --chown=default:root . /app
@@ -28,7 +28,7 @@ RUN rm -rf build
2828
# Build the rest catalog
2929
RUN ./gradlew --no-daemon --info clean shadowJar
3030

31-
FROM registry.access.redhat.com/ubi9/openjdk-21-runtime
31+
FROM registry.access.redhat.com/ubi9/openjdk-21-runtime:1.20-2.1721752928
3232
WORKDIR /app
3333
COPY --from=build /app/polaris-service/build/libs/polaris-service-1.0.0-all.jar /app
3434
COPY --from=build /app/polaris-server.yml /app
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* Copyright (c) 2024 Snowflake Computing Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import org.gradle.api.tasks.compile.JavaCompile
18+
19+
plugins { id("polaris-java") }
20+
21+
tasks.withType(JavaCompile::class.java).configureEach { options.release = 11 }
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/*
2+
* Copyright (c) 2024 Snowflake Computing Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import net.ltgt.gradle.errorprone.errorprone
18+
import org.gradle.api.tasks.compile.JavaCompile
19+
import org.gradle.api.tasks.testing.Test
20+
import org.gradle.kotlin.dsl.named
21+
22+
plugins {
23+
id("jacoco")
24+
id("java")
25+
id("com.diffplug.spotless")
26+
id("jacoco-report-aggregation")
27+
id("net.ltgt.errorprone")
28+
}
29+
30+
tasks.withType(JavaCompile::class.java).configureEach {
31+
options.compilerArgs.addAll(listOf("-Xlint:unchecked", "-Xlint:deprecation"))
32+
options.errorprone.disableAllWarnings = true
33+
options.errorprone.disableWarningsInGeneratedCode = true
34+
options.errorprone.error("StringCaseLocaleUsage")
35+
}
36+
37+
tasks.register("format").configure { dependsOn("spotlessApply") }
38+
39+
tasks.named<Test>("test").configure {
40+
useJUnitPlatform()
41+
jvmArgs("-Duser.language=en")
42+
}
43+
44+
spotless {
45+
val disallowWildcardImports = { text: String ->
46+
val regex = "~/import .*\\.\\*;/".toRegex()
47+
if (regex.matches(text)) {
48+
throw GradleException("Wildcard imports disallowed - ${regex.findAll(text)}")
49+
}
50+
text
51+
}
52+
java {
53+
target("src/main/java/**/*.java", "src/testFixtures/java/**/*.java", "src/test/java/**/*.java")
54+
googleJavaFormat()
55+
licenseHeaderFile(rootProject.file("codestyle/copyright-header-java.txt"))
56+
endWithNewline()
57+
custom("disallowWildcardImports", disallowWildcardImports)
58+
}
59+
kotlinGradle {
60+
ktfmt().googleStyle()
61+
licenseHeaderFile(rootProject.file("codestyle/copyright-header-java.txt"), "$")
62+
target("*.gradle.kts")
63+
}
64+
format("xml") {
65+
target("src/**/*.xml", "src/**/*.xsd")
66+
targetExclude("codestyle/copyright-header.xml")
67+
eclipseWtp(com.diffplug.spotless.extra.wtp.EclipseWtpFormatterStep.XML)
68+
.configFile(rootProject.file("codestyle/org.eclipse.wst.xml.core.prefs"))
69+
// getting the license-header delimiter right is a bit tricky.
70+
// licenseHeaderFile(rootProject.file("codestyle/copyright-header.xml"), '<^[!?].*$')
71+
}
72+
}
73+
74+
dependencies { errorprone(versionCatalogs.named("libs").findLibrary("errorprone").get()) }

build-logic/src/main/kotlin/polaris-server.gradle.kts

Lines changed: 2 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -14,64 +14,8 @@
1414
* limitations under the License.
1515
*/
1616

17-
import net.ltgt.gradle.errorprone.errorprone
1817
import org.gradle.api.tasks.compile.JavaCompile
19-
import org.gradle.api.tasks.testing.Test
20-
import org.gradle.kotlin.dsl.named
2118

22-
plugins {
23-
id("jacoco")
24-
id("java")
25-
id("com.diffplug.spotless")
26-
id("jacoco-report-aggregation")
27-
id("net.ltgt.errorprone")
28-
}
19+
plugins { id("polaris-java") }
2920

30-
tasks.withType(JavaCompile::class.java).configureEach {
31-
options.compilerArgs.addAll(listOf("-Xlint:unchecked", "-Xlint:deprecation"))
32-
options.errorprone.disableAllWarnings = true
33-
options.errorprone.disableWarningsInGeneratedCode = true
34-
options.errorprone.error("StringCaseLocaleUsage")
35-
36-
// TODO Disabled until the code is only Java 11/17/21, see #76
37-
// options.release = 17
38-
}
39-
40-
tasks.register("format").configure { dependsOn("spotlessApply") }
41-
42-
tasks.named<Test>("test").configure {
43-
useJUnitPlatform()
44-
jvmArgs("-Duser.language=en")
45-
}
46-
47-
spotless {
48-
val disallowWildcardImports = { text: String ->
49-
val regex = "~/import .*\\.\\*;/".toRegex()
50-
if (regex.matches(text)) {
51-
throw GradleException("Wildcard imports disallowed - ${regex.findAll(text)}")
52-
}
53-
text
54-
}
55-
java {
56-
target("src/main/java/**/*.java", "src/testFixtures/java/**/*.java", "src/test/java/**/*.java")
57-
googleJavaFormat()
58-
licenseHeaderFile(rootProject.file("codestyle/copyright-header-java.txt"))
59-
endWithNewline()
60-
custom("disallowWildcardImports", disallowWildcardImports)
61-
}
62-
kotlinGradle {
63-
ktfmt().googleStyle()
64-
licenseHeaderFile(rootProject.file("codestyle/copyright-header-java.txt"), "$")
65-
target("*.gradle.kts")
66-
}
67-
format("xml") {
68-
target("src/**/*.xml", "src/**/*.xsd")
69-
targetExclude("codestyle/copyright-header.xml")
70-
eclipseWtp(com.diffplug.spotless.extra.wtp.EclipseWtpFormatterStep.XML)
71-
.configFile(rootProject.file("codestyle/org.eclipse.wst.xml.core.prefs"))
72-
// getting the license-header delimiter right is a bit tricky.
73-
// licenseHeaderFile(rootProject.file("codestyle/copyright-header.xml"), '<^[!?].*$')
74-
}
75-
}
76-
77-
dependencies { errorprone(versionCatalogs.named("libs").findLibrary("errorprone").get()) }
21+
tasks.withType(JavaCompile::class.java).configureEach { options.release = 21 }

gradle/libs.versions.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ sqllite-jdbc = { module = "org.xerial:sqlite-jdbc", version = "3.45.1.0" }
6262
swagger-annotations = { module = "io.swagger:swagger-annotations", version.ref = "swagger" }
6363
swagger-jaxrs = { module = "io.swagger:swagger-jaxrs", version.ref = "swagger" }
6464
testcontainers-bom = { module = "org.testcontainers:testcontainers-bom", version = "1.20.0" }
65+
threeten-extra = { module = "org.threeten:threeten-extra", version = "1.8.0" }
6566

6667
[plugins]
6768
openapi-generator = { id = "org.openapi.generator", version = "7.6.0" }

polaris-core/build.gradle.kts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import org.openapitools.generator.gradle.plugin.tasks.GenerateTask
1818

1919
plugins {
2020
alias(libs.plugins.openapi.generator)
21-
id("polaris-server")
21+
id("polaris-client")
2222
id("java-library")
2323
id("java-test-fixtures")
2424
}
@@ -113,6 +113,7 @@ dependencies {
113113
testFixturesApi("com.fasterxml.jackson.core:jackson-core")
114114
testFixturesApi("com.fasterxml.jackson.core:jackson-databind")
115115
testFixturesApi(libs.commons.lang3)
116+
testFixturesApi(libs.threeten.extra)
116117
testFixturesApi(libs.jetbrains.annotations)
117118
testFixturesApi(platform(libs.jackson.bom))
118119
testRuntimeOnly("org.junit.platform:junit-platform-launcher")

polaris-core/src/main/java/io/polaris/core/persistence/PolarisResolvedPathWrapper.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import io.polaris.core.entity.PolarisEntity;
1919
import java.util.List;
20+
import java.util.stream.Collectors;
2021

2122
/**
2223
* Holds fully-resolved path of PolarisEntities representing the targetEntity with all its grants
@@ -54,7 +55,7 @@ public List<PolarisEntity> getRawFullPath() {
5455
if (resolvedPath == null) {
5556
return null;
5657
}
57-
return resolvedPath.stream().map(ResolvedPolarisEntity::getEntity).toList();
58+
return resolvedPath.stream().map(ResolvedPolarisEntity::getEntity).collect(Collectors.toList());
5859
}
5960

6061
public List<ResolvedPolarisEntity> getResolvedParentPath() {
@@ -68,7 +69,9 @@ public List<PolarisEntity> getRawParentPath() {
6869
if (resolvedPath == null) {
6970
return null;
7071
}
71-
return getResolvedParentPath().stream().map(ResolvedPolarisEntity::getEntity).toList();
72+
return getResolvedParentPath().stream()
73+
.map(ResolvedPolarisEntity::getEntity)
74+
.collect(Collectors.toList());
7275
}
7376

7477
@Override

polaris-core/src/main/java/io/polaris/core/persistence/cache/EntityCacheEntry.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import io.polaris.core.entity.PolarisBaseEntity;
2121
import io.polaris.core.entity.PolarisGrantRecord;
2222
import java.util.List;
23+
import java.util.stream.Collectors;
2324
import org.jetbrains.annotations.NotNull;
2425

2526
/** An entry in our entity cache. Note, this is fully immutable */
@@ -108,13 +109,15 @@ public long getLastAccessedNanoTimestamp() {
108109
}
109110

110111
public @NotNull List<PolarisGrantRecord> getGrantRecordsAsGrantee() {
111-
return grantRecords.stream().filter(record -> record.getGranteeId() == entity.getId()).toList();
112+
return grantRecords.stream()
113+
.filter(record -> record.getGranteeId() == entity.getId())
114+
.collect(Collectors.toList());
112115
}
113116

114117
public @NotNull List<PolarisGrantRecord> getGrantRecordsAsSecurable() {
115118
return grantRecords.stream()
116119
.filter(record -> record.getSecurableId() == entity.getId())
117-
.toList();
120+
.collect(Collectors.toList());
118121
}
119122

120123
public void updateLastAccess() {

polaris-core/src/main/java/io/polaris/core/persistence/resolver/PolarisResolutionManifest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ public PolarisResolvedPathWrapper getPassthroughResolvedPath(Object key) {
206206
"Returning null for key {} due to size mismatch from getPassthroughResolvedPath "
207207
+ "resolvedPath: {}, requestedPath.getEntityNames(): {}",
208208
key,
209-
resolvedPath.stream().map(ResolvedPolarisEntity::new).toList(),
209+
resolvedPath.stream().map(ResolvedPolarisEntity::new).collect(Collectors.toList()),
210210
requestedPath.getEntityNames());
211211
return null;
212212
}

polaris-core/src/main/java/io/polaris/core/persistence/resolver/Resolver.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ public ResolverStatus resolveAll() {
333333
"resolver_must_be_successful");
334334
this.diagnostics.check(this.resolvedPaths.size() == 1, "only_if_single");
335335

336-
return resolvedPaths.getFirst();
336+
return resolvedPaths.get(0);
337337
}
338338

339339
/**

0 commit comments

Comments
 (0)