Change loading of external readers (#1394)
This introduces breaking changes for external readers are loaded: 1. In PklProject, relative paths are resolved relative to the enclosing PklProject file (make behavior consistent with how other settings work) 2. Make CLI flags blow away any settings set on a PklProject 3. Introduce a new `workingDir` property, which defaults to the PklProject dir The overall goal is to make this behavior consistent with how other settings work. For example, relative paths for other evaluator settings are already relative to the project directory. Additionally, in every other case, CLI flags will overwrite any setting set within PklProject.
This commit is contained in:
1 parent
c9f3823952
commit
035ef0a789
51 files changed
+1880
-92
No files matched your search
@@ -488,7 +488,7 @@ public final class EvaluatorBuilder {
|
||||
*/
|
||||
public EvaluatorBuilder applyFromProject(Project project) {
|
||||
this.dependencies = project.getDependencies();
|
||||
var settings = project.getEvaluatorSettings();
|
||||
var settings = project.getResolvedEvaluatorSettings();
|
||||
if (securityManager != null) {
|
||||
throw new IllegalStateException(
|
||||
"Cannot call both `setSecurityManager` and `setProject`, because both define security manager settings. Call `setProjectOnly` if the security manager is desired.");
|
||||
|
||||
@@ -26,7 +26,6 @@ import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Objects;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
import org.jspecify.annotations.Nullable;
|
||||
@@ -57,17 +56,13 @@ public record PklEvaluatorSettings(
|
||||
|
||||
/** Initializes a {@link PklEvaluatorSettings} from a raw object representation. */
|
||||
@SuppressWarnings("unchecked")
|
||||
public static PklEvaluatorSettings parse(
|
||||
Value input, BiFunction<? super String, ? super String, Path> pathNormalizer) {
|
||||
public static PklEvaluatorSettings parse(Value input) {
|
||||
if (!(input instanceof PObject pSettings)) {
|
||||
throw PklBugException.unreachableCode();
|
||||
}
|
||||
|
||||
var moduleCacheDirStr = (String) pSettings.get("moduleCacheDir");
|
||||
var moduleCacheDir =
|
||||
moduleCacheDirStr == null
|
||||
? null
|
||||
: pathNormalizer.apply(moduleCacheDirStr, "moduleCacheDir");
|
||||
var moduleCacheDir = moduleCacheDirStr == null ? null : Path.of(moduleCacheDirStr);
|
||||
|
||||
var allowedModulesStrs = (List<String>) pSettings.get("allowedModules");
|
||||
var allowedModules =
|
||||
@@ -82,13 +77,10 @@ public record PklEvaluatorSettings(
|
||||
: allowedResourcesStrs.stream().map(Pattern::compile).toList();
|
||||
|
||||
var modulePathStrs = (List<String>) pSettings.get("modulePath");
|
||||
var modulePath =
|
||||
modulePathStrs == null
|
||||
? null
|
||||
: modulePathStrs.stream().map(it -> pathNormalizer.apply(it, "modulePath")).toList();
|
||||
var modulePath = modulePathStrs == null ? null : modulePathStrs.stream().map(Path::of).toList();
|
||||
|
||||
var rootDirStr = (String) pSettings.get("rootDir");
|
||||
var rootDir = rootDirStr == null ? null : pathNormalizer.apply(rootDirStr, "rootDir");
|
||||
var rootDir = rootDirStr == null ? null : Path.of(rootDirStr);
|
||||
|
||||
var externalModuleReadersRaw = (Map<String, Value>) pSettings.get("externalModuleReaders");
|
||||
var externalModuleReaders =
|
||||
@@ -219,13 +211,16 @@ public record PklEvaluatorSettings(
|
||||
}
|
||||
}
|
||||
|
||||
public record ExternalReader(String executable, @Nullable List<String> arguments) {
|
||||
public record ExternalReader(
|
||||
String executable, @Nullable List<String> arguments, @Nullable String workingDir) {
|
||||
@SuppressWarnings("unchecked")
|
||||
public static ExternalReader parse(Value input) {
|
||||
if (input instanceof PObject externalReader) {
|
||||
var executable = (String) externalReader.getProperty("executable");
|
||||
var arguments = (List<String>) externalReader.get("arguments");
|
||||
return new ExternalReader(executable, arguments);
|
||||
var workingDir = externalReader.getProperty("workingDir");
|
||||
return new ExternalReader(
|
||||
executable, arguments, workingDir instanceof PNull ? null : (String) workingDir);
|
||||
}
|
||||
throw PklBugException.unreachableCode();
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
package org.pkl.core.externalreader;
|
||||
|
||||
import com.google.errorprone.annotations.concurrent.GuardedBy;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.ProcessBuilder.Redirect;
|
||||
import java.time.Duration;
|
||||
@@ -105,6 +106,10 @@ final class ExternalReaderProcessImpl implements ExternalReaderProcess {
|
||||
}
|
||||
|
||||
var builder = new ProcessBuilder(command);
|
||||
var workingDir = spec.workingDir();
|
||||
if (workingDir != null) {
|
||||
builder.directory(new File(workingDir));
|
||||
}
|
||||
builder.redirectError(Redirect.INHERIT); // inherit stderr from this pkl process
|
||||
try {
|
||||
process = builder.start();
|
||||
|
||||
@@ -62,6 +62,7 @@ public final class Project {
|
||||
private final @Nullable Package pkg;
|
||||
private final DeclaredDependencies dependencies;
|
||||
private final PklEvaluatorSettings evaluatorSettings;
|
||||
private final PklEvaluatorSettings resolvedEvaluatorSettings;
|
||||
private final URI projectFileUri;
|
||||
private final URI projectBaseUri;
|
||||
private final List<URI> tests;
|
||||
@@ -290,7 +291,7 @@ public final class Project {
|
||||
|
||||
public static Project parseProject(PObject module) throws URISyntaxException {
|
||||
var pkgObj = getNullableProperty(module, "package");
|
||||
var projectFileUri = URI.create((String) module.getProperty("projectFileUri"));
|
||||
var projectFileUri = new URI((String) module.getProperty("projectFileUri"));
|
||||
var dependencies = parseDependencies(module, projectFileUri, null);
|
||||
var projectBaseUri = IoUtils.resolve(projectFileUri, ".");
|
||||
Package pkg = null;
|
||||
@@ -301,9 +302,14 @@ public final class Project {
|
||||
getProperty(
|
||||
module,
|
||||
"evaluatorSettings",
|
||||
(settings) ->
|
||||
PklEvaluatorSettings.parse(
|
||||
(Value) settings, (it, name) -> resolveNullablePath(it, projectBaseUri, name)));
|
||||
(settings) -> PklEvaluatorSettings.parse((Value) settings));
|
||||
|
||||
var resolvedEvaluatorSettings =
|
||||
getProperty(
|
||||
module,
|
||||
"resolvedEvaluatorSettings",
|
||||
(settings) -> PklEvaluatorSettings.parse((Value) settings));
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
var testPathStrs = (List<String>) getProperty(module, "tests");
|
||||
var tests =
|
||||
@@ -316,6 +322,7 @@ public final class Project {
|
||||
pkg,
|
||||
dependencies,
|
||||
evaluatorSettings,
|
||||
resolvedEvaluatorSettings,
|
||||
projectFileUri,
|
||||
projectBaseUri,
|
||||
tests,
|
||||
@@ -371,24 +378,6 @@ public final class Project {
|
||||
return new URI((String) value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve a path string against projectBaseUri.
|
||||
*
|
||||
* @throws PackageLoadError if projectBaseUri is not a {@code file:} URI.
|
||||
*/
|
||||
private static @Nullable Path resolveNullablePath(
|
||||
@Nullable String path, URI projectBaseUri, String propertyName) {
|
||||
if (path == null) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return Path.of(projectBaseUri).resolve(path).normalize();
|
||||
} catch (FileSystemNotFoundException e) {
|
||||
throw new PackageLoadError(
|
||||
"relativePathPropertyDefinedByProjectFromNonFileUri", projectBaseUri, propertyName);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static Package parsePackage(PObject pObj) throws URISyntaxException {
|
||||
var name = (String) pObj.getProperty("name");
|
||||
@@ -430,6 +419,7 @@ public final class Project {
|
||||
@Nullable Package pkg,
|
||||
DeclaredDependencies dependencies,
|
||||
PklEvaluatorSettings evaluatorSettings,
|
||||
PklEvaluatorSettings resolvedEvaluatorSettings,
|
||||
URI projectFileUri,
|
||||
URI projectBaseUri,
|
||||
List<URI> tests,
|
||||
@@ -438,6 +428,7 @@ public final class Project {
|
||||
this.pkg = pkg;
|
||||
this.dependencies = dependencies;
|
||||
this.evaluatorSettings = evaluatorSettings;
|
||||
this.resolvedEvaluatorSettings = resolvedEvaluatorSettings;
|
||||
this.projectFileUri = projectFileUri;
|
||||
this.projectBaseUri = projectBaseUri;
|
||||
this.tests = tests;
|
||||
@@ -459,6 +450,15 @@ public final class Project {
|
||||
return evaluatorSettings;
|
||||
}
|
||||
|
||||
/**
|
||||
* The evaluator settings whose paths have been resolved against the project dir.
|
||||
*
|
||||
* @since 0.32.0
|
||||
*/
|
||||
public PklEvaluatorSettings getResolvedEvaluatorSettings() {
|
||||
return resolvedEvaluatorSettings;
|
||||
}
|
||||
|
||||
public URI getProjectFileUri() {
|
||||
return projectFileUri;
|
||||
}
|
||||
@@ -488,6 +488,7 @@ public final class Project {
|
||||
return Objects.equals(pkg, project.pkg)
|
||||
&& dependencies.equals(project.dependencies)
|
||||
&& evaluatorSettings.equals(project.evaluatorSettings)
|
||||
&& resolvedEvaluatorSettings.equals(project.resolvedEvaluatorSettings)
|
||||
&& projectFileUri.equals(project.projectFileUri)
|
||||
&& tests.equals(project.tests)
|
||||
&& annotations.equals(project.annotations);
|
||||
@@ -495,7 +496,14 @@ public final class Project {
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(pkg, dependencies, evaluatorSettings, projectFileUri, tests, annotations);
|
||||
return Objects.hash(
|
||||
pkg,
|
||||
dependencies,
|
||||
evaluatorSettings,
|
||||
resolvedEvaluatorSettings,
|
||||
projectFileUri,
|
||||
tests,
|
||||
annotations);
|
||||
}
|
||||
|
||||
public DeclaredDependencies getDependencies() {
|
||||
@@ -506,6 +514,7 @@ public final class Project {
|
||||
return localProjectDependencies;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public URI getProjectBaseUri() {
|
||||
return projectBaseUri;
|
||||
}
|
||||
|
||||
@@ -1160,7 +1160,7 @@ public final class CommandSpecParser {
|
||||
var uri =
|
||||
IoUtils.isUriLike(moduleName)
|
||||
? new URI(moduleName)
|
||||
: IoUtils.isWindowsAbsolutePath(moduleName)
|
||||
: IoUtils.isWindows() && IoUtils.isWindowsAbsolutePath(moduleName)
|
||||
? Path.of(moduleName).toUri()
|
||||
: new URI(null, null, IoUtils.toNormalizedPathString(Path.of(moduleName)), null);
|
||||
uriString =
|
||||
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright © 2026 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.stdlib.evaluatorsettings;
|
||||
|
||||
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
|
||||
import com.oracle.truffle.api.dsl.Specialization;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import org.pkl.core.runtime.VmTyped;
|
||||
import org.pkl.core.stdlib.ExternalMethod3Node;
|
||||
import org.pkl.core.util.PathResolver;
|
||||
import org.pkl.core.util.PathResolvers;
|
||||
|
||||
public class EvaluatorSettingsNodes {
|
||||
|
||||
public abstract static class resolvePath extends ExternalMethod3Node {
|
||||
@TruffleBoundary
|
||||
private URI toUri(String baseUri) {
|
||||
try {
|
||||
var uri = new URI(baseUri);
|
||||
// guaranteed by Pkl
|
||||
assert uri.getScheme().equals("file");
|
||||
return uri;
|
||||
} catch (URISyntaxException e) {
|
||||
throw exceptionBuilder().evalError("invalidUri", baseUri).build();
|
||||
}
|
||||
}
|
||||
|
||||
private PathResolver getPathResolver(boolean forWindows) {
|
||||
return forWindows ? PathResolvers.forWindows() : PathResolvers.forPosix();
|
||||
}
|
||||
|
||||
@Specialization
|
||||
protected String eval(VmTyped ignored, String uriStr, String path, boolean forWindows) {
|
||||
var uri = toUri(uriStr);
|
||||
var baseUri = uri.resolve(".");
|
||||
var resolver = getPathResolver(forWindows);
|
||||
return resolver.resolvePath(baseUri, path);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
@NullMarked
|
||||
@PklName("EvaluatorSettings")
|
||||
package org.pkl.core.stdlib.evaluatorsettings;
|
||||
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
import org.pkl.core.stdlib.PklName;
|
||||
@@ -16,6 +16,7 @@
|
||||
package org.pkl.core.util;
|
||||
|
||||
import com.oracle.truffle.api.TruffleOptions;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
@@ -52,7 +53,7 @@ public final class IoUtils {
|
||||
// Don't match paths like `C:\`, which are drive letters on Windows.
|
||||
private static final Pattern uriLike = Pattern.compile("[\\w+.-]+:[^\\\\].*");
|
||||
|
||||
private static final Pattern windowsPathLike = Pattern.compile("\\w:\\\\.*");
|
||||
public static final Pattern windowsDriveLetterLike = Pattern.compile("[a-zA-Z]:.*");
|
||||
|
||||
private static final Pattern headerNameLike = Pattern.compile("[a-zA-Z0-9!#$%&'*+-.^_`|~]+");
|
||||
|
||||
@@ -107,8 +108,7 @@ public final class IoUtils {
|
||||
}
|
||||
|
||||
public static boolean isWindowsAbsolutePath(String str) {
|
||||
if (!isWindows()) return false;
|
||||
return windowsPathLike.matcher(str).matches();
|
||||
return windowsDriveLetterLike.matcher(str).matches();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -935,4 +935,44 @@ public final class IoUtils {
|
||||
ErrorMessages.create("invalidHttpHeaderValueTooLong", headerValue));
|
||||
}
|
||||
}
|
||||
|
||||
private static @Nullable String getFilenameExtension(String fileName) {
|
||||
var dotIndex = fileName.lastIndexOf('.');
|
||||
// 0 if hidden file (e.g. `.gitignore`); not an extension
|
||||
if (dotIndex == -1 || dotIndex == 0) {
|
||||
return null;
|
||||
}
|
||||
return fileName.substring(dotIndex + 1);
|
||||
}
|
||||
|
||||
public static @Nullable Path findExecutableOnPath(String executable) {
|
||||
var pathEnvVar = System.getenv("PATH");
|
||||
if (pathEnvVar == null) {
|
||||
return null;
|
||||
}
|
||||
var executableExtension = getFilenameExtension(executable);
|
||||
List<String> extensions;
|
||||
if (executableExtension != null || !isWindows()) {
|
||||
extensions = List.of("");
|
||||
} else {
|
||||
extensions = List.of(".exe", ".cmd", ".bat", ".com");
|
||||
}
|
||||
var pathDirs = pathEnvVar.split(File.pathSeparator);
|
||||
for (var dir : pathDirs) {
|
||||
for (var extension : extensions) {
|
||||
var candidate = Path.of(dir, executable + extension);
|
||||
if (Files.exists(candidate) && Files.isExecutable(candidate)) {
|
||||
return candidate;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static URI fixFileUri(URI uri) {
|
||||
if ("file".equals(uri.getScheme()) && !uri.getSchemeSpecificPart().startsWith("//")) {
|
||||
return URI.create("file://" + uri.getSchemeSpecificPart());
|
||||
}
|
||||
return uri;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,198 @@
|
||||
/*
|
||||
* Copyright © 2026 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.util;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.ArrayList;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
// These are implemented by hand instead of relying on the NIO Path API because the JDK does not
|
||||
// provide libraries for cross-platform resolvers.
|
||||
// For example, from POSIX systems, you cannot resolve Windows-style paths.
|
||||
// The alternative to this approach is to depend on a library (e.g. Apache Commons IO or jimfs).
|
||||
public abstract sealed class PathResolver {
|
||||
public final String resolvePath(URI uri, String path) {
|
||||
if (isAbsolute(path)) {
|
||||
return normalize(path);
|
||||
}
|
||||
var basePath = uriToPath(uri);
|
||||
var resolved = join(basePath, path);
|
||||
return normalize(resolved);
|
||||
}
|
||||
|
||||
protected abstract String uriToPath(URI uri);
|
||||
|
||||
protected abstract String join(String base, String path);
|
||||
|
||||
protected abstract boolean isAbsolute(String path);
|
||||
|
||||
protected abstract String getRoot(String path);
|
||||
|
||||
protected abstract char getSeparator();
|
||||
|
||||
protected String normalize(String path) {
|
||||
var root = getRoot(path);
|
||||
var separator = getSeparator();
|
||||
var remainder = path.substring(root.length());
|
||||
|
||||
var parts = remainder.split(Pattern.quote(((Character) separator).toString()));
|
||||
var stack = new ArrayList<>();
|
||||
|
||||
for (var part : parts) {
|
||||
if (part.equals("..")) {
|
||||
if (!stack.isEmpty()) {
|
||||
stack.remove(stack.size() - 1);
|
||||
}
|
||||
} else if (!part.isEmpty() && !part.equals(".")) {
|
||||
stack.add(part);
|
||||
}
|
||||
}
|
||||
|
||||
if (stack.isEmpty()) {
|
||||
return root;
|
||||
}
|
||||
|
||||
var sb = new StringBuilder(root);
|
||||
|
||||
for (var i = 0; i < stack.size(); i++) {
|
||||
if (i > 0) {
|
||||
sb.append(separator);
|
||||
}
|
||||
sb.append(stack.get(i));
|
||||
}
|
||||
// path ends with trailing separator
|
||||
if (parts[parts.length - 1].isEmpty()) {
|
||||
sb.append(separator);
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
static final class WindowsPathResolver extends PathResolver {
|
||||
@Override
|
||||
protected String uriToPath(URI uri) {
|
||||
var host = uri.getHost();
|
||||
var path = uri.getPath();
|
||||
if (host != null) {
|
||||
// UNC path: \\server\share\path
|
||||
return "\\\\%s%s".formatted(host, path.replace('/', '\\'));
|
||||
}
|
||||
var ret = path.matches("/[A-Z]:/.*") ? path.substring(1) : path;
|
||||
return ret.replace('/', '\\');
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isAbsolute(String path) {
|
||||
// Normalize forward slashes first
|
||||
path = path.replace('/', '\\');
|
||||
return isDriveLetter(path) || path.startsWith("\\\\");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String join(String base, String path) {
|
||||
path = path.replace('/', '\\');
|
||||
if (isAbsolute(path)) {
|
||||
return path;
|
||||
}
|
||||
if (path.startsWith("\\")) {
|
||||
// Root-relative path: skip the leading backslash to avoid double backslash
|
||||
return getRoot(base) + path;
|
||||
}
|
||||
if (base.endsWith("\\")) {
|
||||
return base + path;
|
||||
}
|
||||
return base + '\\' + path;
|
||||
}
|
||||
|
||||
private boolean isDriveLetter(String path) {
|
||||
return path.length() >= 2 && isAlpha(path.charAt(0)) && path.charAt(1) == ':';
|
||||
}
|
||||
|
||||
private boolean isAlpha(char character) {
|
||||
return character >= 65 && character <= 90 || character >= 97 && character <= 122;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getRoot(String path) {
|
||||
// UNC path, e.g. \\server\share
|
||||
if (path.startsWith("\\\\")) {
|
||||
var firstBackslash = path.indexOf('\\', 2);
|
||||
if (firstBackslash == -1) {
|
||||
// Malformed UNC, just return what we have
|
||||
return path;
|
||||
}
|
||||
var secondBackslash = path.indexOf('\\', firstBackslash + 1);
|
||||
if (secondBackslash == -1) {
|
||||
return path + "\\";
|
||||
}
|
||||
return path.substring(0, secondBackslash + 1);
|
||||
} else if (isDriveLetter(path)) {
|
||||
// drive letter without leading slash, e.g. `C:foo\bar` (uncommon but valid)
|
||||
if (path.length() > 2 && path.charAt(2) == '\\') {
|
||||
return path.substring(0, 3);
|
||||
}
|
||||
return path.substring(0, 2);
|
||||
} else if (path.startsWith("\\")) {
|
||||
// drive-relative path
|
||||
return "\\";
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected char getSeparator() {
|
||||
return '\\';
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String normalize(String path) {
|
||||
return super.normalize(path.replace('/', '\\'));
|
||||
}
|
||||
}
|
||||
|
||||
static final class PosixPathResolver extends PathResolver {
|
||||
@Override
|
||||
protected String uriToPath(URI uri) {
|
||||
return uri.getPath();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isAbsolute(String path) {
|
||||
return path.startsWith("/");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String join(String base, String path) {
|
||||
if (isAbsolute(path)) {
|
||||
return path;
|
||||
}
|
||||
if (base.endsWith("/")) {
|
||||
return base + path;
|
||||
}
|
||||
return base + '/' + path;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getRoot(String ignored) {
|
||||
return "/";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected char getSeparator() {
|
||||
return '/';
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright © 2026 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.util;
|
||||
|
||||
import org.pkl.core.util.PathResolver.PosixPathResolver;
|
||||
import org.pkl.core.util.PathResolver.WindowsPathResolver;
|
||||
|
||||
public final class PathResolvers {
|
||||
private PathResolvers() {}
|
||||
|
||||
private static final PathResolver WINDOWS = new WindowsPathResolver();
|
||||
|
||||
private static final PathResolver POSIX = new PosixPathResolver();
|
||||
|
||||
public static PathResolver forWindows() {
|
||||
return WINDOWS;
|
||||
}
|
||||
|
||||
public static PathResolver forPosix() {
|
||||
return POSIX;
|
||||
}
|
||||
}
|
||||
@@ -619,6 +619,9 @@ Cannot analyze relative module URI `{0}`.
|
||||
invalidModuleUri=\
|
||||
Module URI `{0}` has invalid syntax.
|
||||
|
||||
invalidUri=\
|
||||
URI `{0}` has invalid syntax.
|
||||
|
||||
invalidModuleUriMissingSlash=\
|
||||
Module URI `{0}` is missing a `/` after `{1}:`.
|
||||
|
||||
|
||||
Reference in new issue
Block a user