From c39d93ef1259eee584a0a71aea1794bc4136f18c Mon Sep 17 00:00:00 2001 From: AlexisDrogoul Date: Sun, 27 Oct 2024 23:00:50 +0700 Subject: [PATCH] Update FileUtils.java Make sure we do not raise an error when no file is found using the workspace --- .../src/gama/core/common/util/FileUtils.java | 32 +++++++------------ 1 file changed, 11 insertions(+), 21 deletions(-) diff --git a/gama.core/src/gama/core/common/util/FileUtils.java b/gama.core/src/gama/core/common/util/FileUtils.java index 51358dca91..6973a8c606 100644 --- a/gama.core/src/gama/core/common/util/FileUtils.java +++ b/gama.core/src/gama/core/common/util/FileUtils.java @@ -9,8 +9,6 @@ ********************************************************************************************************/ package gama.core.common.util; -import static java.util.stream.Collectors.toList; - import java.io.File; import java.io.IOException; import java.io.InputStream; @@ -19,7 +17,6 @@ import java.net.URLDecoder; import java.nio.file.Files; import java.nio.file.Paths; -import java.util.List; import org.eclipse.core.filesystem.EFS; import org.eclipse.core.filesystem.IFileInfo; @@ -160,13 +157,14 @@ static public String constructAbsoluteFilePath(final IScope scope, final String if (a == null) return fp; if (!a.isHeadless()) { // Necessary to ask the workspace for the containers as projects might be linked - final List paths = a.getWorkingPaths().stream() - .map(s -> ROOT.findContainersForLocation(new Path(s))[0]).collect(toList()); - for (final IContainer folder : paths) { - final String file = findInWorkspace(fp, folder, mustExist); - if (file != null) { - DEBUG.OUT("Hit with workspace-based search: " + file); - return file; + for (final String folder : a.getWorkingPaths()) { + IContainer[] containers = ROOT.findContainersForLocation(new Path(folder)); + for (IContainer container : containers) { + final String file = findInWorkspace(fp, container, mustExist); + if (file != null) { + DEBUG.OUT("Hit with workspace-based search: " + file); + return file; + } } } } @@ -419,10 +417,9 @@ public static URI getURI(final String target, final URI existingResource) { return null; } } - - public static String escapeFilePath(String path) { - return path .replace("\\", "\\\\") - .replace("\"", "\\\""); + + public static String escapeFilePath(final String path) { + return path.replace("\\", "\\\\").replace("\"", "\\\""); } /** @@ -479,13 +476,6 @@ public static IContainer getFolder(final String path, final URI root, final bool return null; } - // public static IFile linkAndGetExternalFile(final URI uri, final URI - // workspaceResource) { - // final String path = URI.decode(uri.isFile() ? uri.toFileString() : - // uri.toString()); - // return linkAndGetExternalFile(URI.decode(path), workspaceResource); - // } - /** * Creates the linked file. *