Skip to content

Commit

Permalink
🐛 Fix windows distribution lookup (QD-9693)
Browse files Browse the repository at this point in the history
  • Loading branch information
tiulpin committed Aug 1, 2024
1 parent 5ae43ee commit 3516dd7
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 33 deletions.
10 changes: 5 additions & 5 deletions cmd/cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -400,10 +400,10 @@ func TestAllCommandsWithContainer(t *testing.T) {
}

func TestScanWithIde(t *testing.T) {
err := os.Setenv("QD_PRODUCT_INTERNAL_FEED", "https://data.services.jetbrains.com/products")
if err != nil {
t.Fatal(err)
}
//err := os.Setenv("QD_PRODUCT_INTERNAL_FEED", "https://data.services.jetbrains.com/products")
//if err != nil {
// t.Fatal(err)
//}
log.SetLevel(log.DebugLevel)
token := os.Getenv("QODANA_LICENSE_ONLY_TOKEN")
if //goland:noinspection GoBoolExpressions
Expand All @@ -412,7 +412,7 @@ func TestScanWithIde(t *testing.T) {
}
projectPath := ".."
resultsPath := filepath.Join(projectPath, "results")
err = os.MkdirAll(resultsPath, 0o755)
err := os.MkdirAll(resultsPath, 0o755)
if err != nil {
t.Fatal(err)
}
Expand Down
6 changes: 6 additions & 0 deletions core/installers.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,12 @@ func downloadAndInstallIDE(opts *QodanaOptions, baseDir string, spinner *pterm.S
log.Fatalf("Error while unpacking: %v", err)
}

if runtime.GOOS == "windows" {
if dirs, err := filepath.Glob(filepath.Join(installDir, "*")); err == nil && len(dirs) == 1 {
installDir = dirs[0]
}
}

return installDir
}

Expand Down
43 changes: 15 additions & 28 deletions core/installers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,14 @@ import (
"github.com/JetBrains/qodana-cli/v2024/platform"
"os"
"path/filepath"
"runtime"
"testing"
)

func TestGetIde(t *testing.T) {
err := os.Setenv("QD_PRODUCT_INTERNAL_FEED", "https://data.services.jetbrains.com/products")
if err != nil {
t.Fatal(err)
}
//err := os.Setenv("QD_PRODUCT_INTERNAL_FEED", "https://data.services.jetbrains.com/products")
//if err != nil {
// t.Fatal(err)
//}
for _, installer := range platform.AllNativeCodes {
//ide := getIde(installer)
//if ide == nil {
Expand All @@ -42,51 +41,39 @@ func TestGetIde(t *testing.T) {
}

func TestDownloadAndInstallIDE(t *testing.T) {
err := os.Setenv("QD_PRODUCT_INTERNAL_FEED", "https://data.services.jetbrains.com/products")
if err != nil {
t.Fatal(err)
}
//err := os.Setenv("QD_PRODUCT_INTERNAL_FEED", "https://data.services.jetbrains.com/products")
//if err != nil {
// t.Fatal(err)
//}
ides := []string{"QDGO-EAP"}
for _, ide := range ides {
DownloadAndInstallIDE(ide, t)
}
}

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

defer func(path string) {
err := os.RemoveAll(path)
if err != nil {
platform.ErrorMessage("Cannot clean up temp dir: %s", err)
}
}(tempDir) // clean up

opts := &QodanaOptions{
&platform.QodanaOptions{
Ide: ideName,
},
}
ide := downloadAndInstallIDE(opts, tempDir, nil)

if ide == "" {
platform.ErrorMessage("Cannot install %s", ideName)
t.Fail()
}

if //goland:noinspection GoBoolExpressions
runtime.GOOS == "darwin" {
ide = filepath.Join(ide, "Contents")
}
prod, err := readIdeProductInfo(ide)
defer func(path string) {
err := os.RemoveAll(path)
if err != nil {
platform.ErrorMessage("Cannot clean up temp dir: %s", err)
}
}(ide) // clean up
if err != nil || prod == nil {
t.Fatalf("Failed to read IDE product info: %v", err)
}
if prod.ProductCode == "" {
t.Fail()
}
Expand Down

0 comments on commit 3516dd7

Please sign in to comment.