From 19623e8b140461f493b38ebdd317e406ef00eca2 Mon Sep 17 00:00:00 2001 From: kunlongli Date: Wed, 13 Nov 2024 17:47:52 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=94=AF=E6=8C=81=E6=A0=87=E5=87=86?= =?UTF-8?q?=E6=89=AB=E6=8F=8F=E5=99=A8=E9=80=82=E9=85=8D=E5=99=A8=E6=A0=B9?= =?UTF-8?q?=E6=8D=AE=E5=8F=82=E6=95=B0=E5=8A=A8=E6=80=81=E7=94=9F=E6=88=90?= =?UTF-8?q?=E5=90=AF=E5=8A=A8=E5=91=BD=E4=BB=A4=20#73?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- standard-adapter/pkg/adapter.go | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/standard-adapter/pkg/adapter.go b/standard-adapter/pkg/adapter.go index c93de40..e986ab7 100644 --- a/standard-adapter/pkg/adapter.go +++ b/standard-adapter/pkg/adapter.go @@ -7,13 +7,17 @@ import ( "github.com/TencentBlueKing/ci-repoAnalysis/analysis-tool-sdk-golang/object" "github.com/TencentBlueKing/ci-repoAnalysis/analysis-tool-sdk-golang/util" "os" - "strings" ) +type CmdBuilder interface { + // Build 生成扫描执行器启动命令, 返回(命令名,参数列表) + Build(input *object.ToolInput) (string, []string, error) +} + // StandardAdapterExecutor 标准扫描器适配器 type StandardAdapterExecutor struct { - Cmd string - WorkDir string + CmdBuilder CmdBuilder + WorkDir string } // Execute 执行扫描 @@ -38,15 +42,12 @@ func (e StandardAdapterExecutor) Execute( // 执行扫描 toolOutputFile := util.WorkDir + "/output.json" - var args []string - cmd := e.Cmd - splitCmd := strings.Split(e.Cmd, " ") - if len(splitCmd) > 1 { - cmd = splitCmd[0] - args = append(args, splitCmd[1:]...) + cmd, args, err := e.CmdBuilder.Build(newToolInput) + if err != nil { + return nil, err } args = append(args, "--input", toolInputFile, "--output", toolOutputFile) - err := util.ExecAndLog(ctx, cmd, args, e.WorkDir) + err = util.ExecAndLog(ctx, cmd, args, e.WorkDir) if err != nil { return nil, err }