Skip to content

Commit

Permalink
refactor: add modules as dependencies of root package
Browse files Browse the repository at this point in the history
  • Loading branch information
DmitriyLewen committed Nov 28, 2024
1 parent 6b1633d commit 775ae7f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 17 deletions.
5 changes: 5 additions & 0 deletions pkg/dependency/parser/java/pom/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,11 @@ func (p *Parser) parseRoot(root artifact, uniqModules map[string]struct{}) ([]ft
return packageID(dependOnName, ver), ver != ""
})

// Add modules as dependencies of root package
if art.Relationship == ftypes.RelationshipRoot {
dependsOn = append(dependsOn, lo.Keys(uniqModules)...)
}

sort.Strings(dependsOn)
if len(dependsOn) > 0 {
deps = append(deps, ftypes.Dependency{
Expand Down
39 changes: 22 additions & 17 deletions pkg/dependency/parser/java/pom/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1230,24 +1230,15 @@ func TestPom_Parse(t *testing.T) {
Relationship: ftypes.RelationshipIndirect,
},
},
// maven doesn't include modules in dep tree of root pom
// for modules uses separate graph:
// ➜ mvn dependency:tree
// [INFO] --------------------------------[ jar ]---------------------------------
// [INFO]
// [INFO] --- dependency:3.6.0:tree (default-cli) @ module ---
// [INFO] com.example:module:jar:1.1.1
// [INFO] \- org.example:example-dependency:jar:1.2.3:compile
// [INFO] \- org.example:example-api:jar:2.0.0:compile
// [INFO]
// [INFO] ----------------------< com.example:aggregation >-----------------------
// [INFO] Building aggregation 1.0.0 [2/2]
// [INFO] from pom.xml
// [INFO] --------------------------------[ pom ]---------------------------------
// [INFO]
// [INFO] --- dependency:3.6.0:tree (default-cli) @ aggregation ---
// [INFO] com.example:aggregation:pom:1.0.0
// `mvn` doesn't include modules in dep tree of root pom and builds separate graphs.
// But we have `root` and `workspace` relationships, so we can merge these graphs.
wantDeps: []ftypes.Dependency{
{
ID: "com.example:aggregation:1.0.0",
DependsOn: []string{
"com.example:module:1.1.1",
},
},
{
ID: "com.example:module:1.1.1",
DependsOn: []string{
Expand Down Expand Up @@ -1301,6 +1292,13 @@ func TestPom_Parse(t *testing.T) {
"org.example:module-1:2.0.0",
},
},
{
ID: "org.example:root:1.0.0",
DependsOn: []string{
"org.example:module-1:2.0.0",
"org.example:module-2:3.0.0",
},
},
},
},
{
Expand Down Expand Up @@ -1342,6 +1340,13 @@ func TestPom_Parse(t *testing.T) {
},
},
wantDeps: []ftypes.Dependency{
{
ID: "com.example:aggregation:1.0.0",
DependsOn: []string{
"com.example:module1:1.1.1",
"com.example:module2:1.1.1",
},
},
{
ID: "com.example:module1:1.1.1",
DependsOn: []string{
Expand Down

0 comments on commit 775ae7f

Please sign in to comment.