Skip to content

Commit 1b728cc

Browse files
dimastevstarostin
andauthored
Enabled the possibility to avoid aggregation of NPM projects in WhitesourceExecuteScan (#4956)
* Enabled the possibility to avoid aggregation of NPM projects * renamed-function --------- Co-authored-by: Vyacheslav Starostin <[email protected]>
1 parent ab88749 commit 1b728cc

File tree

5 files changed

+76
-33
lines changed

5 files changed

+76
-33
lines changed

cmd/whitesourceExecuteScan.go

+29-28
Original file line numberDiff line numberDiff line change
@@ -469,34 +469,35 @@ func validateProductVersion(version string) string {
469469

470470
func wsScanOptions(config *ScanOptions) *ws.ScanOptions {
471471
return &ws.ScanOptions{
472-
BuildTool: config.BuildTool,
473-
ScanType: "", // no longer provided via config
474-
OrgToken: config.OrgToken,
475-
UserToken: config.UserToken,
476-
ProductName: config.ProductName,
477-
ProductToken: config.ProductToken,
478-
ProductVersion: config.Version,
479-
ProjectName: config.ProjectName,
480-
BuildDescriptorFile: config.BuildDescriptorFile,
481-
BuildDescriptorExcludeList: config.BuildDescriptorExcludeList,
482-
PomPath: config.BuildDescriptorFile,
483-
M2Path: config.M2Path,
484-
GlobalSettingsFile: config.GlobalSettingsFile,
485-
ProjectSettingsFile: config.ProjectSettingsFile,
486-
InstallArtifacts: config.InstallArtifacts,
487-
DefaultNpmRegistry: config.DefaultNpmRegistry,
488-
AgentDownloadURL: config.AgentDownloadURL,
489-
AgentFileName: config.AgentFileName,
490-
ConfigFilePath: config.ConfigFilePath,
491-
Includes: config.Includes,
492-
Excludes: config.Excludes,
493-
JreDownloadURL: config.JreDownloadURL,
494-
AgentURL: config.AgentURL,
495-
ServiceURL: config.ServiceURL,
496-
ScanPath: config.ScanPath,
497-
InstallCommand: config.InstallCommand,
498-
Verbose: GeneralConfig.Verbose,
499-
SkipParentProjectResolution: config.SkipParentProjectResolution,
472+
BuildTool: config.BuildTool,
473+
ScanType: "", // no longer provided via config
474+
OrgToken: config.OrgToken,
475+
UserToken: config.UserToken,
476+
ProductName: config.ProductName,
477+
ProductToken: config.ProductToken,
478+
ProductVersion: config.Version,
479+
ProjectName: config.ProjectName,
480+
BuildDescriptorFile: config.BuildDescriptorFile,
481+
BuildDescriptorExcludeList: config.BuildDescriptorExcludeList,
482+
PomPath: config.BuildDescriptorFile,
483+
M2Path: config.M2Path,
484+
GlobalSettingsFile: config.GlobalSettingsFile,
485+
ProjectSettingsFile: config.ProjectSettingsFile,
486+
InstallArtifacts: config.InstallArtifacts,
487+
DefaultNpmRegistry: config.DefaultNpmRegistry,
488+
AgentDownloadURL: config.AgentDownloadURL,
489+
AgentFileName: config.AgentFileName,
490+
ConfigFilePath: config.ConfigFilePath,
491+
Includes: config.Includes,
492+
Excludes: config.Excludes,
493+
JreDownloadURL: config.JreDownloadURL,
494+
AgentURL: config.AgentURL,
495+
ServiceURL: config.ServiceURL,
496+
ScanPath: config.ScanPath,
497+
InstallCommand: config.InstallCommand,
498+
Verbose: GeneralConfig.Verbose,
499+
SkipParentProjectResolution: config.SkipParentProjectResolution,
500+
DisableNpmSubmodulesAggregation: config.DisableNpmSubmodulesAggregation,
500501
}
501502
}
502503

cmd/whitesourceExecuteScan_generated.go

+12-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/whitesource/scanOptions.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ type ScanOptions struct {
4646

4747
InstallCommand string
4848

49-
SkipParentProjectResolution bool
49+
SkipParentProjectResolution bool
50+
DisableNpmSubmodulesAggregation bool
5051

5152
Verbose bool
5253
}

pkg/whitesource/scanUA.go

+23-1
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,26 @@ const projectRegEx = `Project name: ([^,]*), URL: (.*)`
2323
// ExecuteUAScan executes a scan with the Whitesource Unified Agent.
2424
func (s *Scan) ExecuteUAScan(config *ScanOptions, utils Utils) error {
2525
s.AgentName = "WhiteSource Unified Agent"
26-
if config.BuildTool != "mta" {
26+
27+
switch config.BuildTool {
28+
case "mta":
29+
return s.ExecuteUAScanForMTA(config, utils)
30+
case "npm":
31+
if config.DisableNpmSubmodulesAggregation {
32+
return s.ExecuteUAScanForMultiModuleNPM(config, utils)
33+
} else {
34+
return s.ExecuteUAScanInPath(config, utils, config.ScanPath)
35+
}
36+
default:
2737
return s.ExecuteUAScanInPath(config, utils, config.ScanPath)
2838
}
2939

40+
}
41+
42+
func (s *Scan) ExecuteUAScanForMTA(config *ScanOptions, utils Utils) error {
3043
log.Entry().Infof("Executing WhiteSource UA scan for MTA project")
44+
45+
log.Entry().Infof("Executing WhiteSource UA scan for Maven part")
3146
pomExists, _ := utils.FileExists("pom.xml")
3247
if pomExists {
3348
mavenConfig := *config
@@ -42,6 +57,13 @@ func (s *Scan) ExecuteUAScan(config *ScanOptions, utils Utils) error {
4257
}
4358
}
4459

60+
log.Entry().Infof("Executing WhiteSource UA scan for NPM part")
61+
return s.ExecuteUAScanForMultiModuleNPM(config, utils)
62+
}
63+
64+
func (s *Scan) ExecuteUAScanForMultiModuleNPM(config *ScanOptions, utils Utils) error {
65+
log.Entry().Infof("Executing WhiteSource UA scan for multi-module NPM projects")
66+
4567
packageJSONFiles, err := utils.FindPackageJSONFiles(config)
4668
if err != nil {
4769
return errors.Wrap(err, "failed to find package.json files")

resources/metadata/whitesourceExecuteScan.yaml

+10-2
Original file line numberDiff line numberDiff line change
@@ -389,8 +389,7 @@ spec:
389389
- STEPS
390390
- name: skipParentProjectResolution
391391
type: bool
392-
description: "Parameter for multi-module, multi-images projects to skip the parent project resolution for reporing purpose
393-
Could be used if parent project is set as just a placeholder for scan and doesn't contain any dependencies."
392+
description: "Parameter for multi-module, multi-images projects to skip the parent project resolution for reporing purpose. Could be used if parent project is set as just a placeholder for scan and doesn't contain any dependencies."
394393
scope:
395394
- PARAMETERS
396395
- STAGES
@@ -543,6 +542,15 @@ spec:
543542
- STEPS
544543
aliases:
545544
- name: npm/defaultNpmRegistry
545+
- name: disableNpmSubmodulesAggregation
546+
type: bool
547+
description: "The default Mend behavior is to aggregate all submodules of NPM project into one project in Mend. This parameter disables this behavior, thus for each submodule a separate project is created."
548+
default: false
549+
scope:
550+
- PARAMETERS
551+
- GENERAL
552+
- STAGES
553+
- STEPS
546554
- name: githubToken
547555
description: "GitHub personal access token as per
548556
https://help.github.com/en/github/authenticating-to-github/creating-a-personal-access-token-for-the-command-line"

0 commit comments

Comments
 (0)