Repository: workcraft/workcraft
Issue: Use Normalised path for internal file references

Previously Absolute and Canonical paths were attempted.
The former does not eliminate redundant .. and . in the path.
The latter follows symbolic links in Unix file systems and may end up at a file with incorrect extension.
Normalised path seems to resolve both issues.
For example, this code would print `the/file`:
```
String path = Paths.get("path/../to/./../the/file").normalize().toString();
System.out.println(path);
```


Changed files:
workcraft/WorkcraftCore/src/org/workcraft/utils/WorkUtils.java, workcraft/WorkcraftCore/src/org/workcraft/utils/FileUtils.java, workcraft/WorkcraftCore/src/org/workcraft/utils/ExecutableUtils.java

diff --git a/workcraft/WorkcraftCore/src/org/workcraft/utils/ExecutableUtils.java b/workcraft/WorkcraftCore/src/org/workcraft/utils/ExecutableUtils.java
index 2ba44d64c..1580c6ad9 100644
--- a/workcraft/WorkcraftCore/src/org/workcraft/utils/ExecutableUtils.java
+++ b/workcraft/WorkcraftCore/src/org/workcraft/utils/ExecutableUtils.java
@@ -1,20 +1,12 @@
 package org.workcraft.utils;
 
 import java.io.File;
-import java.io.IOException;
 
 public class ExecutableUtils {
 
-    public static String getAbsoluteCommandPath(String toolName) {
-        File toolFile = new File(toolName);
-        if (toolFile.exists()) {
-            try {
-                return toolFile.getCanonicalPath();
-            } catch (IOException e) {
-                e.printStackTrace();
-            }
-        }
-        return toolFile.getPath();
+    public static String getAbsoluteCommandPath(String path) {
+        File file = new File(path);
+        return file.exists() ? file.getAbsolutePath() : file.getPath();
     }
 
 }
diff --git a/workcraft/WorkcraftCore/src/org/workcraft/utils/FileUtils.java b/workcraft/WorkcraftCore/src/org/workcraft/utils/FileUtils.java
index 938e04c45..d6078349a 100644
--- a/workcraft/WorkcraftCore/src/org/workcraft/utils/FileUtils.java
+++ b/workcraft/WorkcraftCore/src/org/workcraft/utils/FileUtils.java
@@ -291,24 +291,11 @@ public class FileUtils {
     }
 
     public static String getFullPath(File file) {
-        if (file == null) {
-            return null;
-        }
-        if (file.exists()) {
-            try {
-                return file.getCanonicalPath();
-            } catch (IOException e) {
-            }
-        }
-        return file.getAbsolutePath();
+        return file == null ? null : Paths.get(file.getAbsolutePath()).normalize().toString();
     }
 
     public static String getBasePath(File file) {
-        try {
-            return file.getCanonicalFile().getParent();
-        } catch (IOException e) {
-            return null;
-        }
+        return file == null ? null : Paths.get(file.getAbsolutePath()).normalize().getParent().toString();
     }
 
     public static String stripBase(String path, String base) {
@@ -349,17 +336,11 @@ public class FileUtils {
         if (path == null) {
             return null;
         }
-        File result = new File(path);
-        if (!result.isAbsolute()) {
-            result = new File(base, path);
-        }
-        if (result.exists()) {
-            try {
-                return result.getCanonicalFile();
-            } catch (IOException e) {
-            }
+        Path result = Paths.get(path);
+        if (!result.isAbsolute() && (base != null)) {
+            result = Paths.get(base, path);
         }
-        return result;
+        return result.normalize().toFile();
     }
 
     public static File getFileByAbsoluteOrRelativePath(String path, File directory) {
diff --git a/workcraft/WorkcraftCore/src/org/workcraft/utils/WorkUtils.java b/workcraft/WorkcraftCore/src/org/workcraft/utils/WorkUtils.java
index c0991c009..20c245e13 100644
--- a/workcraft/WorkcraftCore/src/org/workcraft/utils/WorkUtils.java
+++ b/workcraft/WorkcraftCore/src/org/workcraft/utils/WorkUtils.java
@@ -117,9 +117,9 @@ public final class WorkUtils {
                     CompatibilityManager cm = framework.getCompatibilityManager();
                     InputStream is = cm.process(file);
                     me = loadModel(is);
-                    String base = file.getCanonicalFile().getParent();
+                    String base = FileUtils.getBasePath(file);
                     adjustPropertyFilePaths(me.getVisualModel(), base, true);
-                } catch (OperationCancelledException | IOException e) {
+                } catch (OperationCancelledException e) {
                     // Operation cancelled by the user
                 }
             } else {
@@ -354,7 +354,7 @@ public final class WorkUtils {
 
         try {
             FileOutputStream os = new FileOutputStream(file);
-            String base = file.getCanonicalFile().getParent();
+            String base = FileUtils.getBasePath(file);
             adjustPropertyFilePaths(me.getVisualModel(), base, false);
             Collection<Resource> adjustedResources = adjustResourceFilePaths(resources, base, false);
             saveModel(me, adjustedResources, os);