Skip to content

Commit

Permalink
🐛 Fix native macOS mode (QD-9694)
Browse files Browse the repository at this point in the history
  • Loading branch information
tiulpin committed Aug 27, 2024
1 parent 2bd234d commit c176139
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 7 deletions.
54 changes: 50 additions & 4 deletions core/installers.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ func downloadAndInstallIDE(opts *QodanaOptions, baseDir string, spinner *pterm.S
if dirs, err := filepath.Glob(filepath.Join(installDir, "*")); err == nil && len(dirs) == 1 {
installDir = dirs[0]
}
} else if runtime.GOOS == "darwin" {
if dirs, err := filepath.Glob(filepath.Join(installDir, "*.app")); err == nil && len(dirs) == 1 {
installDir = filepath.Join(dirs[0], "Contents")
}
}
log.Debugf("IDE already installed to %s, skipping download", installDir)
return installDir
Expand All @@ -104,8 +108,10 @@ func downloadAndInstallIDE(opts *QodanaOptions, baseDir string, spinner *pterm.S
}

switch fileExt {
case ".sit":
err = installIdeFromZip(downloadedIdePath, installDir)
case ".zip":
err = installIdeWindowsZip(downloadedIdePath, installDir)
err = installIdeFromZip(downloadedIdePath, installDir)
case ".exe":
err = installIdeWindowsExe(downloadedIdePath, installDir)
case ".gz":
Expand All @@ -124,6 +130,14 @@ func downloadAndInstallIDE(opts *QodanaOptions, baseDir string, spinner *pterm.S
if dirs, err := filepath.Glob(filepath.Join(installDir, "*")); err == nil && len(dirs) == 1 {
installDir = dirs[0]
}
} else if runtime.GOOS == "darwin" {
if dirs, err := filepath.Glob(filepath.Join(installDir, "*.app")); err == nil && len(dirs) == 1 {
installDir = filepath.Join(dirs[0], "Contents")
}
err = downloadCustomPlugins(ideUrl, installDir, spinner)
if err != nil {
log.Warning("Error while downloading custom plugins: " + err.Error())
}
}

return installDir
Expand Down Expand Up @@ -163,13 +177,13 @@ func getIde(productCode string) *ReleaseDownloadInfo {
var downloadType string
switch runtime.GOOS {
case "darwin":
downloadType = "macTar"
downloadType = "macSit"
_, ok := (*release.Downloads)[downloadType]
if !ok {
downloadType = "mac"
}
if runtime.GOARCH == "arm64" {
downloadType = "macTarM1"
downloadType = "macSitM1"
_, ok := (*release.Downloads)[downloadType]
if !ok {
downloadType = "macM1"
Expand Down Expand Up @@ -214,7 +228,7 @@ func installIdeWindowsExe(archivePath string, targetDir string) error {
return nil
}

func installIdeWindowsZip(archivePath string, targetDir string) error {
func installIdeFromZip(archivePath string, targetDir string) error {
if err := os.MkdirAll(targetDir, os.ModePerm); err != nil {
log.Fatal("couldn't create a directory ", err.Error())
}
Expand Down Expand Up @@ -310,3 +324,35 @@ func verifySha256(checksumFile string, checkSumUrl string, filePath string) {
}
log.Info("Checksum of downloaded IDE was verified")
}

func downloadCustomPlugins(ideUrl string, installDir string, spinner *pterm.SpinnerPrinter) error {
pluginsUrl := getPluginsURL(ideUrl)
log.Debugf("Downloading custom plugins from %s", pluginsUrl)
archivePath := filepath.Join(installDir, "custom-plugins.zip")
err := platform.DownloadFile(archivePath, pluginsUrl, spinner)
if err != nil {
return fmt.Errorf("error while downloading plugins: %v", err)
}
_, err = exec.Command("tar", "-xf", archivePath, "-C", installDir).Output()
if err != nil {
return fmt.Errorf("tar: %s", err)
}
disabledPluginsPath := filepath.Join(installDir, "custom-plugins", "disabled_plugins.txt")
err = cp.Copy(disabledPluginsPath, filepath.Join(installDir, "disabled_plugins.txt"))
if err != nil {
return fmt.Errorf("error while copying plugins: %s", err)
}

return nil
}

func getPluginsURL(ideUrl string) string {
pluginsUrl := strings.Replace(ideUrl, "-aarch64", "", 1)
if strings.Contains(pluginsUrl, ".sit") {
return strings.Replace(pluginsUrl, ".sit", "-custom-plugins.zip", 1)
} else if strings.Contains(pluginsUrl, ".win.zip") {
return strings.Replace(pluginsUrl, ".win.zip", "-custom-plugins.zip", 1)
} else {
return strings.Replace(pluginsUrl, ".tar.gz", "-custom-plugins.zip", 1)
}
}
10 changes: 7 additions & 3 deletions core/installers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,19 @@ func TestDownloadAndInstallIDE(t *testing.T) {
//if err != nil {
// t.Fatal(err)
//}
ides := []string{"QDGO-EAP"}
ides := []string{"QDJS-EAP"}
for _, ide := range ides {
DownloadAndInstallIDE(ide, t)
}
}

func DownloadAndInstallIDE(ideName string, t *testing.T) {
tempDir := filepath.Join(os.TempDir(), ".qodana_scan_", "ideTest")
err := os.MkdirAll(tempDir, 0755)
homeDir, err := os.UserHomeDir()
if err != nil {
t.Fatal(err)
}
tempDir := filepath.Join(homeDir, ".qodana_scan_", "ideTest")
err = os.MkdirAll(tempDir, 0755)
if err != nil {
platform.ErrorMessage("Cannot create temp dir: %s", err)
t.Fail()
Expand Down

0 comments on commit c176139

Please sign in to comment.