diff --git a/pkl-commons-cli/src/main/kotlin/org/pkl/commons/cli/CliCommand.kt b/pkl-commons-cli/src/main/kotlin/org/pkl/commons/cli/CliCommand.kt index bde2a0fa2..9d1db738c 100644 --- a/pkl-commons-cli/src/main/kotlin/org/pkl/commons/cli/CliCommand.kt +++ b/pkl-commons-cli/src/main/kotlin/org/pkl/commons/cli/CliCommand.kt @@ -21,7 +21,7 @@ import java.util.regex.Pattern import kotlin.io.path.isRegularFile import org.pkl.core.* import org.pkl.core.evaluatorSettings.PklEvaluatorSettings -import org.pkl.core.externalreader.ExternalReaderProcess +import org.pkl.core.externalreader.ReaderProcess import org.pkl.core.http.HttpClient import org.pkl.core.module.ModuleKeyFactories import org.pkl.core.module.ModuleKeyFactory @@ -191,7 +191,7 @@ abstract class CliCommand(protected val cliOptions: CliBaseOptions) { // with the same spec. This avoids spawning multiple subprocesses if the same reader implements // both reader types and/or multiple schemes. (externalModuleReaders + externalResourceReaders).values.toSet().associateWith { - ExternalReaderProcess.of(it) + ReaderProcess.of(it) } } diff --git a/pkl-core/src/main/java/org/pkl/core/EvaluatorBuilder.java b/pkl-core/src/main/java/org/pkl/core/EvaluatorBuilder.java index 8b5ad5d43..9d402c9f7 100644 --- a/pkl-core/src/main/java/org/pkl/core/EvaluatorBuilder.java +++ b/pkl-core/src/main/java/org/pkl/core/EvaluatorBuilder.java @@ -21,7 +21,7 @@ import java.util.regex.Pattern; import org.pkl.core.SecurityManagers.StandardBuilder; import org.pkl.core.evaluatorSettings.PklEvaluatorSettings.ExternalReader; -import org.pkl.core.externalreader.ExternalReaderProcess; +import org.pkl.core.externalreader.ReaderProcess; import org.pkl.core.http.HttpClient; import org.pkl.core.module.ModuleKeyFactories; import org.pkl.core.module.ModuleKeyFactory; @@ -498,21 +498,19 @@ public EvaluatorBuilder applyFromProject(Project project) { } // this isn't ideal as project and non-project ExternalReaderProcess instances can be dupes - var procs = new HashMap(); + var procs = new HashMap(); if (settings.externalModuleReaders() != null) { for (var entry : settings.externalModuleReaders().entrySet()) { addModuleKeyFactory( ModuleKeyFactories.externalProcess( - entry.getKey(), - procs.computeIfAbsent(entry.getValue(), ExternalReaderProcess::of))); + entry.getKey(), procs.computeIfAbsent(entry.getValue(), ReaderProcess::of))); } } if (settings.externalResourceReaders() != null) { for (var entry : settings.externalResourceReaders().entrySet()) { addResourceReader( ResourceReaders.externalProcess( - entry.getKey(), - procs.computeIfAbsent(entry.getValue(), ExternalReaderProcess::of))); + entry.getKey(), procs.computeIfAbsent(entry.getValue(), ReaderProcess::of))); } } return this; diff --git a/pkl-core/src/main/java/org/pkl/core/ast/builder/AstBuilder.java b/pkl-core/src/main/java/org/pkl/core/ast/builder/AstBuilder.java index 3b34d2c18..7d26a9756 100644 --- a/pkl-core/src/main/java/org/pkl/core/ast/builder/AstBuilder.java +++ b/pkl-core/src/main/java/org/pkl/core/ast/builder/AstBuilder.java @@ -55,7 +55,7 @@ import org.pkl.core.ast.lambda.ApplyVmFunction1NodeGen; import org.pkl.core.ast.member.*; import org.pkl.core.ast.type.*; -import org.pkl.core.externalreader.ExternalReaderProcessException; +import org.pkl.core.externalreader.ReaderProcessException; import org.pkl.core.module.ModuleKey; import org.pkl.core.module.ModuleKeys; import org.pkl.core.module.ResolvedModuleKey; @@ -1864,7 +1864,7 @@ private URI resolveImport(String importUri, StringConstantContext importUriCtx) .withHint(e.getHint()) .withSourceSection(createSourceSection(importUriCtx)) .build(); - } catch (ExternalReaderProcessException e) { + } catch (ReaderProcessException e) { throw exceptionBuilder() .evalError("externalReaderFailure") .withCause(e.getCause()) diff --git a/pkl-core/src/main/java/org/pkl/core/ast/expression/unary/AbstractReadNode.java b/pkl-core/src/main/java/org/pkl/core/ast/expression/unary/AbstractReadNode.java index 607e04189..d4abfeaad 100644 --- a/pkl-core/src/main/java/org/pkl/core/ast/expression/unary/AbstractReadNode.java +++ b/pkl-core/src/main/java/org/pkl/core/ast/expression/unary/AbstractReadNode.java @@ -23,7 +23,7 @@ import java.net.URI; import java.net.URISyntaxException; import org.pkl.core.SecurityManagerException; -import org.pkl.core.externalreader.ExternalReaderProcessException; +import org.pkl.core.externalreader.ReaderProcessException; import org.pkl.core.module.ModuleKey; import org.pkl.core.packages.PackageLoadError; import org.pkl.core.runtime.VmContext; @@ -76,7 +76,7 @@ private URI resolveResource(ModuleKey moduleKey, String resourceUri) { .build(); } catch (PackageLoadError | SecurityManagerException e) { throw exceptionBuilder().withCause(e).build(); - } catch (ExternalReaderProcessException e) { + } catch (ReaderProcessException e) { throw exceptionBuilder().evalError("externalReaderFailure").withCause(e).build(); } diff --git a/pkl-core/src/main/java/org/pkl/core/ast/expression/unary/ImportGlobNode.java b/pkl-core/src/main/java/org/pkl/core/ast/expression/unary/ImportGlobNode.java index 66ae35934..fcaf7dc45 100644 --- a/pkl-core/src/main/java/org/pkl/core/ast/expression/unary/ImportGlobNode.java +++ b/pkl-core/src/main/java/org/pkl/core/ast/expression/unary/ImportGlobNode.java @@ -25,7 +25,7 @@ import java.net.URI; import org.pkl.core.SecurityManagerException; import org.pkl.core.ast.member.SharedMemberNode; -import org.pkl.core.externalreader.ExternalReaderProcessException; +import org.pkl.core.externalreader.ReaderProcessException; import org.pkl.core.http.HttpClientInitException; import org.pkl.core.module.ResolvedModuleKey; import org.pkl.core.packages.PackageLoadError; @@ -105,7 +105,7 @@ public Object executeGeneric(VirtualFrame frame) { .evalError("invalidGlobPattern", globPattern) .withHint(e.getMessage()) .build(); - } catch (ExternalReaderProcessException e) { + } catch (ReaderProcessException e) { throw exceptionBuilder().evalError("externalReaderFailure").withCause(e).build(); } } diff --git a/pkl-core/src/main/java/org/pkl/core/ast/expression/unary/ReadGlobNode.java b/pkl-core/src/main/java/org/pkl/core/ast/expression/unary/ReadGlobNode.java index 9331629bc..a20483568 100644 --- a/pkl-core/src/main/java/org/pkl/core/ast/expression/unary/ReadGlobNode.java +++ b/pkl-core/src/main/java/org/pkl/core/ast/expression/unary/ReadGlobNode.java @@ -26,7 +26,7 @@ import org.graalvm.collections.EconomicMap; import org.pkl.core.SecurityManagerException; import org.pkl.core.ast.member.SharedMemberNode; -import org.pkl.core.externalreader.ExternalReaderProcessException; +import org.pkl.core.externalreader.ReaderProcessException; import org.pkl.core.http.HttpClientInitException; import org.pkl.core.module.ModuleKey; import org.pkl.core.runtime.VmContext; @@ -104,7 +104,7 @@ public Object read(String globPattern) { .evalError("invalidGlobPattern", globPattern) .withHint(e.getMessage()) .build(); - } catch (ExternalReaderProcessException e) { + } catch (ReaderProcessException e) { throw exceptionBuilder().evalError("externalReaderFailure").withCause(e).build(); } } diff --git a/pkl-core/src/main/java/org/pkl/core/externalreader/ExternalReaderMessagePackDecoder.java b/pkl-core/src/main/java/org/pkl/core/externalreader/MessagePackDecoder.java similarity index 88% rename from pkl-core/src/main/java/org/pkl/core/externalreader/ExternalReaderMessagePackDecoder.java rename to pkl-core/src/main/java/org/pkl/core/externalreader/MessagePackDecoder.java index 51bf6a122..3eaef692d 100644 --- a/pkl-core/src/main/java/org/pkl/core/externalreader/ExternalReaderMessagePackDecoder.java +++ b/pkl-core/src/main/java/org/pkl/core/externalreader/MessagePackDecoder.java @@ -21,20 +21,20 @@ import org.msgpack.core.MessagePack; import org.msgpack.core.MessageUnpacker; import org.msgpack.value.Value; -import org.pkl.core.externalreader.ExternalReaderMessages.*; +import org.pkl.core.externalreader.ReaderMessages.*; import org.pkl.core.messaging.BaseMessagePackDecoder; import org.pkl.core.messaging.DecodeException; import org.pkl.core.messaging.Message; import org.pkl.core.messaging.Message.Type; import org.pkl.core.util.Nullable; -final class ExternalReaderMessagePackDecoder extends BaseMessagePackDecoder { +final class MessagePackDecoder extends BaseMessagePackDecoder { - public ExternalReaderMessagePackDecoder(MessageUnpacker unpacker) { + public MessagePackDecoder(MessageUnpacker unpacker) { super(unpacker); } - public ExternalReaderMessagePackDecoder(InputStream inputStream) { + public MessagePackDecoder(InputStream inputStream) { this(MessagePack.newDefaultUnpacker(inputStream)); } diff --git a/pkl-core/src/main/java/org/pkl/core/externalreader/ExternalReaderMessagePackEncoder.java b/pkl-core/src/main/java/org/pkl/core/externalreader/MessagePackEncoder.java similarity index 89% rename from pkl-core/src/main/java/org/pkl/core/externalreader/ExternalReaderMessagePackEncoder.java rename to pkl-core/src/main/java/org/pkl/core/externalreader/MessagePackEncoder.java index b383b4ac6..f5d6d5be1 100644 --- a/pkl-core/src/main/java/org/pkl/core/externalreader/ExternalReaderMessagePackEncoder.java +++ b/pkl-core/src/main/java/org/pkl/core/externalreader/MessagePackEncoder.java @@ -19,19 +19,19 @@ import java.io.OutputStream; import org.msgpack.core.MessagePack; import org.msgpack.core.MessagePacker; -import org.pkl.core.externalreader.ExternalReaderMessages.*; +import org.pkl.core.externalreader.ReaderMessages.*; import org.pkl.core.messaging.BaseMessagePackEncoder; import org.pkl.core.messaging.Message; import org.pkl.core.messaging.ProtocolException; import org.pkl.core.util.Nullable; -final class ExternalReaderMessagePackEncoder extends BaseMessagePackEncoder { +final class MessagePackEncoder extends BaseMessagePackEncoder { - public ExternalReaderMessagePackEncoder(MessagePacker packer) { + public MessagePackEncoder(MessagePacker packer) { super(packer); } - public ExternalReaderMessagePackEncoder(OutputStream outputStream) { + public MessagePackEncoder(OutputStream outputStream) { this(MessagePack.newDefaultPacker(outputStream)); } diff --git a/pkl-core/src/main/java/org/pkl/core/externalreader/ExternalModuleReaderSpec.java b/pkl-core/src/main/java/org/pkl/core/externalreader/ModuleReaderSpec.java similarity index 95% rename from pkl-core/src/main/java/org/pkl/core/externalreader/ExternalModuleReaderSpec.java rename to pkl-core/src/main/java/org/pkl/core/externalreader/ModuleReaderSpec.java index fd199cdbc..0e0770fc4 100644 --- a/pkl-core/src/main/java/org/pkl/core/externalreader/ExternalModuleReaderSpec.java +++ b/pkl-core/src/main/java/org/pkl/core/externalreader/ModuleReaderSpec.java @@ -15,5 +15,5 @@ */ package org.pkl.core.externalreader; -public record ExternalModuleReaderSpec( +public record ModuleReaderSpec( String scheme, boolean hasHierarchicalUris, boolean isLocal, boolean isGlobbable) {} diff --git a/pkl-core/src/main/java/org/pkl/core/externalreader/ExternalModuleResolver.java b/pkl-core/src/main/java/org/pkl/core/externalreader/ModuleResolver.java similarity index 87% rename from pkl-core/src/main/java/org/pkl/core/externalreader/ExternalModuleResolver.java rename to pkl-core/src/main/java/org/pkl/core/externalreader/ModuleResolver.java index a962a3867..0b830ae1a 100644 --- a/pkl-core/src/main/java/org/pkl/core/externalreader/ExternalModuleResolver.java +++ b/pkl-core/src/main/java/org/pkl/core/externalreader/ModuleResolver.java @@ -23,9 +23,9 @@ import org.pkl.core.messaging.MessageTransport; import org.pkl.core.module.PathElement; -public interface ExternalModuleResolver { - static ExternalModuleResolver of(MessageTransport transport, long evaluatorId) { - return new ExternalModuleResolverImpl(transport, evaluatorId); +public interface ModuleResolver { + static ModuleResolver of(MessageTransport transport, long evaluatorId) { + return new ModuleResolverImpl(transport, evaluatorId); } String resolveModule(SecurityManager securityManager, URI uri) diff --git a/pkl-core/src/main/java/org/pkl/core/externalreader/ExternalModuleResolverImpl.java b/pkl-core/src/main/java/org/pkl/core/externalreader/ModuleResolverImpl.java similarity index 97% rename from pkl-core/src/main/java/org/pkl/core/externalreader/ExternalModuleResolverImpl.java rename to pkl-core/src/main/java/org/pkl/core/externalreader/ModuleResolverImpl.java index 4338eafc7..1a16519a5 100644 --- a/pkl-core/src/main/java/org/pkl/core/externalreader/ExternalModuleResolverImpl.java +++ b/pkl-core/src/main/java/org/pkl/core/externalreader/ModuleResolverImpl.java @@ -35,14 +35,14 @@ import org.pkl.core.messaging.ProtocolException; import org.pkl.core.module.PathElement; -final class ExternalModuleResolverImpl implements ExternalModuleResolver { +final class ModuleResolverImpl implements ModuleResolver { private final MessageTransport transport; private final long evaluatorId; private final Map> readResponses = new ConcurrentHashMap<>(); private final Map>> listResponses = new ConcurrentHashMap<>(); private final Random requestIdGenerator = new Random(); - ExternalModuleResolverImpl(MessageTransport transport, long evaluatorId) { + ModuleResolverImpl(MessageTransport transport, long evaluatorId) { this.transport = transport; this.evaluatorId = evaluatorId; } diff --git a/pkl-core/src/main/java/org/pkl/core/externalreader/ExternalReaderMessages.java b/pkl-core/src/main/java/org/pkl/core/externalreader/ReaderMessages.java similarity index 96% rename from pkl-core/src/main/java/org/pkl/core/externalreader/ExternalReaderMessages.java rename to pkl-core/src/main/java/org/pkl/core/externalreader/ReaderMessages.java index cd89f87ce..afcf97f91 100644 --- a/pkl-core/src/main/java/org/pkl/core/externalreader/ExternalReaderMessages.java +++ b/pkl-core/src/main/java/org/pkl/core/externalreader/ReaderMessages.java @@ -20,8 +20,8 @@ import org.pkl.core.messaging.Messages.ResourceReaderSpec; import org.pkl.core.util.Nullable; -final class ExternalReaderMessages { - private ExternalReaderMessages() {} +final class ReaderMessages { + private ReaderMessages() {} record InitializeModuleReaderRequest(long requestId, String scheme) implements Server.Request { public Type type() { diff --git a/pkl-core/src/main/java/org/pkl/core/externalreader/ExternalReaderProcess.java b/pkl-core/src/main/java/org/pkl/core/externalreader/ReaderProcess.java similarity index 73% rename from pkl-core/src/main/java/org/pkl/core/externalreader/ExternalReaderProcess.java rename to pkl-core/src/main/java/org/pkl/core/externalreader/ReaderProcess.java index 7f7caca70..200faf8ff 100644 --- a/pkl-core/src/main/java/org/pkl/core/externalreader/ExternalReaderProcess.java +++ b/pkl-core/src/main/java/org/pkl/core/externalreader/ReaderProcess.java @@ -20,13 +20,13 @@ import org.pkl.core.util.Nullable; /** An external process that reads Pkl modules and resources. */ -public interface ExternalReaderProcess extends AutoCloseable { +public interface ReaderProcess extends AutoCloseable { /** - * Creates a new {@link ExternalReaderProcess} from the given spec. No resources are allocated at - * this time. + * Creates a new {@link ReaderProcess} from the given spec. No resources are allocated at this + * time. */ - static ExternalReaderProcess of(ExternalReader spec) { - return new ExternalReaderProcessImpl(spec); + static ReaderProcess of(ExternalReader spec) { + return new ReaderProcessImpl(spec); } /** @@ -36,7 +36,7 @@ static ExternalReaderProcess of(ExternalReader spec) { * * @throws IllegalStateException if this process has already been closed */ - ExternalModuleResolver getModuleResolver(long evaluatorId) throws ExternalReaderProcessException; + ModuleResolver getModuleResolver(long evaluatorId) throws ReaderProcessException; /** * Returns a resolver for resources provided via this reader. @@ -45,8 +45,7 @@ static ExternalReaderProcess of(ExternalReader spec) { * * @throws IllegalStateException if this process has already been closed */ - ExternalResourceResolver getResourceResolver(long evaluatorId) - throws ExternalReaderProcessException; + ResourceResolver getResourceResolver(long evaluatorId) throws ReaderProcessException; /** * Returns the spec, if available, of this process's module reader with the given scheme. @@ -55,7 +54,7 @@ ExternalResourceResolver getResourceResolver(long evaluatorId) * @throws IOException if an I/O error occurs */ @Nullable - ExternalModuleReaderSpec getModuleReaderSpec(String scheme) throws IOException; + ModuleReaderSpec getModuleReaderSpec(String scheme) throws IOException; /** * Returns the spec, if available, of this process's resource reader with the given scheme. @@ -64,7 +63,7 @@ ExternalResourceResolver getResourceResolver(long evaluatorId) * @throws IOException if an I/O error occurs */ @Nullable - ExternalResourceReaderSpec getResourceReaderSpec(String scheme) throws IOException; + ResourceReaderSpec getResourceReaderSpec(String scheme) throws IOException; /** * Closes this process, releasing any associated resources. @@ -72,8 +71,8 @@ ExternalResourceResolver getResourceResolver(long evaluatorId) *

This method can be safely called multiple times. Subsequent calls have no effect. * * @implNote Implementers should request a graceful termination by sending a {@link - * ExternalReaderMessages.CloseExternalProcess CloseExternalProcess} message to the process - * before terminating it forcibly. + * ReaderMessages.CloseExternalProcess CloseExternalProcess} message to the process before + * terminating it forcibly. */ @Override void close(); diff --git a/pkl-core/src/main/java/org/pkl/core/externalreader/ExternalReaderProcessException.java b/pkl-core/src/main/java/org/pkl/core/externalreader/ReaderProcessException.java similarity index 79% rename from pkl-core/src/main/java/org/pkl/core/externalreader/ExternalReaderProcessException.java rename to pkl-core/src/main/java/org/pkl/core/externalreader/ReaderProcessException.java index 6dbf4bf5d..9b830e413 100644 --- a/pkl-core/src/main/java/org/pkl/core/externalreader/ExternalReaderProcessException.java +++ b/pkl-core/src/main/java/org/pkl/core/externalreader/ReaderProcessException.java @@ -15,12 +15,12 @@ */ package org.pkl.core.externalreader; -public final class ExternalReaderProcessException extends Exception { - public ExternalReaderProcessException(String msg) { +public final class ReaderProcessException extends Exception { + public ReaderProcessException(String msg) { super(msg); } - public ExternalReaderProcessException(Throwable cause) { + public ReaderProcessException(Throwable cause) { super(cause); } } diff --git a/pkl-core/src/main/java/org/pkl/core/externalreader/ExternalReaderProcessImpl.java b/pkl-core/src/main/java/org/pkl/core/externalreader/ReaderProcessImpl.java similarity index 79% rename from pkl-core/src/main/java/org/pkl/core/externalreader/ExternalReaderProcessImpl.java rename to pkl-core/src/main/java/org/pkl/core/externalreader/ReaderProcessImpl.java index ab206dbdd..5d8b69f18 100644 --- a/pkl-core/src/main/java/org/pkl/core/externalreader/ExternalReaderProcessImpl.java +++ b/pkl-core/src/main/java/org/pkl/core/externalreader/ReaderProcessImpl.java @@ -28,7 +28,7 @@ import java.util.concurrent.TimeUnit; import javax.annotation.concurrent.GuardedBy; import org.pkl.core.evaluatorSettings.PklEvaluatorSettings.ExternalReader; -import org.pkl.core.externalreader.ExternalReaderMessages.*; +import org.pkl.core.externalreader.ReaderMessages.*; import org.pkl.core.messaging.MessageTransport; import org.pkl.core.messaging.MessageTransports; import org.pkl.core.messaging.ProtocolException; @@ -36,15 +36,15 @@ import org.pkl.core.util.LateInit; import org.pkl.core.util.Nullable; -final class ExternalReaderProcessImpl implements ExternalReaderProcess { +final class ReaderProcessImpl implements ReaderProcess { private static final Duration CLOSE_TIMEOUT = Duration.ofSeconds(3); private final ExternalReader spec; private final @Nullable String logPrefix; - private final Map> - initializeModuleReaderResponses = new ConcurrentHashMap<>(); - private final Map> + private final Map> initializeModuleReaderResponses = + new ConcurrentHashMap<>(); + private final Map> initializeResourceReaderResponses = new ConcurrentHashMap<>(); private final Random requestIdGenerator = new Random(); @@ -65,7 +65,7 @@ private void log(String msg) { } } - ExternalReaderProcessImpl(ExternalReader spec) { + ReaderProcessImpl(ExternalReader spec) { this.spec = spec; logPrefix = Objects.equals(System.getenv("PKL_DEBUG"), "1") @@ -74,26 +74,23 @@ private void log(String msg) { } @Override - public ExternalModuleResolver getModuleResolver(long evaluatorId) - throws ExternalReaderProcessException { - return ExternalModuleResolver.of(getTransport(), evaluatorId); + public ModuleResolver getModuleResolver(long evaluatorId) throws ReaderProcessException { + return ModuleResolver.of(getTransport(), evaluatorId); } @Override - public ExternalResourceResolver getResourceResolver(long evaluatorId) - throws ExternalReaderProcessException { - return ExternalResourceResolver.of(getTransport(), evaluatorId); + public ResourceResolver getResourceResolver(long evaluatorId) throws ReaderProcessException { + return ResourceResolver.of(getTransport(), evaluatorId); } - private MessageTransport getTransport() throws ExternalReaderProcessException { + private MessageTransport getTransport() throws ReaderProcessException { synchronized (lock) { if (closed) { throw new IllegalStateException("External reader process has already been closed."); } if (process != null) { if (!process.isAlive()) { - throw new ExternalReaderProcessException( - ErrorMessages.create("externalReaderAlreadyTerminated")); + throw new ReaderProcessException(ErrorMessages.create("externalReaderAlreadyTerminated")); } return transport; @@ -110,12 +107,12 @@ private MessageTransport getTransport() throws ExternalReaderProcessException { try { process = builder.start(); } catch (IOException e) { - throw new ExternalReaderProcessException(e); + throw new ReaderProcessException(e); } transport = MessageTransports.stream( - new ExternalReaderMessagePackDecoder(process.getInputStream()), - new ExternalReaderMessagePackEncoder(process.getOutputStream()), + new MessagePackDecoder(process.getInputStream()), + new MessagePackEncoder(process.getOutputStream()), this::log); var rxThread = new Thread(this::runTransport, "ExternalReaderProcessImpl rxThread for " + spec); @@ -169,12 +166,12 @@ public void close() { } @Override - public ExternalModuleReaderSpec getModuleReaderSpec(String uriScheme) throws IOException { + public ModuleReaderSpec getModuleReaderSpec(String uriScheme) throws IOException { return MessageTransports.resolveFuture( initializeModuleReaderResponses.computeIfAbsent( uriScheme, (scheme) -> { - var future = new CompletableFuture<@Nullable ExternalModuleReaderSpec>(); + var future = new CompletableFuture<@Nullable ModuleReaderSpec>(); var request = new InitializeModuleReaderRequest(requestIdGenerator.nextLong(), scheme); try { @@ -186,7 +183,7 @@ public ExternalModuleReaderSpec getModuleReaderSpec(String uriScheme) throws IOE var spec = resp.spec() == null ? null - : new ExternalModuleReaderSpec( + : new ModuleReaderSpec( resp.spec().scheme(), resp.spec().hasHierarchicalUris(), resp.spec().isLocal(), @@ -197,7 +194,7 @@ public ExternalModuleReaderSpec getModuleReaderSpec(String uriScheme) throws IOE new ProtocolException("unexpected response")); } }); - } catch (ProtocolException | IOException | ExternalReaderProcessException e) { + } catch (ProtocolException | IOException | ReaderProcessException e) { future.completeExceptionally(e); } return future; @@ -205,12 +202,12 @@ public ExternalModuleReaderSpec getModuleReaderSpec(String uriScheme) throws IOE } @Override - public ExternalResourceReaderSpec getResourceReaderSpec(String uriScheme) throws IOException { + public ResourceReaderSpec getResourceReaderSpec(String uriScheme) throws IOException { return MessageTransports.resolveFuture( initializeResourceReaderResponses.computeIfAbsent( uriScheme, (scheme) -> { - var future = new CompletableFuture<@Nullable ExternalResourceReaderSpec>(); + var future = new CompletableFuture<@Nullable ResourceReaderSpec>(); var request = new InitializeResourceReaderRequest(requestIdGenerator.nextLong(), scheme); try { @@ -223,7 +220,7 @@ public ExternalResourceReaderSpec getResourceReaderSpec(String uriScheme) throws var spec = resp.spec() == null ? null - : new ExternalResourceReaderSpec( + : new ResourceReaderSpec( resp.spec().scheme(), resp.spec().hasHierarchicalUris(), resp.spec().isGlobbable()); @@ -233,7 +230,7 @@ public ExternalResourceReaderSpec getResourceReaderSpec(String uriScheme) throws new ProtocolException("unexpected response")); } }); - } catch (ProtocolException | IOException | ExternalReaderProcessException e) { + } catch (ProtocolException | IOException | ReaderProcessException e) { future.completeExceptionally(e); } return future; diff --git a/pkl-core/src/main/java/org/pkl/core/externalreader/ExternalResourceReaderSpec.java b/pkl-core/src/main/java/org/pkl/core/externalreader/ResourceReaderSpec.java similarity index 85% rename from pkl-core/src/main/java/org/pkl/core/externalreader/ExternalResourceReaderSpec.java rename to pkl-core/src/main/java/org/pkl/core/externalreader/ResourceReaderSpec.java index fdade079e..0436d3322 100644 --- a/pkl-core/src/main/java/org/pkl/core/externalreader/ExternalResourceReaderSpec.java +++ b/pkl-core/src/main/java/org/pkl/core/externalreader/ResourceReaderSpec.java @@ -15,5 +15,4 @@ */ package org.pkl.core.externalreader; -public record ExternalResourceReaderSpec( - String scheme, boolean hasHierarchicalUris, boolean isGlobbable) {} +public record ResourceReaderSpec(String scheme, boolean hasHierarchicalUris, boolean isGlobbable) {} diff --git a/pkl-core/src/main/java/org/pkl/core/externalreader/ExternalResourceResolver.java b/pkl-core/src/main/java/org/pkl/core/externalreader/ResourceResolver.java similarity index 86% rename from pkl-core/src/main/java/org/pkl/core/externalreader/ExternalResourceResolver.java rename to pkl-core/src/main/java/org/pkl/core/externalreader/ResourceResolver.java index 12712bfd7..7a4aeb008 100644 --- a/pkl-core/src/main/java/org/pkl/core/externalreader/ExternalResourceResolver.java +++ b/pkl-core/src/main/java/org/pkl/core/externalreader/ResourceResolver.java @@ -24,9 +24,9 @@ import org.pkl.core.messaging.MessageTransport; import org.pkl.core.module.PathElement; -public interface ExternalResourceResolver { - static ExternalResourceResolver of(MessageTransport transport, long evaluatorId) { - return new ExternalResourceResolverImpl(transport, evaluatorId); +public interface ResourceResolver { + static ResourceResolver of(MessageTransport transport, long evaluatorId) { + return new ResourceResolverImpl(transport, evaluatorId); } Optional read(URI uri) throws IOException; diff --git a/pkl-core/src/main/java/org/pkl/core/externalreader/ExternalResourceResolverImpl.java b/pkl-core/src/main/java/org/pkl/core/externalreader/ResourceResolverImpl.java similarity index 96% rename from pkl-core/src/main/java/org/pkl/core/externalreader/ExternalResourceResolverImpl.java rename to pkl-core/src/main/java/org/pkl/core/externalreader/ResourceResolverImpl.java index de9e50e5d..aa006fa78 100644 --- a/pkl-core/src/main/java/org/pkl/core/externalreader/ExternalResourceResolverImpl.java +++ b/pkl-core/src/main/java/org/pkl/core/externalreader/ResourceResolverImpl.java @@ -34,14 +34,14 @@ import org.pkl.core.module.PathElement; import org.pkl.core.resource.Resource; -final class ExternalResourceResolverImpl implements ExternalResourceResolver { +final class ResourceResolverImpl implements ResourceResolver { private final MessageTransport transport; private final long evaluatorId; private final Map> readResponses = new ConcurrentHashMap<>(); private final Map>> listResponses = new ConcurrentHashMap<>(); private final Random requestIdGenerator = new Random(); - ExternalResourceResolverImpl(MessageTransport transport, long evaluatorId) { + ResourceResolverImpl(MessageTransport transport, long evaluatorId) { this.transport = transport; this.evaluatorId = evaluatorId; } diff --git a/pkl-core/src/main/java/org/pkl/core/module/ModuleKeyFactories.java b/pkl-core/src/main/java/org/pkl/core/module/ModuleKeyFactories.java index eae4e7e66..7038a1224 100644 --- a/pkl-core/src/main/java/org/pkl/core/module/ModuleKeyFactories.java +++ b/pkl-core/src/main/java/org/pkl/core/module/ModuleKeyFactories.java @@ -28,9 +28,9 @@ import java.util.ServiceLoader; import javax.annotation.concurrent.GuardedBy; import org.pkl.core.Closeables; -import org.pkl.core.externalreader.ExternalModuleResolver; -import org.pkl.core.externalreader.ExternalReaderProcess; -import org.pkl.core.externalreader.ExternalReaderProcessException; +import org.pkl.core.externalreader.ModuleResolver; +import org.pkl.core.externalreader.ReaderProcess; +import org.pkl.core.externalreader.ReaderProcessException; import org.pkl.core.util.ErrorMessages; import org.pkl.core.util.IoUtils; @@ -82,21 +82,21 @@ public static ModuleKeyFactory classPath(ClassLoader classLoader) { /** * Returns a factory for external reader module keys. * - *

NOTE: {@code process} needs to be {@link ExternalReaderProcess#close closed} to avoid - * resource leaks. + *

NOTE: {@code process} needs to be {@link ReaderProcess#close closed} to avoid resource + * leaks. */ - public static ModuleKeyFactory externalProcess(String scheme, ExternalReaderProcess process) { + public static ModuleKeyFactory externalProcess(String scheme, ReaderProcess process) { return new ExternalProcess(scheme, process, 0); } /** * Returns a factory for external reader module keys. * - *

NOTE: {@code process} needs to be {@link ExternalReaderProcess#close closed} to avoid - * resource leaks. + *

NOTE: {@code process} needs to be {@link ReaderProcess#close closed} to avoid resource + * leaks. */ public static ModuleKeyFactory externalProcess( - String scheme, ExternalReaderProcess process, long evaluatorId) { + String scheme, ReaderProcess process, long evaluatorId) { return new ExternalProcess(scheme, process, evaluatorId); } @@ -262,20 +262,19 @@ private static class FromServiceProviders { /** Represents a module from an external reader process. */ private static final class ExternalProcess implements ModuleKeyFactory { private final String scheme; - private final ExternalReaderProcess process; + private final ReaderProcess process; private final long evaluatorId; @GuardedBy("this") - private ExternalModuleResolver resolver; + private ModuleResolver resolver; - ExternalProcess(String scheme, ExternalReaderProcess process, long evaluatorId) { + ExternalProcess(String scheme, ReaderProcess process, long evaluatorId) { this.scheme = scheme; this.process = process; this.evaluatorId = evaluatorId; } - private synchronized ExternalModuleResolver getResolver() - throws ExternalReaderProcessException { + private synchronized ModuleResolver getResolver() throws ReaderProcessException { if (resolver != null) { return resolver; } @@ -284,12 +283,12 @@ private synchronized ExternalModuleResolver getResolver() return resolver; } - public Optional create(URI uri) throws ExternalReaderProcessException, IOException { + public Optional create(URI uri) throws ReaderProcessException, IOException { if (!scheme.equalsIgnoreCase(uri.getScheme())) return Optional.empty(); var spec = process.getModuleReaderSpec(scheme); if (spec == null) { - throw new ExternalReaderProcessException( + throw new ReaderProcessException( ErrorMessages.create("externalReaderDoesNotSupportScheme", "module", scheme)); } diff --git a/pkl-core/src/main/java/org/pkl/core/module/ModuleKeyFactory.java b/pkl-core/src/main/java/org/pkl/core/module/ModuleKeyFactory.java index 7bc17cc98..85b085f85 100644 --- a/pkl-core/src/main/java/org/pkl/core/module/ModuleKeyFactory.java +++ b/pkl-core/src/main/java/org/pkl/core/module/ModuleKeyFactory.java @@ -19,7 +19,7 @@ import java.net.URI; import java.net.URISyntaxException; import java.util.Optional; -import org.pkl.core.externalreader.ExternalReaderProcessException; +import org.pkl.core.externalreader.ReaderProcessException; /** A factory for {@link ModuleKey}s. */ public interface ModuleKeyFactory extends AutoCloseable { @@ -38,7 +38,7 @@ public interface ModuleKeyFactory extends AutoCloseable { * @return a module key for the given URI */ Optional create(URI uri) - throws URISyntaxException, ExternalReaderProcessException, IOException; + throws URISyntaxException, ReaderProcessException, IOException; /** * Closes this factory, releasing any resources held. See the documentation of factory methods in diff --git a/pkl-core/src/main/java/org/pkl/core/module/ModuleKeys.java b/pkl-core/src/main/java/org/pkl/core/module/ModuleKeys.java index 7cc1d916e..afac9147e 100644 --- a/pkl-core/src/main/java/org/pkl/core/module/ModuleKeys.java +++ b/pkl-core/src/main/java/org/pkl/core/module/ModuleKeys.java @@ -29,9 +29,9 @@ import java.util.Map; import org.pkl.core.SecurityManager; import org.pkl.core.SecurityManagerException; -import org.pkl.core.externalreader.ExternalModuleReaderSpec; -import org.pkl.core.externalreader.ExternalModuleResolver; -import org.pkl.core.externalreader.ExternalReaderProcessException; +import org.pkl.core.externalreader.ModuleReaderSpec; +import org.pkl.core.externalreader.ModuleResolver; +import org.pkl.core.externalreader.ReaderProcessException; import org.pkl.core.packages.Dependency; import org.pkl.core.packages.Dependency.LocalDependency; import org.pkl.core.packages.PackageAssetUri; @@ -132,7 +132,7 @@ public static ModuleKey projectpackage(URI uri) throws URISyntaxException { /** Creates a module key for an externally read module. */ public static ModuleKey externalResolver( - URI uri, ExternalModuleReaderSpec spec, ExternalModuleResolver resolver) { + URI uri, ModuleReaderSpec spec, ModuleResolver resolver) { return new ExternalResolver(uri, spec, resolver); } @@ -174,7 +174,7 @@ public ResolvedModuleKey resolve(SecurityManager securityManager) { } @Override - public boolean hasHierarchicalUris() throws IOException, ExternalReaderProcessException { + public boolean hasHierarchicalUris() throws IOException, ReaderProcessException { return delegate.hasHierarchicalUris(); } @@ -184,19 +184,19 @@ public boolean isLocal() { } @Override - public boolean isGlobbable() throws IOException, ExternalReaderProcessException { + public boolean isGlobbable() throws IOException, ReaderProcessException { return delegate.isGlobbable(); } @Override public boolean hasElement(SecurityManager securityManager, URI uri) - throws IOException, SecurityManagerException, ExternalReaderProcessException { + throws IOException, SecurityManagerException, ReaderProcessException { return delegate.hasElement(securityManager, uri); } @Override public List listElements(SecurityManager securityManager, URI baseUri) - throws IOException, SecurityManagerException, ExternalReaderProcessException { + throws IOException, SecurityManagerException, ReaderProcessException { return delegate.listElements(securityManager, baseUri); } } @@ -719,7 +719,7 @@ public ResolvedModuleKey resolve(SecurityManager securityManager) @Override public List listElements(SecurityManager securityManager, URI baseUri) - throws IOException, SecurityManagerException, ExternalReaderProcessException { + throws IOException, SecurityManagerException, ReaderProcessException { securityManager.checkResolveModule(baseUri); var packageAssetUri = PackageAssetUri.create(baseUri); var dependency = @@ -740,7 +740,7 @@ public List listElements(SecurityManager securityManager, URI baseU @Override public boolean hasElement(SecurityManager securityManager, URI elementUri) - throws IOException, SecurityManagerException, ExternalReaderProcessException { + throws IOException, SecurityManagerException, ReaderProcessException { securityManager.checkResolveModule(elementUri); var packageAssetUri = PackageAssetUri.create(elementUri); var dependency = @@ -780,10 +780,10 @@ public boolean hasElement(SecurityManager securityManager, URI elementUri) public static class ExternalResolver implements ModuleKey { private final URI uri; - private final ExternalModuleReaderSpec spec; - private final ExternalModuleResolver resolver; + private final ModuleReaderSpec spec; + private final ModuleResolver resolver; - ExternalResolver(URI uri, ExternalModuleReaderSpec spec, ExternalModuleResolver resolver) { + ExternalResolver(URI uri, ModuleReaderSpec spec, ModuleResolver resolver) { this.uri = uri; this.spec = spec; this.resolver = resolver; diff --git a/pkl-core/src/main/java/org/pkl/core/resource/ResourceReader.java b/pkl-core/src/main/java/org/pkl/core/resource/ResourceReader.java index 40e3f39eb..ad1801a3f 100644 --- a/pkl-core/src/main/java/org/pkl/core/resource/ResourceReader.java +++ b/pkl-core/src/main/java/org/pkl/core/resource/ResourceReader.java @@ -20,7 +20,7 @@ import java.net.URISyntaxException; import java.util.Optional; import org.pkl.core.SecurityManagerException; -import org.pkl.core.externalreader.ExternalReaderProcessException; +import org.pkl.core.externalreader.ReaderProcessException; import org.pkl.core.runtime.ReaderBase; /** @@ -56,10 +56,7 @@ public interface ResourceReader extends ReaderBase, AutoCloseable { * */ Optional read(URI uri) - throws IOException, - URISyntaxException, - SecurityManagerException, - ExternalReaderProcessException; + throws IOException, URISyntaxException, SecurityManagerException, ReaderProcessException; /** * Closes this reader, releasing any resources held. See the documentation of factory methods in diff --git a/pkl-core/src/main/java/org/pkl/core/resource/ResourceReaders.java b/pkl-core/src/main/java/org/pkl/core/resource/ResourceReaders.java index 68361c526..8ec026b79 100644 --- a/pkl-core/src/main/java/org/pkl/core/resource/ResourceReaders.java +++ b/pkl-core/src/main/java/org/pkl/core/resource/ResourceReaders.java @@ -29,10 +29,10 @@ import java.util.ServiceLoader; import org.pkl.core.SecurityManager; import org.pkl.core.SecurityManagerException; -import org.pkl.core.externalreader.ExternalReaderProcess; -import org.pkl.core.externalreader.ExternalReaderProcessException; -import org.pkl.core.externalreader.ExternalResourceReaderSpec; -import org.pkl.core.externalreader.ExternalResourceResolver; +import org.pkl.core.externalreader.ReaderProcess; +import org.pkl.core.externalreader.ReaderProcessException; +import org.pkl.core.externalreader.ResourceReaderSpec; +import org.pkl.core.externalreader.ResourceResolver; import org.pkl.core.module.FileResolver; import org.pkl.core.module.ModulePathResolver; import org.pkl.core.module.PathElement; @@ -144,27 +144,27 @@ public static List fromServiceProviders() { /** * Returns a reader for external reader resources. * - *

NOTE: {@code process} needs to be {@link ExternalReaderProcess#close closed} to avoid - * resource leaks. + *

NOTE: {@code process} needs to be {@link ReaderProcess#close closed} to avoid resource + * leaks. */ - public static ResourceReader externalProcess(String scheme, ExternalReaderProcess process) { + public static ResourceReader externalProcess(String scheme, ReaderProcess process) { return new ExternalProcess(scheme, process, 0); } /** * Returns a reader for external reader resources. * - *

NOTE: {@code process} needs to be {@link ExternalReaderProcess#close closed} to avoid - * resource leaks. + *

NOTE: {@code process} needs to be {@link ReaderProcess#close closed} to avoid resource + * leaks. */ public static ResourceReader externalProcess( - String scheme, ExternalReaderProcess process, long evaluatorId) { + String scheme, ReaderProcess process, long evaluatorId) { return new ExternalProcess(scheme, process, evaluatorId); } /** Returns a reader for external and client reader resources. */ public static ResourceReader externalResolver( - ExternalResourceReaderSpec spec, ExternalResourceResolver resolver) { + ResourceReaderSpec spec, ResourceResolver resolver) { return new ExternalResolver(spec, resolver); } @@ -552,7 +552,7 @@ public boolean hasFragmentPaths() { @Override public List listElements(SecurityManager securityManager, URI baseUri) - throws IOException, SecurityManagerException, ExternalReaderProcessException { + throws IOException, SecurityManagerException, ReaderProcessException { securityManager.checkResolveResource(baseUri); var packageAssetUri = PackageAssetUri.create(baseUri); var dependency = @@ -574,7 +574,7 @@ public List listElements(SecurityManager securityManager, URI baseU @Override public boolean hasElement(SecurityManager securityManager, URI elementUri) - throws IOException, SecurityManagerException, ExternalReaderProcessException { + throws IOException, SecurityManagerException, ReaderProcessException { securityManager.checkResolveResource(elementUri); var packageAssetUri = PackageAssetUri.create(elementUri); var dependency = @@ -629,25 +629,24 @@ private static class FromServiceProviders { private static final class ExternalProcess implements ResourceReader { private final String scheme; - private final ExternalReaderProcess process; + private final ReaderProcess process; private final long evaluatorId; private ExternalResolver underlying; - public ExternalProcess(String scheme, ExternalReaderProcess process, long evaluatorId) { + public ExternalProcess(String scheme, ReaderProcess process, long evaluatorId) { this.scheme = scheme; this.process = process; this.evaluatorId = evaluatorId; } - private ExternalResolver getUnderlyingReader() - throws ExternalReaderProcessException, IOException { + private ExternalResolver getUnderlyingReader() throws ReaderProcessException, IOException { if (underlying != null) { return underlying; } var spec = process.getResourceReaderSpec(scheme); if (spec == null) { - throw new ExternalReaderProcessException( + throw new ReaderProcessException( ErrorMessages.create("externalReaderDoesNotSupportScheme", "resource", scheme)); } underlying = new ExternalResolver(spec, process.getResourceResolver(evaluatorId)); @@ -660,29 +659,29 @@ public String getUriScheme() { } @Override - public boolean hasHierarchicalUris() throws ExternalReaderProcessException, IOException { + public boolean hasHierarchicalUris() throws ReaderProcessException, IOException { return getUnderlyingReader().hasHierarchicalUris(); } @Override - public boolean isGlobbable() throws ExternalReaderProcessException, IOException { + public boolean isGlobbable() throws ReaderProcessException, IOException { return getUnderlyingReader().isGlobbable(); } @Override - public Optional read(URI uri) throws IOException, ExternalReaderProcessException { + public Optional read(URI uri) throws IOException, ReaderProcessException { return getUnderlyingReader().read(uri); } @Override public boolean hasElement(SecurityManager securityManager, URI elementUri) - throws IOException, SecurityManagerException, ExternalReaderProcessException { + throws IOException, SecurityManagerException, ReaderProcessException { return getUnderlyingReader().hasElement(securityManager, elementUri); } @Override public List listElements(SecurityManager securityManager, URI baseUri) - throws IOException, SecurityManagerException, ExternalReaderProcessException { + throws IOException, SecurityManagerException, ReaderProcessException { return getUnderlyingReader().listElements(securityManager, baseUri); } @@ -693,11 +692,10 @@ public void close() { } private static final class ExternalResolver implements ResourceReader { - private final ExternalResourceReaderSpec readerSpec; - private final ExternalResourceResolver resolver; + private final ResourceReaderSpec readerSpec; + private final ResourceResolver resolver; - public ExternalResolver( - ExternalResourceReaderSpec readerSpec, ExternalResourceResolver resolver) { + public ExternalResolver(ResourceReaderSpec readerSpec, ResourceResolver resolver) { this.readerSpec = readerSpec; this.resolver = resolver; } diff --git a/pkl-core/src/main/java/org/pkl/core/runtime/ModuleResolver.java b/pkl-core/src/main/java/org/pkl/core/runtime/ModuleResolver.java index e90719f18..179882bd6 100644 --- a/pkl-core/src/main/java/org/pkl/core/runtime/ModuleResolver.java +++ b/pkl-core/src/main/java/org/pkl/core/runtime/ModuleResolver.java @@ -22,7 +22,7 @@ import java.util.Collection; import java.util.Optional; import org.pkl.core.ModuleSource; -import org.pkl.core.externalreader.ExternalReaderProcessException; +import org.pkl.core.externalreader.ReaderProcessException; import org.pkl.core.module.ModuleKey; import org.pkl.core.module.ModuleKeyFactory; import org.pkl.core.module.ModuleKeys; @@ -84,7 +84,7 @@ public ModuleKey resolve(URI moduleUri, @Nullable Node importNode) { .evalError("invalidModuleUri", moduleUri) .withHint(e.getReason()) .build(); - } catch (ExternalReaderProcessException e) { + } catch (ReaderProcessException e) { throw new VmExceptionBuilder() .withOptionalLocation(importNode) .evalError("externalReaderFailure") diff --git a/pkl-core/src/main/java/org/pkl/core/runtime/ReaderBase.java b/pkl-core/src/main/java/org/pkl/core/runtime/ReaderBase.java index e1f461d25..cfd934633 100644 --- a/pkl-core/src/main/java/org/pkl/core/runtime/ReaderBase.java +++ b/pkl-core/src/main/java/org/pkl/core/runtime/ReaderBase.java @@ -20,7 +20,7 @@ import java.util.List; import org.pkl.core.SecurityManager; import org.pkl.core.SecurityManagerException; -import org.pkl.core.externalreader.ExternalReaderProcessException; +import org.pkl.core.externalreader.ReaderProcessException; import org.pkl.core.module.ModuleKey; import org.pkl.core.module.PathElement; import org.pkl.core.util.IoUtils; @@ -30,10 +30,10 @@ public interface ReaderBase { * Tells if the URIs represented by this module key or resource reader should be interpreted as hierarchical. */ - boolean hasHierarchicalUris() throws ExternalReaderProcessException, IOException; + boolean hasHierarchicalUris() throws ReaderProcessException, IOException; /** Tells if this module key or resource reader supports globbing. */ - boolean isGlobbable() throws ExternalReaderProcessException, IOException; + boolean isGlobbable() throws ReaderProcessException, IOException; /** * Tells if relative paths of this URI should be resolved from {@link URI#getFragment()}, rather @@ -50,7 +50,7 @@ default boolean hasFragmentPaths() { * if either {@link #isGlobbable()} or {@link ModuleKey#isLocal()} returns true. */ default boolean hasElement(SecurityManager securityManager, URI elementUri) - throws IOException, SecurityManagerException, ExternalReaderProcessException { + throws IOException, SecurityManagerException, ReaderProcessException { throw new UnsupportedOperationException(); } @@ -67,7 +67,7 @@ default boolean hasElement(SecurityManager securityManager, URI elementUri) * this reader. */ default List listElements(SecurityManager securityManager, URI baseUri) - throws IOException, SecurityManagerException, ExternalReaderProcessException { + throws IOException, SecurityManagerException, ReaderProcessException { throw new UnsupportedOperationException(); } diff --git a/pkl-core/src/main/java/org/pkl/core/runtime/ResourceManager.java b/pkl-core/src/main/java/org/pkl/core/runtime/ResourceManager.java index 17f2cbdf4..1353163fa 100644 --- a/pkl-core/src/main/java/org/pkl/core/runtime/ResourceManager.java +++ b/pkl-core/src/main/java/org/pkl/core/runtime/ResourceManager.java @@ -26,7 +26,7 @@ import java.util.Optional; import org.pkl.core.SecurityManager; import org.pkl.core.SecurityManagerException; -import org.pkl.core.externalreader.ExternalReaderProcessException; +import org.pkl.core.externalreader.ReaderProcessException; import org.pkl.core.http.HttpClientInitException; import org.pkl.core.packages.PackageLoadError; import org.pkl.core.resource.Resource; @@ -87,7 +87,7 @@ public Optional doRead(ResourceReader reader, URI uri, @Nullable Node re } catch (SecurityManagerException | PackageLoadError | HttpClientInitException - | ExternalReaderProcessException e) { + | ReaderProcessException e) { throw new VmExceptionBuilder().withCause(e).withOptionalLocation(readNode).build(); } return resource; diff --git a/pkl-core/src/main/java/org/pkl/core/runtime/VmImportAnalyzer.java b/pkl-core/src/main/java/org/pkl/core/runtime/VmImportAnalyzer.java index 7a239a4a7..732db9034 100644 --- a/pkl-core/src/main/java/org/pkl/core/runtime/VmImportAnalyzer.java +++ b/pkl-core/src/main/java/org/pkl/core/runtime/VmImportAnalyzer.java @@ -30,7 +30,7 @@ import org.pkl.core.SecurityManagerException; import org.pkl.core.ast.builder.ImportsAndReadsParser; import org.pkl.core.ast.builder.ImportsAndReadsParser.Entry; -import org.pkl.core.externalreader.ExternalReaderProcessException; +import org.pkl.core.externalreader.ReaderProcessException; import org.pkl.core.util.GlobResolver; import org.pkl.core.util.GlobResolver.InvalidGlobPatternException; import org.pkl.core.util.GlobResolver.ResolvedGlobElement; @@ -39,10 +39,7 @@ public class VmImportAnalyzer { @TruffleBoundary public static ImportGraph analyze(URI[] moduleUris, VmContext context) - throws IOException, - URISyntaxException, - SecurityManagerException, - ExternalReaderProcessException { + throws IOException, URISyntaxException, SecurityManagerException, ReaderProcessException { var imports = new TreeMap>(); var resolvedImports = new TreeMap(); for (var moduleUri : moduleUris) { @@ -57,10 +54,7 @@ private static void analyzeSingle( VmContext context, Map> imports, Map resolvedImports) - throws IOException, - URISyntaxException, - SecurityManagerException, - ExternalReaderProcessException { + throws IOException, URISyntaxException, SecurityManagerException, ReaderProcessException { var moduleResolver = context.getModuleResolver(); var securityManager = context.getSecurityManager(); var importsInModule = collectImports(moduleUri, moduleResolver, securityManager); @@ -78,10 +72,7 @@ private static void analyzeSingle( private static Set collectImports( URI moduleUri, ModuleResolver moduleResolver, SecurityManager securityManager) - throws IOException, - URISyntaxException, - SecurityManagerException, - ExternalReaderProcessException { + throws IOException, URISyntaxException, SecurityManagerException, ReaderProcessException { var moduleKey = moduleResolver.resolve(moduleUri); var resolvedModuleKey = moduleKey.resolve(securityManager); List importsAndReads; diff --git a/pkl-core/src/main/java/org/pkl/core/stdlib/analyze/AnalyzeNodes.java b/pkl-core/src/main/java/org/pkl/core/stdlib/analyze/AnalyzeNodes.java index fdfaad1cc..025c6a397 100644 --- a/pkl-core/src/main/java/org/pkl/core/stdlib/analyze/AnalyzeNodes.java +++ b/pkl-core/src/main/java/org/pkl/core/stdlib/analyze/AnalyzeNodes.java @@ -23,7 +23,7 @@ import org.pkl.core.ImportGraph; import org.pkl.core.ImportGraph.Import; import org.pkl.core.SecurityManagerException; -import org.pkl.core.externalreader.ExternalReaderProcessException; +import org.pkl.core.externalreader.ReaderProcessException; import org.pkl.core.packages.PackageLoadError; import org.pkl.core.runtime.AnalyzeModule; import org.pkl.core.runtime.VmContext; @@ -96,7 +96,7 @@ protected Object eval(@SuppressWarnings("unused") VmTyped self, VmSet moduleUris | URISyntaxException | SecurityManagerException | PackageLoadError - | ExternalReaderProcessException e) { + | ReaderProcessException e) { throw exceptionBuilder().withCause(e).build(); } } diff --git a/pkl-core/src/main/java/org/pkl/core/stdlib/benchmark/OutputBenchmarkNodes.java b/pkl-core/src/main/java/org/pkl/core/stdlib/benchmark/OutputBenchmarkNodes.java index 1bce83c1a..91fbe50a6 100644 --- a/pkl-core/src/main/java/org/pkl/core/stdlib/benchmark/OutputBenchmarkNodes.java +++ b/pkl-core/src/main/java/org/pkl/core/stdlib/benchmark/OutputBenchmarkNodes.java @@ -25,7 +25,7 @@ import java.util.List; import org.pkl.core.SecurityManager; import org.pkl.core.SecurityManagerException; -import org.pkl.core.externalreader.ExternalReaderProcessException; +import org.pkl.core.externalreader.ReaderProcessException; import org.pkl.core.module.ModuleKey; import org.pkl.core.module.PathElement; import org.pkl.core.module.ResolvedModuleKey; @@ -109,7 +109,7 @@ public boolean isCached() { } @Override - public boolean hasHierarchicalUris() throws IOException, ExternalReaderProcessException { + public boolean hasHierarchicalUris() throws IOException, ReaderProcessException { return delegate.hasHierarchicalUris(); } @@ -119,19 +119,19 @@ public boolean isLocal() { } @Override - public boolean isGlobbable() throws IOException, ExternalReaderProcessException { + public boolean isGlobbable() throws IOException, ReaderProcessException { return delegate.isGlobbable(); } @Override public boolean hasElement(SecurityManager securityManager, URI uri) - throws IOException, SecurityManagerException, ExternalReaderProcessException { + throws IOException, SecurityManagerException, ReaderProcessException { return delegate.hasElement(securityManager, uri); } @Override public List listElements(SecurityManager securityManager, URI baseUri) - throws IOException, SecurityManagerException, ExternalReaderProcessException { + throws IOException, SecurityManagerException, ReaderProcessException { return delegate.listElements(securityManager, baseUri); } } diff --git a/pkl-core/src/main/java/org/pkl/core/util/GlobResolver.java b/pkl-core/src/main/java/org/pkl/core/util/GlobResolver.java index eca25f358..1789eabcd 100644 --- a/pkl-core/src/main/java/org/pkl/core/util/GlobResolver.java +++ b/pkl-core/src/main/java/org/pkl/core/util/GlobResolver.java @@ -31,7 +31,7 @@ import org.pkl.core.PklBugException; import org.pkl.core.SecurityManager; import org.pkl.core.SecurityManagerException; -import org.pkl.core.externalreader.ExternalReaderProcessException; +import org.pkl.core.externalreader.ReaderProcessException; import org.pkl.core.module.ModuleKey; import org.pkl.core.module.PathElement; import org.pkl.core.runtime.ReaderBase; @@ -244,7 +244,7 @@ private static void resolveOpaqueGlob( URI globUri, Pattern pattern, Map result) - throws IOException, SecurityManagerException, ExternalReaderProcessException { + throws IOException, SecurityManagerException, ReaderProcessException { var elements = reader.listElements(securityManager, globUri); for (var elem : sorted(elements)) { URI resolvedUri; @@ -305,7 +305,7 @@ private static List expandHierarchicalGlobPart( throws IOException, SecurityManagerException, InvalidGlobPatternException, - ExternalReaderProcessException { + ReaderProcessException { var result = new ArrayList(); doExpandHierarchicalGlobPart( securityManager, @@ -333,7 +333,7 @@ private static void doExpandHierarchicalGlobPart( throws IOException, SecurityManagerException, InvalidGlobPatternException, - ExternalReaderProcessException { + ReaderProcessException { if (listElementCallCount.getAndIncrement() > maxListElements()) { throw new InvalidGlobPatternException(ErrorMessages.create("invalidGlobTooComplex")); @@ -377,7 +377,7 @@ private static void resolveHierarchicalGlob( throws IOException, SecurityManagerException, InvalidGlobPatternException, - ExternalReaderProcessException { + ReaderProcessException { var isLeaf = idx == globPatternParts.length - 1; var patternPart = globPatternParts[idx]; if (isRegularPathPart(patternPart)) { @@ -477,7 +477,7 @@ public static Map resolveGlob( throws IOException, SecurityManagerException, InvalidGlobPatternException, - ExternalReaderProcessException { + ReaderProcessException { var result = new LinkedHashMap(); var hasAbsoluteGlob = globPattern.matches("\\w+:.*"); diff --git a/pkl-core/src/main/java/org/pkl/core/util/IoUtils.java b/pkl-core/src/main/java/org/pkl/core/util/IoUtils.java index f7a8bbd79..8f885d571 100644 --- a/pkl-core/src/main/java/org/pkl/core/util/IoUtils.java +++ b/pkl-core/src/main/java/org/pkl/core/util/IoUtils.java @@ -38,7 +38,7 @@ import org.pkl.core.Platform; import org.pkl.core.SecurityManager; import org.pkl.core.SecurityManagerException; -import org.pkl.core.externalreader.ExternalReaderProcessException; +import org.pkl.core.externalreader.ReaderProcessException; import org.pkl.core.module.ModuleKey; import org.pkl.core.packages.PackageLoadError; import org.pkl.core.runtime.ReaderBase; @@ -318,7 +318,7 @@ public static URI resolve(ReaderBase reader, URI baseUri, URI importUri) { private static URI resolveTripleDotImport( SecurityManager securityManager, ModuleKey moduleKey, String tripleDotPath) - throws IOException, SecurityManagerException, ExternalReaderProcessException { + throws IOException, SecurityManagerException, ReaderProcessException { var moduleKeyUri = moduleKey.getUri(); if (!moduleKey.isLocal() || !moduleKey.hasHierarchicalUris()) { throw new VmExceptionBuilder() @@ -365,7 +365,7 @@ public static Pair parseDependencyNotation(String importPath) { } private static URI resolveProjectDependency(ModuleKey moduleKey, String notation) - throws IOException, ExternalReaderProcessException { + throws IOException, ReaderProcessException { var parsed = parseDependencyNotation(notation); var name = parsed.getFirst(); var path = parsed.getSecond(); @@ -397,10 +397,7 @@ private static URI resolveProjectDependency(ModuleKey moduleKey, String notation * dependency notation () */ public static URI resolve(SecurityManager securityManager, ModuleKey moduleKey, URI importUri) - throws URISyntaxException, - IOException, - SecurityManagerException, - ExternalReaderProcessException { + throws URISyntaxException, IOException, SecurityManagerException, ReaderProcessException { if (importUri.isAbsolute()) { return moduleKey.resolveUri(importUri); } diff --git a/pkl-core/src/test/kotlin/org/pkl/core/externalreader/ExternalProcessProcessReaderMessagePackCodecTest.kt b/pkl-core/src/test/kotlin/org/pkl/core/externalreader/MessagePackCodecTest.kt similarity index 87% rename from pkl-core/src/test/kotlin/org/pkl/core/externalreader/ExternalProcessProcessReaderMessagePackCodecTest.kt rename to pkl-core/src/test/kotlin/org/pkl/core/externalreader/MessagePackCodecTest.kt index 235524fdc..ac04db2f8 100644 --- a/pkl-core/src/test/kotlin/org/pkl/core/externalreader/ExternalProcessProcessReaderMessagePackCodecTest.kt +++ b/pkl-core/src/test/kotlin/org/pkl/core/externalreader/MessagePackCodecTest.kt @@ -20,18 +20,18 @@ import java.io.PipedOutputStream import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test import org.msgpack.core.MessagePack -import org.pkl.core.externalreader.ExternalReaderMessages.* +import org.pkl.core.externalreader.ReaderMessages.* import org.pkl.core.messaging.* -class ExternalProcessProcessReaderMessagePackCodecTest { +class MessagePackCodecTest { private val encoder: MessageEncoder private val decoder: MessageDecoder init { val inputStream = PipedInputStream() val outputStream = PipedOutputStream(inputStream) - encoder = ExternalReaderMessagePackEncoder(MessagePack.newDefaultPacker(outputStream)) - decoder = ExternalReaderMessagePackDecoder(MessagePack.newDefaultUnpacker(inputStream)) + encoder = MessagePackEncoder(MessagePack.newDefaultPacker(outputStream)) + decoder = MessagePackDecoder(MessagePack.newDefaultUnpacker(inputStream)) } private fun roundtrip(message: Message) { diff --git a/pkl-core/src/test/kotlin/org/pkl/core/externalreader/ExternalModuleReader.kt b/pkl-core/src/test/kotlin/org/pkl/core/externalreader/ModuleReader.kt similarity index 87% rename from pkl-core/src/test/kotlin/org/pkl/core/externalreader/ExternalModuleReader.kt rename to pkl-core/src/test/kotlin/org/pkl/core/externalreader/ModuleReader.kt index e9be21d6f..34a639de3 100644 --- a/pkl-core/src/test/kotlin/org/pkl/core/externalreader/ExternalModuleReader.kt +++ b/pkl-core/src/test/kotlin/org/pkl/core/externalreader/ModuleReader.kt @@ -18,8 +18,8 @@ package org.pkl.core.externalreader import java.net.URI import org.pkl.core.messaging.Messages.ModuleReaderSpec -/** An external module reader, to be used with [ExternalReaderRuntime]. */ -interface ExternalModuleReader : ExternalReaderBase { +/** An external module reader, to be used with [ReaderRuntime]. */ +interface ModuleReader : ExternalReaderBase { val isLocal: Boolean fun read(uri: URI): String diff --git a/pkl-core/src/test/kotlin/org/pkl/core/externalreader/ExternalReaderRuntime.kt b/pkl-core/src/test/kotlin/org/pkl/core/externalreader/ReaderRuntime.kt similarity index 92% rename from pkl-core/src/test/kotlin/org/pkl/core/externalreader/ExternalReaderRuntime.kt rename to pkl-core/src/test/kotlin/org/pkl/core/externalreader/ReaderRuntime.kt index 95b7dba32..0e87a1db2 100644 --- a/pkl-core/src/test/kotlin/org/pkl/core/externalreader/ExternalReaderRuntime.kt +++ b/pkl-core/src/test/kotlin/org/pkl/core/externalreader/ReaderRuntime.kt @@ -16,17 +16,18 @@ package org.pkl.core.externalreader import java.io.IOException -import org.pkl.core.externalreader.ExternalReaderMessages.* +import org.pkl.core.externalreader.ReaderMessages.* import org.pkl.core.messaging.Message import org.pkl.core.messaging.MessageTransport +import org.pkl.core.messaging.Messages import org.pkl.core.messaging.Messages.* import org.pkl.core.messaging.ProtocolException import org.pkl.core.util.Nullable /** An implementation of the client side of the external reader flow */ -class ExternalReaderRuntime( - private val moduleReaders: List, - private val resourceReaders: List, +class ReaderRuntime( + private val moduleReaders: List, + private val resourceReaders: List, private val transport: MessageTransport ) { /** Close the runtime and its transport. */ @@ -34,7 +35,7 @@ class ExternalReaderRuntime( transport.close() } - private fun findModuleReader(scheme: String): @Nullable ExternalModuleReader? { + private fun findModuleReader(scheme: String): @Nullable ModuleReader? { for (moduleReader in moduleReaders) { if (moduleReader.scheme.equals(scheme, ignoreCase = true)) { return moduleReader @@ -43,7 +44,7 @@ class ExternalReaderRuntime( return null } - private fun findResourceReader(scheme: String): @Nullable ExternalResourceReader? { + private fun findResourceReader(scheme: String): @Nullable ResourceReader? { for (resourceReader in resourceReaders) { if (resourceReader.scheme.equals(scheme, ignoreCase = true)) { return resourceReader @@ -72,7 +73,7 @@ class ExternalReaderRuntime( Message.Type.INITIALIZE_MODULE_READER_REQUEST -> { val req = msg as InitializeModuleReaderRequest val reader = findModuleReader(req.scheme) - var spec: @Nullable ModuleReaderSpec? = null + var spec: Messages.ModuleReaderSpec? = null if (reader != null) { spec = reader.spec } @@ -81,7 +82,7 @@ class ExternalReaderRuntime( Message.Type.INITIALIZE_RESOURCE_READER_REQUEST -> { val req = msg as InitializeResourceReaderRequest val reader = findResourceReader(req.scheme) - var spec: @Nullable ResourceReaderSpec? = null + var spec: Messages.ResourceReaderSpec? = null if (reader != null) { spec = reader.spec } diff --git a/pkl-core/src/test/kotlin/org/pkl/core/externalreader/ExternalResourceReader.kt b/pkl-core/src/test/kotlin/org/pkl/core/externalreader/ResourceReader.kt similarity index 87% rename from pkl-core/src/test/kotlin/org/pkl/core/externalreader/ExternalResourceReader.kt rename to pkl-core/src/test/kotlin/org/pkl/core/externalreader/ResourceReader.kt index bf5ab46f3..d209e545e 100644 --- a/pkl-core/src/test/kotlin/org/pkl/core/externalreader/ExternalResourceReader.kt +++ b/pkl-core/src/test/kotlin/org/pkl/core/externalreader/ResourceReader.kt @@ -18,8 +18,8 @@ package org.pkl.core.externalreader import java.net.URI import org.pkl.core.messaging.Messages.ResourceReaderSpec -/** An external resource reader, to be used with [ExternalReaderRuntime]. */ -interface ExternalResourceReader : ExternalReaderBase { +/** An external resource reader, to be used with [ReaderRuntime]. */ +interface ResourceReader : ExternalReaderBase { fun read(uri: URI): ByteArray val spec: ResourceReaderSpec diff --git a/pkl-core/src/test/kotlin/org/pkl/core/externalreader/TestExternalModuleReader.kt b/pkl-core/src/test/kotlin/org/pkl/core/externalreader/TestModuleReader.kt similarity index 95% rename from pkl-core/src/test/kotlin/org/pkl/core/externalreader/TestExternalModuleReader.kt rename to pkl-core/src/test/kotlin/org/pkl/core/externalreader/TestModuleReader.kt index 12b543cec..f826b7e98 100644 --- a/pkl-core/src/test/kotlin/org/pkl/core/externalreader/TestExternalModuleReader.kt +++ b/pkl-core/src/test/kotlin/org/pkl/core/externalreader/TestModuleReader.kt @@ -18,7 +18,7 @@ package org.pkl.core.externalreader import java.net.URI import org.pkl.core.module.PathElement -class TestExternalModuleReader : ExternalModuleReader { +class TestModuleReader : ModuleReader { override val scheme: String = "test" override val hasHierarchicalUris: Boolean = false diff --git a/pkl-core/src/test/kotlin/org/pkl/core/externalreader/TestExternalReaderProcess.kt b/pkl-core/src/test/kotlin/org/pkl/core/externalreader/TestReaderProcess.kt similarity index 63% rename from pkl-core/src/test/kotlin/org/pkl/core/externalreader/TestExternalReaderProcess.kt rename to pkl-core/src/test/kotlin/org/pkl/core/externalreader/TestReaderProcess.kt index cccbf83f7..75d52a95c 100644 --- a/pkl-core/src/test/kotlin/org/pkl/core/externalreader/TestExternalReaderProcess.kt +++ b/pkl-core/src/test/kotlin/org/pkl/core/externalreader/TestReaderProcess.kt @@ -23,17 +23,15 @@ import java.util.concurrent.ConcurrentHashMap import java.util.concurrent.ExecutionException import java.util.concurrent.Future import kotlin.random.Random -import org.pkl.core.externalreader.ExternalReaderMessages.* +import org.pkl.core.externalreader.ReaderMessages.* import org.pkl.core.messaging.MessageTransport import org.pkl.core.messaging.MessageTransports import org.pkl.core.messaging.ProtocolException -class TestExternalReaderProcess(private val transport: MessageTransport) : ExternalReaderProcess { - private val initializeModuleReaderResponses: - MutableMap> = +class TestReaderProcess(private val transport: MessageTransport) : ReaderProcess { + private val initializeModuleReaderResponses: MutableMap> = ConcurrentHashMap() - private val initializeResourceReaderResponses: - MutableMap> = + private val initializeResourceReaderResponses: MutableMap> = ConcurrentHashMap() override fun close() { @@ -41,11 +39,11 @@ class TestExternalReaderProcess(private val transport: MessageTransport) : Exter transport.close() } - override fun getModuleResolver(evaluatorId: Long): ExternalModuleResolver = - ExternalModuleResolver.of(transport, evaluatorId) + override fun getModuleResolver(evaluatorId: Long): ModuleResolver = + ModuleResolver.of(transport, evaluatorId) - override fun getResourceResolver(evaluatorId: Long): ExternalResourceResolver = - ExternalResourceResolver.of(transport, evaluatorId) + override fun getResourceResolver(evaluatorId: Long): ResourceResolver = + ResourceResolver.of(transport, evaluatorId) fun run() { try { @@ -60,22 +58,17 @@ class TestExternalReaderProcess(private val transport: MessageTransport) : Exter } } - override fun getModuleReaderSpec(scheme: String): ExternalModuleReaderSpec? = + override fun getModuleReaderSpec(scheme: String): ModuleReaderSpec? = initializeModuleReaderResponses .computeIfAbsent(scheme) { - CompletableFuture().apply { + CompletableFuture().apply { val request = InitializeModuleReaderRequest(Random.nextLong(), scheme) transport.send(request) { response -> when (response) { is InitializeModuleReaderResponse -> { val spec = response.spec?.let { - ExternalModuleReaderSpec( - it.scheme, - it.hasHierarchicalUris, - it.isLocal, - it.isGlobbable - ) + ModuleReaderSpec(it.scheme, it.hasHierarchicalUris, it.isLocal, it.isGlobbable) } complete(spec) } @@ -86,17 +79,17 @@ class TestExternalReaderProcess(private val transport: MessageTransport) : Exter } .getUnderlying() - override fun getResourceReaderSpec(scheme: String): ExternalResourceReaderSpec? = + override fun getResourceReaderSpec(scheme: String): ResourceReaderSpec? = initializeResourceReaderResponses .computeIfAbsent(scheme) { - CompletableFuture().apply { + CompletableFuture().apply { val request = InitializeResourceReaderRequest(Random.nextLong(), scheme) transport.send(request) { response -> when (response) { is InitializeResourceReaderResponse -> { val spec = response.spec?.let { - ExternalResourceReaderSpec(it.scheme, it.hasHierarchicalUris, it.isGlobbable) + ResourceReaderSpec(it.scheme, it.hasHierarchicalUris, it.isGlobbable) } complete(spec) } @@ -109,26 +102,20 @@ class TestExternalReaderProcess(private val transport: MessageTransport) : Exter companion object { fun initializeTestHarness( - moduleReaders: List, - resourceReaders: List - ): Pair { + moduleReaders: List, + resourceReaders: List + ): Pair { val rxIn = PipedInputStream(10240) val rxOut = PipedOutputStream(rxIn) val txIn = PipedInputStream(10240) val txOut = PipedOutputStream(txIn) val serverTransport = - MessageTransports.stream( - ExternalReaderMessagePackDecoder(rxIn), - ExternalReaderMessagePackEncoder(txOut) - ) {} + MessageTransports.stream(MessagePackDecoder(rxIn), MessagePackEncoder(txOut)) {} val clientTransport = - MessageTransports.stream( - ExternalReaderMessagePackDecoder(txIn), - ExternalReaderMessagePackEncoder(rxOut) - ) {} + MessageTransports.stream(MessagePackDecoder(txIn), MessagePackEncoder(rxOut)) {} - val runtime = ExternalReaderRuntime(moduleReaders, resourceReaders, clientTransport) - val proc = TestExternalReaderProcess(serverTransport) + val runtime = ReaderRuntime(moduleReaders, resourceReaders, clientTransport) + val proc = TestReaderProcess(serverTransport) Thread(runtime::run).start() Thread(proc::run).start() diff --git a/pkl-core/src/test/kotlin/org/pkl/core/externalreader/TestExternalResourceReader.kt b/pkl-core/src/test/kotlin/org/pkl/core/externalreader/TestResourceReader.kt similarity index 94% rename from pkl-core/src/test/kotlin/org/pkl/core/externalreader/TestExternalResourceReader.kt rename to pkl-core/src/test/kotlin/org/pkl/core/externalreader/TestResourceReader.kt index 6cabf362b..434dd4754 100644 --- a/pkl-core/src/test/kotlin/org/pkl/core/externalreader/TestExternalResourceReader.kt +++ b/pkl-core/src/test/kotlin/org/pkl/core/externalreader/TestResourceReader.kt @@ -18,7 +18,7 @@ package org.pkl.core.externalreader import java.net.URI import org.pkl.core.module.PathElement -class TestExternalResourceReader : ExternalResourceReader { +class TestResourceReader : ResourceReader { override val scheme: String = "test" override val hasHierarchicalUris: Boolean = false diff --git a/pkl-core/src/test/kotlin/org/pkl/core/module/ModuleKeyFactoriesTest.kt b/pkl-core/src/test/kotlin/org/pkl/core/module/ModuleKeyFactoriesTest.kt index 032fc5fe6..7f1b370b2 100644 --- a/pkl-core/src/test/kotlin/org/pkl/core/module/ModuleKeyFactoriesTest.kt +++ b/pkl-core/src/test/kotlin/org/pkl/core/module/ModuleKeyFactoriesTest.kt @@ -130,9 +130,8 @@ class ModuleKeyFactoriesTest { @Test fun externalProcess() { - val extReader = TestExternalModuleReader() - val (proc, runtime) = - TestExternalReaderProcess.initializeTestHarness(listOf(extReader), emptyList()) + val extReader = TestModuleReader() + val (proc, runtime) = TestReaderProcess.initializeTestHarness(listOf(extReader), emptyList()) val factory = ModuleKeyFactories.externalProcess(extReader.scheme, proc) diff --git a/pkl-core/src/test/kotlin/org/pkl/core/resource/ResourceReadersTest.kt b/pkl-core/src/test/kotlin/org/pkl/core/resource/ResourceReadersTest.kt index 58c34b469..24f63e080 100644 --- a/pkl-core/src/test/kotlin/org/pkl/core/resource/ResourceReadersTest.kt +++ b/pkl-core/src/test/kotlin/org/pkl/core/resource/ResourceReadersTest.kt @@ -23,8 +23,8 @@ import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test import org.junit.jupiter.api.assertThrows import org.junit.jupiter.api.io.TempDir -import org.pkl.core.externalreader.TestExternalReaderProcess -import org.pkl.core.externalreader.TestExternalResourceReader +import org.pkl.core.externalreader.TestReaderProcess +import org.pkl.core.externalreader.TestResourceReader import org.pkl.core.module.ModulePathResolver class ResourceReadersTest { @@ -137,9 +137,8 @@ class ResourceReadersTest { @Test fun externalProcess() { - val extReader = TestExternalResourceReader() - val (proc, runtime) = - TestExternalReaderProcess.initializeTestHarness(emptyList(), listOf(extReader)) + val extReader = TestResourceReader() + val (proc, runtime) = TestReaderProcess.initializeTestHarness(emptyList(), listOf(extReader)) val reader = ResourceReaders.externalProcess(extReader.scheme, proc) val resource = reader.read(URI("test:foo")) diff --git a/pkl-server/src/main/kotlin/org/pkl/server/ClientModuleKeyFactory.kt b/pkl-server/src/main/kotlin/org/pkl/server/ClientModuleKeyFactory.kt index 84c9f7800..abe5d67a5 100644 --- a/pkl-server/src/main/kotlin/org/pkl/server/ClientModuleKeyFactory.kt +++ b/pkl-server/src/main/kotlin/org/pkl/server/ClientModuleKeyFactory.kt @@ -17,19 +17,19 @@ package org.pkl.server import java.net.URI import java.util.Optional -import org.pkl.core.externalreader.ExternalModuleReaderSpec -import org.pkl.core.externalreader.ExternalModuleResolver +import org.pkl.core.externalreader.ModuleReaderSpec +import org.pkl.core.externalreader.ModuleResolver import org.pkl.core.messaging.* import org.pkl.core.module.* internal class ClientModuleKeyFactory( - private val readerSpecs: Collection, + private val readerSpecs: Collection, transport: MessageTransport, evaluatorId: Long ) : ModuleKeyFactory { private val schemes = readerSpecs.map { it.scheme } - private val resolver: ExternalModuleResolver = ExternalModuleResolver.of(transport, evaluatorId) + private val resolver: ModuleResolver = ModuleResolver.of(transport, evaluatorId) override fun create(uri: URI): Optional = when (uri.scheme) { diff --git a/pkl-server/src/main/kotlin/org/pkl/server/Server.kt b/pkl-server/src/main/kotlin/org/pkl/server/Server.kt index 6b10e9e00..b108f2254 100644 --- a/pkl-server/src/main/kotlin/org/pkl/server/Server.kt +++ b/pkl-server/src/main/kotlin/org/pkl/server/Server.kt @@ -25,10 +25,10 @@ import java.util.regex.Pattern import kotlin.random.Random import org.pkl.core.* import org.pkl.core.evaluatorSettings.PklEvaluatorSettings -import org.pkl.core.externalreader.ExternalModuleReaderSpec -import org.pkl.core.externalreader.ExternalReaderProcess -import org.pkl.core.externalreader.ExternalResourceReaderSpec -import org.pkl.core.externalreader.ExternalResourceResolver +import org.pkl.core.externalreader.ModuleReaderSpec +import org.pkl.core.externalreader.ReaderProcess +import org.pkl.core.externalreader.ResourceReaderSpec +import org.pkl.core.externalreader.ResourceResolver import org.pkl.core.http.HttpClient import org.pkl.core.messaging.MessageTransport import org.pkl.core.messaging.MessageTransports @@ -49,8 +49,7 @@ class Server(private val transport: MessageTransport) : AutoCloseable { private val executor: ExecutorService = Executors.newSingleThreadExecutor() // ExternalProcess instances with the same ExternalReader spec are shared per evaluator - private val externalReaderProcesses: - MutableMap> = + private val readerProcesses: MutableMap> = ConcurrentHashMap() companion object { @@ -144,7 +143,7 @@ class Server(private val transport: MessageTransport) : AutoCloseable { evaluator.close() // close any running ExternalProcess instances for the closed evaluator - externalReaderProcesses[message.evaluatorId]?.values?.forEach { it.close() } + readerProcesses[message.evaluatorId]?.values?.forEach { it.close() } } private fun buildDeclaredDependencies( @@ -250,12 +249,12 @@ class Server(private val transport: MessageTransport) : AutoCloseable { for (readerSpec in message.clientResourceReaders ?: emptyList()) { add( ResourceReaders.externalResolver( - ExternalResourceReaderSpec( + ResourceReaderSpec( readerSpec.scheme, readerSpec.hasHierarchicalUris, readerSpec.isGlobbable ), - ExternalResourceResolver.of(transport, evaluatorId) + ResourceResolver.of(transport, evaluatorId) ) ) } @@ -270,7 +269,7 @@ class Server(private val transport: MessageTransport) : AutoCloseable { if (message.clientModuleReaders?.isNotEmpty() == true) { val readerSpecs = message.clientModuleReaders.map { - ExternalModuleReaderSpec(it.scheme, it.hasHierarchicalUris, it.isLocal, it.isGlobbable) + ModuleReaderSpec(it.scheme, it.hasHierarchicalUris, it.isLocal, it.isGlobbable) } add(ClientModuleKeyFactory(readerSpecs, transport, evaluatorId)) } @@ -293,10 +292,10 @@ class Server(private val transport: MessageTransport) : AutoCloseable { add(ModuleKeyFactories.genericUrl) } - private fun getExternalProcess(evaluatorId: Long, spec: ExternalReader): ExternalReaderProcess = - externalReaderProcesses + private fun getExternalProcess(evaluatorId: Long, spec: ExternalReader): ReaderProcess = + readerProcesses .computeIfAbsent(evaluatorId) { ConcurrentHashMap() } .computeIfAbsent(spec) { - ExternalReaderProcess.of(PklEvaluatorSettings.ExternalReader(it.executable, it.arguments)) + ReaderProcess.of(PklEvaluatorSettings.ExternalReader(it.executable, it.arguments)) } }