From a0a56007e5ab807bd99c7cb4ca7cd832a6beaa72 Mon Sep 17 00:00:00 2001 From: Josh Tynjala Date: Thu, 25 Jan 2024 09:34:57 -0800 Subject: [PATCH] asconfigc: fix issues with mainClass file resolution (close #726) Fixes quick compile commands by restoring relative paths. Absolute paths with spaces could not be parsed by FCSH. Fixes mainClass resolution when no source-path compiler option is specified by checking relative to project root. Restores final fallback cwd mainClass resolution (which started incorrectly resolving from the project root). --- .../as3mxml/asconfigc/utils/ConfigUtils.java | 52 ++++++++++++++----- 1 file changed, 40 insertions(+), 12 deletions(-) diff --git a/asconfigc/src/main/java/com/as3mxml/asconfigc/utils/ConfigUtils.java b/asconfigc/src/main/java/com/as3mxml/asconfigc/utils/ConfigUtils.java index 4b4af3a33..ee5b7f806 100644 --- a/asconfigc/src/main/java/com/as3mxml/asconfigc/utils/ConfigUtils.java +++ b/asconfigc/src/main/java/com/as3mxml/asconfigc/utils/ConfigUtils.java @@ -49,33 +49,61 @@ public static String resolveMainClass(String mainClass, List sourcePaths for (String sourcePath : sourcePaths) { Path sourcePathPath = Paths.get(sourcePath); Path mainClassPathAS = sourcePathPath.resolve(mainClassBasePath + FILE_EXTENSION_AS); - if (!mainClassPathAS.isAbsolute() && rootWorkspacePath != null) { - mainClassPathAS = Paths.get(rootWorkspacePath).resolve(mainClassPathAS); + Path absoluteMainClassPathAS = mainClassPathAS; + if (!absoluteMainClassPathAS.isAbsolute() && rootWorkspacePath != null) { + absoluteMainClassPathAS = Paths.get(rootWorkspacePath).resolve(absoluteMainClassPathAS); } - if (mainClassPathAS.toFile().exists()) { + if (absoluteMainClassPathAS.toFile().exists()) { + // verify that the absolute path exists, but return the + // relative path instead. + // this keeps the compile command smaller, but it also + // reduces the possibility of spaces appearing in the + // compile command options. + // FCSH doesn't like paths with spaces. + // see BowlerHatLLC/vscode-as3mxml#726 return mainClassPathAS.toString(); } Path mainClassPathMXML = sourcePathPath.resolve(mainClassBasePath + FILE_EXTENSION_MXML); - if (!mainClassPathMXML.isAbsolute() && rootWorkspacePath != null) { - mainClassPathMXML = Paths.get(rootWorkspacePath).resolve(mainClassPathMXML); + Path absoluteMainClassPathMXML = mainClassPathMXML; + if (!absoluteMainClassPathMXML.isAbsolute() && rootWorkspacePath != null) { + absoluteMainClassPathMXML = Paths.get(rootWorkspacePath).resolve(absoluteMainClassPathMXML); } - if (mainClassPathMXML.toFile().exists()) { + if (absoluteMainClassPathMXML.toFile().exists()) { + // verify that the absolute path exists, but return the + // relative path instead. see note above. return mainClassPathMXML.toString(); } } + } else { + // no source paths, so assume the root of the project (which is the + // same directory as asconfig.json) + Path mainClassPathAS = Paths.get(mainClassBasePath + FILE_EXTENSION_AS); + Path absoluteMainClassPathAS = mainClassPathAS; + if (!absoluteMainClassPathAS.isAbsolute() && rootWorkspacePath != null) { + absoluteMainClassPathAS = Paths.get(rootWorkspacePath).resolve(absoluteMainClassPathAS); + } + if (absoluteMainClassPathAS.toFile().exists()) { + // verify that the absolute path exists, but return the relative + // path instead. see note above. + return mainClassPathAS.toString(); + } + Path mainClassPathMXML = Paths.get(mainClassBasePath + FILE_EXTENSION_MXML); + Path absoluteMainClassPathMXML = mainClassPathMXML; + if (!absoluteMainClassPathMXML.isAbsolute() && rootWorkspacePath != null) { + absoluteMainClassPathMXML = Paths.get(rootWorkspacePath).resolve(absoluteMainClassPathMXML); + } + if (absoluteMainClassPathMXML.toFile().exists()) { + // verify that the absolute path exists, but return the relative + // path instead. see note above. + return mainClassPathMXML.toString(); + } } // as a final fallback, try in the current working directory Path mainClassPathAS = Paths.get(mainClassBasePath + FILE_EXTENSION_AS); - if (!mainClassPathAS.isAbsolute() && rootWorkspacePath != null) { - mainClassPathAS = Paths.get(rootWorkspacePath).resolve(mainClassPathAS); - } if (mainClassPathAS.toFile().exists()) { return mainClassPathAS.toString(); } Path mainClassPathMXML = Paths.get(mainClassBasePath + FILE_EXTENSION_MXML); - if (!mainClassPathMXML.isAbsolute() && rootWorkspacePath != null) { - mainClassPathMXML = Paths.get(rootWorkspacePath).resolve(mainClassPathMXML); - } if (mainClassPathMXML.toFile().exists()) { return mainClassPathMXML.toString(); }