Skip to content

Commit b0222fe

Browse files
authored
revert(java): stop supporting of test scope for pom.xml files (#7488)
1 parent 8876e70 commit b0222fe

File tree

6 files changed

+7
-51
lines changed

6 files changed

+7
-51
lines changed

docs/docs/coverage/language/java.md

+6-12
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ Each artifact supports the following scanners:
1212

1313
The following table provides an outline of the features Trivy offers.
1414

15-
| Artifact | Internet access | Dev dependencies | [Dependency graph][dependency-graph] | Position | [Detection Priority][detection-priority] |
16-
|------------------|:---------------------:|:------------------:|:------------------------------------:|:--------:|:----------------------------------------:|
17-
| JAR/WAR/PAR/EAR | Trivy Java DB | Include | - | - | Not needed |
18-
| pom.xml | Maven repository [^1] | [Exclude](#scopes) ||[^7] | - |
19-
| *gradle.lockfile | - | Exclude ||| Not needed |
20-
| *.sbt.lock | - | Exclude | - || Not needed |
15+
| Artifact | Internet access | Dev dependencies | [Dependency graph][dependency-graph] | Position | [Detection Priority][detection-priority] |
16+
|------------------|:---------------------:|:----------------:|:------------------------------------:|:--------:|:----------------------------------------:|
17+
| JAR/WAR/PAR/EAR | Trivy Java DB | Include | - | - | Not needed |
18+
| pom.xml | Maven repository [^1] | Exclude ||[^7] | - |
19+
| *gradle.lockfile | - | Exclude ||| Not needed |
20+
| *.sbt.lock | - | Exclude | - || Not needed |
2121

2222
These may be enabled or disabled depending on the target.
2323
See [here](./index.md) for the detail.
@@ -69,11 +69,6 @@ The vulnerability database will be downloaded anyway.
6969
!!! Warning
7070
Trivy may skip some dependencies (that were not found on your local machine) when the `--offline-scan` flag is passed.
7171

72-
### scopes
73-
Trivy supports `runtime`, `compile`, `test` and `import` (for `dependencyManagement`) [dependency scopes][dependency-scopes].
74-
Dependencies without scope are also detected.
75-
76-
By default, Trivy doesn't report dependencies with `test` scope. Use the `--include-dev-deps` flag to include them.
7772

7873
### maven-invoker-plugin
7974
Typically, the integration tests directory (`**/[src|target]/it/*/pom.xml`) of [maven-invoker-plugin][maven-invoker-plugin] doesn't contain actual `pom.xml` files and should be skipped to avoid noise.
@@ -125,4 +120,3 @@ Make sure that you have cache[^8] directory to find licenses from `*.pom` depend
125120
[maven-pom-repos]: https://maven.apache.org/settings.html#repositories
126121
[sbt-dependency-lock]: https://stringbean.github.io/sbt-dependency-lock
127122
[detection-priority]: ../../scanner/vulnerability.md#detection-priority
128-
[dependency-scopes]: https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#Dependency_Scope

pkg/dependency/parser/java/pom/artifact.go

-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ type artifact struct {
2727

2828
Module bool
2929
Relationship ftypes.Relationship
30-
Test bool
3130

3231
Locations ftypes.Locations
3332
}

pkg/dependency/parser/java/pom/parse.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,6 @@ func (p *Parser) parseRoot(root artifact, uniqModules map[string]struct{}) ([]ft
214214
Licenses: result.artifact.Licenses,
215215
Relationship: art.Relationship,
216216
Locations: art.Locations,
217-
Test: art.Test,
218217
}
219218

220219
// save only dependency names
@@ -235,7 +234,6 @@ func (p *Parser) parseRoot(root artifact, uniqModules map[string]struct{}) ([]ft
235234
Licenses: art.Licenses,
236235
Relationship: art.Relationship,
237236
Locations: art.Locations,
238-
Dev: art.Test,
239237
}
240238
pkgs = append(pkgs, pkg)
241239

@@ -402,7 +400,7 @@ func (p *Parser) parseDependencies(deps []pomDependency, props map[string]string
402400
// Resolve dependencies
403401
d = d.Resolve(props, depManagement, rootDepManagement)
404402

405-
if (d.Scope != "" && d.Scope != "compile" && d.Scope != "runtime" && d.Scope != "test") || d.Optional {
403+
if (d.Scope != "" && d.Scope != "compile" && d.Scope != "runtime") || d.Optional {
406404
continue
407405
}
408406

pkg/dependency/parser/java/pom/parse_test.go

-28
Original file line numberDiff line numberDiff line change
@@ -61,27 +61,13 @@ func TestPom_Parse(t *testing.T) {
6161
},
6262
},
6363
},
64-
{
65-
ID: "org.example:example-test:2.0.0",
66-
Name: "org.example:example-test",
67-
Version: "2.0.0",
68-
Relationship: ftypes.RelationshipDirect,
69-
Dev: true,
70-
Locations: ftypes.Locations{
71-
{
72-
StartLine: 49,
73-
EndLine: 54,
74-
},
75-
},
76-
},
7764
},
7865
wantDeps: []ftypes.Dependency{
7966
{
8067
ID: "com.example:happy:1.0.0",
8168
DependsOn: []string{
8269
"org.example:example-api:1.7.30",
8370
"org.example:example-runtime:1.0.0",
84-
"org.example:example-test:2.0.0",
8571
},
8672
},
8773
},
@@ -123,27 +109,13 @@ func TestPom_Parse(t *testing.T) {
123109
},
124110
},
125111
},
126-
{
127-
ID: "org.example:example-test:2.0.0",
128-
Name: "org.example:example-test",
129-
Version: "2.0.0",
130-
Relationship: ftypes.RelationshipDirect,
131-
Dev: true,
132-
Locations: ftypes.Locations{
133-
{
134-
StartLine: 49,
135-
EndLine: 54,
136-
},
137-
},
138-
},
139112
},
140113
wantDeps: []ftypes.Dependency{
141114
{
142115
ID: "com.example:happy:1.0.0",
143116
DependsOn: []string{
144117
"org.example:example-api:1.7.30",
145118
"org.example:example-runtime:1.0.0",
146-
"org.example:example-test:2.0.0",
147119
},
148120
},
149121
},

pkg/dependency/parser/java/pom/pom.go

-1
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,6 @@ func (d pomDependency) ToArtifact(opts analysisOptions) artifact {
303303
Exclusions: exclusions,
304304
Locations: locations,
305305
Relationship: ftypes.RelationshipIndirect, // default
306-
Test: d.Scope == "test",
307306
}
308307
}
309308

pkg/dependency/parser/java/pom/testdata/happy/pom.xml

-6
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,5 @@
4646
<version>999</version>
4747
<scope>provided</scope>
4848
</dependency>
49-
<dependency>
50-
<groupId>org.example</groupId>
51-
<artifactId>example-test</artifactId>
52-
<version>2.0.0</version>
53-
<scope>test</scope>
54-
</dependency>
5549
</dependencies>
5650
</project>

0 commit comments

Comments
 (0)