One concern here (which applies before this change as well) is that the semantics of module key factories and resource reader factories is reversed. For module key factories, the first factory that answers for a URI scheme "wins", while for resource reader factories, the last reader factory that answers for a URI scheme "wins". This PR preserves that behavior, but it may be worth reconsidering this design at this time.
This behavior can be observed in practice in ResourceReadersEvaluatorTest.`module path` where ResourceReaders.modulePath is added after the pre-configured ResourceReaders.classPath and takes precedence.
This is a fairly large breaking API change, but in practice most clients will only need to replace a few lines in their calls to EvaluatorBuilder, eg.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.
## 📋 Pull Request Information
**Original PR:** https://github.com/apple/pkl/pull/647
**Author:** [@HT154](https://github.com/HT154)
**Created:** 9/15/2024
**Status:** ❌ Closed
**Base:** `main` ← **Head:** `resource-reader-factory`
---
### 📝 Commits (1)
- [`bbb67e2`](https://github.com/apple/pkl/commit/bbb67e2a5cda8bbb82ca00c579f5140f69c623dc) Add ResourceReaderFactory abstraction
### 📊 Changes
**20 files changed** (+435 additions, -124 deletions)
<details>
<summary>View changed files</summary>
📝 `docs/src/test/kotlin/DocSnippetTests.kt` (+3 -2)
📝 `pkl-cli/src/main/kotlin/org/pkl/cli/CliRepl.kt` (+9 -9)
📝 `pkl-commons-cli/src/main/kotlin/org/pkl/commons/cli/CliCommand.kt` (+14 -12)
📝 `pkl-core/src/main/java/org/pkl/core/EvaluatorBuilder.java` (+22 -21)
📝 `pkl-core/src/main/java/org/pkl/core/EvaluatorImpl.java` (+3 -3)
📝 `pkl-core/src/main/java/org/pkl/core/project/Project.java` (+5 -5)
📝 `pkl-core/src/main/java/org/pkl/core/repl/ReplServer.java` (+3 -3)
➕ `pkl-core/src/main/java/org/pkl/core/resource/ResourceReaderFactories.java` (+227 -0)
➕ `pkl-core/src/main/java/org/pkl/core/resource/ResourceReaderFactory.java` (+38 -0)
📝 `pkl-core/src/main/java/org/pkl/core/resource/ResourceReaders.java` (+0 -21)
📝 `pkl-core/src/main/java/org/pkl/core/runtime/ResourceManager.java` (+18 -7)
📝 `pkl-core/src/main/java/org/pkl/core/service/ExecutorSpiImpl.java` (+9 -9)
📝 `pkl-core/src/main/java/org/pkl/core/settings/PklSettings.java` (+2 -2)
📝 `pkl-core/src/test/kotlin/org/pkl/core/ReplServerTest.kt` (+5 -2)
📝 `pkl-core/src/test/kotlin/org/pkl/core/resource/ResourceReadersEvaluatorTest.kt` (+3 -2)
📝 `pkl-core/src/test/kotlin/org/pkl/core/resource/ResourceReadersTest.kt` (+7 -4)
📝 `pkl-server/src/main/kotlin/org/pkl/server/BinaryEvaluator.kt` (+3 -3)
➕ `pkl-server/src/main/kotlin/org/pkl/server/ClientResourceReaderFactory.kt` (+39 -0)
📝 `pkl-server/src/main/kotlin/org/pkl/server/Server.kt` (+20 -17)
📝 `pkl-server/src/test/kotlin/org/pkl/server/BinaryEvaluatorTest.kt` (+5 -2)
</details>
### 📄 Description
This is preparatory work for [SPICE-0009](https://github.com/apple/pkl-evolution/pull/10). It is being contributed in a separate pull request to ease review.
This is required to allow deferred launch of external reader processes without requiring up-front configuration of scheme->process mappings. More details on why this is required here: https://github.com/apple/pkl-evolution/pull/10#discussion_r1724145677
One concern here (which applies before this change as well) is that the semantics of module key factories and resource reader factories is reversed. For module key factories, the first factory that answers for a URI scheme "wins", while for resource reader factories, the _last_ reader factory that answers for a URI scheme "wins". This PR preserves that behavior, but it may be worth reconsidering this design at this time.
This behavior can be observed in practice in <code>ResourceReadersEvaluatorTest.\`module path\`</code> where `ResourceReaders.modulePath` is added after the pre-configured `ResourceReaders.classPath` and takes precedence.
This is a fairly large breaking API change, but in practice most clients will only need to replace a few lines in their calls to `EvaluatorBuilder`, eg.
```java
.addResourceReader(ResourceReaders.environmentVariable())
// becomes
.addResourceReaderFactory(ResourceReaderFactories.environmentVariable())
```
---
<sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
📋 Pull Request Information
Original PR: https://github.com/apple/pkl/pull/647
Author: @HT154
Created: 9/15/2024
Status: ❌ Closed
Base:
main← Head:resource-reader-factory📝 Commits (1)
bbb67e2Add ResourceReaderFactory abstraction📊 Changes
20 files changed (+435 additions, -124 deletions)
View changed files
📝
docs/src/test/kotlin/DocSnippetTests.kt(+3 -2)📝
pkl-cli/src/main/kotlin/org/pkl/cli/CliRepl.kt(+9 -9)📝
pkl-commons-cli/src/main/kotlin/org/pkl/commons/cli/CliCommand.kt(+14 -12)📝
pkl-core/src/main/java/org/pkl/core/EvaluatorBuilder.java(+22 -21)📝
pkl-core/src/main/java/org/pkl/core/EvaluatorImpl.java(+3 -3)📝
pkl-core/src/main/java/org/pkl/core/project/Project.java(+5 -5)📝
pkl-core/src/main/java/org/pkl/core/repl/ReplServer.java(+3 -3)➕
pkl-core/src/main/java/org/pkl/core/resource/ResourceReaderFactories.java(+227 -0)➕
pkl-core/src/main/java/org/pkl/core/resource/ResourceReaderFactory.java(+38 -0)📝
pkl-core/src/main/java/org/pkl/core/resource/ResourceReaders.java(+0 -21)📝
pkl-core/src/main/java/org/pkl/core/runtime/ResourceManager.java(+18 -7)📝
pkl-core/src/main/java/org/pkl/core/service/ExecutorSpiImpl.java(+9 -9)📝
pkl-core/src/main/java/org/pkl/core/settings/PklSettings.java(+2 -2)📝
pkl-core/src/test/kotlin/org/pkl/core/ReplServerTest.kt(+5 -2)📝
pkl-core/src/test/kotlin/org/pkl/core/resource/ResourceReadersEvaluatorTest.kt(+3 -2)📝
pkl-core/src/test/kotlin/org/pkl/core/resource/ResourceReadersTest.kt(+7 -4)📝
pkl-server/src/main/kotlin/org/pkl/server/BinaryEvaluator.kt(+3 -3)➕
pkl-server/src/main/kotlin/org/pkl/server/ClientResourceReaderFactory.kt(+39 -0)📝
pkl-server/src/main/kotlin/org/pkl/server/Server.kt(+20 -17)📝
pkl-server/src/test/kotlin/org/pkl/server/BinaryEvaluatorTest.kt(+5 -2)📄 Description
This is preparatory work for SPICE-0009. It is being contributed in a separate pull request to ease review.
This is required to allow deferred launch of external reader processes without requiring up-front configuration of scheme->process mappings. More details on why this is required here: https://github.com/apple/pkl-evolution/pull/10#discussion_r1724145677
One concern here (which applies before this change as well) is that the semantics of module key factories and resource reader factories is reversed. For module key factories, the first factory that answers for a URI scheme "wins", while for resource reader factories, the last reader factory that answers for a URI scheme "wins". This PR preserves that behavior, but it may be worth reconsidering this design at this time.
This behavior can be observed in practice in
ResourceReadersEvaluatorTest.`module path`whereResourceReaders.modulePathis added after the pre-configuredResourceReaders.classPathand takes precedence.This is a fairly large breaking API change, but in practice most clients will only need to replace a few lines in their calls to
EvaluatorBuilder, eg.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.