Skip to content

Commit

Permalink
reduse the amount of errors when haxe SDK is unavailable
Browse files Browse the repository at this point in the history
  • Loading branch information
m0rkeulv committed Jun 7, 2023
1 parent fb27e84 commit 8d93934
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand All @@ -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
Expand Down Expand Up @@ -74,11 +76,19 @@ public Map<String, List<String>> 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));
}

Expand Down Expand Up @@ -116,6 +126,10 @@ private static Map<String, List<String>> readInstalledLibraries(@NotNull Sdk sdk
public List<String> 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<String> list = HaxelibCommandUtils.issueHaxelibCommand(sdk, "info", name);
// filter to find version numbers

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> installedLibs = HaxelibUtil.getInstalledLibraryNames(sdk);
for (String libName : installedLibs) {
HaxeLibrary lib = HaxeLibrary.load(this, libName, mySdk);
Expand Down

0 comments on commit 8d93934

Please sign in to comment.