pkl-executor: fix loading projects and fix incorrectly thrown PklException

* Load `PklProject` using the same security settings and env vars passed provided via ExecutorSPIOptions
* Handle thrown `PklException` from loading `PklProject` and throw `ExecutorSPIException`
* Handle thrown `PklException` of older Pkl distributions, converting them into `ExecutorSpiException`
This commit is contained in:
Josh B
2024-10-29 23:29:19 -07:00
committed by GitHub
parent acd2222534
commit dd16f7469e
3 changed files with 82 additions and 7 deletions

View File

@@ -116,13 +116,22 @@ public final class ExecutorSpiImpl implements ExecutorSpi {
.setTimeout(options.getTimeout())
.setOutputFormat(options.getOutputFormat())
.setModuleCacheDir(options.getModuleCacheDir());
if (options.getProjectDir() != null) {
var project = Project.loadFromPath(options.getProjectDir().resolve(PKL_PROJECT_FILENAME));
builder.setProjectDependencies(project.getDependencies());
}
try (var evaluator = builder.build()) {
return evaluator.evaluateOutputText(ModuleSource.path(modulePath));
try {
if (options.getProjectDir() != null) {
var project =
Project.loadFromPath(
options.getProjectDir().resolve(PKL_PROJECT_FILENAME),
securityManager,
null,
transformer,
options.getEnvironmentVariables());
builder.setProjectDependencies(project.getDependencies());
}
try (var evaluator = builder.build()) {
return evaluator.evaluateOutputText(ModuleSource.path(modulePath));
}
} catch (PklException e) {
throw new ExecutorSpiException(e.getMessage(), e.getCause());
} finally {