mirror of
https://github.com/apple/pkl.git
synced 2026-04-19 15:01:26 +02:00
Untangle external reader code (#776)
- move the following classes into package externalreader: - ExternalModuleResolver - ExternalResourceResolver - MessageTransportModuleResolver (renamed to ExternalModuleResolverImpl, made package-private) - MessageTransportResourceResolver (renamed to ExternalResourceResolverImpl, made package-private) - replace interface ExternalModuleResolver.Spec with record ExternalModuleReaderSpec - replace interface ExternalResourceResolver.Spec with record ExternalResourceReaderSpec - translate between messaging.ResourceReaderSpec and ExternalResourceReaderSpec (eliminates dependency from messaging on higher layer) - translate between messaging.ResourceResolverSpec and ExternalResourceResolverSpec (eliminates dependency from messaging on higher layer) - add ServerMessages.ExternalReader and translate between this message component and the PklEvaluatorSettings.ExternalReader API - add ServerMessages.Proxy and translate between this message component and the PklEvaluatorSettings.Proxy API - change type of CreateEvaluatorRequest.allowedModules/allowedResources from List<Pattern>? to List<String>? - removes a lot of code - should not need to create a Pattern object to send a message - deprecate method evaluatorSettings.PklEvaluatorSettings.Proxy.create() - only seems useful internally, inlined Co-authored-by: Dan Chao <dan.chao@apple.com>
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
|
||||
* Copyright © 2024-2025 Apple Inc. and the Pkl project authors. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -137,6 +137,7 @@ public record PklEvaluatorSettings(
|
||||
}
|
||||
|
||||
public record Proxy(@Nullable URI address, @Nullable List<String> noProxy) {
|
||||
@Deprecated(forRemoval = true)
|
||||
public static Proxy create(@Nullable String address, @Nullable List<String> noProxy) {
|
||||
URI addressUri;
|
||||
try {
|
||||
@@ -147,14 +148,19 @@ public record PklEvaluatorSettings(
|
||||
return new Proxy(addressUri, noProxy);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static @Nullable Proxy parse(Value input) {
|
||||
if (input instanceof PNull) {
|
||||
return null;
|
||||
} else if (input instanceof PObject proxy) {
|
||||
var address = (String) proxy.get("address");
|
||||
@SuppressWarnings("unchecked")
|
||||
var noProxy = (List<String>) proxy.get("noProxy");
|
||||
return create(address, noProxy);
|
||||
try {
|
||||
var addressUri = address == null ? null : new URI(address);
|
||||
return new Proxy(addressUri, noProxy);
|
||||
} catch (URISyntaxException e) {
|
||||
throw new PklException(ErrorMessages.create("invalidUri", address));
|
||||
}
|
||||
} else {
|
||||
throw PklBugException.unreachableCode();
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
|
||||
* Copyright © 2024-2025 Apple Inc. and the Pkl project authors. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -13,24 +13,19 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.pkl.core.module;
|
||||
package org.pkl.core.externalreader;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.util.List;
|
||||
import org.pkl.core.SecurityManager;
|
||||
import org.pkl.core.SecurityManagerException;
|
||||
import org.pkl.core.messaging.MessageTransport;
|
||||
import org.pkl.core.module.PathElement;
|
||||
|
||||
public interface ExternalModuleResolver {
|
||||
|
||||
interface Spec {
|
||||
boolean hasHierarchicalUris();
|
||||
|
||||
boolean isGlobbable();
|
||||
|
||||
boolean isLocal();
|
||||
|
||||
String scheme();
|
||||
static ExternalModuleResolver of(MessageTransport transport, long evaluatorId) {
|
||||
return new ExternalModuleResolverImpl(transport, evaluatorId);
|
||||
}
|
||||
|
||||
String resolveModule(SecurityManager securityManager, URI uri)
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
|
||||
* Copyright © 2024-2025 Apple Inc. and the Pkl project authors. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.pkl.core.messaging;
|
||||
package org.pkl.core.externalreader;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
@@ -26,21 +26,23 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.Future;
|
||||
import org.pkl.core.SecurityManager;
|
||||
import org.pkl.core.SecurityManagerException;
|
||||
import org.pkl.core.messaging.MessageTransport;
|
||||
import org.pkl.core.messaging.MessageTransports;
|
||||
import org.pkl.core.messaging.Messages.ListModulesRequest;
|
||||
import org.pkl.core.messaging.Messages.ListModulesResponse;
|
||||
import org.pkl.core.messaging.Messages.ReadModuleRequest;
|
||||
import org.pkl.core.messaging.Messages.ReadModuleResponse;
|
||||
import org.pkl.core.module.ExternalModuleResolver;
|
||||
import org.pkl.core.messaging.ProtocolException;
|
||||
import org.pkl.core.module.PathElement;
|
||||
|
||||
public class MessageTransportModuleResolver implements ExternalModuleResolver {
|
||||
final class ExternalModuleResolverImpl implements ExternalModuleResolver {
|
||||
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();
|
||||
|
||||
public MessageTransportModuleResolver(MessageTransport transport, long evaluatorId) {
|
||||
ExternalModuleResolverImpl(MessageTransport transport, long evaluatorId) {
|
||||
this.transport = transport;
|
||||
this.evaluatorId = evaluatorId;
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
|
||||
* Copyright © 2024-2025 Apple Inc. and the Pkl project authors. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
|
||||
* Copyright © 2024-2025 Apple Inc. and the Pkl project authors. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -23,35 +23,33 @@ import org.pkl.core.util.Nullable;
|
||||
final class ExternalReaderMessages {
|
||||
private ExternalReaderMessages() {}
|
||||
|
||||
public record InitializeModuleReaderRequest(long requestId, String scheme)
|
||||
implements Server.Request {
|
||||
record InitializeModuleReaderRequest(long requestId, String scheme) implements Server.Request {
|
||||
public Type type() {
|
||||
return Type.INITIALIZE_MODULE_READER_REQUEST;
|
||||
}
|
||||
}
|
||||
|
||||
public record InitializeResourceReaderRequest(long requestId, String scheme)
|
||||
implements Server.Request {
|
||||
record InitializeResourceReaderRequest(long requestId, String scheme) implements Server.Request {
|
||||
public Type type() {
|
||||
return Type.INITIALIZE_RESOURCE_READER_REQUEST;
|
||||
}
|
||||
}
|
||||
|
||||
public record InitializeModuleReaderResponse(long requestId, @Nullable ModuleReaderSpec spec)
|
||||
record InitializeModuleReaderResponse(long requestId, @Nullable ModuleReaderSpec spec)
|
||||
implements Client.Response {
|
||||
public Type type() {
|
||||
return Type.INITIALIZE_MODULE_READER_RESPONSE;
|
||||
}
|
||||
}
|
||||
|
||||
public record InitializeResourceReaderResponse(long requestId, @Nullable ResourceReaderSpec spec)
|
||||
record InitializeResourceReaderResponse(long requestId, @Nullable ResourceReaderSpec spec)
|
||||
implements Client.Response {
|
||||
public Type type() {
|
||||
return Type.INITIALIZE_RESOURCE_READER_RESPONSE;
|
||||
}
|
||||
}
|
||||
|
||||
public record CloseExternalProcess() implements Server.OneWay {
|
||||
record CloseExternalProcess() implements Server.OneWay {
|
||||
public Type type() {
|
||||
return Type.CLOSE_EXTERNAL_PROCESS;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
|
||||
* Copyright © 2024-2025 Apple Inc. and the Pkl project authors. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -17,8 +17,6 @@ package org.pkl.core.externalreader;
|
||||
|
||||
import java.io.IOException;
|
||||
import org.pkl.core.evaluatorSettings.PklEvaluatorSettings.ExternalReader;
|
||||
import org.pkl.core.module.ExternalModuleResolver;
|
||||
import org.pkl.core.resource.ExternalResourceResolver;
|
||||
import org.pkl.core.util.Nullable;
|
||||
|
||||
/** An external process that reads Pkl modules and resources. */
|
||||
@@ -56,7 +54,8 @@ public interface ExternalReaderProcess extends AutoCloseable {
|
||||
* @throws IllegalStateException if this process has already been {@linkplain #close closed}
|
||||
* @throws IOException if an I/O error occurs
|
||||
*/
|
||||
ExternalModuleResolver.@Nullable Spec getModuleReaderSpec(String scheme) throws IOException;
|
||||
@Nullable
|
||||
ModuleReaderSpec getModuleReaderSpec(String scheme) throws IOException;
|
||||
|
||||
/**
|
||||
* Returns the spec, if available, of this process's resource reader with the given scheme.
|
||||
@@ -64,7 +63,8 @@ public interface ExternalReaderProcess extends AutoCloseable {
|
||||
* @throws IllegalStateException if this process has already been {@linkplain #close closed}
|
||||
* @throws IOException if an I/O error occurs
|
||||
*/
|
||||
ExternalResourceResolver.@Nullable Spec getResourceReaderSpec(String scheme) throws IOException;
|
||||
@Nullable
|
||||
ResourceReaderSpec getResourceReaderSpec(String scheme) throws IOException;
|
||||
|
||||
/**
|
||||
* Closes this process, releasing any associated resources.
|
||||
|
||||
@@ -30,12 +30,8 @@ import javax.annotation.concurrent.GuardedBy;
|
||||
import org.pkl.core.evaluatorSettings.PklEvaluatorSettings.ExternalReader;
|
||||
import org.pkl.core.externalreader.ExternalReaderMessages.*;
|
||||
import org.pkl.core.messaging.MessageTransport;
|
||||
import org.pkl.core.messaging.MessageTransportModuleResolver;
|
||||
import org.pkl.core.messaging.MessageTransportResourceResolver;
|
||||
import org.pkl.core.messaging.MessageTransports;
|
||||
import org.pkl.core.messaging.ProtocolException;
|
||||
import org.pkl.core.module.ExternalModuleResolver;
|
||||
import org.pkl.core.resource.ExternalResourceResolver;
|
||||
import org.pkl.core.util.ErrorMessages;
|
||||
import org.pkl.core.util.LateInit;
|
||||
import org.pkl.core.util.Nullable;
|
||||
@@ -46,9 +42,9 @@ final class ExternalReaderProcessImpl implements ExternalReaderProcess {
|
||||
|
||||
private final ExternalReader spec;
|
||||
private final @Nullable String logPrefix;
|
||||
private final Map<String, Future<ExternalModuleResolver.@Nullable Spec>>
|
||||
initializeModuleReaderResponses = new ConcurrentHashMap<>();
|
||||
private final Map<String, Future<ExternalResourceResolver.@Nullable Spec>>
|
||||
private final Map<String, Future<@Nullable ModuleReaderSpec>> initializeModuleReaderResponses =
|
||||
new ConcurrentHashMap<>();
|
||||
private final Map<String, Future<@Nullable ResourceReaderSpec>>
|
||||
initializeResourceReaderResponses = new ConcurrentHashMap<>();
|
||||
private final Random requestIdGenerator = new Random();
|
||||
|
||||
@@ -80,13 +76,13 @@ final class ExternalReaderProcessImpl implements ExternalReaderProcess {
|
||||
@Override
|
||||
public ExternalModuleResolver getModuleResolver(long evaluatorId)
|
||||
throws ExternalReaderProcessException {
|
||||
return new MessageTransportModuleResolver(getTransport(), evaluatorId);
|
||||
return ExternalModuleResolver.of(getTransport(), evaluatorId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExternalResourceResolver getResourceResolver(long evaluatorId)
|
||||
throws ExternalReaderProcessException {
|
||||
return new MessageTransportResourceResolver(getTransport(), evaluatorId);
|
||||
return ExternalResourceResolver.of(getTransport(), evaluatorId);
|
||||
}
|
||||
|
||||
private MessageTransport getTransport() throws ExternalReaderProcessException {
|
||||
@@ -175,13 +171,12 @@ final class ExternalReaderProcessImpl implements ExternalReaderProcess {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExternalModuleResolver.@Nullable Spec getModuleReaderSpec(String uriScheme)
|
||||
throws IOException {
|
||||
public ModuleReaderSpec getModuleReaderSpec(String uriScheme) throws IOException {
|
||||
return MessageTransports.resolveFuture(
|
||||
initializeModuleReaderResponses.computeIfAbsent(
|
||||
uriScheme,
|
||||
(scheme) -> {
|
||||
var future = new CompletableFuture<ExternalModuleResolver.@Nullable Spec>();
|
||||
var future = new CompletableFuture<@Nullable ModuleReaderSpec>();
|
||||
var request =
|
||||
new InitializeModuleReaderRequest(requestIdGenerator.nextLong(), scheme);
|
||||
try {
|
||||
@@ -190,7 +185,15 @@ final class ExternalReaderProcessImpl implements ExternalReaderProcess {
|
||||
request,
|
||||
(response) -> {
|
||||
if (response instanceof InitializeModuleReaderResponse resp) {
|
||||
future.complete(resp.spec());
|
||||
var spec =
|
||||
resp.spec() == null
|
||||
? null
|
||||
: new ModuleReaderSpec(
|
||||
resp.spec().scheme(),
|
||||
resp.spec().hasHierarchicalUris(),
|
||||
resp.spec().isLocal(),
|
||||
resp.spec().isGlobbable());
|
||||
future.complete(spec);
|
||||
} else {
|
||||
future.completeExceptionally(
|
||||
new ProtocolException("unexpected response"));
|
||||
@@ -204,13 +207,12 @@ final class ExternalReaderProcessImpl implements ExternalReaderProcess {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExternalResourceResolver.@Nullable Spec getResourceReaderSpec(String uriScheme)
|
||||
throws IOException {
|
||||
public ResourceReaderSpec getResourceReaderSpec(String uriScheme) throws IOException {
|
||||
return MessageTransports.resolveFuture(
|
||||
initializeResourceReaderResponses.computeIfAbsent(
|
||||
uriScheme,
|
||||
(scheme) -> {
|
||||
var future = new CompletableFuture<ExternalResourceResolver.@Nullable Spec>();
|
||||
var future = new CompletableFuture<@Nullable ResourceReaderSpec>();
|
||||
var request =
|
||||
new InitializeResourceReaderRequest(requestIdGenerator.nextLong(), scheme);
|
||||
try {
|
||||
@@ -220,7 +222,14 @@ final class ExternalReaderProcessImpl implements ExternalReaderProcess {
|
||||
(response) -> {
|
||||
log(response.toString());
|
||||
if (response instanceof InitializeResourceReaderResponse resp) {
|
||||
future.complete(resp.spec());
|
||||
var spec =
|
||||
resp.spec() == null
|
||||
? null
|
||||
: new ResourceReaderSpec(
|
||||
resp.spec().scheme(),
|
||||
resp.spec().hasHierarchicalUris(),
|
||||
resp.spec().isGlobbable());
|
||||
future.complete(spec);
|
||||
} else {
|
||||
future.completeExceptionally(
|
||||
new ProtocolException("unexpected response"));
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
|
||||
* Copyright © 2024-2025 Apple Inc. and the Pkl project authors. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.pkl.core.resource;
|
||||
package org.pkl.core.externalreader;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
@@ -21,16 +21,12 @@ import java.util.List;
|
||||
import java.util.Optional;
|
||||
import org.pkl.core.SecurityManager;
|
||||
import org.pkl.core.SecurityManagerException;
|
||||
import org.pkl.core.messaging.MessageTransport;
|
||||
import org.pkl.core.module.PathElement;
|
||||
|
||||
public interface ExternalResourceResolver {
|
||||
|
||||
interface Spec {
|
||||
boolean hasHierarchicalUris();
|
||||
|
||||
boolean isGlobbable();
|
||||
|
||||
String scheme();
|
||||
static ExternalResourceResolver of(MessageTransport transport, long evaluatorId) {
|
||||
return new ExternalResourceResolverImpl(transport, evaluatorId);
|
||||
}
|
||||
|
||||
Optional<Object> read(URI uri) throws IOException;
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
|
||||
* Copyright © 2024-2025 Apple Inc. and the Pkl project authors. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.pkl.core.messaging;
|
||||
package org.pkl.core.externalreader;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
@@ -27,19 +27,21 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.Future;
|
||||
import org.pkl.core.SecurityManager;
|
||||
import org.pkl.core.SecurityManagerException;
|
||||
import org.pkl.core.messaging.MessageTransport;
|
||||
import org.pkl.core.messaging.MessageTransports;
|
||||
import org.pkl.core.messaging.Messages.*;
|
||||
import org.pkl.core.messaging.ProtocolException;
|
||||
import org.pkl.core.module.PathElement;
|
||||
import org.pkl.core.resource.ExternalResourceResolver;
|
||||
import org.pkl.core.resource.Resource;
|
||||
|
||||
public class MessageTransportResourceResolver implements ExternalResourceResolver {
|
||||
final class ExternalResourceResolverImpl implements ExternalResourceResolver {
|
||||
private final MessageTransport transport;
|
||||
private final long evaluatorId;
|
||||
private final Map<URI, Future<byte[]>> readResponses = new ConcurrentHashMap<>();
|
||||
private final Map<URI, Future<List<PathElement>>> listResponses = new ConcurrentHashMap<>();
|
||||
private final Random requestIdGenerator = new Random();
|
||||
|
||||
public MessageTransportResourceResolver(MessageTransport transport, long evaluatorId) {
|
||||
ExternalResourceResolverImpl(MessageTransport transport, long evaluatorId) {
|
||||
this.transport = transport;
|
||||
this.evaluatorId = evaluatorId;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
* Copyright © 2024-2025 Apple Inc. and the Pkl project authors. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.pkl.core.externalreader;
|
||||
|
||||
public record ModuleReaderSpec(
|
||||
String scheme, boolean hasHierarchicalUris, boolean isLocal, boolean isGlobbable) {}
|
||||
@@ -0,0 +1,18 @@
|
||||
/*
|
||||
* Copyright © 2024-2025 Apple Inc. and the Pkl project authors. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.pkl.core.externalreader;
|
||||
|
||||
public record ResourceReaderSpec(String scheme, boolean hasHierarchicalUris, boolean isGlobbable) {}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
|
||||
* Copyright © 2024-2025 Apple Inc. and the Pkl project authors. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -20,20 +20,17 @@ import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import org.pkl.core.messaging.Message.*;
|
||||
import org.pkl.core.module.ExternalModuleResolver;
|
||||
import org.pkl.core.module.PathElement;
|
||||
import org.pkl.core.resource.ExternalResourceResolver;
|
||||
import org.pkl.core.util.Nullable;
|
||||
|
||||
public final class Messages {
|
||||
private Messages() {}
|
||||
|
||||
public record ModuleReaderSpec(
|
||||
String scheme, boolean hasHierarchicalUris, boolean isLocal, boolean isGlobbable)
|
||||
implements ExternalModuleResolver.Spec {}
|
||||
String scheme, boolean hasHierarchicalUris, boolean isLocal, boolean isGlobbable) {}
|
||||
|
||||
public record ResourceReaderSpec(String scheme, boolean hasHierarchicalUris, boolean isGlobbable)
|
||||
implements ExternalResourceResolver.Spec {}
|
||||
public record ResourceReaderSpec(
|
||||
String scheme, boolean hasHierarchicalUris, boolean isGlobbable) {}
|
||||
|
||||
public record ListResourcesRequest(long requestId, long evaluatorId, URI uri)
|
||||
implements Server.Request {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
|
||||
* Copyright © 2024-2025 Apple Inc. and the Pkl project authors. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -28,6 +28,7 @@ import java.util.Optional;
|
||||
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.util.ErrorMessages;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
|
||||
* Copyright © 2024-2025 Apple Inc. and the Pkl project authors. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -29,7 +29,9 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import org.pkl.core.SecurityManager;
|
||||
import org.pkl.core.SecurityManagerException;
|
||||
import org.pkl.core.externalreader.ExternalModuleResolver;
|
||||
import org.pkl.core.externalreader.ExternalReaderProcessException;
|
||||
import org.pkl.core.externalreader.ModuleReaderSpec;
|
||||
import org.pkl.core.packages.Dependency;
|
||||
import org.pkl.core.packages.Dependency.LocalDependency;
|
||||
import org.pkl.core.packages.PackageAssetUri;
|
||||
@@ -130,7 +132,7 @@ public final class ModuleKeys {
|
||||
|
||||
/** Creates a module key for an externally read module. */
|
||||
public static ModuleKey externalResolver(
|
||||
URI uri, ExternalModuleResolver.Spec spec, ExternalModuleResolver resolver) {
|
||||
URI uri, ModuleReaderSpec spec, ExternalModuleResolver resolver) {
|
||||
return new ExternalResolver(uri, spec, resolver);
|
||||
}
|
||||
|
||||
@@ -778,10 +780,10 @@ public final class ModuleKeys {
|
||||
public static class ExternalResolver implements ModuleKey {
|
||||
|
||||
private final URI uri;
|
||||
private final ExternalModuleResolver.Spec spec;
|
||||
private final ModuleReaderSpec spec;
|
||||
private final ExternalModuleResolver resolver;
|
||||
|
||||
ExternalResolver(URI uri, ExternalModuleResolver.Spec spec, ExternalModuleResolver resolver) {
|
||||
ExternalResolver(URI uri, ModuleReaderSpec spec, ExternalModuleResolver resolver) {
|
||||
this.uri = uri;
|
||||
this.spec = spec;
|
||||
this.resolver = resolver;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
|
||||
* Copyright © 2024-2025 Apple Inc. and the Pkl project authors. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -31,6 +31,8 @@ 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.ExternalResourceResolver;
|
||||
import org.pkl.core.externalreader.ResourceReaderSpec;
|
||||
import org.pkl.core.module.FileResolver;
|
||||
import org.pkl.core.module.ModulePathResolver;
|
||||
import org.pkl.core.module.PathElement;
|
||||
@@ -162,7 +164,7 @@ public final class ResourceReaders {
|
||||
|
||||
/** Returns a reader for external and client reader resources. */
|
||||
public static ResourceReader externalResolver(
|
||||
ExternalResourceResolver.Spec spec, ExternalResourceResolver resolver) {
|
||||
ResourceReaderSpec spec, ExternalResourceResolver resolver) {
|
||||
return new ExternalResolver(spec, resolver);
|
||||
}
|
||||
|
||||
@@ -691,11 +693,10 @@ public final class ResourceReaders {
|
||||
}
|
||||
|
||||
private static final class ExternalResolver implements ResourceReader {
|
||||
private final ExternalResourceResolver.Spec readerSpec;
|
||||
private final ResourceReaderSpec readerSpec;
|
||||
private final ExternalResourceResolver resolver;
|
||||
|
||||
public ExternalResolver(
|
||||
ExternalResourceResolver.Spec readerSpec, ExternalResourceResolver resolver) {
|
||||
public ExternalResolver(ResourceReaderSpec readerSpec, ExternalResourceResolver resolver) {
|
||||
this.readerSpec = readerSpec;
|
||||
this.resolver = resolver;
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ import org.pkl.core.util.IoUtils;
|
||||
public class VmImportAnalyzer {
|
||||
@TruffleBoundary
|
||||
public static ImportGraph analyze(URI[] moduleUris, VmContext context)
|
||||
throws IOException, SecurityManagerException {
|
||||
throws IOException, SecurityManagerException, ExternalReaderProcessException {
|
||||
var imports = new TreeMap<URI, Set<ImportGraph.Import>>();
|
||||
var resolvedImports = new TreeMap<URI, URI>();
|
||||
for (var moduleUri : moduleUris) {
|
||||
|
||||
@@ -23,6 +23,7 @@ import java.net.URISyntaxException;
|
||||
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.packages.PackageLoadError;
|
||||
import org.pkl.core.runtime.AnalyzeModule;
|
||||
import org.pkl.core.runtime.VmContext;
|
||||
@@ -91,7 +92,10 @@ public final class AnalyzeNodes {
|
||||
try {
|
||||
var results = VmImportAnalyzer.analyze(uris, context);
|
||||
return importGraphFactory.create(results);
|
||||
} catch (IOException | SecurityManagerException | PackageLoadError e) {
|
||||
} catch (IOException
|
||||
| SecurityManagerException
|
||||
| PackageLoadError
|
||||
| ExternalReaderProcessException e) {
|
||||
throw exceptionBuilder().withCause(e).build();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user