mirror of
https://github.com/apple/pkl.git
synced 2026-04-23 16:58:37 +02:00
Support building with JDK 21 (#234)
- Update google-java-format to a version compatible with JDK 21 and run "gw spotlessApply". - Fix wrong test assumption JavaCodeGenerator writes a properties file using java.util.Properties, which doesn't guarantee order of entries. - Fix most deprecation warnings - Add CI job for JDK 21
This commit is contained in:
@@ -148,6 +148,10 @@ local gradleCheckJobs: Mapping<String, GradleCheckJob> = new {
|
|||||||
javaVersion = "17.0"
|
javaVersion = "17.0"
|
||||||
isRelease = false
|
isRelease = false
|
||||||
}
|
}
|
||||||
|
["gradle-check-jdk21"] {
|
||||||
|
javaVersion = "21.0"
|
||||||
|
isRelease = false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
jobs {
|
jobs {
|
||||||
|
|||||||
@@ -615,6 +615,24 @@ jobs:
|
|||||||
LANG: en_US.UTF-8
|
LANG: en_US.UTF-8
|
||||||
docker:
|
docker:
|
||||||
- image: cimg/openjdk:17.0
|
- image: cimg/openjdk:17.0
|
||||||
|
gradle-check-jdk21:
|
||||||
|
steps:
|
||||||
|
- checkout
|
||||||
|
- run:
|
||||||
|
command: ./gradlew --info --stacktrace check
|
||||||
|
name: gradle check
|
||||||
|
- run:
|
||||||
|
command: |-
|
||||||
|
mkdir ~/test-results/
|
||||||
|
find . -type f -regex ".*/build/test-results/.*xml" -exec cp {} ~/test-results/ \;
|
||||||
|
name: Gather test results
|
||||||
|
when: always
|
||||||
|
- store_test_results:
|
||||||
|
path: ~/test-results
|
||||||
|
environment:
|
||||||
|
LANG: en_US.UTF-8
|
||||||
|
docker:
|
||||||
|
- image: cimg/openjdk:21.0
|
||||||
bench:
|
bench:
|
||||||
steps:
|
steps:
|
||||||
- checkout
|
- checkout
|
||||||
@@ -765,6 +783,9 @@ workflows:
|
|||||||
- gradle-check-jdk17:
|
- gradle-check-jdk17:
|
||||||
requires:
|
requires:
|
||||||
- hold
|
- hold
|
||||||
|
- gradle-check-jdk21:
|
||||||
|
requires:
|
||||||
|
- hold
|
||||||
- check-patch-file:
|
- check-patch-file:
|
||||||
requires:
|
requires:
|
||||||
- hold
|
- hold
|
||||||
@@ -776,6 +797,7 @@ workflows:
|
|||||||
jobs:
|
jobs:
|
||||||
- gradle-check-jdk11
|
- gradle-check-jdk11
|
||||||
- gradle-check-jdk17
|
- gradle-check-jdk17
|
||||||
|
- gradle-check-jdk21
|
||||||
- check-patch-file
|
- check-patch-file
|
||||||
- bench
|
- bench
|
||||||
- gradle-compatibility
|
- gradle-compatibility
|
||||||
@@ -788,6 +810,7 @@ workflows:
|
|||||||
requires:
|
requires:
|
||||||
- gradle-check-jdk11
|
- gradle-check-jdk11
|
||||||
- gradle-check-jdk17
|
- gradle-check-jdk17
|
||||||
|
- gradle-check-jdk21
|
||||||
- check-patch-file
|
- check-patch-file
|
||||||
- bench
|
- bench
|
||||||
- gradle-compatibility
|
- gradle-compatibility
|
||||||
@@ -820,6 +843,12 @@ workflows:
|
|||||||
ignore: /.*/
|
ignore: /.*/
|
||||||
tags:
|
tags:
|
||||||
only: /^v?\d+\.\d+\.\d+$/
|
only: /^v?\d+\.\d+\.\d+$/
|
||||||
|
- gradle-check-jdk21:
|
||||||
|
filters:
|
||||||
|
branches:
|
||||||
|
ignore: /.*/
|
||||||
|
tags:
|
||||||
|
only: /^v?\d+\.\d+\.\d+$/
|
||||||
- check-patch-file:
|
- check-patch-file:
|
||||||
filters:
|
filters:
|
||||||
branches:
|
branches:
|
||||||
@@ -872,6 +901,7 @@ workflows:
|
|||||||
requires:
|
requires:
|
||||||
- gradle-check-jdk11
|
- gradle-check-jdk11
|
||||||
- gradle-check-jdk17
|
- gradle-check-jdk17
|
||||||
|
- gradle-check-jdk21
|
||||||
- check-patch-file
|
- check-patch-file
|
||||||
- bench
|
- bench
|
||||||
- gradle-compatibility
|
- gradle-compatibility
|
||||||
@@ -917,6 +947,9 @@ workflows:
|
|||||||
- gradle-check-jdk17:
|
- gradle-check-jdk17:
|
||||||
requires:
|
requires:
|
||||||
- hold
|
- hold
|
||||||
|
- gradle-check-jdk21:
|
||||||
|
requires:
|
||||||
|
- hold
|
||||||
- check-patch-file:
|
- check-patch-file:
|
||||||
requires:
|
requires:
|
||||||
- hold
|
- hold
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ extends "GradleJob.pkl"
|
|||||||
|
|
||||||
import "package://pkg.pkl-lang.org/pkl-pantry/com.circleci.v2@1.1.0#/Config.pkl"
|
import "package://pkg.pkl-lang.org/pkl-pantry/com.circleci.v2@1.1.0#/Config.pkl"
|
||||||
|
|
||||||
javaVersion: "11.0"|"17.0"
|
javaVersion: "11.0"|"17.0"|"21.0"
|
||||||
|
|
||||||
steps {
|
steps {
|
||||||
new Config.RunStep {
|
new Config.RunStep {
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import java.io.File
|
|||||||
import org.gradle.api.Project
|
import org.gradle.api.Project
|
||||||
import org.gradle.api.artifacts.VersionCatalog
|
import org.gradle.api.artifacts.VersionCatalog
|
||||||
import org.gradle.api.artifacts.VersionCatalogsExtension
|
import org.gradle.api.artifacts.VersionCatalogsExtension
|
||||||
import org.gradle.api.artifacts.VersionConstraint
|
|
||||||
import org.gradle.kotlin.dsl.getByType
|
import org.gradle.kotlin.dsl.getByType
|
||||||
|
|
||||||
// `buildInfo` in main build scripts
|
// `buildInfo` in main build scripts
|
||||||
@@ -109,7 +108,7 @@ open class BuildInfo(project: Project) {
|
|||||||
// only run command once per build invocation
|
// only run command once per build invocation
|
||||||
if (project === project.rootProject) {
|
if (project === project.rootProject) {
|
||||||
Runtime.getRuntime()
|
Runtime.getRuntime()
|
||||||
.exec("git rev-parse --short HEAD", arrayOf(), project.rootDir)
|
.exec(arrayOf("git", "rev-parse", "--short", "HEAD"), arrayOf(), project.rootDir)
|
||||||
.inputStream.reader().readText().trim()
|
.inputStream.reader().readText().trim()
|
||||||
} else {
|
} else {
|
||||||
project.rootProject.extensions.getByType(BuildInfo::class.java).commitId
|
project.rootProject.extensions.getByType(BuildInfo::class.java).commitId
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import java.net.URL
|
|
||||||
import org.gradle.util.GradleVersion
|
import org.gradle.util.GradleVersion
|
||||||
import groovy.json.JsonSlurper
|
import groovy.json.JsonSlurper
|
||||||
|
import java.net.URI
|
||||||
|
|
||||||
@Suppress("unused")
|
@Suppress("unused")
|
||||||
class GradleVersionInfo(json: Map<String, Any>) {
|
class GradleVersionInfo(json: Map<String, Any>) {
|
||||||
@@ -50,18 +50,18 @@ class GradleVersionInfo(json: Map<String, Any>) {
|
|||||||
|
|
||||||
private fun fetchSingle(url: String): GradleVersionInfo {
|
private fun fetchSingle(url: String): GradleVersionInfo {
|
||||||
@Suppress("UNCHECKED_CAST")
|
@Suppress("UNCHECKED_CAST")
|
||||||
return GradleVersionInfo(JsonSlurper().parse(URL(url)) as Map<String, Any>)
|
return GradleVersionInfo(JsonSlurper().parse(URI(url).toURL()) as Map<String, Any>)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun fetchSingleOrNull(url: String): GradleVersionInfo? {
|
private fun fetchSingleOrNull(url: String): GradleVersionInfo? {
|
||||||
@Suppress("UNCHECKED_CAST")
|
@Suppress("UNCHECKED_CAST")
|
||||||
val json = JsonSlurper().parse(URL(url)) as Map<String, Any>
|
val json = JsonSlurper().parse(URI(url).toURL()) as Map<String, Any>
|
||||||
return if (json.isEmpty()) null else GradleVersionInfo(json)
|
return if (json.isEmpty()) null else GradleVersionInfo(json)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun fetchMultiple(url: String): List<GradleVersionInfo> {
|
private fun fetchMultiple(url: String): List<GradleVersionInfo> {
|
||||||
@Suppress("UNCHECKED_CAST")
|
@Suppress("UNCHECKED_CAST")
|
||||||
return (JsonSlurper().parse(URL(url)) as List<Map<String, Any>>)
|
return (JsonSlurper().parse(URI(url).toURL()) as List<Map<String, Any>>)
|
||||||
.map { GradleVersionInfo(it) }
|
.map { GradleVersionInfo(it) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ clikt = "3.5.1"
|
|||||||
commonMark = "0.+"
|
commonMark = "0.+"
|
||||||
downloadTaskPlugin = "4.1.2"
|
downloadTaskPlugin = "4.1.2"
|
||||||
geantyref = "1.+"
|
geantyref = "1.+"
|
||||||
googleJavaFormat = "1.15.0"
|
googleJavaFormat = "1.21.0"
|
||||||
# must not use `+` because used in download URL
|
# must not use `+` because used in download URL
|
||||||
graalVm = "22.3.3"
|
graalVm = "22.3.3"
|
||||||
# intentionally empty; replaced by patch file when building pkl-cli macos/aarch64
|
# intentionally empty; replaced by patch file when building pkl-cli macos/aarch64
|
||||||
|
|||||||
@@ -108,7 +108,7 @@ index f242210..e2e8ee8 100644
|
|||||||
+++ b/gradle/libs.versions.toml
|
+++ b/gradle/libs.versions.toml
|
||||||
@@ -8,11 +8,11 @@ downloadTaskPlugin = "4.1.2"
|
@@ -8,11 +8,11 @@ downloadTaskPlugin = "4.1.2"
|
||||||
geantyref = "1.+"
|
geantyref = "1.+"
|
||||||
googleJavaFormat = "1.15.0"
|
googleJavaFormat = "1.21.0"
|
||||||
# must not use `+` because used in download URL
|
# must not use `+` because used in download URL
|
||||||
-graalVm = "22.3.3"
|
-graalVm = "22.3.3"
|
||||||
-# intentionally empty; replaced by patch file when building pkl-cli macos/aarch64
|
-# intentionally empty; replaced by patch file when building pkl-cli macos/aarch64
|
||||||
|
|||||||
@@ -97,22 +97,21 @@ class CliJavaCodeGeneratorTest {
|
|||||||
|
|
||||||
val module1PropertiesFile = resourcesDir.resolve("org.mod1.properties")
|
val module1PropertiesFile = resourcesDir.resolve("org.mod1.properties")
|
||||||
|
|
||||||
|
val module1PropertiesString = module1PropertiesFile.readString()
|
||||||
|
// use two assertions because java.util.Properties doesn't guarantee order
|
||||||
assertContains(
|
assertContains(
|
||||||
"""
|
"""org.pkl.config.java.mapper.org.mod1\#Person=org.Mod1${dollar}Person""",
|
||||||
org.pkl.config.java.mapper.org.mod1\#Person=org.Mod1${dollar}Person
|
module1PropertiesString
|
||||||
org.pkl.config.java.mapper.org.mod1\#ModuleClass=org.Mod1
|
)
|
||||||
"""
|
assertContains(
|
||||||
.trimIndent(),
|
"""org.pkl.config.java.mapper.org.mod1\#ModuleClass=org.Mod1""",
|
||||||
module1PropertiesFile.readString()
|
module1PropertiesString
|
||||||
)
|
)
|
||||||
|
|
||||||
val module2PropertiesFile = resourcesDir.resolve("org.mod2.properties")
|
val module2PropertiesFile = resourcesDir.resolve("org.mod2.properties")
|
||||||
|
|
||||||
assertContains(
|
assertContains(
|
||||||
"""
|
"""org.pkl.config.java.mapper.org.mod2\#ModuleClass=org.Mod2""",
|
||||||
org.pkl.config.java.mapper.org.mod2\#ModuleClass=org.Mod2
|
|
||||||
"""
|
|
||||||
.trimIndent(),
|
|
||||||
module2PropertiesFile.readString()
|
module2PropertiesFile.readString()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -304,8 +304,7 @@ public final class ResourceReaders {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
var url = IoUtils.toUrl(uri);
|
var content = IoUtils.readBytes(uri);
|
||||||
var content = IoUtils.readBytes(url);
|
|
||||||
return Optional.of(new Resource(uri, content));
|
return Optional.of(new Resource(uri, content));
|
||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
|
|||||||
@@ -111,11 +111,11 @@ public final class IoUtils {
|
|||||||
return new String(inputStream.readAllBytes(), StandardCharsets.UTF_8);
|
return new String(inputStream.readAllBytes(), StandardCharsets.UTF_8);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static byte[] readBytes(URL url) throws IOException {
|
public static byte[] readBytes(URI uri) throws IOException {
|
||||||
if (HttpUtils.isHttpUrl(url)) {
|
if (HttpUtils.isHttpUrl(uri)) {
|
||||||
throw new IllegalArgumentException("Should use HTTP client to GET " + url);
|
throw new IllegalArgumentException("Should use HTTP client to GET " + uri);
|
||||||
}
|
}
|
||||||
try (var stream = url.openStream()) {
|
try (var stream = IoUtils.toUrl(uri).openStream()) {
|
||||||
return stream.readAllBytes();
|
return stream.readAllBytes();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import org.junit.jupiter.api.assertThrows
|
|||||||
import org.pkl.commons.test.FakeHttpResponse
|
import org.pkl.commons.test.FakeHttpResponse
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
import java.net.URI
|
import java.net.URI
|
||||||
import java.net.URL
|
|
||||||
|
|
||||||
class HttpUtilsTest {
|
class HttpUtilsTest {
|
||||||
@Test
|
@Test
|
||||||
@@ -17,10 +16,10 @@ class HttpUtilsTest {
|
|||||||
assertThat(HttpUtils.isHttpUrl(URI("HtTpS://example.com"))).isTrue
|
assertThat(HttpUtils.isHttpUrl(URI("HtTpS://example.com"))).isTrue
|
||||||
assertThat(HttpUtils.isHttpUrl(URI("file://example.com"))).isFalse
|
assertThat(HttpUtils.isHttpUrl(URI("file://example.com"))).isFalse
|
||||||
|
|
||||||
assertThat(HttpUtils.isHttpUrl(URL("http://example.com"))).isTrue
|
assertThat(HttpUtils.isHttpUrl(URI("http://example.com").toURL())).isTrue
|
||||||
assertThat(HttpUtils.isHttpUrl(URL("https://example.com"))).isTrue
|
assertThat(HttpUtils.isHttpUrl(URI("https://example.com").toURL())).isTrue
|
||||||
assertThat(HttpUtils.isHttpUrl(URL("HtTpS://example.com"))).isTrue
|
assertThat(HttpUtils.isHttpUrl(URI("HtTpS://example.com").toURL())).isTrue
|
||||||
assertThat(HttpUtils.isHttpUrl(URL("file://example.com"))).isFalse
|
assertThat(HttpUtils.isHttpUrl(URI("file://example.com").toURL())).isFalse
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@@ -415,20 +415,20 @@ class IoUtilsTest {
|
|||||||
@Test
|
@Test
|
||||||
fun `readBytes(URL) does not support HTTP URLs`() {
|
fun `readBytes(URL) does not support HTTP URLs`() {
|
||||||
assertThrows<IllegalArgumentException> {
|
assertThrows<IllegalArgumentException> {
|
||||||
IoUtils.readBytes(URL("https://example.com"))
|
IoUtils.readBytes(URI("https://example.com"))
|
||||||
}
|
}
|
||||||
assertThrows<IllegalArgumentException> {
|
assertThrows<IllegalArgumentException> {
|
||||||
IoUtils.readBytes(URL("http://example.com"))
|
IoUtils.readBytes(URI("http://example.com"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `readString(URL) does not support HTTP URLs`() {
|
fun `readString(URL) does not support HTTP URLs`() {
|
||||||
assertThrows<IllegalArgumentException> {
|
assertThrows<IllegalArgumentException> {
|
||||||
IoUtils.readString(URL("https://example.com"))
|
IoUtils.readString(URI("https://example.com").toURL())
|
||||||
}
|
}
|
||||||
assertThrows<IllegalArgumentException> {
|
assertThrows<IllegalArgumentException> {
|
||||||
IoUtils.readString(URL("http://example.com"))
|
IoUtils.readString(URI("http://example.com").toURL())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,5 +20,6 @@ package org.pkl.tools;
|
|||||||
*/
|
*/
|
||||||
// TODO: figure out how to generate javadoc for a shadow jar.
|
// TODO: figure out how to generate javadoc for a shadow jar.
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public class Empty {
|
public final class Empty {
|
||||||
|
private Empty() {}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user