Skip to content

Commit d77a2ef

Browse files
committed
fix(manifest): keep the paths of a module excluded with --exclude-paths
An excluded module emitted no project record, so its sources and classpath vanished from the sidecar and the kept projects depending on it were analysed without its code. The Maven, Gradle and sbt producers now emit an excludedProject record for it under --with-files: it gets no project of its own, but its paths stay.
1 parent 1132a3a commit d77a2ef

7 files changed

Lines changed: 75 additions & 22 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
1919
- Gradle dependencies that fail dependency verification, or whose jars cannot be fetched, are reported instead of passed on as healthy.
2020
- Failed Gradle project dependencies are reported instead of silently dropping everything they pull in, and failures name the version that actually failed.
2121
- sbt dependencies whose jars coursier skips or Ivy fails to download are reported instead of passed off as POM-only modules, and POM-only, war and aar modules keep their real shape.
22+
- A module excluded with `--exclude-paths` is still analysed as part of the projects that depend on it.
2223

2324
## [1.10.0](https://github.com/SocketDev/socket-cli/releases/tag/v1.10.0) - 2026-10-22
2425

‎src/commands/manifest/scripts/assemble.mts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ export function assembleFacts(
9191
artifactPaths: buildArtifactPaths(
9292
finalNodes,
9393
[...parsed.projects.values()],
94+
[...parsed.excludedProjects.values()],
9495
graphs,
9596
fileExists,
9697
),
@@ -411,6 +412,7 @@ function byProject(
411412
function buildArtifactPaths(
412413
finalNodes: Map<string, MergedNode>,
413414
projects: RawProject[],
415+
excludedProjects: RawProject[],
414416
graphs: Map<string, SubprojectGraph>,
415417
fileExists: (path: string) => boolean,
416418
): ResolvedArtifactPaths {
@@ -426,7 +428,7 @@ function buildArtifactPaths(
426428
}
427429
// A project's own component shares its id, so this also covers dependency
428430
// edges onto a sibling project.
429-
for (const p of projects) {
431+
for (const p of [...projects, ...excludedProjects]) {
430432
pathsById.set(p.projectKey, {
431433
sources: [...new Set(p.sources)].filter(fileExists).sort(),
432434
targets: [...new Set(p.targets)].filter(fileExists).sort(),

‎src/commands/manifest/scripts/assemble.test.mts‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,29 @@ describe('records → assemble → sidecar', () => {
115115
expect(bom?.targets).toEqual([])
116116
expect(bom?.sources).toEqual([])
117117
})
118+
it("carries an excluded module's paths into the kept project that depends on it", () => {
119+
const records = [
120+
'meta\tgradle\t8.10\t17',
121+
'project\t:app\tg\tapp\t1\tapp',
122+
'projectSrc\t:app\t/abs/app/src',
123+
'projectTgt\t:app\t/abs/app/classes',
124+
'excludedProject\t:lib',
125+
'projectSrc\t:lib\t/abs/lib/src',
126+
'projectTgt\t:lib\t/abs/lib/classes',
127+
'root\t0\t:app\tcompileClasspath\t1',
128+
'node\t0\t:lib\tg\tlib\t1\tjar\t\t1\t:lib',
129+
].join('\n')
130+
const { artifactPaths, facts } = assembleFacts(parseRecords(records), {
131+
fileExists: () => true,
132+
})
133+
134+
expect(facts.projects?.map(p => p.id)).toEqual([':app'])
135+
expect(artifactPaths.pathsById.get(':lib')).toEqual({
136+
sources: ['/abs/lib/src'],
137+
targets: ['/abs/lib/classes'],
138+
})
139+
expect([...artifactPaths.classpathByProject.keys()]).toEqual([':app'])
140+
})
118141
it('states no targets for an artifact that failed to resolve or is gone from disk', () => {
119142
const records = [
120143
'meta\tmaven\t3.9.6\t17',

‎src/commands/manifest/scripts/maven-extension/src/main/java/tech/coana/socket/SocketFactsRecordsEngine.java‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,16 @@ public void run(MavenSession session, List<MavenProject> reactor, File rootDir,
131131
// own "no POM in this directory" error surface instead of an NPE.
132132
if (module.getBasedir() == null) continue;
133133
String ws = SocketSupport.workspace(rootDir.toPath(), module.getBasedir().toPath());
134-
if (SocketSupport.isExcludedPath(ws, excludes)) continue;
135134
String key = projectKey(module);
136-
rec(lines, "project", key, module.getGroupId(), module.getArtifactId(), module.getVersion(), ws);
137-
File pom = module.getFile();
138-
if (pom != null && pom.isFile()) rec(lines, "projectBuild", key, SocketSupport.relativePath(rootDir.toPath(), pom.toPath()));
135+
boolean excluded = SocketSupport.isExcludedPath(ws, excludes);
136+
if (excluded) {
137+
// Not analysed on its own, but a kept module depending on it is analysed with its code.
138+
if (opts.withFiles) rec(lines, "excludedProject", key);
139+
} else {
140+
rec(lines, "project", key, module.getGroupId(), module.getArtifactId(), module.getVersion(), ws);
141+
File pom = module.getFile();
142+
if (pom != null && pom.isFile()) rec(lines, "projectBuild", key, SocketSupport.relativePath(rootDir.toPath(), pom.toPath()));
143+
}
139144
if (opts.withFiles) {
140145
for (String s : collectSources(module)) rec(lines, "projectSrc", key, s);
141146
for (String t : collectTargets(module)) rec(lines, "projectTgt", key, t);

‎src/commands/manifest/scripts/records.mts‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import type { ResolutionFailure, Unscannable } from './resolution-report.mts'
1313
// projectSrc projectKey path (--with-files only)
1414
// projectTgt projectKey path (--with-files only)
1515
// projectBuild projectKey path (build-root-relative; may be absent on disk)
16+
// excludedProject projectKey (--with-files only; paths without a project)
1617
// root rootId projectKey config prod(0|1)
1718
// node rootId coordId group name version ext classifier direct(0|1) project
1819
// edge rootId parentCoordId childCoordId
@@ -80,6 +81,9 @@ export type ParsedRecords = {
8081
// directory-addressed build.
8182
entry: string
8283
projects: Map<string, RawProject>
84+
// Excluded from the scan: not projects of their own, but their paths serve
85+
// the kept projects depending on them.
86+
excludedProjects: Map<string, RawProject>
8387
roots: Map<string, RawRoot>
8488
scannedConfigs: string[]
8589
failures: ResolutionFailure[]
@@ -115,12 +119,14 @@ export function parseRecords(text: string): ParsedRecords {
115119
buildRoot: '',
116120
entry: '',
117121
projects: new Map(),
122+
excludedProjects: new Map(),
118123
roots: new Map(),
119124
scannedConfigs: [],
120125
failures: [],
121126
unscannable: [],
122127
}
123128
const scanned = new Set<string>()
129+
const excluded = new Set<string>()
124130

125131
const root = (id: string): RawRoot => {
126132
let r = result.roots.get(id)
@@ -190,6 +196,9 @@ export function parseRecords(text: string): ParsedRecords {
190196
project(f[1] ?? '').targets.push(f[2])
191197
}
192198
break
199+
case 'excludedProject':
200+
excluded.add(f[1] ?? '')
201+
break
193202
case 'projectBuild':
194203
if (f[2]) {
195204
project(f[1] ?? '').buildFiles.push(f[2])
@@ -271,6 +280,13 @@ export function parseRecords(text: string): ParsedRecords {
271280
break
272281
}
273282
}
283+
for (const key of excluded) {
284+
const p = result.projects.get(key)
285+
if (p) {
286+
result.projects.delete(key)
287+
result.excludedProjects.set(key, p)
288+
}
289+
}
274290
result.scannedConfigs = [...scanned].sort()
275291
return result
276292
}

‎src/commands/manifest/scripts/socket-facts.init.gradle‎

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,9 @@ gradle.projectsEvaluated { g ->
9292
g.socketFactsState.projectGaByPath[p.path] = "${p.group ?: ''}:${p.name}".toString()
9393
g.socketFactsState.projectGavByPath[p.path] = "${p.group ?: ''}:${p.name}:${p.version ?: ''}".toString()
9494
// A wholly excluded subproject emits no project record and its configs are never resolved (see the
95-
// collector). The project maps above stay populated so a KEPT project depending on it still
96-
// recognizes it as a first-party module.
97-
if (g.ext.socketIsExcluded.call(rel(p.projectDir))) {
98-
return
99-
}
95+
// collector). The project maps above stay populated so a KEPT project depending on it
96+
// still recognizes it as a first-party module, and its paths are kept so it is analysed with its code.
97+
def excluded = g.ext.socketIsExcluded.call(rel(p.projectDir))
10098
// Guarded: projects without the java `sourceSets` convention (pure aggregators, AGP-only
10199
// Android modules) contribute empty lists rather than failing.
102100
// ALL source sets are emitted (not just main/test) so custom ones (integrationTest,
@@ -134,6 +132,7 @@ gradle.projectsEvaluated { g ->
134132
sources: (sources as List).sort(),
135133
targets: (targets as List).sort(),
136134
buildFiles: buildFiles,
135+
excluded: excluded,
137136
])
138137
}
139138
}
@@ -670,8 +669,12 @@ rootProject { rp ->
670669
def projectsInfo
671670
synchronized (state.projectsInfo) { projectsInfo = new ArrayList(state.projectsInfo) }
672671
projectsInfo.each { pi ->
673-
rec(['project', pi.path, pi.group ?: '', pi.name, pi.version ?: '', pi.dir])
674-
pi.buildFiles.each { f -> rec(['projectBuild', pi.path, f]) }
672+
if (pi.excluded) {
673+
if (withFilesProjects) rec(['excludedProject', pi.path])
674+
} else {
675+
rec(['project', pi.path, pi.group ?: '', pi.name, pi.version ?: '', pi.dir])
676+
pi.buildFiles.each { f -> rec(['projectBuild', pi.path, f]) }
677+
}
675678
if (withFilesProjects) {
676679
pi.sources.each { s -> rec(['projectSrc', pi.path, s]) }
677680
pi.targets.each { t -> rec(['projectTgt', pi.path, t]) }

‎src/commands/manifest/scripts/socket-facts.plugin.scala‎

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -117,21 +117,24 @@ object SocketFactsPlugin extends AutoPlugin {
117117
rec("buildRoot", rootCanonPath.toString)
118118

119119
// One `project` record per build module (sources/targets only with --with-files). Excluded
120-
// subprojects are omitted (they were also skipped during resolution above).
120+
// subprojects get none (they were also skipped during resolution above), but keep their paths so
121+
// a kept project depending on one is analysed with its code.
121122
allRefs.foreach { ref =>
122-
if (!isExcludedRef(ref)) {
123-
val mid = rootIdOf(extracted, ref)
124-
val ver = if (mid.revision == null) "" else mid.revision
123+
val mid = rootIdOf(extracted, ref)
124+
val ver = if (mid.revision == null) "" else mid.revision
125+
if (isExcludedRef(ref)) {
126+
if (withFiles) rec("excludedProject", ref.project)
127+
} else {
125128
val baseDir = extracted.get(baseDirectory.in(ref))
126129
rec("project", ref.project, mid.organization, mid.name, ver, relOf(baseDir))
127130
(buildFilesByRef.getOrElse(ref, Nil) ++ baseBuildSbt(baseDir, rootCanonPath).map(relOf)).distinct.sorted
128131
.foreach(f => rec("projectBuild", ref.project, f))
129-
if (withFiles) {
130-
moduleDirs.get(mid.organization + ":" + mid.name + ":" + ver).foreach {
131-
case (sources, targets) =>
132-
sources.foreach(s => rec("projectSrc", ref.project, s))
133-
targets.foreach(t => rec("projectTgt", ref.project, t))
134-
}
132+
}
133+
if (withFiles) {
134+
moduleDirs.get(mid.organization + ":" + mid.name + ":" + ver).foreach {
135+
case (sources, targets) =>
136+
sources.foreach(s => rec("projectSrc", ref.project, s))
137+
targets.foreach(t => rec("projectTgt", ref.project, t))
135138
}
136139
}
137140
}

0 commit comments

Comments
 (0)