diff --git a/src/main/java/com/intellij/plugins/haxe/haxelib/HaxelibCacheManager.java b/src/main/java/com/intellij/plugins/haxe/haxelib/HaxelibCacheManager.java index 2c56b8315..5553827d8 100644 --- a/src/main/java/com/intellij/plugins/haxe/haxelib/HaxelibCacheManager.java +++ b/src/main/java/com/intellij/plugins/haxe/haxelib/HaxelibCacheManager.java @@ -2,6 +2,7 @@ import com.intellij.openapi.module.Module; import com.intellij.openapi.projectRoots.Sdk; +import lombok.CustomLog; import org.jetbrains.annotations.NotNull; import java.util.*; @@ -11,6 +12,7 @@ /** * A cache manager for library information retrieved from haxelib */ +@CustomLog public class HaxelibCacheManager { // current version of haxelib shows versions as date + version + description @@ -74,11 +76,19 @@ public Map> getAvailableLibraries() { private void fetchInstalledLibraryData() { Sdk sdk = HaxelibSdkUtils.lookupSdk(module); + if(!HaxelibSdkUtils.isValidHaxeSdk(sdk)) { + log.warn("Unable to fetchInstalledLibraryData, invalid SDK paths"); + return; + } installedLibraries.putAll(readInstalledLibraries(sdk)); } private void fetchAvailableForDownload() { Sdk sdk = HaxelibSdkUtils.lookupSdk(module); + if(!HaxelibSdkUtils.isValidHaxeSdk(sdk)) { + log.warn("Unable to fetchAvailableForDownload, invalid SDK paths"); + return; + } availableLibraries.putAll(readAvailableOnline(sdk)); } @@ -116,6 +126,10 @@ private static Map> readInstalledLibraries(@NotNull Sdk sdk public List fetchAvailableVersions(String name) { if (getAvailableLibraries().getOrDefault(name, List.of()).isEmpty()) { Sdk sdk = HaxelibSdkUtils.lookupSdk(module); + if(!HaxelibSdkUtils.isValidHaxeSdk(sdk)) { + log.warn("Unable to fetch Available Versions, invalid SDK paths"); + return List.of(); + } List list = HaxelibCommandUtils.issueHaxelibCommand(sdk, "info", name); // filter to find version numbers diff --git a/src/main/java/com/intellij/plugins/haxe/haxelib/HaxelibSdkUtils.java b/src/main/java/com/intellij/plugins/haxe/haxelib/HaxelibSdkUtils.java index 9a00273e0..8cfe1cb80 100644 --- a/src/main/java/com/intellij/plugins/haxe/haxelib/HaxelibSdkUtils.java +++ b/src/main/java/com/intellij/plugins/haxe/haxelib/HaxelibSdkUtils.java @@ -24,11 +24,15 @@ import com.intellij.openapi.projectRoots.impl.ProjectJdkImpl; import com.intellij.openapi.roots.ModuleRootManager; import com.intellij.openapi.roots.ProjectRootManager; +import com.intellij.plugins.haxe.config.sdk.HaxeSdkData; import com.intellij.plugins.haxe.config.sdk.HaxeSdkType; import lombok.CustomLog; import org.jetbrains.annotations.NotNull; +import java.nio.file.Files; +import java.nio.file.Path; + /** * Static interface for SDK utility functions. */ @@ -91,6 +95,12 @@ public static Sdk lookupSdk(@NotNull Project project) { } return sdk; } + public static boolean isValidHaxeSdk(@NotNull Sdk haxeSdk) { + HaxeSdkData data = (HaxeSdkData)haxeSdk.getSdkAdditionalData(); + if(data == null) return false; + if(!Files.exists(Path.of(data.getHomePath()))) return false; + return Files.exists(Path.of(data.getHaxelibPath())); + } @NotNull diff --git a/src/main/java/com/intellij/plugins/haxe/haxelib/ProjectLibraryCache.java b/src/main/java/com/intellij/plugins/haxe/haxelib/ProjectLibraryCache.java index 978baacaa..15974470a 100644 --- a/src/main/java/com/intellij/plugins/haxe/haxelib/ProjectLibraryCache.java +++ b/src/main/java/com/intellij/plugins/haxe/haxelib/ProjectLibraryCache.java @@ -65,6 +65,10 @@ public void reload() { } private void loadInstalledLibrariesList(@NotNull Sdk sdk) { + if(!HaxelibSdkUtils.isValidHaxeSdk(sdk)){ + log.warn("Unable to load install library list, invalid SDK paths"); + return; + } List installedLibs = HaxelibUtil.getInstalledLibraryNames(sdk); for (String libName : installedLibs) { HaxeLibrary lib = HaxeLibrary.load(this, libName, mySdk);