Skip to content

Commit

Permalink
🗑️ Deprecate stub-profile flag (QD-6638)
Browse files Browse the repository at this point in the history
Removes the `--stub-profile` flag from generated IDE args, remove default `profile.xml` argument too.
  • Loading branch information
jckoenen authored and tiulpin committed Oct 6, 2023
1 parent 22c6e11 commit e316e0c
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 17 deletions.
25 changes: 25 additions & 0 deletions cmd/cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"path/filepath"
"runtime"
"sort"
"strings"
"testing"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -110,6 +111,30 @@ func TestHelp(t *testing.T) {
}
}

func TestDeprecatedScanFlags(t *testing.T) {
deprecations := []string{"fixes-strategy", "stub-profile"}

out := bytes.NewBufferString("")
command := newScanCommand()
command.SetOut(out)
command.SetArgs([]string{"--help"})
err := command.Execute()
if err != nil {
t.Fatal(err)
}
raw, err := io.ReadAll(out)
if err != nil {
t.Fatal(err)
}
output := string(raw)

for _, dep := range deprecations {
if strings.Contains(output, dep) {
t.Fatalf("Deprecated flag in output %s", dep)
}
}
}

func TestInitCommand(t *testing.T) {
projectPath := createProject(t, "qodana_init")
err := os.WriteFile(projectPath+"/qodana.yml", []byte("version: 1.0"), 0o755)
Expand Down
4 changes: 2 additions & 2 deletions cmd/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,11 @@ But you can always override qodana.yaml options with the following command-line
cmd.MarkFlagsMutuallyExclusive("profile-name", "profile-path")
cmd.MarkFlagsMutuallyExclusive("apply-fixes", "cleanup")

err := cmd.Flags().MarkHidden("fixes-strategy")
err := cmd.Flags().MarkDeprecated("fixes-strategy", "use --apply-fixes / --cleanup instead")
if err != nil {
return nil
}
err = cmd.Flags().MarkDeprecated("fixes-strategy", "use --apply-fixes / --cleanup instead")
err = cmd.Flags().MarkDeprecated("stub-profile", "this option has no effect and no replacement")
if err != nil {
return nil
}
Expand Down
17 changes: 11 additions & 6 deletions core/core_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,32 +56,37 @@ func TestCliArgs(t *testing.T) {
{
name: "typical set up",
opts: &QodanaOptions{ProjectDir: projectDir, CacheDir: cacheDir, ResultsDir: resultsDir, Linter: "jetbrains/qodana-jvm-community:latest", SourceDirectory: "./src", DisableSanity: true, RunPromo: "true", Baseline: "qodana.sarif.json", BaselineIncludeAbsent: true, SaveReport: true, ShowReport: true, Port: 8888, Property: []string{"foo.baz=bar", "foo.bar=baz"}, Script: "default", FailThreshold: "0", AnalysisId: "id", Env: []string{"A=B"}, Volumes: []string{"/tmp/foo:/tmp/foo"}, User: "1001:1001", PrintProblems: true, ProfileName: "Default", ApplyFixes: true},
res: []string{filepath.FromSlash("/opt/idea/bin/idea.sh"), "inspect", "qodana", "--stub-profile", filepath.Join(cacheDir, "profile.xml"), "--save-report", "--source-directory", "./src", "--disable-sanity", "--profile-name", "Default", "--run-promo", "true", "--baseline", "qodana.sarif.json", "--baseline-include-absent", "--fail-threshold", "0", "--fixes-strategy", "apply", "--analysis-id", "id", "--property=foo.baz=bar", "--property=foo.bar=baz", projectDir, resultsDir},
res: []string{filepath.FromSlash("/opt/idea/bin/idea.sh"), "inspect", "qodana", "--save-report", "--source-directory", "./src", "--disable-sanity", "--profile-name", "Default", "--run-promo", "true", "--baseline", "qodana.sarif.json", "--baseline-include-absent", "--fail-threshold", "0", "--fixes-strategy", "apply", "--analysis-id", "id", "--property=foo.baz=bar", "--property=foo.bar=baz", projectDir, resultsDir},
},
{
name: "arguments with spaces, no properties for local runs",
opts: &QodanaOptions{ProjectDir: projectDir, CacheDir: cacheDir, ResultsDir: resultsDir, ProfileName: "separated words", Property: []string{"qodana.format=SARIF_AND_PROJECT_STRUCTURE", "qodana.variable.format=JSON"}, Ide: Prod.Home},
res: []string{filepath.FromSlash("/opt/idea/bin/idea.sh"), "inspect", "qodana", "--stub-profile", filepath.Join(cacheDir, "profile.xml"), "--profile-name", "\"separated words\"", projectDir, resultsDir},
res: []string{filepath.FromSlash("/opt/idea/bin/idea.sh"), "inspect", "qodana", "--profile-name", "\"separated words\"", projectDir, resultsDir},
},
{
name: "deprecated --fixes-strategy=apply",
opts: &QodanaOptions{ProjectDir: projectDir, CacheDir: cacheDir, ResultsDir: resultsDir, FixesStrategy: "apply"},
res: []string{filepath.FromSlash("/opt/idea/bin/idea.sh"), "inspect", "qodana", "--stub-profile", filepath.Join(cacheDir, "profile.xml"), "--fixes-strategy", "apply", projectDir, resultsDir},
res: []string{filepath.FromSlash("/opt/idea/bin/idea.sh"), "inspect", "qodana", "--fixes-strategy", "apply", projectDir, resultsDir},
},
{
name: "deprecated --fixes-strategy=cleanup",
opts: &QodanaOptions{ProjectDir: projectDir, CacheDir: cacheDir, ResultsDir: resultsDir, FixesStrategy: "cleanup"},
res: []string{filepath.FromSlash("/opt/idea/bin/idea.sh"), "inspect", "qodana", "--stub-profile", filepath.Join(cacheDir, "profile.xml"), "--fixes-strategy", "cleanup", projectDir, resultsDir},
res: []string{filepath.FromSlash("/opt/idea/bin/idea.sh"), "inspect", "qodana", "--fixes-strategy", "cleanup", projectDir, resultsDir},
},
{
name: "--fixes-strategy=apply for new versions",
opts: &QodanaOptions{ProjectDir: projectDir, CacheDir: cacheDir, ResultsDir: resultsDir, FixesStrategy: "apply", Ide: "/opt/idea/233"},
res: []string{filepath.FromSlash("/opt/idea/bin/idea.sh"), "inspect", "qodana", "--stub-profile", filepath.Join(cacheDir, "profile.xml"), "--apply-fixes", projectDir, resultsDir},
res: []string{filepath.FromSlash("/opt/idea/bin/idea.sh"), "inspect", "qodana", "--apply-fixes", projectDir, resultsDir},
},
{
name: "--fixes-strategy=cleanup for new versions",
opts: &QodanaOptions{ProjectDir: projectDir, CacheDir: cacheDir, ResultsDir: resultsDir, FixesStrategy: "cleanup", Ide: "/opt/idea/233"},
res: []string{filepath.FromSlash("/opt/idea/bin/idea.sh"), "inspect", "qodana", "--stub-profile", filepath.Join(cacheDir, "profile.xml"), "--cleanup", projectDir, resultsDir},
res: []string{filepath.FromSlash("/opt/idea/bin/idea.sh"), "inspect", "qodana", "--cleanup", projectDir, resultsDir},
},
{
name: "--stub-profile ignored",
opts: &QodanaOptions{StubProfile: "ignored", ProjectDir: projectDir, CacheDir: cacheDir, ResultsDir: resultsDir, FixesStrategy: "cleanup", Ide: "/opt/idea/233"},
res: []string{filepath.FromSlash("/opt/idea/bin/idea.sh"), "inspect", "qodana", "--cleanup", projectDir, resultsDir},
},
} {
t.Run(tc.name, func(t *testing.T) {
Expand Down
5 changes: 1 addition & 4 deletions core/ide.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ func runQodanaLocal(opts *QodanaOptions) int {
}

func getIdeRunCommand(opts *QodanaOptions) []string {
args := []string{QuoteForWindows(Prod.IdeScript), "inspect", "qodana", "--stub-profile", QuoteForWindows(opts.stabProfilePath())}
args := []string{QuoteForWindows(Prod.IdeScript), "inspect", "qodana"}
args = append(args, getIdeArgs(opts)...)
args = append(args, QuoteForWindows(opts.ProjectDir), QuoteForWindows(opts.ResultsDir))
return args
Expand Down Expand Up @@ -258,9 +258,6 @@ func getIdeArgs(opts *QodanaOptions) []string {
if opts.Script != "" && opts.Script != "default" {
arguments = append(arguments, "--script", opts.Script)
}
if opts.StubProfile != "" {
arguments = append(arguments, "--stub-profile", opts.StubProfile)
}
if opts.Baseline != "" {
arguments = append(arguments, "--baseline", QuoteForWindows(opts.Baseline))
}
Expand Down
6 changes: 1 addition & 5 deletions core/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ type QodanaOptions struct {
ProfileName string
ProfilePath string
RunPromo string
StubProfile string
StubProfile string // note: deprecated option
Baseline string
BaselineIncludeAbsent bool
SaveReport bool
Expand Down Expand Up @@ -167,10 +167,6 @@ func (o *QodanaOptions) ReportDirPath() string {
return o.ReportDir
}

func (o *QodanaOptions) stabProfilePath() string {
return filepath.Join(o.CacheDirPath(), "profile.xml")
}

func (o *QodanaOptions) ReportResultsPath() string {
return filepath.Join(o.ReportDirPath(), "results")
}
Expand Down

0 comments on commit e316e0c

Please sign in to comment.