Skip to content

Commit

Permalink
Making detect8 default script (#4568)
Browse files Browse the repository at this point in the history
* made detect8 default

* amended tests to reflect detect 8

* amended

* amend

* amend

* amend tests

* 1

* 1

* tests-with-temp-changes-for-transition

* removed auto unmapping for detect7

* added-old-parameters-as-deprecated
  • Loading branch information
dimaste authored Sep 18, 2023
1 parent caee8db commit 971d5d1
Show file tree
Hide file tree
Showing 4 changed files with 304 additions and 226 deletions.
43 changes: 22 additions & 21 deletions cmd/detectExecuteScan.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,11 +294,11 @@ func getDetectScript(config detectExecuteScanOptions, utils detectUtils) error {

log.Entry().Infof("Downloading Detect Script")

if config.UseDetect8 {
return utils.DownloadFile("https://detect.synopsys.com/detect8.sh", "detect.sh", nil, nil)
if config.UseDetect7 {
return utils.DownloadFile("https://detect.synopsys.com/detect7.sh", "detect.sh", nil, nil)
}

return utils.DownloadFile("https://detect.synopsys.com/detect7.sh", "detect.sh", nil, nil)
return utils.DownloadFile("https://detect.synopsys.com/detect8.sh", "detect.sh", nil, nil)
}

func addDetectArgs(args []string, config detectExecuteScanOptions, utils detectUtils, sys *blackduckSystem) ([]string, error) {
Expand Down Expand Up @@ -337,6 +337,12 @@ func addDetectArgs(args []string, config detectExecuteScanOptions, utils detectU
} else {
// When unmap is set to false, any occurances of unmap=true from scanProperties must be removed
config.ScanProperties, _ = piperutils.RemoveAll(config.ScanProperties, "--detect.project.codelocation.unmap=true")

// TEMPORARY OPTION DURING THE MIGRATION TO DETECT8
if !config.UseDetect7 {
args = append(args, "--detect.project.codelocation.unmap=true")
}
// REMOVE AFTER 25.09.2023
}

args = append(args, config.ScanProperties...)
Expand All @@ -346,7 +352,7 @@ func addDetectArgs(args []string, config detectExecuteScanOptions, utils detectU
// ProjectNames, VersionName, GroupName etc can contain spaces and need to be escaped using double quotes in CLI
// Hence the string need to be surrounded by \"

// Maven Parameters
// Moved parameters
mavenArgs, err := maven.DownloadAndGetMavenParameters(config.GlobalSettingsFile, config.ProjectSettingsFile, utils)
if err != nil {
return nil, err
Expand All @@ -366,51 +372,46 @@ func addDetectArgs(args []string, config detectExecuteScanOptions, utils detectU
}

// Since detect8 adds quotes by default, to avoid double quotation they should be removed for several arguments
if config.UseDetect8 {

args = append(args, fmt.Sprintf("\"--detect.project.name=%v\"", config.ProjectName))
args = append(args, fmt.Sprintf("\"--detect.project.version.name=%v\"", detectVersionName))
if config.UseDetect7 {
args = append(args, fmt.Sprintf("\"--detect.project.name='%v'\"", config.ProjectName))
args = append(args, fmt.Sprintf("\"--detect.project.version.name='%v'\"", detectVersionName))

// Groups parameter is added only when there is atleast one non-empty groupname provided
if len(config.Groups) > 0 && len(config.Groups[0]) > 0 {
args = append(args, fmt.Sprintf("\"--detect.project.user.groups=%v\"", strings.Join(config.Groups, ",")))
args = append(args, fmt.Sprintf("\"--detect.project.user.groups='%v'\"", strings.Join(config.Groups, ",")))
}

// Atleast 1, non-empty category to fail on must be provided
if len(config.FailOn) > 0 && len(config.FailOn[0]) > 0 {
args = append(args, fmt.Sprintf("--detect.policy.check.fail.on.severities=%v", strings.Join(config.FailOn, ",")))
}

args = append(args, fmt.Sprintf("\"--detect.code.location.name=%v\"", codelocation))
args = append(args, fmt.Sprintf("\"--detect.code.location.name='%v'\"", codelocation))

if len(mavenArgs) > 0 && !checkIfArgumentIsInScanProperties(config, "detect.maven.build.command") {
args = append(args, fmt.Sprintf("\"--detect.maven.build.command=%v\"", strings.Join(mavenArgs, " ")))
args = append(args, fmt.Sprintf("\"--detect.maven.build.command='%v'\"", strings.Join(mavenArgs, " ")))
}

} else {

args = append(args, fmt.Sprintf("\"--detect.project.name='%v'\"", config.ProjectName))
args = append(args, fmt.Sprintf("\"--detect.project.version.name='%v'\"", detectVersionName))
args = append(args, fmt.Sprintf("\"--detect.project.name=%v\"", config.ProjectName))
args = append(args, fmt.Sprintf("\"--detect.project.version.name=%v\"", detectVersionName))

// Groups parameter is added only when there is atleast one non-empty groupname provided
if len(config.Groups) > 0 && len(config.Groups[0]) > 0 {
args = append(args, fmt.Sprintf("\"--detect.project.user.groups='%v'\"", strings.Join(config.Groups, ",")))
args = append(args, fmt.Sprintf("\"--detect.project.user.groups=%v\"", strings.Join(config.Groups, ",")))
}

// Atleast 1, non-empty category to fail on must be provided
if len(config.FailOn) > 0 && len(config.FailOn[0]) > 0 {
args = append(args, fmt.Sprintf("--detect.policy.check.fail.on.severities=%v", strings.Join(config.FailOn, ",")))
}

args = append(args, fmt.Sprintf("\"--detect.code.location.name='%v'\"", codelocation))
args = append(args, fmt.Sprintf("\"--detect.code.location.name=%v\"", codelocation))

if len(mavenArgs) > 0 && !checkIfArgumentIsInScanProperties(config, "detect.maven.build.command") {
args = append(args, fmt.Sprintf("\"--detect.maven.build.command='%v'\"", strings.Join(mavenArgs, " ")))
args = append(args, fmt.Sprintf("\"--detect.maven.build.command=%v\"", strings.Join(mavenArgs, " ")))
}
}

if config.SuccessOnSkip {
args = append(args, fmt.Sprintf("\"--detect.force.success.on.skip=%v\"", config.SuccessOnSkip))
args = append(args, fmt.Sprintf("\"--detect.force.success.on.skip=true\""))
}

if len(config.ScanPaths) > 0 && len(config.ScanPaths[0]) > 0 {
Expand Down
23 changes: 17 additions & 6 deletions cmd/detectExecuteScan_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 971d5d1

Please sign in to comment.