Skip to content

Commit

Permalink
Add maven native-like build workaround for detect (#4712)
Browse files Browse the repository at this point in the history
* added-native-like-build

* pom-path-uncommented

* Run install only for maven

* Added log

* debug

* Print config params

* Added pipeline env

* Added parameter to specify path to pom.xml

* Returned condition

* Added logging of config in verbose mode

---------

Co-authored-by: Andrei Kireev <[email protected]>
Co-authored-by: Andrei Kireev <[email protected]>
  • Loading branch information
3 people authored Jan 15, 2024
1 parent 9074822 commit 808b21f
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 0 deletions.
39 changes: 39 additions & 0 deletions cmd/detectExecuteScan.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,9 @@ func detectExecuteScan(config detectExecuteScanOptions, _ *telemetry.CustomData,
log.Entry().WithError(err).Warning("Failed to get GitHub client")
}

// Log config for debug purpose
logConfigInVerboseMode(config)

if config.PrivateModules != "" && config.PrivateModulesGitToken != "" {
//configuring go private packages
if err := golang.PrepareGolangPrivatePackages("detectExecuteStep", config.PrivateModules, config.PrivateModulesGitToken); err != nil {
Expand Down Expand Up @@ -185,6 +188,17 @@ func runDetect(ctx context.Context, config detectExecuteScanOptions, utils detec
}
}

if config.BuildMaven {
log.Entry().Infof("running Maven Build")
mavenConfig := setMavenConfig(config)
mavenUtils := maven.NewUtilsBundle()

err := runMavenBuild(&mavenConfig, nil, mavenUtils, &mavenBuildCommonPipelineEnvironment{})
if err != nil {
return err
}
}

blackduckSystem := newBlackduckSystem(config)

args := []string{"./detect.sh"}
Expand Down Expand Up @@ -895,3 +909,28 @@ func createToolRecordDetect(utils detectUtils, workspace string, config detectEx
}
return record.GetFileName(), nil
}

func setMavenConfig(config detectExecuteScanOptions) mavenBuildOptions {
mavenConfig := mavenBuildOptions{
PomPath: config.PomPath,
Flatten: true,
Verify: false,
ProjectSettingsFile: config.ProjectSettingsFile,
GlobalSettingsFile: config.GlobalSettingsFile,
M2Path: config.M2Path,
LogSuccessfulMavenTransfers: false,
CreateBOM: false,
CustomTLSCertificateLinks: config.CustomTLSCertificateLinks,
Publish: false,
}

return mavenConfig
}

func logConfigInVerboseMode(config detectExecuteScanOptions) {
config.Token = "********"
config.GithubToken = "********"
config.PrivateModulesGitToken = "********"
debugLog, _ := json.Marshal(config)
log.Entry().Debugf("Detect configuration: %v", string(debugLog))
}
22 changes: 22 additions & 0 deletions cmd/detectExecuteScan_generated.go

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

16 changes: 16 additions & 0 deletions resources/metadata/detectExecuteScan.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,22 @@ spec:
- STEPS
- STAGES
- PARAMETERS
- name: buildMaven
type: bool
default: false
description:
"Experiment parameter for maven multi-modules projects building"
scope:
- STEPS
- STAGES
- PARAMETERS
- name: pomPath
type: string
description: Path to the pom file which should be installed including all children.
scope:
- STEPS
mandatory: false
default: pom.xml
- name: includedPackageManagers
description:
"The package managers that need to be included for this scan. Providing the package manager names with this parameter will ensure that the build descriptor file of that package manager will be searched in the scan folder
Expand Down

0 comments on commit 808b21f

Please sign in to comment.