@mustafagoksever/java-inspector 3.0.0 → 3.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/README.md +28 -17
  2. package/dist/analyzer/ApiDiff.d.ts +35 -0
  3. package/dist/analyzer/ApiDiff.d.ts.map +1 -0
  4. package/dist/analyzer/ApiDiff.js +199 -0
  5. package/dist/analyzer/ApiDiff.js.map +1 -0
  6. package/dist/analyzer/JavaClassAnalyzer.d.ts +10 -0
  7. package/dist/analyzer/JavaClassAnalyzer.d.ts.map +1 -1
  8. package/dist/analyzer/JavaClassAnalyzer.js +37 -10
  9. package/dist/analyzer/JavaClassAnalyzer.js.map +1 -1
  10. package/dist/cache/ProjectCache.d.ts +9 -1
  11. package/dist/cache/ProjectCache.d.ts.map +1 -1
  12. package/dist/cache/ProjectCache.js +72 -4
  13. package/dist/cache/ProjectCache.js.map +1 -1
  14. package/dist/decompiler/DecompilerService.d.ts +5 -0
  15. package/dist/decompiler/DecompilerService.d.ts.map +1 -1
  16. package/dist/decompiler/DecompilerService.js +87 -13
  17. package/dist/decompiler/DecompilerService.js.map +1 -1
  18. package/dist/index.d.ts +73 -6
  19. package/dist/index.d.ts.map +1 -1
  20. package/dist/index.js +820 -198
  21. package/dist/index.js.map +1 -1
  22. package/dist/scanner/ArtifactService.d.ts +65 -1
  23. package/dist/scanner/ArtifactService.d.ts.map +1 -1
  24. package/dist/scanner/ArtifactService.js +273 -14
  25. package/dist/scanner/ArtifactService.js.map +1 -1
  26. package/dist/scanner/DependencyScanner.d.ts +76 -0
  27. package/dist/scanner/DependencyScanner.d.ts.map +1 -1
  28. package/dist/scanner/DependencyScanner.js +365 -41
  29. package/dist/scanner/DependencyScanner.js.map +1 -1
  30. package/dist/scanner/LazyResolver.js +1 -1
  31. package/dist/scanner/LazyResolver.js.map +1 -1
  32. package/dist/scanner/ProjectDiscovery.d.ts +8 -1
  33. package/dist/scanner/ProjectDiscovery.d.ts.map +1 -1
  34. package/dist/scanner/ProjectDiscovery.js +40 -5
  35. package/dist/scanner/ProjectDiscovery.js.map +1 -1
  36. package/dist/utils/javaOutline.d.ts +70 -0
  37. package/dist/utils/javaOutline.d.ts.map +1 -0
  38. package/dist/utils/javaOutline.js +444 -0
  39. package/dist/utils/javaOutline.js.map +1 -0
  40. package/dist/utils/methodExtractor.d.ts +7 -0
  41. package/dist/utils/methodExtractor.d.ts.map +1 -1
  42. package/dist/utils/methodExtractor.js +50 -0
  43. package/dist/utils/methodExtractor.js.map +1 -1
  44. package/lib/vineflower-1.12.0.jar +0 -0
  45. package/package.json +5 -4
  46. package/lib/vineflower-1.11.2.jar +0 -0
@@ -10,7 +10,28 @@ export interface ScanResult {
10
10
  };
11
11
  message?: string;
12
12
  }
13
+ export interface DependencyNode {
14
+ groupId: string;
15
+ artifactId: string;
16
+ version: string;
17
+ type: string;
18
+ classifier?: string;
19
+ scope?: string;
20
+ optional?: boolean;
21
+ /** 1 = declared in the module's pom (direct), >1 = transitive. */
22
+ depth: number;
23
+ /** groupId:artifactId of the dependency that pulled this one in (direct dependencies: the module). */
24
+ via?: string;
25
+ }
26
+ export interface ModuleDependencies {
27
+ module: string;
28
+ dependencies: DependencyNode[];
29
+ }
30
+ /** Parse the text output of `mvn dependency:tree -DoutputFile=...` (one module per file). */
31
+ export declare function parseDependencyTree(text: string): ModuleDependencies | null;
13
32
  export declare class DependencyScanner {
33
+ /** Projects whose last classpath came from recoverReactorClasspath with JARs missing. */
34
+ private partialClasspaths;
14
35
  private static instance;
15
36
  private classpathPromises;
16
37
  private mavenCommand;
@@ -46,6 +67,15 @@ export declare class DependencyScanner {
46
67
  * Check if Maven classpath resolution is currently in progress.
47
68
  */
48
69
  isResolvingClasspath(projectPath: string): boolean;
70
+ /**
71
+ * Wait (bounded) for a classpath that is being resolved by this process or, via scan.lock,
72
+ * by another server process. Returns null if it is still unavailable when the time is up.
73
+ * Single-class lookups use this so a cold start does not answer "class not found" while
74
+ * Maven is still running.
75
+ */
76
+ /** The last classpath/scan failure of a project, without clearing it (scanProject reports and clears it). */
77
+ peekScanError(projectPath: string): string | undefined;
78
+ waitForClasspath(projectPath: string, timeoutMs: number, onWait?: (elapsedMs: number) => Promise<void>): Promise<string[] | null>;
49
79
  /**
50
80
  * Find corresponding JAR package path by class name.
51
81
  * Uses cache + lazy on-demand scanning.
@@ -75,6 +105,52 @@ export declare class DependencyScanner {
75
105
  */
76
106
  getClasspath(projectPath: string): Promise<string[] | null>;
77
107
  explainDependency(projectPath: string, coordinates: string): Promise<string>;
108
+ /**
109
+ * Download the -sources.jar of one artifact into the local repository (`mvn dependency:get`).
110
+ * Opt-in: it reaches the network. Returns Maven's error output on failure.
111
+ */
112
+ downloadSources(projectPath: string, coordinates: {
113
+ groupId: string;
114
+ artifactId: string;
115
+ version: string;
116
+ }): Promise<{
117
+ ok: boolean;
118
+ message?: string;
119
+ }>;
120
+ /** `mvn dependency:get` for one artifact (no transitives) into the local repository. Opt-in: it reaches the network. */
121
+ downloadArtifact(projectPath: string, coordinates: {
122
+ groupId: string;
123
+ artifactId: string;
124
+ version: string;
125
+ }, classifier?: string): Promise<{
126
+ ok: boolean;
127
+ message?: string;
128
+ }>;
129
+ /**
130
+ * Gradle: an init script adds a task to every project that writes the resolved compile/runtime/test
131
+ * classpath files (lenient, so one unresolvable dependency does not lose the rest) to one file per project.
132
+ */
133
+ private getGradleClasspath;
134
+ /** GRADLE_CMD, then the project's wrapper (gradlew), then GRADLE_HOME/bin/gradle, then gradle on PATH. */
135
+ private resolveGradleCommand;
136
+ /**
137
+ * A multi-module checkout whose modules depend on each other fails `dependency:build-classpath` on Maven 3
138
+ * until the sibling modules are installed ("Could not resolve dependencies ... demo:a:jar"). Recover by
139
+ * re-running with --fail-at-end (modules that resolve still write their file) and adding the external
140
+ * dependencies of the dependency tree (which only needs poms) that exist in the local repository.
141
+ */
142
+ private recoverReactorClasspath;
143
+ /** groupId:artifactId of every module pom under the project (parent groupId when the module has none). */
144
+ private reactorCoordinates;
145
+ private runDependencyTree;
146
+ /**
147
+ * Resolved dependency tree of every reactor module (`mvn dependency:tree`, one output file per module).
148
+ * Cached per project until pom.xml or the resolved classpath changes.
149
+ */
150
+ listDependencies(projectPath: string): Promise<{
151
+ modules: ModuleDependencies[];
152
+ cached: boolean;
153
+ }>;
78
154
  private withClasspathResolutionSlot;
79
155
  /**
80
156
  * Resolve the Maven command to use.
@@ -1 +1 @@
1
- {"version":3,"file":"DependencyScanner.d.ts","sourceRoot":"","sources":["../../src/scanner/DependencyScanner.ts"],"names":[],"mappings":"AAMA,OAAO,EAAgB,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAOnE,MAAM,WAAW,UAAU;IACvB,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,aAAa,EAAE,MAAM,EAAE,CAAC;IACxB,MAAM,EAAE,UAAU,GAAG,aAAa,CAAC;IACnC,QAAQ,CAAC,EAAE;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;IAChD,OAAO,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,qBAAa,iBAAiB;IAC1B,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAoB;IAC3C,OAAO,CAAC,iBAAiB,CAAwC;IACjE,OAAO,CAAC,YAAY,CAAuB;IAC3C,OAAO,CAAC,UAAU,CAA6B;IAC/C,OAAO,CAAC,0BAA0B,CAAK;IACvC,OAAO,CAAC,wBAAwB,CAAyB;IAEzD,OAAO,CAAC,gBAAgB,CAA0C;IAElE,MAAM,CAAC,WAAW,IAAI,iBAAiB;;IAcvC;;;;;;OAMG;IACG,WAAW,CACb,WAAW,EAAE,MAAM,EACnB,YAAY,GAAE,OAAe,EAC7B,UAAU,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,KAAK,OAAO,CAA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AAE,GAAG,IAAI,CAAC;IAI3D,iBAAiB,CAAC,WAAW,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAmBlF;;;OAGG;IACG,eAAe,CAAC,WAAW,EAAE,MAAM,EAAE,WAAW,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC;QAAE,EAAE,EAAE,OAAO,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IAI7J,wHAAwH;IAClH,gBAAgB,CAAC,WAAW,EAAE,MAAM,EAAE,WAAW,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;QAAE,EAAE,EAAE,OAAO,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IAqBnL;;;OAGG;YACW,kBAAkB;IAqChC,0GAA0G;YAC5F,oBAAoB;IAUlC;;;;;OAKG;YACW,uBAAuB;IAkCrC,0GAA0G;YAC5F,kBAAkB;YAiBlB,iBAAiB;IAyB/B;;;OAGG;IACG,gBAAgB,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC;QAAE,OAAO,EAAE,kBAAkB,EAAE,CAAC;QAAC,MAAM,EAAE,OAAO,CAAA;KAAE,CAAC;YAgB1F,2BAA2B;IAazC;;;;;;;OAOG;YACW,mBAAmB;CAoCpC"}
@@ -1,5 +1,6 @@
1
1
  import { execFile } from 'child_process';
2
2
  import { promisify } from 'util';
3
+ import * as os from 'os';
3
4
  import * as path from 'path';
4
5
  import fs from 'fs-extra';
5
6
  import { projectCache } from '../cache/ProjectCache.js';
@@ -8,8 +9,68 @@ import { lazyResolver } from './LazyResolver.js';
8
9
  import { getProjectCacheDir } from '../utils/cachePaths.js';
9
10
  import { Logger } from '../utils/Logger.js';
10
11
  import { CrossProcessLock } from '../utils/CrossProcessLock.js';
12
+ import { buildToolOf } from './ProjectDiscovery.js';
11
13
  const execFileAsync = promisify(execFile);
14
+ /** Parse the text output of `mvn dependency:tree -DoutputFile=...` (one module per file). */
15
+ export function parseDependencyTree(text) {
16
+ const lines = text.split(/\r?\n/).filter(line => line.trim());
17
+ if (!lines.length)
18
+ return null;
19
+ const parse = (token) => {
20
+ const parts = token.split(':');
21
+ if (parts.length < 4)
22
+ return null;
23
+ const [groupId, artifactId, type] = parts;
24
+ if (parts.length === 4)
25
+ return { groupId, artifactId, type, version: parts[3] };
26
+ if (parts.length === 5)
27
+ return { groupId, artifactId, type, version: parts[3], scope: parts[4] };
28
+ return { groupId, artifactId, type, classifier: parts[3], version: parts[4], scope: parts[5] };
29
+ };
30
+ const root = parse(lines[0].trim().split(/\s+/)[0]);
31
+ if (!root)
32
+ return null;
33
+ const module = `${root.groupId}:${root.artifactId}:${root.version}`;
34
+ const stack = [`${root.groupId}:${root.artifactId}`];
35
+ const dependencies = [];
36
+ for (const line of lines.slice(1)) {
37
+ const prefix = line.match(/^[| +\\-]*/)?.[0] ?? '';
38
+ const depth = Math.max(1, Math.round(prefix.length / 3));
39
+ const body = line.substring(prefix.length).trim();
40
+ const node = parse(body.split(/\s+/)[0]);
41
+ if (!node)
42
+ continue;
43
+ stack.length = depth;
44
+ dependencies.push({ ...node, depth, via: stack[depth - 1], ...(/\(optional\)/.test(body) ? { optional: true } : {}) });
45
+ stack[depth] = `${node.groupId}:${node.artifactId}`;
46
+ }
47
+ return { module, dependencies };
48
+ }
49
+ const GRADLE_INIT_SCRIPT = `
50
+ allprojects { p ->
51
+ p.tasks.register('javaInspectorClasspath') {
52
+ doLast {
53
+ def outDir = new File(System.getProperty('javaInspector.out'))
54
+ def files = new LinkedHashSet<File>()
55
+ ['compileClasspath', 'runtimeClasspath', 'testCompileClasspath', 'testRuntimeClasspath'].each { name ->
56
+ def conf = p.configurations.findByName(name)
57
+ if (conf != null && conf.canBeResolved) {
58
+ try {
59
+ files.addAll(conf.incoming.artifactView { lenient = true }.files.files)
60
+ } catch (Exception e) {
61
+ p.logger.warn("java-inspector: could not resolve " + p.path + ":" + name + ": " + e.message)
62
+ }
63
+ }
64
+ }
65
+ def safe = p.path.replaceAll('[^A-Za-z0-9_.-]', '_')
66
+ new File(outDir, "cp-" + (safe ?: 'root') + ".txt").text = files.collect { it.absolutePath }.join('\\n')
67
+ }
68
+ }
69
+ }
70
+ `;
12
71
  export class DependencyScanner {
72
+ /** Projects whose last classpath came from recoverReactorClasspath with JARs missing. */
73
+ partialClasspaths = new Set();
13
74
  static instance;
14
75
  classpathPromises = new Map();
15
76
  mavenCommand = null;
@@ -66,7 +127,7 @@ export class DependencyScanner {
66
127
  classCount: 0,
67
128
  sampleEntries: [],
68
129
  status: 'in_progress',
69
- message: `Previous scan failed: ${storedError}. Call scan_dependencies with forceRefresh=true to retry.`,
130
+ message: `Previous scan failed: ${storedError}. Call scan_project with forceRefresh=true to retry.`,
70
131
  };
71
132
  }
72
133
  // Check for complete index
@@ -83,24 +144,6 @@ export class DependencyScanner {
83
144
  };
84
145
  }
85
146
  }
86
- // Cross-process check: is another process currently scanning?
87
- const isLockedByOther = await CrossProcessLock.check(projectPath, 'scan');
88
- if (isLockedByOther) {
89
- logger.info('[SCAN] Another process is currently scanning this project.');
90
- const progress = await projectCache.getScanProgress(projectPath) ?? undefined;
91
- const progressText = progress
92
- ? `${progress.processed}/${progress.total} JARs processed`
93
- : 'scanning in progress';
94
- await onProgress?.(`Another process is scanning: ${progressText}`, progress ? Math.floor((progress.processed / progress.total) * 100) : 0, 100);
95
- return {
96
- jarCount: progress?.total ?? 0,
97
- classCount: 0,
98
- sampleEntries: [],
99
- status: 'in_progress',
100
- progress,
101
- message: 'Another process is currently scanning this project. Please wait or call again later.',
102
- };
103
- }
104
147
  // Check if classpath resolution is already in progress (in-process)
105
148
  if (this.classpathPromises.has(projectPath)) {
106
149
  await onProgress?.('Maven classpath resolution in progress...', 5, 100);
@@ -109,7 +152,7 @@ export class DependencyScanner {
109
152
  classCount: 0,
110
153
  sampleEntries: [],
111
154
  status: 'in_progress',
112
- message: 'Maven classpath is being resolved in the background. This may take a few minutes for large projects (e.g. Spring Boot). Call scan_dependencies again to check progress.',
155
+ message: 'Maven classpath is being resolved in the background. This may take a few minutes for large projects (e.g. Spring Boot). Call scan_project again to check progress; other tools already work on the partial index.',
113
156
  };
114
157
  }
115
158
  // Check if background scan is already running (in-process)
@@ -125,6 +168,24 @@ export class DependencyScanner {
125
168
  progress,
126
169
  };
127
170
  }
171
+ // Cross-process check: is another process currently scanning?
172
+ const isLockedByOther = await CrossProcessLock.check(projectPath, 'scan');
173
+ if (isLockedByOther) {
174
+ logger.info('[SCAN] Another process is currently scanning this project.');
175
+ const progress = await projectCache.getScanProgress(projectPath) ?? undefined;
176
+ const progressText = progress
177
+ ? `${progress.processed}/${progress.total} JARs processed`
178
+ : 'scanning in progress';
179
+ await onProgress?.(`Another process is scanning: ${progressText}`, progress ? Math.floor((progress.processed / progress.total) * 100) : 0, 100);
180
+ return {
181
+ jarCount: progress?.total ?? 0,
182
+ classCount: 0,
183
+ sampleEntries: [],
184
+ status: 'in_progress',
185
+ progress,
186
+ message: 'Another process is currently scanning this project. Please wait or call again later.',
187
+ };
188
+ }
128
189
  // Check if we already have classpath cached (scan may have finished or been interrupted)
129
190
  const cachedClasspath = await projectCache.getClasspath(projectPath);
130
191
  if (cachedClasspath && cachedClasspath.length > 0) {
@@ -153,7 +214,7 @@ export class DependencyScanner {
153
214
  classCount: 0,
154
215
  sampleEntries: [],
155
216
  status: 'in_progress',
156
- message: 'Maven classpath resolution started in the background. This may take a few minutes for large projects (e.g. Spring Boot). Call scan_dependencies again to check progress.',
217
+ message: 'Maven classpath resolution started in the background. This may take a few minutes for large projects (e.g. Spring Boot). Call scan_project again to check progress; other tools already work on the partial index.',
157
218
  };
158
219
  }
159
220
  /**
@@ -215,7 +276,10 @@ export class DependencyScanner {
215
276
  }
216
277
  const pomHash = await projectCache.getPomHash(projectPath);
217
278
  const classpathHash = projectCache.getClasspathHash(jarPaths);
218
- await projectCache.saveClasspath(projectPath, jarPaths, pomHash);
279
+ const partial = this.partialClasspaths.delete(projectPath);
280
+ await projectCache.saveClasspath(projectPath, jarPaths, pomHash, partial);
281
+ if (partial)
282
+ logger.warn('[MAVEN] Classpath is partial (some dependencies are not in the local repository); it will be resolved again in 10 minutes.');
219
283
  logger.info(`[MAVEN] Classpath resolved. ${jarPaths.length} JARs found. Starting background scan...`);
220
284
  await onProgress?.(`Classpath resolved: ${jarPaths.length} JARs. Starting background scan...`, 10, 100);
221
285
  await this.acquireScanLockAndStart(projectPath, jarPaths, pomHash, classpathHash, onProgress);
@@ -232,18 +296,29 @@ export class DependencyScanner {
232
296
  * Use Maven to get the dependency classpath.
233
297
  */
234
298
  async getBuildClasspath(projectPath, onProgress) {
299
+ if (await buildToolOf(projectPath) === 'gradle')
300
+ return this.getGradleClasspath(projectPath, onProgress);
235
301
  const logger = Logger.get(projectPath);
236
302
  const mavenCmd = await this.resolveMavenCommand(projectPath);
237
303
  const cacheDir = getProjectCacheDir(projectPath);
238
304
  await fs.ensureDir(cacheDir);
239
- const outputFile = path.join(cacheDir, 'maven-cp.txt');
305
+ // One output file per reactor module. A single shared -Dmdep.outputFile is overwritten by every
306
+ // module of a multi-module build (only the last module would survive), and -Dmdep.appendOutput
307
+ // is not reliable across plugin versions. Maven interpolates ${project.*} in the CLI property.
308
+ const outputDir = path.join(cacheDir, 'maven-cp');
309
+ await fs.remove(outputDir).catch(() => { });
310
+ await fs.ensureDir(outputDir);
311
+ const outputFile = path.join(outputDir, 'cp-${project.groupId}__${project.artifactId}.txt');
240
312
  const isDebug = process.env.NODE_ENV === 'development';
241
313
  logger.info(`[MAVEN] Running: ${mavenCmd} dependency:build-classpath...`);
242
314
  logger.debug(`[MAVEN] Config: cwd=${projectPath}, timeout=300000ms, shell=${process.platform === 'win32'}, maxBuffer=1MB, outputFile=${outputFile}`);
243
315
  await onProgress?.(`Running Maven: ${mavenCmd} dependency:build-classpath...`, 5, 100);
244
316
  const start = performance.now();
317
+ let recovered = null;
245
318
  try {
246
- const { stdout, stderr } = await execFileAsync(mavenCmd, ['dependency:build-classpath', `-Dmdep.outputFile=${outputFile}`, '-q'], {
319
+ const { stdout, stderr } = await execFileAsync(mavenCmd,
320
+ // -B: never block on interactive prompts.
321
+ ['-B', '-q', 'dependency:build-classpath', `-Dmdep.outputFile=${outputFile}`], {
247
322
  cwd: projectPath,
248
323
  timeout: 300000, // 5 minutes for large projects (e.g. Spring Boot)
249
324
  shell: process.platform === 'win32',
@@ -268,25 +343,27 @@ export class DependencyScanner {
268
343
  if (error.code)
269
344
  details += `\nexit code: ${error.code}`;
270
345
  logger.error(`[MAVEN] Command failed after ${duration}s: ${error.message}${details}`);
271
- throw new Error(`Maven command failed: ${error.message}${details}`);
346
+ recovered = await this.recoverReactorClasspath(projectPath, mavenCmd, outputFile, details);
347
+ if (!recovered)
348
+ throw new Error(`Maven command failed: ${error.message}${details}`);
272
349
  }
273
- if (!(await fs.pathExists(outputFile))) {
350
+ const outputFiles = (await fs.readdir(outputDir)).filter(name => name.endsWith('.txt')).sort();
351
+ if (outputFiles.length === 0 && !recovered?.length) {
274
352
  throw new Error('Maven did not produce classpath output file');
275
353
  }
276
- const content = await fs.readFile(outputFile, 'utf-8');
277
- // Remove the temp file
278
- try {
279
- await fs.remove(outputFile);
280
- }
281
- catch {
282
- // ignore cleanup errors
283
- }
284
- // Classpath entries are separated by path.delimiter (: on Unix, ; on Windows)
285
- const jarPaths = content
286
- .trim()
287
- .split(path.delimiter)
288
- .map(p => p.trim())
289
- .filter(p => p.length > 0 && p.endsWith('.jar'));
354
+ const contents = [];
355
+ for (const name of outputFiles)
356
+ contents.push(await fs.readFile(path.join(outputDir, name), 'utf-8'));
357
+ await fs.remove(outputDir).catch(() => { });
358
+ // Classpath entries are separated by path.delimiter (: on Unix, ; on Windows); the same JAR
359
+ // usually appears in several modules.
360
+ const jarPaths = [...new Set(contents
361
+ .flatMap(content => content.split(/\r?\n/))
362
+ .flatMap(line => line.split(path.delimiter))
363
+ .map(p => p.trim())
364
+ .filter(p => p.length > 0 && p.endsWith('.jar'))
365
+ .concat(recovered ?? []))];
366
+ logger.info(`[MAVEN] Read classpath of ${outputFiles.length} module(s).`);
290
367
  // Validate paths exist
291
368
  const validPaths = [];
292
369
  for (const jar of jarPaths) {
@@ -306,6 +383,49 @@ export class DependencyScanner {
306
383
  isResolvingClasspath(projectPath) {
307
384
  return this.classpathPromises.has(projectPath);
308
385
  }
386
+ /**
387
+ * Wait (bounded) for a classpath that is being resolved by this process or, via scan.lock,
388
+ * by another server process. Returns null if it is still unavailable when the time is up.
389
+ * Single-class lookups use this so a cold start does not answer "class not found" while
390
+ * Maven is still running.
391
+ */
392
+ /** The last classpath/scan failure of a project, without clearing it (scanProject reports and clears it). */
393
+ peekScanError(projectPath) {
394
+ return this.scanErrors.get(projectPath);
395
+ }
396
+ async waitForClasspath(projectPath, timeoutMs, onWait) {
397
+ const deadline = Date.now() + Math.max(0, timeoutMs);
398
+ const started = Date.now();
399
+ while (true) {
400
+ const cached = await projectCache.getClasspath(projectPath).catch(() => null);
401
+ if (cached !== null)
402
+ return cached;
403
+ const remaining = deadline - Date.now();
404
+ if (remaining <= 0)
405
+ return null;
406
+ const inProcess = this.classpathPromises.get(projectPath);
407
+ if (inProcess) {
408
+ let timer;
409
+ const result = await Promise.race([
410
+ inProcess.then(paths => paths, () => null),
411
+ new Promise(resolve => { timer = setTimeout(() => resolve(undefined), Math.min(remaining, 2_000)); }),
412
+ ]);
413
+ if (timer)
414
+ clearTimeout(timer);
415
+ if (result === null)
416
+ return null; // resolution failed; the error is reported by scanProject
417
+ if (result !== undefined)
418
+ return result;
419
+ }
420
+ else if (await CrossProcessLock.check(projectPath, 'scan')) {
421
+ await new Promise(resolve => setTimeout(resolve, Math.min(remaining, 500)));
422
+ }
423
+ else {
424
+ return null;
425
+ }
426
+ await onWait?.(Date.now() - started);
427
+ }
428
+ }
309
429
  /**
310
430
  * Find corresponding JAR package path by class name.
311
431
  * Uses cache + lazy on-demand scanning.
@@ -344,11 +464,13 @@ export class DependencyScanner {
344
464
  return projectCache.getClasspath(projectPath);
345
465
  }
346
466
  async explainDependency(projectPath, coordinates) {
467
+ if (await buildToolOf(projectPath) === 'gradle')
468
+ throw new Error(`explain_dependency supports Maven only; for this Gradle build run \`gradle dependencyInsight --dependency ${coordinates}\`.`);
347
469
  if (!coordinates || /[&|;<>$()]/.test(coordinates)) {
348
470
  throw new Error('coordinates is required and may not contain shell metacharacters');
349
471
  }
350
472
  const mavenCmd = await this.resolveMavenCommand(projectPath);
351
- const { stdout, stderr } = await execFileAsync(mavenCmd, ['dependency:tree', `-Dincludes=${coordinates}`, '-Dverbose'], {
473
+ const { stdout, stderr } = await execFileAsync(mavenCmd, ['-B', 'dependency:tree', `-Dincludes=${coordinates}`, '-Dverbose'], {
352
474
  cwd: projectPath,
353
475
  timeout: 120000,
354
476
  shell: process.platform === 'win32',
@@ -356,6 +478,208 @@ export class DependencyScanner {
356
478
  });
357
479
  return [stdout, stderr].filter(value => value?.trim()).join('\n');
358
480
  }
481
+ /**
482
+ * Download the -sources.jar of one artifact into the local repository (`mvn dependency:get`).
483
+ * Opt-in: it reaches the network. Returns Maven's error output on failure.
484
+ */
485
+ async downloadSources(projectPath, coordinates) {
486
+ return this.downloadArtifact(projectPath, coordinates, 'sources');
487
+ }
488
+ /** `mvn dependency:get` for one artifact (no transitives) into the local repository. Opt-in: it reaches the network. */
489
+ async downloadArtifact(projectPath, coordinates, classifier) {
490
+ const gav = `${coordinates.groupId}:${coordinates.artifactId}:${coordinates.version}`;
491
+ if (!/^[\w.\-]+:[\w.\-]+:[\w.\-+]+$/.test(gav))
492
+ return { ok: false, message: `Invalid coordinates: ${gav}` };
493
+ const mavenCmd = await this.resolveMavenCommand(projectPath);
494
+ const logger = Logger.get(projectPath);
495
+ logger.info(`[MAVEN] Downloading ${gav}${classifier ? `:${classifier}` : ''}`);
496
+ try {
497
+ await execFileAsync(mavenCmd, ['-B', '-q', 'dependency:get', `-Dartifact=${gav}:jar${classifier ? `:${classifier}` : ''}`, '-Dtransitive=false'], {
498
+ cwd: projectPath,
499
+ timeout: 120000,
500
+ shell: process.platform === 'win32',
501
+ maxBuffer: 10 * 1024 * 1024,
502
+ });
503
+ return { ok: true };
504
+ }
505
+ catch (error) {
506
+ const output = `${error?.stdout ?? ''}\n${error?.stderr ?? ''}`.split('\n').filter(line => /ERROR|Could not/.test(line)).slice(0, 3).join(' ').trim();
507
+ logger.info(`[MAVEN] Download failed for ${gav}: ${output || error?.message}`);
508
+ return { ok: false, message: output || String(error?.message ?? error) };
509
+ }
510
+ }
511
+ /**
512
+ * Gradle: an init script adds a task to every project that writes the resolved compile/runtime/test
513
+ * classpath files (lenient, so one unresolvable dependency does not lose the rest) to one file per project.
514
+ */
515
+ async getGradleClasspath(projectPath, onProgress) {
516
+ const logger = Logger.get(projectPath);
517
+ const gradleCmd = await this.resolveGradleCommand(projectPath);
518
+ const outputDir = path.join(getProjectCacheDir(projectPath), `gradle-cp-${process.pid}`);
519
+ await fs.remove(outputDir).catch(() => { });
520
+ await fs.ensureDir(outputDir);
521
+ const initScript = path.join(outputDir, 'java-inspector-init.gradle');
522
+ await fs.writeFile(initScript, GRADLE_INIT_SCRIPT, 'utf-8');
523
+ logger.info(`[GRADLE] Running: ${gradleCmd} javaInspectorClasspath`);
524
+ await onProgress?.(`Running Gradle: ${gradleCmd} (resolving classpath)...`, 5, 100);
525
+ const start = performance.now();
526
+ try {
527
+ await execFileAsync(gradleCmd, ['-q', '--console=plain', '--no-configuration-cache', '--init-script', initScript, `-DjavaInspector.out=${outputDir}`, 'javaInspectorClasspath'], {
528
+ cwd: projectPath,
529
+ timeout: 300000,
530
+ shell: process.platform === 'win32',
531
+ maxBuffer: 10 * 1024 * 1024,
532
+ });
533
+ const contents = await Promise.all((await fs.readdir(outputDir)).filter(name => name.endsWith('.txt')).map(name => fs.readFile(path.join(outputDir, name), 'utf-8')));
534
+ if (!contents.length)
535
+ throw new Error('Gradle did not produce classpath output (no Java projects?)');
536
+ const jars = [...new Set(contents.flatMap(content => content.split(/\r?\n/)).map(line => line.trim()).filter(line => line.endsWith('.jar')))];
537
+ const existing = [];
538
+ for (const jar of jars)
539
+ if (await fs.pathExists(jar))
540
+ existing.push(jar);
541
+ logger.info(`[GRADLE] Classpath of ${contents.length} project(s) resolved in ${((performance.now() - start) / 1000).toFixed(1)}s: ${existing.length} JARs.`);
542
+ return existing;
543
+ }
544
+ catch (error) {
545
+ const details = [error?.stdout, error?.stderr].filter(Boolean).join('\n').split('\n').filter(line => line.trim()).slice(0, 15).join('\n');
546
+ logger.error(`[GRADLE] Classpath resolution failed: ${error?.message}\n${details}`);
547
+ throw new Error(`Gradle command failed: ${String(error?.message ?? error).split('\n')[0]}${details ? `\n${details}` : ''}`);
548
+ }
549
+ finally {
550
+ await fs.remove(outputDir).catch(() => { });
551
+ }
552
+ }
553
+ /** GRADLE_CMD, then the project's wrapper (gradlew), then GRADLE_HOME/bin/gradle, then gradle on PATH. */
554
+ async resolveGradleCommand(projectPath) {
555
+ if (process.env.GRADLE_CMD) {
556
+ if (/[&|;<>$()]/.test(process.env.GRADLE_CMD))
557
+ throw new Error('Invalid GRADLE_CMD: Shell metacharacters are not allowed.');
558
+ return process.env.GRADLE_CMD;
559
+ }
560
+ const wrapper = path.join(projectPath, process.platform === 'win32' ? 'gradlew.bat' : 'gradlew');
561
+ if (await fs.pathExists(wrapper))
562
+ return wrapper;
563
+ return process.env.GRADLE_HOME ? path.join(process.env.GRADLE_HOME, 'bin', 'gradle') : 'gradle';
564
+ }
565
+ /**
566
+ * A multi-module checkout whose modules depend on each other fails `dependency:build-classpath` on Maven 3
567
+ * until the sibling modules are installed ("Could not resolve dependencies ... demo:a:jar"). Recover by
568
+ * re-running with --fail-at-end (modules that resolve still write their file) and adding the external
569
+ * dependencies of the dependency tree (which only needs poms) that exist in the local repository.
570
+ */
571
+ async recoverReactorClasspath(projectPath, mavenCmd, outputFile, details) {
572
+ if (!/Could not resolve dependencies|was not found in|Could not find artifact/.test(details))
573
+ return null;
574
+ const logger = Logger.get(projectPath);
575
+ const reactorPoms = await this.reactorCoordinates(projectPath);
576
+ // Only an unresolved *reactor module* is recoverable; a missing external artifact (network or
577
+ // repository problem) must stay an error instead of becoming a silently incomplete classpath.
578
+ const unresolved = details.replace(/for project \S+/g, '');
579
+ if (![...reactorPoms].some(ga => unresolved.includes(`${ga}:`)))
580
+ return null;
581
+ logger.info('[MAVEN] Classpath resolution failed on a module dependency; retrying with --fail-at-end and dependency:tree (unbuilt sibling modules?)');
582
+ await execFileAsync(mavenCmd, ['-B', '-q', '-fae', 'dependency:build-classpath', `-Dmdep.outputFile=${outputFile}`], {
583
+ cwd: projectPath, timeout: 300000, shell: process.platform === 'win32', maxBuffer: 10 * 1024 * 1024,
584
+ }).catch(() => { });
585
+ let modules;
586
+ try {
587
+ modules = await this.runDependencyTree(projectPath, mavenCmd);
588
+ }
589
+ catch (error) {
590
+ logger.error(`[MAVEN] dependency:tree fallback failed: ${error instanceof Error ? error.message : String(error)}`);
591
+ return null;
592
+ }
593
+ const reactor = new Set(modules.map(module => module.module.split(':').slice(0, 2).join(':')));
594
+ const repository = path.resolve(process.env.MAVEN_REPO || path.join(os.homedir(), '.m2', 'repository'));
595
+ const jars = [];
596
+ let missing = 0;
597
+ for (const dep of modules.flatMap(module => module.dependencies)) {
598
+ if (reactor.has(`${dep.groupId}:${dep.artifactId}`) || (dep.type !== 'jar' && dep.type !== 'bundle' && dep.type !== 'test-jar'))
599
+ continue;
600
+ const classifier = dep.classifier ?? (dep.type === 'test-jar' ? 'tests' : undefined);
601
+ const jar = path.join(repository, ...dep.groupId.split('.'), dep.artifactId, dep.version, `${dep.artifactId}-${dep.version}${classifier ? `-${classifier}` : ''}.jar`);
602
+ if (await fs.pathExists(jar))
603
+ jars.push(jar);
604
+ else
605
+ missing++;
606
+ }
607
+ logger.info(`[MAVEN] Recovered ${jars.length} JAR(s) from the dependency tree of ${modules.length} module(s)${missing ? `; ${missing} not downloaded yet` : ''}. Reactor modules are skipped (their code is in the workspace).`);
608
+ if (missing)
609
+ this.partialClasspaths.add(projectPath);
610
+ else
611
+ this.partialClasspaths.delete(projectPath);
612
+ return jars;
613
+ }
614
+ /** groupId:artifactId of every module pom under the project (parent groupId when the module has none). */
615
+ async reactorCoordinates(projectPath) {
616
+ const result = new Set();
617
+ const visit = async (directory, depth) => {
618
+ const pom = await fs.readFile(path.join(directory, 'pom.xml'), 'utf-8').catch(() => null);
619
+ if (pom === null)
620
+ return;
621
+ const withoutParent = pom.replace(/<parent>[\s\S]*?<\/parent>/, '').replace(/<(dependencies|dependencyManagement|build|profiles|plugins)>[\s\S]*$/, '');
622
+ const parentGroup = pom.match(/<parent>[\s\S]*?<groupId>\s*([^<\s]+)\s*<\/groupId>/)?.[1];
623
+ const groupId = withoutParent.match(/<groupId>\s*([^<\s]+)\s*<\/groupId>/)?.[1] ?? parentGroup;
624
+ const artifactId = withoutParent.match(/<artifactId>\s*([^<\s]+)\s*<\/artifactId>/)?.[1];
625
+ if (groupId && artifactId)
626
+ result.add(`${groupId}:${artifactId}`);
627
+ if (depth >= 6)
628
+ return;
629
+ for (const module of pom.matchAll(/<module>\s*([^<]+?)\s*<\/module>/g))
630
+ await visit(path.resolve(directory, module[1]), depth + 1);
631
+ };
632
+ await visit(projectPath, 0);
633
+ return result;
634
+ }
635
+ async runDependencyTree(projectPath, mavenCmd) {
636
+ const outputDir = path.join(getProjectCacheDir(projectPath), `maven-tree-${process.pid}-${Date.now()}`);
637
+ await fs.ensureDir(outputDir);
638
+ const outputFile = path.join(outputDir, 'tree-${project.groupId}__${project.artifactId}.txt');
639
+ try {
640
+ try {
641
+ await execFileAsync(mavenCmd, ['-B', '-q', 'dependency:tree', `-DoutputFile=${outputFile}`, '-DoutputType=text'], {
642
+ cwd: projectPath, timeout: 300000, shell: process.platform === 'win32', maxBuffer: 10 * 1024 * 1024,
643
+ });
644
+ }
645
+ catch (error) {
646
+ const details = `${error?.stdout ?? ''}\n${error?.stderr ?? ''}`.split('\n').filter(line => /ERROR/.test(line)).slice(0, 5).join('\n');
647
+ throw new Error(`mvn dependency:tree failed: ${error?.message?.split('\n')[0] ?? error}${details ? `\n${details}` : ''}`);
648
+ }
649
+ const modules = [];
650
+ for (const name of (await fs.readdir(outputDir)).filter(file => file.endsWith('.txt')).sort()) {
651
+ const parsed = parseDependencyTree(await fs.readFile(path.join(outputDir, name), 'utf-8'));
652
+ if (parsed)
653
+ modules.push(parsed);
654
+ }
655
+ if (!modules.length)
656
+ throw new Error('Maven did not produce dependency:tree output');
657
+ return modules;
658
+ }
659
+ finally {
660
+ await fs.remove(outputDir).catch(() => { });
661
+ }
662
+ }
663
+ /**
664
+ * Resolved dependency tree of every reactor module (`mvn dependency:tree`, one output file per module).
665
+ * Cached per project until pom.xml or the resolved classpath changes.
666
+ */
667
+ async listDependencies(projectPath) {
668
+ if (await buildToolOf(projectPath) === 'gradle')
669
+ throw new Error('list_dependencies supports Maven only; for this Gradle build run `gradle dependencies`. Classes, sources and the other tools work for Gradle projects.');
670
+ const key = `${await projectCache.getPomHash(projectPath).catch(() => '')}:${projectCache.getClasspathHash((await projectCache.getClasspath(projectPath).catch(() => null)) ?? [])}`;
671
+ const cacheFile = path.join(getProjectCacheDir(projectPath), 'dependency-tree.json');
672
+ const cached = await fs.readJson(cacheFile).catch(() => null);
673
+ if (cached?.key === key && Array.isArray(cached.modules))
674
+ return { modules: cached.modules, cached: true };
675
+ const logger = Logger.get(projectPath);
676
+ const start = performance.now();
677
+ logger.info('[MAVEN] Running dependency:tree for list_dependencies');
678
+ const modules = await this.runDependencyTree(projectPath, await this.resolveMavenCommand(projectPath));
679
+ logger.info(`[MAVEN] Dependency tree of ${modules.length} module(s) in ${((performance.now() - start) / 1000).toFixed(1)}s`);
680
+ await fs.writeJson(cacheFile, { key, modules }).catch(() => { });
681
+ return { modules, cached: false };
682
+ }
359
683
  async withClasspathResolutionSlot(task) {
360
684
  if (this.activeClasspathResolutions >= 2) {
361
685
  await new Promise(resolve => this.classpathResolutionQueue.push(resolve));