Skip to content

Commit

Permalink
Strip "External" from class names in package externalreader
Browse files Browse the repository at this point in the history
- class names were too long/repetitive
- package name provides sufficient context
  • Loading branch information
odenix committed Nov 12, 2024
1 parent 5d0da54 commit 32b0fa8
Show file tree
Hide file tree
Showing 42 changed files with 222 additions and 262 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
}

Expand Down
10 changes: 4 additions & 6 deletions pkl-core/src/main/java/org/pkl/core/EvaluatorBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<ExternalReader, ExternalReaderProcess>();
var procs = new HashMap<ExternalReader, ReaderProcess>();
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@
*/
package org.pkl.core.externalreader;

public record ExternalModuleReaderSpec(
public record ModuleReaderSpec(
String scheme, boolean hasHierarchicalUris, boolean isLocal, boolean isGlobbable) {}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<URI, Future<String>> readResponses = new ConcurrentHashMap<>();
private final Map<URI, Future<List<PathElement>>> 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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -64,16 +63,16 @@ 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.
*
* <p>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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Loading

0 comments on commit 32b0fa8

Please sign in to comment.