Skip to content

Commit f43de92

Browse files
committed
Updated gradle-dep-tree plugin and added support for the included builds param
1 parent 0c29c0a commit f43de92

File tree

10 files changed

+62
-34
lines changed

10 files changed

+62
-34
lines changed

cli/docs/flags.go

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"github.com/jfrog/jfrog-cli-core/v2/common/cliutils"
88
pluginsCommon "github.com/jfrog/jfrog-cli-core/v2/plugins/common"
99
"github.com/jfrog/jfrog-cli-core/v2/plugins/components"
10+
1011
"github.com/jfrog/jfrog-cli-security/commands/git/contributors"
1112
"github.com/jfrog/jfrog-cli-security/commands/xray/offlineupdate"
1213
"github.com/jfrog/jfrog-cli-security/utils"
@@ -71,15 +72,16 @@ const (
7172
InsecureTls = "insecure-tls"
7273

7374
// Generic command flags
74-
SpecFlag = "spec"
75-
Threads = "threads"
76-
Recursive = "recursive"
77-
RegexpFlag = "regexp"
78-
AntFlag = "ant"
79-
Project = "project"
80-
Exclusions = "exclusions"
81-
IncludeDirs = "include-dirs"
82-
UseWrapper = "use-wrapper"
75+
SpecFlag = "spec"
76+
Threads = "threads"
77+
Recursive = "recursive"
78+
RegexpFlag = "regexp"
79+
AntFlag = "ant"
80+
Project = "project"
81+
Exclusions = "exclusions"
82+
IncludeDirs = "include-dirs"
83+
UseWrapper = "use-wrapper"
84+
UseIncludedBuilds = "use-included-builds"
8385
)
8486

8587
const (

cli/scancommands.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"github.com/jfrog/jfrog-cli-core/v2/plugins/components"
1818
coreConfig "github.com/jfrog/jfrog-cli-core/v2/utils/config"
1919
"github.com/jfrog/jfrog-cli-core/v2/utils/coreutils"
20+
2021
flags "github.com/jfrog/jfrog-cli-security/cli/docs"
2122
auditSpecificDocs "github.com/jfrog/jfrog-cli-security/cli/docs/auditspecific"
2223
enrichDocs "github.com/jfrog/jfrog-cli-security/cli/docs/enrich"
@@ -28,14 +29,15 @@ import (
2829
scanDocs "github.com/jfrog/jfrog-cli-security/cli/docs/scan/scan"
2930
uploadCdxDocs "github.com/jfrog/jfrog-cli-security/cli/docs/upload"
3031

32+
"github.com/jfrog/jfrog-client-go/utils/io/fileutils"
33+
"github.com/jfrog/jfrog-client-go/utils/log"
34+
"github.com/urfave/cli"
35+
3136
"github.com/jfrog/jfrog-cli-security/commands/enrich"
3237
"github.com/jfrog/jfrog-cli-security/commands/source_mcp"
3338
"github.com/jfrog/jfrog-cli-security/jas"
3439
"github.com/jfrog/jfrog-cli-security/sca/bom/indexer"
3540
"github.com/jfrog/jfrog-cli-security/utils/xray"
36-
"github.com/jfrog/jfrog-client-go/utils/io/fileutils"
37-
"github.com/jfrog/jfrog-client-go/utils/log"
38-
"github.com/urfave/cli"
3941

4042
"github.com/jfrog/jfrog-cli-security/commands/audit"
4143
"github.com/jfrog/jfrog-cli-security/commands/curation"
@@ -491,7 +493,8 @@ func CreateAuditCmd(c *components.Context) (string, string, *coreConfig.ServerDe
491493
SetNpmScope(c.GetStringFlagValue(flags.DepType)).
492494
SetPipRequirementsFile(c.GetStringFlagValue(flags.RequirementsFile)).
493495
SetMaxTreeDepth(c.GetStringFlagValue(flags.MaxTreeDepth)).
494-
SetExclusions(pluginsCommon.GetStringsArrFlagValue(c, flags.Exclusions))
496+
SetExclusions(pluginsCommon.GetStringsArrFlagValue(c, flags.Exclusions)).
497+
SetUseIncludedBuilds(c.GetBoolFlagValue(flags.UseIncludedBuilds))
495498
return xrayVersion, xscVersion, serverDetails, auditCmd, err
496499
}
497500

commands/audit/auditparams.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package audit
33
import (
44
"time"
55

6+
"github.com/jfrog/jfrog-client-go/xray/services"
7+
68
"github.com/jfrog/jfrog-cli-security/sca/bom"
79
"github.com/jfrog/jfrog-cli-security/sca/bom/buildinfo"
810
"github.com/jfrog/jfrog-cli-security/sca/bom/buildinfo/technologies"
@@ -12,7 +14,6 @@ import (
1214
"github.com/jfrog/jfrog-cli-security/utils/severityutils"
1315
"github.com/jfrog/jfrog-cli-security/utils/techutils"
1416
"github.com/jfrog/jfrog-cli-security/utils/xray/scangraph"
15-
"github.com/jfrog/jfrog-client-go/xray/services"
1617
)
1718

1819
type AuditParams struct {
@@ -206,7 +207,8 @@ func (params *AuditParams) ToBuildInfoBomGenParams() (bomParams technologies.Bui
206207
// Python params
207208
PipRequirementsFile: params.PipRequirementsFile(),
208209
// Pnpm params
209-
MaxTreeDepth: params.MaxTreeDepth(),
210+
MaxTreeDepth: params.MaxTreeDepth(),
211+
UseIncludedBuilds: params.UseIncludedBuilds(),
210212
}
211213
return
212214
}

sca/bom/buildinfo/buildinfobom.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ func GetTechDependencyTree(params technologies.BuildInfoBomGeneratorParams, arti
195195
UseWrapper: params.UseWrapper,
196196
IsCurationCmd: params.IsCurationCmd,
197197
CurationCacheFolder: curationCacheFolder,
198+
UseIncludedBuilds: params.UseIncludedBuilds,
198199
}, tech)
199200
case techutils.Npm:
200201
depTreeResult.FullDepTrees, uniqueDepsIds, err = npm.BuildDependencyTree(params)

sca/bom/buildinfo/technologies/common.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,18 @@ import (
1010
buildInfoUtils "github.com/jfrog/build-info-go/utils"
1111
"github.com/jfrog/jfrog-cli-core/v2/utils/config"
1212
"github.com/jfrog/jfrog-cli-core/v2/utils/tests"
13-
"github.com/jfrog/jfrog-cli-security/utils"
14-
"github.com/jfrog/jfrog-cli-security/utils/techutils"
15-
"github.com/jfrog/jfrog-cli-security/utils/xray"
16-
"github.com/jfrog/jfrog-cli-security/utils/xray/scangraph"
1713
"github.com/jfrog/jfrog-client-go/artifactory/services/fspatterns"
1814
clientutils "github.com/jfrog/jfrog-client-go/utils"
1915
"github.com/jfrog/jfrog-client-go/utils/errorutils"
2016
ioUtils "github.com/jfrog/jfrog-client-go/utils/io"
2117
"github.com/jfrog/jfrog-client-go/utils/log"
2218
"github.com/jfrog/jfrog-client-go/xray/services"
2319
xscservices "github.com/jfrog/jfrog-client-go/xsc/services"
20+
21+
"github.com/jfrog/jfrog-cli-security/utils"
22+
"github.com/jfrog/jfrog-cli-security/utils/techutils"
23+
"github.com/jfrog/jfrog-cli-security/utils/xray"
24+
"github.com/jfrog/jfrog-cli-security/utils/xray/scangraph"
2425
)
2526

2627
const (
@@ -57,7 +58,8 @@ type BuildInfoBomGeneratorParams struct {
5758
NpmIgnoreNodeModules bool
5859
NpmOverwritePackageLock bool
5960
// Pnpm params
60-
MaxTreeDepth string
61+
MaxTreeDepth string
62+
UseIncludedBuilds bool
6163
}
6264

6365
func (bbp *BuildInfoBomGeneratorParams) SetNpmScope(depType string) *BuildInfoBomGeneratorParams {

sca/bom/buildinfo/technologies/java/deptreemanager.go

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,18 @@ type DepTreeParams struct {
3131
IsMavenDepTreeInstalled bool
3232
IsCurationCmd bool
3333
CurationCacheFolder string
34+
UseIncludedBuilds bool
3435
}
3536

3637
type DepTreeManager struct {
37-
server *config.ServerDetails
38-
depsRepo string
39-
useWrapper bool
38+
server *config.ServerDetails
39+
depsRepo string
40+
useWrapper bool
41+
useIncludedBuilds bool
4042
}
4143

4244
func NewDepTreeManager(params *DepTreeParams) DepTreeManager {
43-
return DepTreeManager{useWrapper: params.UseWrapper, depsRepo: params.DepsRepo, server: params.Server}
45+
return DepTreeManager{useWrapper: params.UseWrapper, depsRepo: params.DepsRepo, server: params.Server, useIncludedBuilds: params.UseIncludedBuilds}
4446
}
4547

4648
// The structure of a dependency tree of a module in a Gradle/Maven project, as created by the gradle-dep-tree and maven-dep-tree plugins.
@@ -78,10 +80,13 @@ func GetModuleTreeAndDependencies(module *moduleDepTree) (*xrayUtils.GraphNode,
7880
childId := GavPackageTypeIdentifier + childName
7981
childrenList = append(childrenList, childId)
8082
}
83+
8184
moduleTreeMap[dependencyId] = xray.DepTreeNode{
82-
Classifier: dependency.Classifier,
83-
Types: dependency.Types,
84-
Children: childrenList,
85+
Classifier: dependency.Classifier,
86+
Types: dependency.Types,
87+
Children: childrenList,
88+
Unresolved: dependency.Unresolved,
89+
Configurations: dependency.Configurations,
8590
}
8691
}
8792
return xray.BuildXrayDependencyTree(moduleTreeMap, GavPackageTypeIdentifier+module.Root)

sca/bom/buildinfo/technologies/java/gradle.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,8 @@ func (gdt *gradleDepTreeManager) execGradleDepTree(depTreeDir string) (outputFil
159159
"-q",
160160
gradleNoCacheFlag,
161161
fmt.Sprintf("-Dcom.jfrog.depsTreeOutputFile=%s", outputFilePath),
162-
"-Dcom.jfrog.includeAllBuildFiles=true"}
162+
"-Dcom.jfrog.includeAllBuildFiles=true",
163+
fmt.Sprintf("-Dcom.jfrog.includeIncludedBuilds=%t", gdt.useIncludedBuilds)}
163164
log.Info("Running gradle deps tree command:", gradleExecPath, strings.Join(tasks, " "))
164165
if output, err := exec.Command(gradleExecPath, tasks...).CombinedOutput(); err != nil {
165166
return nil, errorutils.CheckErrorf("error running gradle-dep-tree: %s\n%s", err.Error(), string(output))
Binary file not shown.

utils/auditbasicparams.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ type AuditBasicParams struct {
7878
xrayVersion string
7979
xscVersion string
8080
configProfile *xscservices.ConfigProfile
81+
useIncludedBuilds bool
8182
}
8283

8384
func (abp *AuditBasicParams) DirectDependencies() *[]string {
@@ -136,6 +137,13 @@ func (abp *AuditBasicParams) SetMaxTreeDepth(maxTreeDepth string) *AuditBasicPar
136137
return abp
137138
}
138139

140+
func (abp *AuditBasicParams) UseIncludedBuilds() bool { return abp.useIncludedBuilds }
141+
142+
func (abp *AuditBasicParams) SetUseIncludedBuilds(useIncludedBuilds bool) *AuditBasicParams {
143+
abp.useIncludedBuilds = useIncludedBuilds
144+
return abp
145+
}
146+
139147
func (abp *AuditBasicParams) PipRequirementsFile() string {
140148
return abp.pipRequirementsFile
141149
}

utils/xray/xrayutils.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,23 @@ import (
77
const MaxUniqueAppearances = 10
88

99
type DepTreeNode struct {
10-
Classifier *string `json:"classifier"`
11-
Types *[]string `json:"types"`
12-
Children []string `json:"children"`
10+
Classifier *string `json:"classifier"`
11+
Types *[]string `json:"types"`
12+
Children []string `json:"children"`
13+
Unresolved bool `json:"unresolved,omitempty"`
14+
Configurations *[]string `json:"configurations,omitempty"`
1315
}
1416

1517
func toNodeTypesMap(depMap map[string]DepTreeNode) map[string]*DepTreeNode {
1618
mapOfTypes := map[string]*DepTreeNode{}
1719
for nodId, value := range depMap {
1820
mapOfTypes[nodId] = nil
19-
if value.Types != nil || value.Classifier != nil {
21+
if value.Types != nil || value.Classifier != nil || value.Configurations != nil {
2022
mapOfTypes[nodId] = &DepTreeNode{
21-
Classifier: value.Classifier,
22-
Types: value.Types,
23+
Classifier: value.Classifier,
24+
Types: value.Types,
25+
Configurations: value.Configurations,
26+
Unresolved: value.Unresolved,
2327
}
2428
}
2529
}

0 commit comments

Comments
 (0)