Skip to content

Commit ea8ec86

Browse files
jfblaaclaude
andauthored
feat(manifest): build every POM a scan uploads with --dynamic-sbom-inference (#1660)
* feat(manifest): build every POM a scan uploads with --dynamic-sbom-inference Maven build roots are discovered with the API's supported-file pattern for POMs, case-insensitively as the upload matches it, instead of only pom.xml. Each POM is its own build root: a non-default POM runs with `--file`, and coverage by a parent build is judged per file. Discovery also applies socket.yml's projectIgnorePaths, as the upload does, so a POM a scan would not upload is not built either. --exclude-paths and .gitignore matching stay case-sensitive. The recursive setup wizard asks once per directory holding several POMs, and no longer disables a whole directory when --exclude-paths matches only one of its POMs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * refactor(manifest): address review on per-POM DSI discovery - Match build markers in the glob filter, POMs case-insensitively, instead of case-folding the pattern. - Pass the POM to build as ManifestScriptOptions.entryFile; invokeMaven adds --file, and progress and failure messages name the POM. - Resolve socket.yml once per caller and pass it to discovery. - One table for file-addressed tools; one shared depth-then-path sort. - Group setup-wizard candidates by directory: one prompt and one summary count per directory, each of its POMs enumerated unless already covered, including POMs at cwd. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * refactor(manifest): one build-file record per tool, per-directory DSI config - Move build-file names, the POM pattern and its case rule into one BUILD_FILES record; discovery walks narrow globs again and matches after. - Build every discovered POM with its own --file; a user -f/--file in mavenOpts is dropped with a warning during config resolution. - Resolve DSI and wizard settings once per directory. - Require socketConfig for discovery, loaded through loadSocketConfig. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 92f673a commit ea8ec86

21 files changed

Lines changed: 995 additions & 281 deletions

‎CHANGELOG.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
44

55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
66

7+
## [Unreleased]
8+
9+
### Changed
10+
- `--dynamic-sbom-inference` now builds every Maven POM a scan uploads, not only `pom.xml`: `<artifactId>-<version>.pom` and `.pom.xml` files, a bare `pom`, and names in any case, each as a build of its own. Like the upload, it skips POMs matched by `.gitignore` or by `projectIgnorePaths` in `socket.yml`.
11+
712
## [1.11.0](https://github.com/SocketDev/socket-cli/releases/tag/v1.11.0) - 2026-10-26
813

914
### Added

‎src/commands/manifest/discover-manifest-roots.mts‎

Lines changed: 89 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,45 @@
11
import { existsSync } from 'node:fs'
22
import path from 'node:path'
33

4+
import micromatch from 'micromatch'
5+
6+
import { BUILD_FILES } from './scripts/build-tool.mts'
47
import { realpathOrResolved } from '../../utils/fs.mts'
58
import { globWithGitIgnore } from '../../utils/glob.mts'
69
import { excludePathToScanIgnores } from '../scan/exclude-paths.mts'
710

811
import type { BuildTool } from './scripts/build-tool.mts'
912
import type { SocketFactsSbomProject } from './scripts/facts.mts'
1013
import type { SocketJson } from '../../utils/socket-json.mts'
14+
import type { SocketYml } from '@socketsecurity/config'
1115

1216
const BUILD_TOOLS: BuildTool[] = ['gradle', 'maven', 'sbt']
1317

14-
// One glob-suffix set per ecosystem's build-descriptor marker(s); `settings.gradle(.kts)`
15-
// covers Kotlin-DSL roots that have no root `build.gradle`.
16-
const MARKERS_BY_TOOL: Record<BuildTool, string[]> = {
17-
__proto__: null,
18-
gradle: [
19-
'build.gradle',
20-
'build.gradle.kts',
21-
'settings.gradle',
22-
'settings.gradle.kts',
23-
],
24-
maven: ['pom.xml'],
25-
sbt: ['build.sbt'],
26-
} as unknown as Record<BuildTool, string[]>
27-
28-
const TOOL_BY_MARKER: Record<string, BuildTool> = {
29-
__proto__: null,
30-
} as unknown as Record<string, BuildTool>
31-
for (const tool of BUILD_TOOLS) {
32-
for (const marker of MARKERS_BY_TOOL[tool]) {
33-
TOOL_BY_MARKER[marker] = tool
34-
}
18+
const BUILD_FILE_MATCHERS = new Map(
19+
BUILD_TOOLS.map(tool => {
20+
const files = BUILD_FILES[tool]
21+
return [
22+
tool,
23+
files.byFile
24+
? micromatch.matcher(files.nocaseGlob, { dot: true, nocase: true })
25+
: (basename: string) => files.names.includes(basename),
26+
]
27+
}),
28+
)
29+
30+
// `entryFile` (a basename in `dir`) is set only for a tool that addresses its
31+
// builds by file, where one directory can hold several builds.
32+
export type BuildRoot = { dir: string; entryFile?: string | undefined }
33+
34+
export function buildRootPath(root: BuildRoot): string {
35+
return path.join(root.dir, root.entryFile ?? '')
36+
}
37+
38+
function buildFileTool(
39+
tools: readonly BuildTool[],
40+
basename: string,
41+
): BuildTool | undefined {
42+
return tools.find(tool => BUILD_FILE_MATCHERS.get(tool)?.(basename))
3543
}
3644

3745
// A disabled ecosystem is skipped entirely by the glob scan below, so a
@@ -85,27 +93,37 @@ export async function addCoveredBuildFiles(
8593
}
8694
}
8795

88-
// `dir` must be realpath-resolved, as findBuildToolCandidates returns it.
96+
// `root.dir` must be realpath-resolved, as findBuildToolCandidates returns it.
8997
export function isBuildRootCovered(
9098
covered: ReadonlySet<string>,
9199
tool: BuildTool,
92-
dir: string,
100+
root: BuildRoot,
93101
): boolean {
94-
return MARKERS_BY_TOOL[tool].some(marker =>
95-
covered.has(path.join(dir, marker)),
96-
)
102+
const files = BUILD_FILES[tool]
103+
if (files.byFile) {
104+
return !!root.entryFile && covered.has(buildRootPath(root))
105+
}
106+
return files.names.some(name => covered.has(path.join(root.dir, name)))
97107
}
98108

99-
function sortByDepthThenPath(dirs: readonly string[], cwd: string): string[] {
100-
return [...dirs].sort((a, b) => {
101-
const relA = path.relative(cwd, a)
102-
const relB = path.relative(cwd, b)
109+
function compareStrings(a: string, b: string): number {
110+
return a < b ? -1 : a > b ? 1 : 0
111+
}
112+
113+
export function sortByDepthThenPath<T extends BuildRoot>(
114+
roots: readonly T[],
115+
cwd: string,
116+
): T[] {
117+
return [...roots].sort((a, b) => {
118+
const relA = path.relative(cwd, a.dir)
119+
const relB = path.relative(cwd, b.dir)
103120
const depthA = relA === '' ? 0 : relA.split(path.sep).length
104121
const depthB = relB === '' ? 0 : relB.split(path.sep).length
105-
if (depthA !== depthB) {
106-
return depthA - depthB
107-
}
108-
return relA < relB ? -1 : relA > relB ? 1 : 0
122+
return (
123+
depthA - depthB ||
124+
compareStrings(relA, relB) ||
125+
compareStrings(a.entryFile ?? '', b.entryFile ?? '')
126+
)
109127
})
110128
}
111129

@@ -115,51 +133,67 @@ export async function findBuildToolCandidates({
115133
cwd,
116134
excludePaths,
117135
sockJson,
136+
socketConfig,
118137
}: {
119138
cwd: string
120139
excludePaths?: string[] | undefined
140+
// The socket.yml a scan applies to its upload, so a build file a scan would
141+
// not upload is not built either.
142+
socketConfig: SocketYml | undefined
121143
sockJson: SocketJson
122-
}): Promise<Map<BuildTool, string[]>> {
144+
}): Promise<Map<BuildTool, BuildRoot[]>> {
123145
const enabledTools = BUILD_TOOLS.filter(
124146
tool => !sockJson.defaults?.manifest?.[tool]?.disabled,
125147
)
126-
const result = new Map<BuildTool, string[]>()
148+
const result = new Map<BuildTool, BuildRoot[]>()
127149
if (!enabledTools.length) {
128150
return result
129151
}
130152

131-
const patterns = enabledTools.flatMap(tool =>
132-
MARKERS_BY_TOOL[tool].map(marker => `**/${marker}`),
133-
)
134153
const additionalIgnores = (excludePaths ?? []).flatMap(
135154
excludePathToScanIgnores,
136155
)
137-
const hits = await globWithGitIgnore(patterns, {
138-
absolute: true,
139-
additionalIgnores,
140-
cwd,
141-
})
156+
// Build files are matched after the walk, as a scan matches them after its
157+
// ignores, so --exclude-paths and .gitignore stay case-sensitive.
158+
const hits = await globWithGitIgnore(
159+
enabledTools.flatMap(tool => {
160+
const files = BUILD_FILES[tool]
161+
return (files.byFile ? [files.walkGlob] : files.names).map(
162+
glob => `**/${glob}`,
163+
)
164+
}),
165+
{ absolute: true, additionalIgnores, cwd, socketConfig },
166+
)
142167

143-
const dirSetsByTool = new Map<BuildTool, Set<string>>(
144-
enabledTools.map(tool => [tool, new Set<string>()]),
168+
const rootsByTool = new Map<BuildTool, Map<string, BuildRoot>>(
169+
enabledTools.map(tool => [tool, new Map<string, BuildRoot>()]),
145170
)
146-
const resolvedHits = await Promise.all(
147-
hits.map(async hit => ({
148-
dir: await realpathOrResolved(path.dirname(hit)),
149-
tool: TOOL_BY_MARKER[path.basename(hit)],
171+
const matched = hits.flatMap(hit => {
172+
const basename = path.basename(hit)
173+
const tool = buildFileTool(enabledTools, basename)
174+
return tool ? [{ basename, hit, tool }] : []
175+
})
176+
const roots = await Promise.all(
177+
matched.map(async ({ basename, hit, tool }) => ({
178+
root: {
179+
dir: await realpathOrResolved(path.dirname(hit)),
180+
entryFile: BUILD_FILES[tool].byFile ? basename : undefined,
181+
},
182+
tool,
150183
})),
151184
)
152-
for (const { dir, tool } of resolvedHits) {
153-
if (tool) {
154-
dirSetsByTool.get(tool)?.add(dir)
155-
}
185+
for (const { root, tool } of roots) {
186+
rootsByTool.get(tool)?.set(buildRootPath(root), root)
156187
}
157188

158189
const realCwd = await realpathOrResolved(cwd)
159190
for (const tool of enabledTools) {
160191
result.set(
161192
tool,
162-
sortByDepthThenPath([...(dirSetsByTool.get(tool) ?? [])], realCwd),
193+
sortByDepthThenPath(
194+
[...(rootsByTool.get(tool)?.values() ?? [])],
195+
realCwd,
196+
),
163197
)
164198
}
165199
return result

0 commit comments

Comments
 (0)