@@ -13,16 +13,19 @@ import (
1313
1414 "github.com/murphysecurity/murphysec/env"
1515 "github.com/murphysecurity/murphysec/infra/logctx"
16+ "github.com/murphysecurity/murphysec/toolver"
1617 "go.uber.org/zap"
1718)
1819
19- const M2SettingsFilePathCtxKey = "MavenSettingsFilePathCtxKey"
20-
2120type MvnCommandInfo struct {
2221 Path string `json:"path"`
2322 MvnVersion string `json:"mvn_version"`
2423 UserSettingsPath string `json:"user_settings_path"`
2524 JavaHome string `json:"java_home"`
25+
26+ AdditionalArgs []string `json:"additional_args,omitempty"`
27+
28+ AdditionalPrependArgs []string `json:"additional_prepend_args,omitempty"`
2629}
2730
2831func (m MvnCommandInfo ) String () string {
@@ -33,12 +36,14 @@ func (m MvnCommandInfo) Command(ctx context.Context, args ...string) *exec.Cmd {
3336 if ctx == nil {
3437 ctx = context .TODO ()
3538 }
36- var _args = make ([]string , 0 , len (args )+ 5 )
39+ var _args = make ([]string , 0 )
40+ _args = append (_args , m .AdditionalPrependArgs ... )
3741 if m .UserSettingsPath != "" {
3842 _args = append (_args , "--settings" , m .UserSettingsPath )
3943 }
4044 _args = append (_args , "--batch-mode" )
4145 _args = append (_args , args ... )
46+ _args = append (_args , m .AdditionalArgs ... )
4247 cmd := exec .CommandContext (ctx , m .Path , _args ... )
4348 if m .JavaHome != "" {
4449 cmd .Env = os .Environ ()
@@ -55,7 +60,7 @@ type _MvnCommandResult struct {
5560}
5661
5762func CheckMvnCommand (ctx context.Context , isNoBuild bool ) (info * MvnCommandInfo , err error ) {
58-
63+ var toolVer = toolver . Get ( ctx )
5964 var logger = logctx .Use (ctx )
6065 if cachedMvnCommandResult != nil {
6166 if cachedMvnCommandResult .e != nil {
@@ -83,18 +88,15 @@ func CheckMvnCommand(ctx context.Context, isNoBuild bool) (info *MvnCommandInfo,
8388 }
8489
8590 info = & MvnCommandInfo {}
86- info .Path = env . IdeaMavenHome
91+ info .Path = toolVer . Maven . MavenCommand
8792 if info .Path == "" {
8893 info .Path = getMvnCommandOs ()
8994 }
9095 if info .Path == "" {
9196 return nil , ErrMvnNotFound
9297 }
93- info .JavaHome = env .IdeaMavenJre
94- info .UserSettingsPath = env .IdeaMavenConf
95- if r , ok := ctx .Value (M2SettingsFilePathCtxKey ).(string ); ok {
96- info .UserSettingsPath = r
97- }
98+ info .JavaHome = toolVer .Maven .JavaHome
99+ info .UserSettingsPath = toolVer .Maven .MavenSettingPath
98100 // check version
99101 ver , e := checkMvnVersion (ctx , info .Path , info .JavaHome )
100102 if e != nil {
0 commit comments