Add ResourceReaders#fromServiceProviders to preconfigured evaluator (#1094)

The preconfigured evaluator currently adds module key factories from
service providers, but not resource readers.

This means that users of pkl-spring, for example, cannot add custom
resource readers.
This is also inconsistent (in the preconfigured evaluator, `import` can
 use custom schemes, but not `read`).
This commit is contained in:
Daniel Chao
2025-06-06 17:26:38 -07:00
committed by GitHub
parent 568c6ccbc2
commit 0b0f3b131d
2 changed files with 11 additions and 2 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
* Copyright © 2024-2025 Apple Inc. and the Pkl project authors. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -91,6 +91,7 @@ public final class EvaluatorBuilder {
* <li>{@link ResourceReaders#https}
* <li>{@link ResourceReaders#pkg}
* <li>{@link ResourceReaders#projectpackage}
* <li>{@link ResourceReaders#fromServiceProviders}
* <li>{@link System#getProperties}
* </ul>
*/
@@ -108,6 +109,7 @@ public final class EvaluatorBuilder {
.addResourceReader(ResourceReaders.https())
.addResourceReader(ResourceReaders.pkg())
.addResourceReader(ResourceReaders.projectpackage())
.addResourceReaders(ResourceReaders.fromServiceProviders())
.addModuleKeyFactory(ModuleKeyFactories.standardLibrary);
if (!TruffleOptions.AOT) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
* Copyright © 2024-2025 Apple Inc. and the Pkl project authors. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,6 +21,7 @@ import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.assertThrows
import org.pkl.core.project.Project
import org.pkl.core.resource.TestResourceReader
class EvaluatorBuilderTest {
@Test
@@ -35,6 +36,12 @@ class EvaluatorBuilderTest {
assertThat(builder.externalProperties).isEqualTo(System.getProperties())
}
@Test
fun `preconfigured builder adds resource readers from service providers`() {
val builder = EvaluatorBuilder.preconfigured()
assertThat(builder.resourceReaders).hasAtLeastOneElementOfType(TestResourceReader::class.java)
}
@Test
fun `unconfigured builder does not set process env vars`() {
val builder = EvaluatorBuilder.unconfigured()