Skip to content

Commit 9eeca67

Browse files
chenhaoxuaniseki0
authored andcommitted
feature: 增加maven指定模块参数和自定义branch参数
1 parent aedc5dc commit 9eeca67

File tree

5 files changed

+28
-2
lines changed

5 files changed

+28
-2
lines changed

cmd/murphy/internal/scan/cmd.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ var webhookMode common.WebhookModeFlag
4242
var extraData string
4343
var scanCodeHash bool
4444
var gradleProjectFilter gradle.ProjectFilter
45+
var branch string
46+
var mavenModuleName []string
4547

4648
func Cmd() *cobra.Command {
4749
var c cobra.Command
@@ -52,6 +54,7 @@ func Cmd() *cobra.Command {
5254
c.Flags().BoolVar(&jsonOutput, "json", false, "output in json format")
5355
c.Flags().BoolVar(&isDeep, "deep", false, "enable enhanced deep insight, code features identification, vulnerability accessibility analysis")
5456
c.Flags().BoolVar(&noBuild, "no-build", false, "skip project building")
57+
c.Flags().StringVar(&branch, "branch", "", "")
5558
c.Flags().StringVar(&projectNameCli, "project-name", "", "specify project name")
5659
c.Flags().BoolVar(&onlyTaskId, "only-task-id", false, "print task id after task created, the scan result will not be printed")
5760
c.Flags().StringVar(&privateSourceId, "maven-setting-id", "", "specify the id of the Maven settings.xml file used during the scan")
@@ -74,6 +77,8 @@ func DfCmd() *cobra.Command {
7477
c.Flags().BoolVar(&jsonOutput, "json", false, "output in json format")
7578
c.Flags().BoolVar(&isDeep, "deep", false, "enable enhanced deep insight, code features identification, vulnerability accessibility analysis")
7679
c.Flags().BoolVar(&noBuild, "no-build", false, "skip project building")
80+
c.Flags().StringVar(&branch, "branch", "", "")
81+
c.Flags().StringArrayVar(&mavenModuleName, "maven-module-name", make([]string, 0), "retains module")
7782
c.Flags().StringVar(&projectNameCli, "project-name", "", "specify project name")
7883
c.Flags().StringVar(&mavenSettingsPath, "maven-settings", "", "specify the path of maven settings")
7984
c.Flags().BoolVar(&onlyTaskId, "only-task-id", false, "print task id after task created, the scan result will not be printed")

cmd/murphy/internal/scan/scan.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ func scan(ctx context.Context, dir string, accessType model.AccessType, mode mod
153153
createSubtask.PackagePrivateName = privateSourceName
154154
createSubtask.ProjectTagNames = projectTagNames
155155
createSubtask.IsAutonomous = scanCodeHash
156+
createSubtask.Branch = &branch
156157
if createSubtask.ProjectTagNames == nil {
157158
createSubtask.ProjectTagNames = make([]string, 0)
158159
}
@@ -194,7 +195,6 @@ func scan(ctx context.Context, dir string, accessType model.AccessType, mode mod
194195
}
195196
cv.DisplayAlertMessage(ctx, createTaskResp.AlertMessage)
196197
cv.DisplaySubtaskCreated(ctx, createTaskResp.ProjectsName, createTaskResp.SubtaskID)
197-
198198
// create task object
199199
task := &model.ScanTask{
200200
Mode: mode,
@@ -207,6 +207,7 @@ func scan(ctx context.Context, dir string, accessType model.AccessType, mode mod
207207
MavenSourceName: privateSourceName,
208208
IsNoBuild: noBuild,
209209
IsAutonomous: scanCodeHash,
210+
MavenModuleName: mavenModuleName,
210211
}
211212
if gitSummary != nil {
212213
task.GitUrl = gitSummary.RemoteAddr

model/inspection_task.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ type InspectionTask struct {
1010
inspectionDir string
1111
}
1212

13+
func (i *InspectionTask) MavenModuleName() []string {
14+
return i.scanTask.MavenModuleName
15+
}
16+
1317
// IsNoBuild返回当前扫描器是否编译
1418
func (i *InspectionTask) IsNoBuild() bool {
1519
return i.scanTask.IsNoBuild

model/scantask.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ type ScanTask struct {
2121
IsNoBuild bool
2222
IsInternalCmd bool
2323
IsAutonomous bool
24+
MavenModuleName []string
2425
}
2526

2627
func (s *ScanTask) BuildInspectionTask(dir string) *InspectionTask {

module/maven/maven.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,19 @@ type Dependency struct {
2323
func (d Dependency) IsZero() bool {
2424
return len(d.Children) == 0 && d.ArtifactId == "" && d.GroupId == "" && d.Version == ""
2525
}
26-
26+
func checkMavenModule(ctx context.Context, dir string) bool {
27+
task := model.UseInspectionTask(ctx)
28+
mavenModule := task.MavenModuleName()
29+
if len(mavenModule) == 0 {
30+
return true
31+
}
32+
for _, j := range mavenModule {
33+
if j == filepath.Dir(dir) {
34+
return true
35+
}
36+
}
37+
return false
38+
}
2739
func (d Dependency) String() string {
2840
return fmt.Sprintf("%v: %v", d.Coordinate, d.Children)
2941
}
@@ -80,6 +92,9 @@ func ScanMavenProject(ctx context.Context, task *model.InspectionTask) ([]model.
8092
strategy = model.ScanStrategyBackup
8193
}
8294
for _, entry := range deps.ListAllEntries() {
95+
if !checkMavenModule(ctx, entry.relativePath) {
96+
continue
97+
}
8398
task.AddModule(model.Module{
8499
PackageManager: "maven",
85100
ModuleName: entry.coordinate.Name(),

0 commit comments

Comments
 (0)