Skip to content

Commit df3b2da

Browse files
committed
Merge remote-tracking branch 'origin/dev'
2 parents 60cd17a + 44220ef commit df3b2da

File tree

20 files changed

+512
-32
lines changed

20 files changed

+512
-32
lines changed

artifactory/utils/commandsummary/commandsummary.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,10 @@ const (
6565
OutputDirName = "jfrog-command-summary"
6666
finalMarkdownFileName = "markdown.md"
6767
// Filenames formats
68-
SarifFileFormat = "*.sarif"
69-
DataFileFormat = "*-data"
70-
NoneScannedResult = "default"
68+
SarifFileFormat = "*.sarif"
69+
DataFileFormat = "*-data"
70+
NoneScannedResult = "default"
71+
Evidence Index = "evidence"
7172
)
7273

7374
type CommandSummary struct {

artifactory/utils/yarn/configget.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"strings"
77
)
88

9-
// This method runs "yarn config set" command and sets the yarn configuration.
9+
// This method runs "yarn config get" command and sets the yarn configuration.
1010
func ConfigGet(key, executablePath string, jsonOutput bool) (string, error) {
1111
var flags []string = nil
1212
if jsonOutput {
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package yarn
2+
3+
import (
4+
gofrogcmd "github.com/jfrog/gofrog/io"
5+
"github.com/jfrog/gofrog/version"
6+
"github.com/jfrog/jfrog-client-go/utils/errorutils"
7+
"strings"
8+
)
9+
10+
const unsupportedYarnVersion = "4.0.0"
11+
12+
func IsInstalledYarnVersionSupported(executablePath string) error {
13+
versionGetCmdConfig := getVersionCmdConfig(executablePath)
14+
output, err := gofrogcmd.RunCmdOutput(versionGetCmdConfig)
15+
if err != nil {
16+
return errorutils.CheckError(err)
17+
}
18+
yarnVersion := strings.TrimSpace(output)
19+
return IsVersionSupported(yarnVersion)
20+
}
21+
22+
func IsVersionSupported(versionStr string) error {
23+
yarnVersion := version.NewVersion(versionStr)
24+
if yarnVersion.Compare(unsupportedYarnVersion) <= 0 {
25+
return errorutils.CheckErrorf("Yarn version 4 is not supported. The current version is: " + versionStr +
26+
". Please downgrade to a compatible version to continue")
27+
}
28+
return nil
29+
}
30+
31+
func getVersionCmdConfig(executablePath string) *YarnConfig {
32+
return &YarnConfig{
33+
Executable: executablePath,
34+
Command: []string{"--version"},
35+
CommandFlags: nil,
36+
StrWriter: nil,
37+
ErrWriter: nil,
38+
}
39+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package yarn
2+
3+
import (
4+
"github.com/stretchr/testify/assert"
5+
"testing"
6+
)
7+
8+
func TestIsVersionSupported(t *testing.T) {
9+
tests := []struct {
10+
versionStr string
11+
expectErr bool
12+
}{
13+
{"3.9.0", false},
14+
{"4.0.0", true},
15+
{"4.1.0", true},
16+
}
17+
18+
for _, test := range tests {
19+
err := IsVersionSupported(test.versionStr)
20+
if test.expectErr {
21+
assert.Error(t, err, "Expected an error for version: %s", test.versionStr)
22+
} else {
23+
assert.NoError(t, err, "Did not expect an error for version: %s", test.versionStr)
24+
}
25+
}
26+
}

common/build/buildinfoproperties.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ const Repo = "repo"
4545
const SnapshotRepo = "snapshotRepo"
4646
const ReleaseRepo = "releaseRepo"
4747

48+
const DisableSnapshots = "disableSnapshots"
49+
const SnapshotsUpdatePolicy = "snapshotsUpdatePolicy"
50+
4851
const ServerId = "serverId"
4952
const Url = "url"
5053
const Username = "username"
@@ -123,6 +126,8 @@ var mavenConfigMapping = map[string]string{
123126
"buildInfoConfig.artifactoryResolutionEnabled": "buildInfoConfig.artifactoryResolutionEnabled",
124127
"resolve.repoKey": ResolverPrefix + ReleaseRepo,
125128
"resolve.downSnapshotRepoKey": ResolverPrefix + SnapshotRepo,
129+
"resolve.snapshots.disabled": ResolverPrefix + DisableSnapshots,
130+
"resolve.snapshots.updatePolicy": ResolverPrefix + SnapshotsUpdatePolicy,
126131
"publish.repoKey": DeployerPrefix + ReleaseRepo,
127132
"publish.snapshot.repoKey": DeployerPrefix + SnapshotRepo,
128133
"publish.includePatterns": DeployerPrefix + IncludePatterns,

common/cliutils/spec.go

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
package cliutils
2+
3+
import (
4+
speccore "github.com/jfrog/jfrog-cli-core/v2/common/spec"
5+
"github.com/jfrog/jfrog-cli-core/v2/plugins/components"
6+
"github.com/jfrog/jfrog-cli-core/v2/utils/coreutils"
7+
"strings"
8+
)
9+
10+
func GetSpec(c *components.Context, isDownload, overrideFieldsIfSet bool) (specFiles *speccore.SpecFiles, err error) {
11+
specFiles, err = speccore.CreateSpecFromFile(c.GetStringFlagValue("spec"), coreutils.SpecVarsStringToMap(c.GetStringFlagValue("spec-vars")))
12+
if err != nil {
13+
return nil, err
14+
}
15+
if isDownload {
16+
trimPatternPrefix(specFiles)
17+
}
18+
if overrideFieldsIfSet {
19+
overrideSpecFields(c, specFiles)
20+
}
21+
return
22+
}
23+
24+
func overrideSpecFields(c *components.Context, specFiles *speccore.SpecFiles) {
25+
for i := 0; i < len(specFiles.Files); i++ {
26+
OverrideFieldsIfSet(specFiles.Get(i), c)
27+
}
28+
}
29+
30+
func trimPatternPrefix(specFiles *speccore.SpecFiles) {
31+
for i := 0; i < len(specFiles.Files); i++ {
32+
specFiles.Get(i).Pattern = strings.TrimPrefix(specFiles.Get(i).Pattern, "/")
33+
}
34+
}
35+
36+
func OverrideFieldsIfSet(spec *speccore.File, c *components.Context) {
37+
overrideArrayIfSet(&spec.Exclusions, c, "exclusions")
38+
overrideArrayIfSet(&spec.SortBy, c, "sort-by")
39+
overrideIntIfSet(&spec.Offset, c, "offset")
40+
overrideIntIfSet(&spec.Limit, c, "limit")
41+
overrideStringIfSet(&spec.SortOrder, c, "sort-order")
42+
overrideStringIfSet(&spec.Props, c, "props")
43+
overrideStringIfSet(&spec.TargetProps, c, "target-props")
44+
overrideStringIfSet(&spec.ExcludeProps, c, "exclude-props")
45+
overrideStringIfSet(&spec.Build, c, "build")
46+
overrideStringIfSet(&spec.Project, c, "project")
47+
overrideStringIfSet(&spec.ExcludeArtifacts, c, "exclude-artifacts")
48+
overrideStringIfSet(&spec.IncludeDeps, c, "include-deps")
49+
overrideStringIfSet(&spec.Bundle, c, "bundle")
50+
overrideStringIfSet(&spec.Recursive, c, "recursive")
51+
overrideStringIfSet(&spec.Flat, c, "flat")
52+
overrideStringIfSet(&spec.Explode, c, "explode")
53+
overrideStringIfSet(&spec.BypassArchiveInspection, c, "bypass-archive-inspection")
54+
overrideStringIfSet(&spec.Regexp, c, "regexp")
55+
overrideStringIfSet(&spec.IncludeDirs, c, "include-dirs")
56+
overrideStringIfSet(&spec.ValidateSymlinks, c, "validate-symlinks")
57+
overrideStringIfSet(&spec.Symlinks, c, "symlinks")
58+
overrideStringIfSet(&spec.Transitive, c, "transitive")
59+
overrideStringIfSet(&spec.PublicGpgKey, c, "gpg-key")
60+
}
61+
62+
// If `fieldName` exist in the cli args, read it to `field` as a string.
63+
func overrideStringIfSet(field *string, c *components.Context, fieldName string) {
64+
if c.IsFlagSet(fieldName) {
65+
*field = c.GetStringFlagValue(fieldName)
66+
}
67+
}
68+
69+
// If `fieldName` exist in the cli args, read it to `field` as an array split by `;`.
70+
func overrideArrayIfSet(field *[]string, c *components.Context, fieldName string) {
71+
if c.IsFlagSet(fieldName) {
72+
*field = append([]string{}, strings.Split(c.GetStringFlagValue(fieldName), ";")...)
73+
}
74+
}
75+
76+
// If `fieldName` exist in the cli args, read it to `field` as a int.
77+
func overrideIntIfSet(field *int, c *components.Context, fieldName string) {
78+
if c.IsFlagSet(fieldName) {
79+
*field, _ = c.GetIntFlagValue(fieldName)
80+
}
81+
}

common/cliutils/summary/summary.go

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
package summary
2+
3+
import (
4+
"encoding/json"
5+
clientutils "github.com/jfrog/jfrog-client-go/utils"
6+
"github.com/jfrog/jfrog-client-go/utils/errorutils"
7+
"github.com/jfrog/jfrog-client-go/utils/log"
8+
"strings"
9+
)
10+
11+
type StatusType int
12+
13+
const (
14+
Success StatusType = iota
15+
Failure
16+
)
17+
18+
var StatusTypes = []string{
19+
"success",
20+
"failure",
21+
}
22+
23+
func (statusType StatusType) MarshalJSON() ([]byte, error) {
24+
return json.Marshal(StatusTypes[statusType])
25+
}
26+
27+
func (statusType *StatusType) UnmarshalJSON(b []byte) error {
28+
var s string
29+
if err := json.Unmarshal(b, &s); err != nil {
30+
return err
31+
}
32+
switch strings.ToLower(s) {
33+
default:
34+
*statusType = Failure
35+
case "success":
36+
*statusType = Success
37+
38+
}
39+
return nil
40+
}
41+
42+
func NewBuildInfoSummary(success, failed int, sha256 string, err error) *BuildInfoSummary {
43+
summaryReport := GetSummaryReport(success, failed, false, err)
44+
buildInfoSummary := BuildInfoSummary{Summary: *summaryReport, Sha256Array: []Sha256{}}
45+
if success == 1 {
46+
buildInfoSummary.AddSha256(sha256)
47+
}
48+
return &buildInfoSummary
49+
}
50+
51+
func (summary *Summary) Marshal() ([]byte, error) {
52+
return json.Marshal(summary)
53+
}
54+
55+
func (bis *BuildInfoSummary) Marshal() ([]byte, error) {
56+
return json.Marshal(bis)
57+
}
58+
59+
type Summary struct {
60+
Status StatusType `json:"status"`
61+
Totals *Totals `json:"totals"`
62+
}
63+
64+
type Totals struct {
65+
Success int `json:"success"`
66+
Failure int `json:"failure"`
67+
}
68+
69+
type BuildInfoSummary struct {
70+
Summary
71+
Sha256Array []Sha256 `json:"files"`
72+
}
73+
74+
type Sha256 struct {
75+
Sha256Str string `json:"sha256"`
76+
}
77+
78+
func (bis *BuildInfoSummary) AddSha256(sha256Str string) {
79+
sha256 := Sha256{Sha256Str: sha256Str}
80+
bis.Sha256Array = append(bis.Sha256Array, sha256)
81+
}
82+
83+
func GetSummaryReport(success, failed int, failNoOp bool, err error) *Summary {
84+
summary := &Summary{Totals: &Totals{}}
85+
if err != nil || failed > 0 || (success == 0 && failNoOp) {
86+
summary.Status = Failure
87+
} else {
88+
summary.Status = Success
89+
}
90+
summary.Totals.Success = success
91+
summary.Totals.Failure = failed
92+
return summary
93+
}
94+
95+
func PrintBuildInfoSummaryReport(succeeded bool, sha256 string, originalErr error) error {
96+
success, failed := 1, 0
97+
if !succeeded {
98+
success, failed = 0, 1
99+
}
100+
buildInfoSummary, mErr := CreateBuildInfoSummaryReportString(success, failed, sha256, originalErr)
101+
if mErr != nil {
102+
return summaryPrintError(mErr, originalErr)
103+
}
104+
log.Output(buildInfoSummary)
105+
return summaryPrintError(mErr, originalErr)
106+
}
107+
108+
func CreateBuildInfoSummaryReportString(success, failed int, sha256 string, err error) (string, error) {
109+
buildInfoSummary := NewBuildInfoSummary(success, failed, sha256, err)
110+
buildInfoSummaryContent, mErr := buildInfoSummary.Marshal()
111+
if errorutils.CheckError(mErr) != nil {
112+
return "", mErr
113+
}
114+
return clientutils.IndentJson(buildInfoSummaryContent), mErr
115+
}
116+
117+
// Print summary report.
118+
// a given non-nil error will pass through and be returned as is if no other errors are raised.
119+
// In case of a nil error, the current function error will be returned.
120+
func summaryPrintError(summaryError, originalError error) error {
121+
if originalError != nil {
122+
if summaryError != nil {
123+
log.Error(summaryError)
124+
}
125+
return originalError
126+
}
127+
return summaryError
128+
}

common/commands/configfile.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ const (
3939
deploymentSnapshotsRepo = "repo-deploy-snapshots"
4040
includePatterns = "include-patterns"
4141
excludePatterns = "exclude-patterns"
42+
disableSnapshots = "disable-snapshots"
43+
snapshotsUpdatePolicy = "snapshots-update-policy"
4244

4345
// Gradle flags
4446
usesPlugin = "uses-plugin"
@@ -251,14 +253,16 @@ func WithDeployerRepo(repoId string) ConfigOption {
251253
// Populate Maven related configuration from cli flags
252254
func (configFile *ConfigFile) populateMavenConfigFromFlags(c *cli.Context) {
253255
configFile.Resolver.SnapshotRepo = c.String(resolutionSnapshotsRepo)
256+
configFile.Resolver.DisableSnapshots = c.Bool(disableSnapshots)
257+
configFile.Resolver.SnapshotsUpdatePolicy = c.String(snapshotsUpdatePolicy)
254258
configFile.Resolver.ReleaseRepo = c.String(resolutionReleasesRepo)
255259
configFile.Deployer.SnapshotRepo = c.String(deploymentSnapshotsRepo)
256260
configFile.Deployer.ReleaseRepo = c.String(deploymentReleasesRepo)
257261
configFile.Deployer.IncludePatterns = c.String(includePatterns)
258262
configFile.Deployer.ExcludePatterns = c.String(excludePatterns)
259263
configFile.UseWrapper = c.Bool(useWrapper)
260264
configFile.Interactive = configFile.Interactive && !isAnyFlagSet(c, resolutionSnapshotsRepo, resolutionReleasesRepo,
261-
deploymentSnapshotsRepo, deploymentReleasesRepo, includePatterns, excludePatterns)
265+
disableSnapshots, snapshotsUpdatePolicy, deploymentSnapshotsRepo, deploymentReleasesRepo, includePatterns, excludePatterns)
262266
}
263267

264268
func WithResolverSnapshotRepo(repoId string) ConfigOption {

common/commands/flag_test.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package commands
2+
3+
import (
4+
"github.com/stretchr/testify/assert"
5+
"testing"
6+
7+
"github.com/urfave/cli"
8+
)
9+
10+
// This test demonstrates an existing bug in the urfave/cli library.
11+
// It highlights that both BoolT and Bool flags have their default values set to false.
12+
// Ideally, the BoolT flag should have a default value of true.
13+
func TestBoolVsBoolTFlag(t *testing.T) {
14+
tests := []struct {
15+
name string
16+
args []string
17+
shouldUseBoolT bool
18+
expectValue bool
19+
}{
20+
{"Resolving flag value using Bool (default false)", []string{"cmd"}, false, false},
21+
{"Resolving flag value using Bool (default false)", []string{"cmd"}, true, false},
22+
}
23+
24+
for _, tt := range tests {
25+
t.Run(tt.name, func(t *testing.T) {
26+
app := &cli.App{
27+
Flags: []cli.Flag{
28+
&cli.BoolFlag{
29+
Name: "myflag",
30+
Usage: "Test boolean flag",
31+
},
32+
},
33+
Action: func(c *cli.Context) error {
34+
if tt.shouldUseBoolT {
35+
assert.Equal(t, tt.expectValue, c.BoolT("myflag"), "Expected %v, got %v", tt.expectValue, c.BoolT("myflag"))
36+
} else {
37+
assert.Equal(t, tt.expectValue, c.Bool("myflag"), "Expected %v, got %v", tt.expectValue, c.Bool("myflag"))
38+
}
39+
return nil
40+
},
41+
}
42+
43+
_ = app.Run(tt.args)
44+
})
45+
}
46+
}

0 commit comments

Comments
 (0)