From dcdcb70b2b273c24d24cae685f1c523fabcec516 Mon Sep 17 00:00:00 2001 From: Josh Tynjala Date: Mon, 11 Dec 2023 09:46:43 -0800 Subject: [PATCH] asconfigc: fix resolution of mainClass if asconfig.json is not in root of workspace (closes #718) --- .../src/main/java/com/as3mxml/asconfigc/ASConfigC.java | 2 +- .../main/java/com/as3mxml/asconfigc/utils/ConfigUtils.java | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/asconfigc/src/main/java/com/as3mxml/asconfigc/ASConfigC.java b/asconfigc/src/main/java/com/as3mxml/asconfigc/ASConfigC.java index 7672259b6..8e0127f40 100644 --- a/asconfigc/src/main/java/com/as3mxml/asconfigc/ASConfigC.java +++ b/asconfigc/src/main/java/com/as3mxml/asconfigc/ASConfigC.java @@ -564,7 +564,7 @@ private void parseConfig(JsonNode json) throws ASConfigCException { // if set already, clear it because we're going to replace it boolean hadMainFile = mainFile != null; String mainClass = json.get(TopLevelFields.MAIN_CLASS).asText(); - mainFile = ConfigUtils.resolveMainClass(mainClass, sourcePaths); + mainFile = ConfigUtils.resolveMainClass(mainClass, sourcePaths, System.getProperty("user.dir")); if (mainFile == null) { throw new ASConfigCException("Main class not found in source paths: " + mainClass); } 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 d41aa964b..d605220b8 100644 --- a/asconfigc/src/main/java/com/as3mxml/asconfigc/utils/ConfigUtils.java +++ b/asconfigc/src/main/java/com/as3mxml/asconfigc/utils/ConfigUtils.java @@ -66,10 +66,16 @@ public static String resolveMainClass(String mainClass, List sourcePaths } // 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(); }