From c4b5ab7881c1538d32d87ac21e67e3586e207cd7 Mon Sep 17 00:00:00 2001
From: DmitriyLewen <91113035+DmitriyLewen@users.noreply.github.com>
Date: Mon, 4 Mar 2024 20:23:13 +0600
Subject: [PATCH] fix(java): don't ignore runtime scope for pom.xml files
(#6223)
---
pkg/dependency/parser/java/pom/parse.go | 2 +-
pkg/dependency/parser/java/pom/parse_test.go | 24 +++++++++++++++++++
.../parser/java/pom/testdata/happy/pom.xml | 6 +++++
3 files changed, 31 insertions(+), 1 deletion(-)
diff --git a/pkg/dependency/parser/java/pom/parse.go b/pkg/dependency/parser/java/pom/parse.go
index 979801313d3e..fa70995ea5aa 100644
--- a/pkg/dependency/parser/java/pom/parse.go
+++ b/pkg/dependency/parser/java/pom/parse.go
@@ -381,7 +381,7 @@ func (p *parser) parseDependencies(deps []pomDependency, props map[string]string
// Resolve dependencies
d = d.Resolve(props, depManagement, rootDepManagement)
- if (d.Scope != "" && d.Scope != "compile") || d.Optional {
+ if (d.Scope != "" && d.Scope != "compile" && d.Scope != "runtime") || d.Optional {
continue
}
diff --git a/pkg/dependency/parser/java/pom/parse_test.go b/pkg/dependency/parser/java/pom/parse_test.go
index 7c7410bd9834..f3c8c7a41c89 100644
--- a/pkg/dependency/parser/java/pom/parse_test.go
+++ b/pkg/dependency/parser/java/pom/parse_test.go
@@ -47,12 +47,24 @@ func TestPom_Parse(t *testing.T) {
},
},
},
+ {
+ ID: "org.example:example-runtime:1.0.0",
+ Name: "org.example:example-runtime",
+ Version: "1.0.0",
+ Locations: types.Locations{
+ {
+ StartLine: 37,
+ EndLine: 42,
+ },
+ },
+ },
},
wantDeps: []types.Dependency{
{
ID: "com.example:happy:1.0.0",
DependsOn: []string{
"org.example:example-api:1.7.30",
+ "org.example:example-runtime:1.0.0",
},
},
},
@@ -80,12 +92,24 @@ func TestPom_Parse(t *testing.T) {
},
},
},
+ {
+ ID: "org.example:example-runtime:1.0.0",
+ Name: "org.example:example-runtime",
+ Version: "1.0.0",
+ Locations: types.Locations{
+ {
+ StartLine: 37,
+ EndLine: 42,
+ },
+ },
+ },
},
wantDeps: []types.Dependency{
{
ID: "com.example:happy:1.0.0",
DependsOn: []string{
"org.example:example-api:1.7.30",
+ "org.example:example-runtime:1.0.0",
},
},
},
diff --git a/pkg/dependency/parser/java/pom/testdata/happy/pom.xml b/pkg/dependency/parser/java/pom/testdata/happy/pom.xml
index 3da117ee9950..1f3c9697a17d 100644
--- a/pkg/dependency/parser/java/pom/testdata/happy/pom.xml
+++ b/pkg/dependency/parser/java/pom/testdata/happy/pom.xml
@@ -34,6 +34,12 @@
example-api
${api.version}
+
+ org.example
+ example-runtime
+ 1.0.0
+ runtime
+
org.example
example-provided