Skip to content

Commit c7f4110

Browse files
committed
[GR-55014] Make VFS.resourcePathToPlatformPath public again with deprecation.
PullRequest: graalpython/3386
2 parents 215ed99 + 305c392 commit c7f4110

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

graalpython/graalpy-maven-plugin/src/main/java/org/graalvm/python/maven/plugin/ManageResourcesMojo.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,14 @@ public void execute() throws MojoExecutionException {
155155
if (Files.exists(Path.of(r.getDirectory(), VFS_ROOT, "proj"))) {
156156
getLog().warn(String.format("usage of %s is deprecated, use %s instead", Path.of(VFS_ROOT, "proj"), Path.of(VFS_ROOT, "src")));
157157
}
158+
if (!Files.exists(Path.of(r.getDirectory(), VFS_ROOT)) && Files.exists(Path.of(r.getDirectory(), "vfs", "proj"))) {
159+
// there isn't the actual vfs resource root "org.graalvm.python.vfs" (VFS_ROOT), and there is only the outdated "vfs/proj"
160+
// => looks like a project created < 24.1.0
161+
throw new MojoExecutionException(String.format(
162+
"Wrong virtual filesystem root!\n" +
163+
"Since 24.1.0 the virtual filesystem root has to be '%s'.\n" +
164+
"Please rename the resource directory '%s' to '%s'", VFS_ROOT, Path.of(r.getDirectory(), "vfs"), Path.of(r.getDirectory(), VFS_ROOT)));
165+
}
158166
}
159167

160168
}

graalpython/org.graalvm.python.embedding/src/org/graalvm/python/embedding/utils/VirtualFileSystem.java

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -404,14 +404,27 @@ String vfsVenvPath() {
404404
return resourcePathToPlatformPath(VENV_PREFIX);
405405
}
406406

407-
private String resourcePathToPlatformPath(String inputPath) {
408-
assert inputPath.length() > VFS_ROOT.length() && inputPath.startsWith(VFS_ROOT) : "inputPath expected to start with '" + VFS_ROOT + "' but was '" + inputPath + "'";
409-
var path = inputPath.substring(VFS_ROOT.length() + 1);
407+
/**
408+
* Converts the given path starting with the internal resource root to the path as seen by
409+
* Python IO. For example if no other mount point was set then the path
410+
* "/org.graalvm.python.vfs/src/hello.py" will be converted to the default mount point
411+
* "/graalpy_vfs/src/hello.py" .
412+
*
413+
* @deprecated use {@link #getMountPoint()} instead
414+
*/
415+
@Deprecated
416+
public String resourcePathToPlatformPath(String resourcePath) {
417+
if (!(resourcePath.length() > VFS_ROOT.length() && resourcePath.startsWith(VFS_ROOT))) {
418+
String msg = "Resource path is expected to start with '" + VFS_ROOT + "' but was '" + resourcePath + "'.\n" +
419+
"Please also ensure that your virtual file system resources root directory is '" + VFS_ROOT + "'";
420+
throw new IllegalArgumentException(msg);
421+
}
422+
var path = resourcePath.substring(VFS_ROOT.length() + 1);
410423
if (!PLATFORM_SEPARATOR.equals(RESOURCE_SEPARATOR)) {
411424
path = path.replace(RESOURCE_SEPARATOR, PLATFORM_SEPARATOR);
412425
}
413426
String absolute = mountPoint.resolve(path).toString();
414-
if (inputPath.endsWith(RESOURCE_SEPARATOR) && !absolute.endsWith(PLATFORM_SEPARATOR)) {
427+
if (resourcePath.endsWith(RESOURCE_SEPARATOR) && !absolute.endsWith(PLATFORM_SEPARATOR)) {
415428
absolute += PLATFORM_SEPARATOR;
416429
}
417430
return absolute;

0 commit comments

Comments
 (0)