Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update 232 with 233 eap #221

Merged
merged 4 commits into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 50 additions & 7 deletions cmd/cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"bytes"
"encoding/json"
"fmt"
"github.com/JetBrains/qodana-cli/v2023/cloud"
"io"
"os"
"os/exec"
Expand Down Expand Up @@ -55,6 +56,34 @@ func createProject(t *testing.T, name string) string {
return location
}

func createNativeProject(t *testing.T, name string) string {
home, err := os.UserHomeDir()
if err != nil {
t.Fatal(err)
}
location := filepath.Join(home, ".qodana_scan_", name)
err = gitClone("https://github.com/hybloid/BadRulesProject", location)
if err != nil {
t.Fatal(err)
}
return location
}

func gitClone(repoURL, directory string) error {
if _, err := os.Stat(directory); !os.IsNotExist(err) {
err = os.RemoveAll(directory)
if err != nil {
return err
}
}
cmd := exec.Command("git", "clone", repoURL, directory)
err := cmd.Run()
if err != nil {
return err
}
return nil
}

// TestVersion verifies that the version command returns the correct version
func TestVersion(t *testing.T) {
b := bytes.NewBufferString("")
Expand Down Expand Up @@ -331,13 +360,17 @@ func TestAllCommandsWithContainer(t *testing.T) {

func TestScanWithIde(t *testing.T) {
log.SetLevel(log.DebugLevel)
ide := "QDPY"
token := os.Getenv("TESTS_QODANA_TOKEN")
ide := "QDNET"
token := os.Getenv("QODANA_LICENSE_ONLY_TOKEN")
if //goland:noinspection GoBoolExpressions
token == "" {
t.Skip("set your token here to run the test")
}
projectPath := createProject(t, "qodana_scan_python")
if //goland:noinspection GoBoolExpressions
runtime.GOOS == "darwin" {
t.Skip("Mac OS not supported in native")
}
projectPath := createNativeProject(t, "qodana_scan_rd")
resultsPath := filepath.Join(projectPath, "results")
err := os.MkdirAll(resultsPath, 0o755)
if err != nil {
Expand All @@ -363,7 +396,7 @@ func TestScanWithIde(t *testing.T) {
func propertiesFixture(enableStats bool, additionalProperties []string) []string {
properties := []string{
"-Dfus.internal.reduce.initial.delay=true",
fmt.Sprintf("-Didea.application.info.value=%s", filepath.Join(os.TempDir(), "entrypoint", "QodanaAppInfo.xml")),
fmt.Sprintf("-Didea.application.info.value=%s", filepath.Join(core.Prod.IdeBin(), "QodanaAppInfo.xml")),
"-Didea.class.before.app=com.jetbrains.rider.protocol.EarlyBackendStarter",
fmt.Sprintf("-Didea.config.path=%s", filepath.Join(os.TempDir(), "entrypoint")),
fmt.Sprintf("-Didea.headless.enable.statistics=%t", enableStats),
Expand All @@ -373,9 +406,9 @@ func propertiesFixture(enableStats bool, additionalProperties []string) []string
fmt.Sprintf("-Didea.log.path=%s", filepath.Join(os.TempDir(), "entrypoint", "log")),
"-Didea.parent.prefix=Rider",
"-Didea.platform.prefix=Qodana",
fmt.Sprintf("-Didea.plugins.path=%s", filepath.Join(os.TempDir(), "entrypoint", "plugins", "master")),
fmt.Sprintf("-Didea.plugins.path=%s", filepath.Join(os.TempDir(), "entrypoint", "plugins", "233")),
"-Didea.qodana.thirdpartyplugins.accept=true",
fmt.Sprintf("-Didea.system.path=%s", filepath.Join(os.TempDir(), "entrypoint", "idea", "master")),
fmt.Sprintf("-Didea.system.path=%s", filepath.Join(os.TempDir(), "entrypoint", "idea", "233")),
"-Dinspect.save.project.settings=true",
"-Djava.awt.headless=true",
"-Djava.net.useSystemProxies=true",
Expand All @@ -386,6 +419,8 @@ func propertiesFixture(enableStats bool, additionalProperties []string) []string
"-Dqodana.automation.guid=FAKE",
"-Didea.job.launcher.without.timeout=true",
"-Dqodana.coverage.input=/data/coverage",
"-Dqodana.recommended.profile.resource=qodana-dotnet.recommended.yaml",
"-Dqodana.starter.profile.resource=qodana-dotnet.starter.yaml",
"-Drider.collect.full.container.statistics=true",
"-Drider.suppress.std.redirect=true",
"-Dsun.io.useCanonCaches=false",
Expand Down Expand Up @@ -417,7 +452,15 @@ func Test_Properties(t *testing.T) {

core.Prod.BaseScriptName = "rider"
core.Prod.Code = "QDNET"
core.Prod.Version = "main"
core.Prod.Version = "2023.3"
core.Prod.Name = ""
core.Prod.IdeScript = ""
core.Prod.Build = ""
core.Prod.Home = ""
core.Prod.EAP = false

cloud.Token.LicenseOnly = false
cloud.Token.Token = ""

err := os.Setenv(core.QodanaDistEnv, opts.ProjectDir)
if err != nil {
Expand Down
4 changes: 3 additions & 1 deletion core/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ var (
)

// AllSupportedCodes is a list of all supported Qodana linters product codes
var AllSupportedCodes = []string{QDJVMC, QDJVM, QDPHP, QDPY, QDPYC, QDJS, QDGO, QDNET}
var AllSupportedCodes = []string{QDNET}

// support has been disabled now for QDJVMC, QDJVM, QDPHP, QDPY, QDPYC, QDJS, QDGO until further testing

func Image(code string) string {
switch code {
Expand Down
34 changes: 0 additions & 34 deletions core/core_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -803,40 +803,6 @@ func Test_SaveProperty(t *testing.T) {
}
}

func Test_WriteAppInfo(t *testing.T) {
tmpDir := filepath.Join(os.TempDir(), "appinfo")
err := os.MkdirAll(tmpDir, 0o755)
if err != nil {
t.Fatal(err)
}
Prod.Version = "2022.1"
Prod.EAP = true
Prod.Build = "420.69"
Prod.Code = "QDTEST"
Prod.Name = "Qodana for Tests"
xmlFilePath := filepath.Join(tmpDir, "QodanaAppInfo.xml")
writeAppInfo(xmlFilePath)
actual, err := os.ReadFile(xmlFilePath)
if err != nil {
t.Fatal(err)
}
expected := `<component xmlns="http://jetbrains.org/intellij/schema/application-info"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://jetbrains.org/intellij/schema/application-info http://jetbrains.org/intellij/schema/ApplicationInfo.xsd">
<version major="2022" minor="1" eap="true"/>
<company name="JetBrains s.r.o." url="https://www.jetbrains.com" copyrightStart="2000"/>
<build number="QDTEST-420.69" date="202212060511" />
<names product="Qodana for Tests" fullname="Qodana for Tests"/>
<icon svg="xxx.svg" svg-small="xxx.svg"/>
<plugins url="https://plugins.jetbrains.com/" builtin-url="__BUILTIN_PLUGINS_URL__"/>
</component>`
assert.Equal(t, expected, string(actual))
err = os.RemoveAll(tmpDir)
if err != nil {
t.Fatal(err)
}
}

func Test_ReadAppInfo(t *testing.T) {
tempDir := os.TempDir()
entrypointDir := filepath.Join(tempDir, "appinfo")
Expand Down
153 changes: 0 additions & 153 deletions core/ide.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,12 @@
package core

import (
bt "bytes"
"encoding/json"
"encoding/xml"
"errors"
"fmt"
"github.com/JetBrains/qodana-cli/v2023/cloud"
"github.com/owenrumney/go-sarif/v2/sarif"
"io"
"os"
"path/filepath"
"runtime"
Expand All @@ -36,153 +34,6 @@ import (
cp "github.com/otiai10/copy"
)

func genExcludedPluginsLocal(opts *QodanaOptions) {
products := map[string]string{
QDJVM: "jvm",
QDJVMC: "jvm-community",
QDPHP: "php",
QDJS: "js",
QDNET: "dotnet",
QDPY: "python",
QDPYC: "python-community",
QDGO: "go",
// QDAND: android, // don't use it right now
// QDANDC: android-community, // don't use it right now
// QDRST: "rust", // don't use it right now
// QDRUBY: "ruby", // don't use it right now
}

if _, ok := products[Prod.Code]; ok {
includedPlugins := filepath.Join(opts.ConfDirPath(), "included_plugins.txt")
dockerIgnore := filepath.Join(opts.ConfDirPath(), ".docker_ignore")
disabledPlugins := filepath.Join(opts.ConfDirPath(), "disabled_plugins.txt")
if _, err := os.Stat(disabledPlugins); err != nil {
url := fmt.Sprintf("https://raw.githubusercontent.com/JetBrains/qodana-docker/main/%s/%s/included_plugins.txt", MajorVersion, products[Prod.Code])
if err := DownloadFile(includedPlugins, url, nil); err != nil {
log.Errorf("Not possible to download included plugins, skipping: %v", err)
} else {
if err := appendIncludedPlugins(includedPlugins); err != nil {
log.Fatal(err)
}
consoleOutput, err := getExcludedPlugins(includedPlugins, dockerIgnore)
if err != nil {
log.Fatal(err)
} else if consoleOutput != "" {
if idx := strings.Index(consoleOutput, "=====DISABLED======="); idx != -1 {
plugins := strings.TrimSpace(consoleOutput[idx+len("=====DISABLED======="):])
if err := os.WriteFile(disabledPlugins, []byte(plugins), 0644); err != nil {
log.Errorf("Error while writing disabled plugins list: %v", err)
} else {
log.Debug("Successfully created the list of disabled plugins")
}
} else {
log.Error("Error while generating list of excluded plugins, no plugins found")
}
} else {
log.Error("Error while asking Qodana to create disabled plugins list")
}
}
}
} else {
log.Warningf("Not possible to fetch excluded plugins for %s", Prod.Code)
}
}

func appendIncludedPlugins(filename string) error {
if len(Config.Plugins) == 0 {
return nil
}
bytes, err := os.ReadFile(filename)
if err != nil {
return err
}
if len(bytes) > 0 && bytes[len(bytes)-1] != '\n' {
err = appendToFile(filename, "\n")
if err != nil {
return err
}
}
var pluginIds []string
for _, plugin := range Config.Plugins {
pluginIds = append(pluginIds, plugin.Id)
}
pluginsStr := strings.Join(pluginIds, "\n")
err = appendToFile(filename, pluginsStr)
return err
}

func appendToFile(filename string, data string) error {
f, err := os.OpenFile(filename, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
if err != nil {
return err
}
defer func(f *os.File) {
err := f.Close()
if err != nil {
log.Fatal(err)
}
}(f)

_, err2 := f.WriteString(data)

return err2
}

func getExcludedPlugins(includedPlugins string, dockerIgnore string) (string, error) {
args := []string{QuoteForWindows(Prod.IdeScript), "qodanaExcludedPlugins", QuoteForWindows(includedPlugins), QuoteForWindows(dockerIgnore)}
outReader, outWriter, err := os.Pipe()
if err != nil {
return "", fmt.Errorf("failed to create stdout pipe: %w", err)
}
errReader, errWriter, err := os.Pipe()
if err != nil {
return "", fmt.Errorf("failed to create stderr pipe: %w", err)
}

origOut := os.Stdout
origErr := os.Stderr
os.Stdout = outWriter
os.Stderr = errWriter

outChannel := make(chan string)
errChannel := make(chan string)

go func() {
var buf bt.Buffer
_, err := io.Copy(&buf, outReader)
if err != nil {
log.Fatal(err)
}
outChannel <- buf.String()
}()

go func() {
var buf bt.Buffer
_, err := io.Copy(&buf, errReader)
if err != nil {
log.Fatal(err)
}
errChannel <- buf.String()
}()

res := RunCmd("", args...)
os.Stdout = origOut
os.Stderr = origErr
if err := outWriter.Close(); err != nil {
return "", fmt.Errorf("error while closing Qodana stdout: %v", err)
}
if err := errWriter.Close(); err != nil {
return "", fmt.Errorf("error while closing Qodana stderr: %v", err)
}
stdout := <-outChannel
stderr := <-errChannel
log.Warn(stderr)
if res == QodanaSuccessExitCode {
return stdout, nil
}
return "", fmt.Errorf("error while exectuing qodanaExcludedPlugins: %d", res)
}

// getIdeExitCode gets IDEA "exitCode" from SARIF.
func getIdeExitCode(resultsDir string, c int) (res int) {
if c != 0 {
Expand All @@ -208,9 +59,6 @@ func getIdeExitCode(resultsDir string, c int) (res int) {
}

func runQodanaLocal(opts *QodanaOptions) int {
if !IsContainer() {
genExcludedPluginsLocal(opts)
}
args := getIdeRunCommand(opts)
res := getIdeExitCode(opts.ResultsDir, RunCmd("", args...))
if res > QodanaSuccessExitCode && res != QodanaFailThresholdExitCode {
Expand Down Expand Up @@ -448,7 +296,6 @@ func prepareLocalIdeSettings(opts *QodanaOptions) {
opts.ConfDirPath(),
)
Config = GetQodanaYaml(opts.ProjectDir)
writeAppInfo(opts.appInfoXmlPath(Prod.IdeBin()))
writeProperties(opts)

if IsContainer() {
Expand Down
Loading
Loading