Skip to content

Commit 2b8c6ff

Browse files
committed
feat: replace pomxmlenhanceable extractor with transitive enricher
1 parent e2a5d93 commit 2b8c6ff

File tree

7 files changed

+56
-141
lines changed

7 files changed

+56
-141
lines changed

cmd/osv-scanner/scan/source/command_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1295,6 +1295,11 @@ func TestCommand_Transitive(t *testing.T) {
12951295
Args: []string{"", "source", "--experimental-disable-plugins=python/requirements", "./testdata/locks-requirements/requirements-transitive.txt"},
12961296
Exit: 128,
12971297
},
1298+
{
1299+
Name: "transitive_pomxml_enricher_requires_enabled_pomxml_extractor",
1300+
Args: []string{"", "source", "--experimental-disable-plugins=java/pomxml", "./testdata/maven-transitive/abc.xml"},
1301+
Exit: 128,
1302+
},
12981303
}
12991304

13001305
for _, tt := range tests {

internal/scalibrextract/language/java/pomxmlenhanceable/pomxmlenhanceable.go

Lines changed: 0 additions & 103 deletions
This file was deleted.

internal/scalibrplugin/__snapshots__/resolve_test.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ haskell/cabal
5353
haskell/stacklock
5454
java/gradlelockfile
5555
java/gradleverificationmetadataxml
56-
java/pomxmlenhanceable
56+
java/pomxml
5757
javascript/bunlock
5858
javascript/packagelockjson
5959
javascript/pnpmlock

internal/scalibrplugin/presets.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"github.com/google/osv-scalibr/extractor/filesystem/language/java/archive"
2525
"github.com/google/osv-scalibr/extractor/filesystem/language/java/gradlelockfile"
2626
"github.com/google/osv-scalibr/extractor/filesystem/language/java/gradleverificationmetadataxml"
27+
"github.com/google/osv-scalibr/extractor/filesystem/language/java/pomxml"
2728
"github.com/google/osv-scalibr/extractor/filesystem/language/javascript/bunlock"
2829
"github.com/google/osv-scalibr/extractor/filesystem/language/javascript/packagelockjson"
2930
"github.com/google/osv-scalibr/extractor/filesystem/language/javascript/pnpmlock"
@@ -47,7 +48,6 @@ import (
4748
"github.com/google/osv-scanner/v2/internal/datasource"
4849
"github.com/google/osv-scanner/v2/internal/depsdev"
4950
"github.com/google/osv-scanner/v2/internal/scalibrextract/filesystem/vendored"
50-
"github.com/google/osv-scanner/v2/internal/scalibrextract/language/java/pomxmlenhanceable"
5151
"github.com/google/osv-scanner/v2/internal/scalibrextract/language/javascript/nodemodules"
5252
"github.com/google/osv-scanner/v2/internal/scalibrextract/language/osv/osvscannerjson"
5353
"github.com/google/osv-scanner/v2/internal/scalibrextract/vcs/gitrepo"
@@ -82,7 +82,7 @@ var ExtractorPresets = map[string]extractors.InitMap{
8282
// Java
8383
gradlelockfile.Name: {noCFG(gradlelockfile.New)},
8484
gradleverificationmetadataxml.Name: {noCFG(gradleverificationmetadataxml.New)},
85-
pomxmlenhanceable.Name: {noCFG(pomxmlenhanceable.New)},
85+
pomxml.Name: {noCFG(pomxml.New)},
8686

8787
// Javascript
8888
packagelockjson.Name: {noCFG(packagelockjson.NewDefault)},

internal/scalibrplugin/resolve.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"github.com/google/osv-scalibr/plugin/list"
99
"github.com/google/osv-scanner/v2/internal/cmdlogger"
1010
"github.com/google/osv-scanner/v2/internal/scalibrextract/filesystem/vendored"
11-
"github.com/google/osv-scanner/v2/internal/scalibrextract/language/java/pomxmlenhanceable"
1211
"github.com/google/osv-scanner/v2/internal/scalibrextract/language/javascript/nodemodules"
1312
"github.com/google/osv-scanner/v2/internal/scalibrextract/language/osv/osvscannerjson"
1413
"github.com/google/osv-scanner/v2/internal/scalibrextract/vcs/gitrepo"
@@ -22,9 +21,6 @@ func resolveFromName(name string) (plugin.Plugin, error) {
2221
}
2322

2423
switch name {
25-
// Java
26-
case pomxmlenhanceable.Name:
27-
return pomxmlenhanceable.New(), nil
2824
// Javascript
2925
case nodemodules.Name:
3026
return nodemodules.New(), nil

pkg/osvscanner/internal/scanners/lockfile.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"github.com/google/osv-scalibr/extractor/filesystem/language/haskell/stacklock"
2222
"github.com/google/osv-scalibr/extractor/filesystem/language/java/gradlelockfile"
2323
"github.com/google/osv-scalibr/extractor/filesystem/language/java/gradleverificationmetadataxml"
24+
"github.com/google/osv-scalibr/extractor/filesystem/language/java/pomxml"
2425
"github.com/google/osv-scalibr/extractor/filesystem/language/javascript/bunlock"
2526
"github.com/google/osv-scalibr/extractor/filesystem/language/javascript/packagelockjson"
2627
"github.com/google/osv-scalibr/extractor/filesystem/language/javascript/pnpmlock"
@@ -37,7 +38,6 @@ import (
3738
"github.com/google/osv-scalibr/extractor/filesystem/os/apk"
3839
"github.com/google/osv-scalibr/extractor/filesystem/os/dpkg"
3940
"github.com/google/osv-scalibr/plugin"
40-
"github.com/google/osv-scanner/v2/internal/scalibrextract/language/java/pomxmlenhanceable"
4141
"github.com/google/osv-scanner/v2/internal/scalibrextract/language/osv/osvscannerjson"
4242
)
4343

@@ -49,7 +49,7 @@ var osvscannerScalibrExtractionMapping = map[string][]string{
4949
"pnpm-lock.yaml": {pnpmlock.Name},
5050
"yarn.lock": {yarnlock.Name},
5151
"package-lock.json": {packagelockjson.Name},
52-
"pom.xml": {pomxmlenhanceable.Name},
52+
"pom.xml": {pomxml.Name},
5353
"buildscript-gradle.lockfile": {gradlelockfile.Name},
5454
"gradle.lockfile": {gradlelockfile.Name},
5555
"verification-metadata.xml": {gradleverificationmetadataxml.Name},

pkg/osvscanner/scan.go

Lines changed: 46 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"github.com/google/osv-scalibr/enricher"
1616
"github.com/google/osv-scalibr/enricher/packagedeprecation"
1717
"github.com/google/osv-scalibr/enricher/reachability/java"
18+
transitivedependencypomxml "github.com/google/osv-scalibr/enricher/transitivedependency/pomxml"
1819
transitivedependencyrequirements "github.com/google/osv-scalibr/enricher/transitivedependency/requirements"
1920
"github.com/google/osv-scalibr/extractor"
2021
"github.com/google/osv-scalibr/extractor/filesystem"
@@ -27,7 +28,6 @@ import (
2728
"github.com/google/osv-scanner/v2/internal/cmdlogger"
2829
"github.com/google/osv-scanner/v2/internal/imodels"
2930
"github.com/google/osv-scanner/v2/internal/scalibrextract/filesystem/vendored"
30-
"github.com/google/osv-scanner/v2/internal/scalibrextract/language/java/pomxmlenhanceable"
3131
"github.com/google/osv-scanner/v2/internal/scalibrextract/vcs/gitcommitdirect"
3232
"github.com/google/osv-scanner/v2/internal/scalibrextract/vcs/gitrepo"
3333
"github.com/google/osv-scanner/v2/internal/scalibrplugin"
@@ -39,25 +39,6 @@ var ErrExtractorNotFound = errors.New("could not determine extractor suitable to
3939

4040
func configurePlugins(plugins []plugin.Plugin, accessors ExternalAccessors, actions ScannerActions) {
4141
for _, plug := range plugins {
42-
if !actions.TransitiveScanning.Disabled {
43-
err := pomxmlenhanceable.EnhanceIfPossible(plug, &cpb.PluginConfig{
44-
UserAgent: actions.RequestUserAgent,
45-
PluginSpecific: []*cpb.PluginSpecificConfig{
46-
{
47-
Config: &cpb.PluginSpecificConfig_PomXmlNet{
48-
PomXmlNet: &cpb.POMXMLNetConfig{
49-
UpstreamRegistry: actions.TransitiveScanning.MavenRegistry,
50-
DepsDevRequirements: !actions.TransitiveScanning.NativeDataSource,
51-
},
52-
},
53-
},
54-
},
55-
})
56-
if err != nil {
57-
log.Errorf("Failed to enhance pomxml extractor: %v", err)
58-
}
59-
}
60-
6142
vendored.Configure(plug, vendored.Config{
6243
// Only attempt to vendor check git directories if we are not skipping scanning root git directories
6344
ScanGitDir: !actions.IncludeGitRoot,
@@ -78,6 +59,18 @@ func isRequirementsExtractorEnabled(plugins []plugin.Plugin) bool {
7859
return false
7960
}
8061

62+
func isPomXmlExtractorEnabled(plugins []plugin.Plugin) bool {
63+
for _, plug := range plugins {
64+
_, ok := plug.(*requirements.Extractor)
65+
66+
if ok {
67+
return true
68+
}
69+
}
70+
71+
return false
72+
}
73+
8174
func getPlugins(defaultPlugins []string, accessors ExternalAccessors, actions ScannerActions) []plugin.Plugin {
8275
if !actions.PluginsNoDefaults {
8376
actions.PluginsEnabled = append(actions.PluginsEnabled, defaultPlugins...)
@@ -93,15 +86,39 @@ func getPlugins(defaultPlugins []string, accessors ExternalAccessors, actions Sc
9386

9487
plugins := scalibrplugin.Resolve(actions.PluginsEnabled, actions.PluginsDisabled)
9588

96-
// TODO: Use Enricher.RequiredPlugins to check this generically
97-
if !actions.TransitiveScanning.Disabled && isRequirementsExtractorEnabled(plugins) {
98-
p, err := transitivedependencyrequirements.New(&cpb.PluginConfig{
99-
UserAgent: actions.RequestUserAgent,
100-
})
101-
if err != nil {
102-
log.Errorf("Failed to make transitivedependencyrequirements enricher: %v", err)
103-
} else {
104-
plugins = append(plugins, p)
89+
if !actions.TransitiveScanning.Disabled {
90+
// TODO: Use Enricher.RequiredPlugins to check this generically
91+
if isRequirementsExtractorEnabled(plugins) {
92+
p, err := transitivedependencyrequirements.New(&cpb.PluginConfig{
93+
UserAgent: actions.RequestUserAgent,
94+
})
95+
if err != nil {
96+
log.Errorf("Failed to make transitivedependencyrequirements enricher: %v", err)
97+
} else {
98+
plugins = append(plugins, p)
99+
}
100+
}
101+
102+
// TODO: Use Enricher.RequiredPlugins to check this generically
103+
if isPomXmlExtractorEnabled(plugins) {
104+
p, err := transitivedependencypomxml.New(&cpb.PluginConfig{
105+
UserAgent: actions.RequestUserAgent,
106+
PluginSpecific: []*cpb.PluginSpecificConfig{
107+
{
108+
Config: &cpb.PluginSpecificConfig_PomXmlNet{
109+
PomXmlNet: &cpb.POMXMLNetConfig{
110+
UpstreamRegistry: actions.TransitiveScanning.MavenRegistry,
111+
DepsDevRequirements: !actions.TransitiveScanning.NativeDataSource,
112+
},
113+
},
114+
},
115+
},
116+
})
117+
if err != nil {
118+
log.Errorf("Failed to make transitivedependencypomxml enricher: %v", err)
119+
} else {
120+
plugins = append(plugins, p)
121+
}
105122
}
106123
}
107124

0 commit comments

Comments
 (0)