@mustafagoksever/java-inspector 2.3.3 → 3.0.0
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.
- package/README.md +138 -263
- package/dist/analyzer/JavaClassAnalyzer.d.ts +7 -4
- package/dist/analyzer/JavaClassAnalyzer.d.ts.map +1 -1
- package/dist/analyzer/JavaClassAnalyzer.js +47 -28
- package/dist/analyzer/JavaClassAnalyzer.js.map +1 -1
- package/dist/analyzer/JdkSourceService.d.ts +17 -0
- package/dist/analyzer/JdkSourceService.d.ts.map +1 -0
- package/dist/analyzer/JdkSourceService.js +138 -0
- package/dist/analyzer/JdkSourceService.js.map +1 -0
- package/dist/cache/ProjectCache.d.ts +6 -1
- package/dist/cache/ProjectCache.d.ts.map +1 -1
- package/dist/cache/ProjectCache.js +59 -18
- package/dist/cache/ProjectCache.js.map +1 -1
- package/dist/cli.js +1 -12
- package/dist/cli.js.map +1 -1
- package/dist/decompiler/DecompilerService.d.ts +10 -4
- package/dist/decompiler/DecompilerService.d.ts.map +1 -1
- package/dist/decompiler/DecompilerService.js +86 -30
- package/dist/decompiler/DecompilerService.js.map +1 -1
- package/dist/index.d.ts +26 -14
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +515 -581
- package/dist/index.js.map +1 -1
- package/dist/scanner/ArtifactService.d.ts +104 -0
- package/dist/scanner/ArtifactService.d.ts.map +1 -0
- package/dist/scanner/ArtifactService.js +569 -0
- package/dist/scanner/ArtifactService.js.map +1 -0
- package/dist/scanner/BackgroundScanner.d.ts.map +1 -1
- package/dist/scanner/BackgroundScanner.js +38 -26
- package/dist/scanner/BackgroundScanner.js.map +1 -1
- package/dist/scanner/ClassFileMetadataReader.d.ts +31 -0
- package/dist/scanner/ClassFileMetadataReader.d.ts.map +1 -0
- package/dist/scanner/ClassFileMetadataReader.js +215 -0
- package/dist/scanner/ClassFileMetadataReader.js.map +1 -0
- package/dist/scanner/DependencyScanner.d.ts +5 -0
- package/dist/scanner/DependencyScanner.d.ts.map +1 -1
- package/dist/scanner/DependencyScanner.js +59 -2
- package/dist/scanner/DependencyScanner.js.map +1 -1
- package/dist/scanner/JarIndexer.d.ts +73 -0
- package/dist/scanner/JarIndexer.d.ts.map +1 -0
- package/dist/scanner/JarIndexer.js +445 -0
- package/dist/scanner/JarIndexer.js.map +1 -0
- package/dist/scanner/JarScanCoordinator.d.ts +32 -0
- package/dist/scanner/JarScanCoordinator.d.ts.map +1 -0
- package/dist/scanner/JarScanCoordinator.js +124 -0
- package/dist/scanner/JarScanCoordinator.js.map +1 -0
- package/dist/scanner/LazyResolver.d.ts.map +1 -1
- package/dist/scanner/LazyResolver.js +80 -70
- package/dist/scanner/LazyResolver.js.map +1 -1
- package/dist/scanner/ProjectDiscovery.d.ts +6 -0
- package/dist/scanner/ProjectDiscovery.d.ts.map +1 -0
- package/dist/scanner/ProjectDiscovery.js +49 -0
- package/dist/scanner/ProjectDiscovery.js.map +1 -0
- package/dist/utils/Logger.d.ts +3 -0
- package/dist/utils/Logger.d.ts.map +1 -1
- package/dist/utils/Logger.js +27 -6
- package/dist/utils/Logger.js.map +1 -1
- package/dist/utils/cachePaths.d.ts +3 -0
- package/dist/utils/cachePaths.d.ts.map +1 -1
- package/dist/utils/cachePaths.js +9 -0
- package/dist/utils/cachePaths.js.map +1 -1
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -1,340 +1,215 @@
|
|
|
1
1
|
# Java Inspector
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Java Inspector is an MCP server that gives AI agents fast, read-only access to code and metadata inside Maven dependencies, local JARs, executable JARs, WARs, and the JDK.
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
[](LICENSE)
|
|
5
|
+
The server starts accepting MCP calls immediately. Maven dependency scanning continues in the background, while an interactive query can promote the JAR it needs to a foreground queue and return without waiting for the complete project index.
|
|
7
6
|
|
|
8
|
-
|
|
7
|
+
## Requirements
|
|
9
8
|
|
|
10
|
-
|
|
9
|
+
- Node.js 16 or newer
|
|
10
|
+
- Java 17 or newer (`java` and `javap`); required by bundled Vineflower 1.11.2
|
|
11
|
+
- Maven for Maven project discovery and dependency resolution
|
|
11
12
|
|
|
12
|
-
|
|
13
|
+
Vineflower 1.11.2 is bundled in `lib/`.
|
|
13
14
|
|
|
14
|
-
|
|
15
|
+
## Install and configure
|
|
15
16
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|------|--------------|
|
|
20
|
-
| `scan_dependencies` | Kicks off a background scan of every JAR on the Maven classpath. Call again to poll progress. |
|
|
21
|
-
| `decompile_class` | Returns the **full Java source** (method bodies and all) via Vineflower. Optionally extract a single method by `methodName`, or paginate with `offset`/`limit`. |
|
|
22
|
-
| `analyze_class` | Returns the **structural signature** — fields, methods, constructors, inheritance — via `javap`. No method bodies. |
|
|
23
|
-
| `search_class` | Fuzzy-find classes by partial name (e.g. `"ObservationRegistry"`). |
|
|
24
|
-
| `get_inheritance_tree` | Walks the superclass chain up to `java.lang.Object`. |
|
|
17
|
+
```bash
|
|
18
|
+
npm install -g @mustafagoksever/java-inspector
|
|
19
|
+
```
|
|
25
20
|
|
|
26
|
-
|
|
21
|
+
```json
|
|
22
|
+
{
|
|
23
|
+
"mcpServers": {
|
|
24
|
+
"java-inspector": {
|
|
25
|
+
"command": "java-inspector",
|
|
26
|
+
"args": ["start"]
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
```
|
|
27
31
|
|
|
28
|
-
|
|
32
|
+
For local development:
|
|
29
33
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
34
|
+
```bash
|
|
35
|
+
npm ci
|
|
36
|
+
npm run build
|
|
37
|
+
node dist/cli.js start
|
|
38
|
+
```
|
|
35
39
|
|
|
36
|
-
|
|
37
|
-
**`toon`** encodes the same payload via `@toon-format/toon`, giving you YAML-like readability with CSV-like compactness for uniform arrays.
|
|
40
|
+
## Startup discovery
|
|
38
41
|
|
|
39
|
-
|
|
42
|
+
After the MCP transport connects, Java Inspector performs non-blocking discovery:
|
|
40
43
|
|
|
41
|
-
|
|
44
|
+
1. If `cwd/pom.xml` exists, that Maven project is used.
|
|
45
|
+
2. Otherwise directories are searched breadth-first.
|
|
46
|
+
3. Every `pom.xml` at the first matching depth is selected.
|
|
47
|
+
4. Deeper POMs are not independently scanned.
|
|
48
|
+
5. Maven classpaths are resolved and their JARs enter the background light-scan queue.
|
|
42
49
|
|
|
43
|
-
|
|
44
|
-
graph LR
|
|
45
|
-
A[AI Agent<br/>Claude / Cursor / Codex / Opencode] -->|MCP| B[java-inspector<br/>TypeScript Server]
|
|
46
|
-
B -->|auto-detect| C{Maven Resolver}
|
|
47
|
-
C -->|priority 1| D[MAVEN_CMD env]
|
|
48
|
-
C -->|priority 2| E[mvnd daemon<br/>~2x faster]
|
|
49
|
-
C -->|priority 3| F[MAVEN_HOME/bin/mvn]
|
|
50
|
-
C -->|priority 4| G[mvn from PATH]
|
|
51
|
-
B -->|dependency:build-classpath| H[~/.m2/repository]
|
|
52
|
-
H -->|JAR streams| I[yauzl extractor]
|
|
53
|
-
I -->|class names| J[JSON Lines Cache]
|
|
54
|
-
B -->|cache hit| J
|
|
55
|
-
B -->|cache miss| I
|
|
56
|
-
B -->|java -jar vineflower.jar| K[Vineflower 1.11.2<br/>Decompiler]
|
|
57
|
-
K -->|*.java source| A
|
|
58
|
-
```
|
|
50
|
+
Directories such as `.git`, `node_modules`, `.gradle`, `target`, `build`, and `out` are excluded from POM discovery.
|
|
59
51
|
|
|
60
|
-
|
|
52
|
+
Local, non-Maven JARs are not scanned at startup. They are found and indexed only when a tool call supplies a path, directory, or filename prefix.
|
|
61
53
|
|
|
62
|
-
|
|
54
|
+
## Tools
|
|
63
55
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
56
|
+
| Tool | Purpose |
|
|
57
|
+
|---|---|
|
|
58
|
+
| `scan_project` | Start, refresh, or poll the non-blocking Maven scan. |
|
|
59
|
+
| `find_jar` | Find an artifact by path, filename, prefix, substring, or Maven coordinates without opening it. |
|
|
60
|
+
| `inspect_jar` | Inspect manifest, Maven metadata, packages, classes, resources, and nested artifacts. |
|
|
61
|
+
| `search_class` | Search the live partial index and foreground-scan relevant JARs on a miss. |
|
|
62
|
+
| `search_code` | Search methods, fields, annotations, references, or string constants without mass decompilation. |
|
|
63
|
+
| `find_implementations` | Find direct or transitive implementations/subtypes from lazy deep indexes. |
|
|
64
|
+
| `inspect_class` | Return source, API, hierarchy, bytecode, or all views for a class. |
|
|
65
|
+
| `explain_dependency` | Run a filtered Maven dependency tree for a selected artifact. |
|
|
66
|
+
| `search_resources` | Search resource paths or bounded text content. |
|
|
67
|
+
| `read_resource` | Read an exact text resource with line pagination. |
|
|
67
68
|
|
|
68
|
-
|
|
69
|
+
Every tool supports `text`, `json`, and `toon` output where applicable.
|
|
69
70
|
|
|
70
|
-
|
|
71
|
-
~/.cache/java-inspector/<project>_<hash>/
|
|
72
|
-
├── classpath.json # pomHash + jarPaths[] + classpathHash + timestamp
|
|
73
|
-
├── class-index.jsonl # Append-only ClassIndexEntry batches
|
|
74
|
-
├── scan-state.json # jarCount, processedJars[], isComplete
|
|
75
|
-
├── server-<pid>.log # Per-process append-only logs (multi-process safe)
|
|
76
|
-
├── write.lock # Cross-process lock for JSONL / state writes
|
|
77
|
-
├── scan.lock # Cross-process lock for scan lifecycle
|
|
78
|
-
└── decompile-cache-vineflower/ # Cached .java sources
|
|
79
|
-
```
|
|
71
|
+
## Artifact selectors
|
|
80
72
|
|
|
81
|
-
|
|
73
|
+
Class, JAR, and resource tools share the same selection model:
|
|
82
74
|
|
|
83
|
-
|
|
75
|
+
- `jarPath`: exact absolute JAR path; fastest and unambiguous.
|
|
76
|
+
- `jarDirectory` + `jarNamePrefix`: useful for Maven-free projects with `lib/` directories.
|
|
77
|
+
- `workspacePath` + `jarNamePrefix`: search the Maven classpath and workspace.
|
|
78
|
+
- `workspacePath`: use the live partial index and bounded lazy fallback.
|
|
79
|
+
- `coordinates`: `groupId:artifactId[:version[:classifier]]`.
|
|
84
80
|
|
|
85
|
-
|
|
81
|
+
When no selector is supplied, tools use the server's current working directory. If Maven classpath resolution is still running, searches return `complete: false` instead of reporting a definitive miss. Per-JAR scan failures are returned in `errors`; an unreadable exact `jarPath` fails the tool call.
|
|
86
82
|
|
|
87
|
-
|
|
83
|
+
If multiple JARs or classes match, the server returns candidates instead of silently choosing one.
|
|
88
84
|
|
|
89
|
-
|
|
85
|
+
### Inspect a class from a local JAR
|
|
90
86
|
|
|
91
87
|
```json
|
|
92
88
|
{
|
|
93
|
-
"
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
"args": ["-y", "@mustafagoksever/java-inspector"]
|
|
97
|
-
}
|
|
98
|
-
}
|
|
89
|
+
"className": "com.vendor.Client",
|
|
90
|
+
"jarPath": "C:\\project\\lib\\vendor-client-2.1.jar",
|
|
91
|
+
"view": "source"
|
|
99
92
|
}
|
|
100
93
|
```
|
|
101
94
|
|
|
102
|
-
###
|
|
103
|
-
|
|
104
|
-
`Settings` → `MCP Servers` → Add:
|
|
95
|
+
### Find an exception message
|
|
105
96
|
|
|
106
97
|
```json
|
|
107
98
|
{
|
|
108
|
-
"
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
}
|
|
113
|
-
}
|
|
99
|
+
"query": "Connection refused",
|
|
100
|
+
"kind": "string",
|
|
101
|
+
"workspacePath": "C:\\project",
|
|
102
|
+
"mode": "balanced"
|
|
114
103
|
}
|
|
115
104
|
```
|
|
116
105
|
|
|
117
|
-
###
|
|
118
|
-
|
|
119
|
-
Edit `~/.codex/config.toml`:
|
|
106
|
+
### Find implementations
|
|
120
107
|
|
|
121
|
-
```
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
108
|
+
```json
|
|
109
|
+
{
|
|
110
|
+
"className": "com.vendor.Transport",
|
|
111
|
+
"workspacePath": "C:\\project",
|
|
112
|
+
"transitive": true
|
|
113
|
+
}
|
|
125
114
|
```
|
|
126
115
|
|
|
127
|
-
###
|
|
128
|
-
|
|
129
|
-
Edit `%APPDATA%\opencode\config.json`:
|
|
116
|
+
### Inspect a JDK class
|
|
130
117
|
|
|
131
118
|
```json
|
|
132
119
|
{
|
|
133
|
-
"
|
|
134
|
-
|
|
135
|
-
"type": "local",
|
|
136
|
-
"command": [
|
|
137
|
-
"npx",
|
|
138
|
-
"-y",
|
|
139
|
-
"@mustafagoksever/java-inspector"
|
|
140
|
-
]
|
|
141
|
-
}
|
|
142
|
-
}
|
|
120
|
+
"className": "java.util.ArrayList",
|
|
121
|
+
"view": "all"
|
|
143
122
|
}
|
|
144
123
|
```
|
|
145
124
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
That's it. No `JAVA_HOME` tweaks. No manual decompiler download. The server ships the ~1.8 MB Vineflower JAR inside the package.
|
|
149
|
-
|
|
150
|
-
---
|
|
151
|
-
|
|
152
|
-
## Workflow
|
|
153
|
-
|
|
154
|
-
```mermaid
|
|
155
|
-
sequenceDiagram
|
|
156
|
-
participant U as User
|
|
157
|
-
participant A as AI Agent
|
|
158
|
-
participant S as java-inspector
|
|
159
|
-
participant M as Maven / mvnd
|
|
160
|
-
participant C as Cache
|
|
161
|
-
|
|
162
|
-
U->>A: "Show me JpaRepository source"
|
|
163
|
-
A->>S: decompile_class("org.springframework.data.jpa.repository.JpaRepository")
|
|
164
|
-
alt Index not built yet
|
|
165
|
-
S->>M: dependency:build-classpath
|
|
166
|
-
M-->>S: JAR list
|
|
167
|
-
S->>S: Background scan (20 JARs in parallel)
|
|
168
|
-
S-->>A: Class found via lazy JAR search
|
|
169
|
-
else Cache hit
|
|
170
|
-
S->>C: Map.get(className) — O(1)
|
|
171
|
-
C-->>S: ClassIndexEntry
|
|
172
|
-
end
|
|
173
|
-
S->>S: Extract .class from JAR (yauzl)
|
|
174
|
-
S->>S: java -jar vineflower.jar ...
|
|
175
|
-
S-->>A: Decompiled .java source
|
|
176
|
-
A-->>U: Formatted response
|
|
177
|
-
```
|
|
178
|
-
|
|
125
|
+
JDK source is read from `src.zip` when available. API and bytecode views use `javap`.
|
|
179
126
|
|
|
127
|
+
## Foreground and background scheduling
|
|
180
128
|
|
|
181
|
-
|
|
129
|
+
All JAR reads pass through a shared coordinator:
|
|
182
130
|
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
C --> E[Delete ~/.cache/java-inspector/<hash>/*]
|
|
190
|
-
E --> F[Re-run Maven dependency:build-classpath]
|
|
191
|
-
F --> G[Start background scan]
|
|
192
|
-
D --> H[Return Map of classes]
|
|
193
|
-
```
|
|
131
|
+
- Up to eight JAR reads run concurrently.
|
|
132
|
+
- Background scanning may occupy at most six slots.
|
|
133
|
+
- Two slots remain available for interactive foreground work.
|
|
134
|
+
- A foreground request promotes a queued background JAR.
|
|
135
|
+
- Concurrent requests for the same JAR share one Promise and one cache write.
|
|
136
|
+
- Light scans time out after 30 seconds; deep scans time out after 60 seconds.
|
|
194
137
|
|
|
195
|
-
|
|
138
|
+
The background scan builds a light index from ZIP entries. More expensive class-file metadata is generated only when `search_code` or `find_implementations` needs it.
|
|
196
139
|
|
|
197
|
-
|
|
198
|
-
2. **Parent POM / dependency-management changes** — `classpathHash` mismatch.
|
|
199
|
-
3. **Manual** — call `scan_dependencies` with `forceRefresh: true`. This force-releases cross-process locks and wipes the cache directory before restarting.
|
|
140
|
+
Context-wide deep searches are intentionally bounded. A partial response includes `complete`, `scannedJarCount`, and `remainingJarCount`. Calling the tool again continues using the already cached deep indexes.
|
|
200
141
|
|
|
201
|
-
|
|
142
|
+
## Class inspection
|
|
202
143
|
|
|
203
|
-
|
|
144
|
+
`inspect_class` supports:
|
|
204
145
|
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
146
|
+
- `source`: local `*-sources.jar`, embedded `.java`, or Vineflower decompilation.
|
|
147
|
+
- `api`: fields, methods, constructors, modifiers, superclass, and interfaces via `javap`.
|
|
148
|
+
- `hierarchy`: resolved superclass chain.
|
|
149
|
+
- `bytecode`: `javap -c -l -p -s` output.
|
|
150
|
+
- `all`: all available views.
|
|
210
151
|
|
|
211
|
-
|
|
152
|
+
Source responses support `methodName`, `paramTypes`, `offset`, and `limit`.
|
|
212
153
|
|
|
213
|
-
|
|
154
|
+
The decompiler executable cannot be overridden by a tool argument. Java Inspector uses the bundled Vineflower JAR or the operator-controlled `DECOMPILER_PATH` environment variable.
|
|
214
155
|
|
|
215
|
-
##
|
|
156
|
+
## JAR layouts
|
|
216
157
|
|
|
217
|
-
|
|
218
|
-
|----------|--------|
|
|
219
|
-
| `JAVA_HOME` | Locates `java` and `javap`. |
|
|
220
|
-
| `MAVEN_HOME` | Locates `mvn` / `mvn.cmd`. |
|
|
221
|
-
| `MAVEN_CMD` | Override executable entirely — e.g. `mvnd`, `mvnw`, or a full path. |
|
|
222
|
-
| `MAVEN_REPO` | Overrides `~/.m2/repository`. |
|
|
223
|
-
| `DECOMPILER_PATH` | Use a custom Vineflower JAR instead of the bundled one. |
|
|
224
|
-
| `NODE_ENV=development` | Enables verbose `server.log` output. |
|
|
158
|
+
Light indexing understands:
|
|
225
159
|
|
|
226
|
-
|
|
160
|
+
- Ordinary and shaded JARs
|
|
161
|
+
- Multi-release entries under `META-INF/versions/`
|
|
162
|
+
- Spring Boot classes under `BOOT-INF/classes`
|
|
163
|
+
- WAR classes under `WEB-INF/classes`
|
|
164
|
+
- JMOD class paths under `classes/`
|
|
165
|
+
- Nested artifact metadata under `BOOT-INF/lib`, `WEB-INF/lib`, and `lib`
|
|
166
|
+
- Maven `pom.properties`, manifests, source JARs, and text resources
|
|
227
167
|
|
|
228
|
-
|
|
168
|
+
Nested JAR contents are extracted and scanned only when explicitly needed.
|
|
229
169
|
|
|
230
|
-
|
|
231
|
-
```bash
|
|
232
|
-
npx @mustafagoksever/java-inspector
|
|
233
|
-
```
|
|
170
|
+
## Cache
|
|
234
171
|
|
|
235
|
-
|
|
236
|
-
```bash
|
|
237
|
-
npm install -g @mustafagoksever/java-inspector
|
|
238
|
-
java-inspector start
|
|
239
|
-
```
|
|
172
|
+
Cache data is stored under:
|
|
240
173
|
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
git clone https://github.com/mustafagoksever/java-inspector.git
|
|
244
|
-
cd java-inspector
|
|
245
|
-
npm install
|
|
246
|
-
npm run build
|
|
174
|
+
```text
|
|
175
|
+
~/.cache/java-inspector/<context>_<hash>/
|
|
247
176
|
```
|
|
248
177
|
|
|
249
|
-
|
|
178
|
+
Important entries include:
|
|
250
179
|
|
|
251
|
-
|
|
180
|
+
```text
|
|
181
|
+
classpath.json
|
|
182
|
+
class-index.jsonl
|
|
183
|
+
scan-state.json
|
|
184
|
+
jar-indexes-v3/
|
|
185
|
+
results-v3/
|
|
186
|
+
server-<pid>.log
|
|
187
|
+
```
|
|
252
188
|
|
|
253
|
-
|
|
189
|
+
Per-JAR caches use resolved path, size, and modification time as their fingerprint. Nested artifacts additionally use their parent fingerprint and ZIP entry identity. JSONL project indexes remain append-only and crash-safe, with cross-process locks protecting writes.
|
|
254
190
|
|
|
255
|
-
|
|
191
|
+
## Environment variables
|
|
256
192
|
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
193
|
+
| Variable | Purpose |
|
|
194
|
+
|---|---|
|
|
195
|
+
| `NODE_ENV` | Enables additional development logging. |
|
|
196
|
+
| `JAVA_HOME` | Locates `java`, `javap`, and JDK `src.zip`. |
|
|
197
|
+
| `MAVEN_HOME` | Locates Maven. |
|
|
198
|
+
| `MAVEN_CMD` | Overrides the Maven executable. |
|
|
199
|
+
| `MAVEN_REPO` | Overrides the local Maven repository path. |
|
|
200
|
+
| `DECOMPILER_PATH` | Overrides the bundled Vineflower JAR. |
|
|
260
201
|
|
|
261
|
-
|
|
202
|
+
Maven command resolution order is `MAVEN_CMD`, `mvnd`, `MAVEN_HOME/bin/mvn`, then `mvn` from `PATH`.
|
|
262
203
|
|
|
263
|
-
|
|
264
|
-
# PowerShell
|
|
265
|
-
Get-Content ~/.cache/java-inspector/<project>_<hash>/server-<pid>.log -Wait -Tail 20
|
|
204
|
+
## Development
|
|
266
205
|
|
|
267
|
-
|
|
268
|
-
|
|
206
|
+
```bash
|
|
207
|
+
npm run build
|
|
208
|
+
npm test
|
|
209
|
+
npm run dev
|
|
269
210
|
```
|
|
270
211
|
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
| Tag | Description |
|
|
274
|
-
|-----|-------------|
|
|
275
|
-
| `[SERVER]` | Server startup/shutdown |
|
|
276
|
-
| `[AUTO-SCAN]` | Automatic scan on startup |
|
|
277
|
-
| `[MAVEN]` | Maven command resolution & classpath building |
|
|
278
|
-
| `[SCAN]` | Background JAR scanning |
|
|
279
|
-
| `[JAVAP]` | `javap` class analysis |
|
|
280
|
-
| `[DECOMPILE]` | Vineflower decompilation |
|
|
281
|
-
| `[TOOL:<name>]` | Tool call entry/exit with duration |
|
|
282
|
-
| `[CACHE]` | Cache invalidation & state |
|
|
283
|
-
| `[LOCK]` | Cross-process lock acquire/release/compromise |
|
|
284
|
-
|
|
285
|
-
### Common Issues
|
|
286
|
-
|
|
287
|
-
**"command not found" error**
|
|
288
|
-
- Ensure Node.js and npm are in your PATH.
|
|
289
|
-
|
|
290
|
-
**Maven not found**
|
|
291
|
-
- Set `MAVEN_HOME` environment variable or ensure Maven is in your PATH.
|
|
292
|
-
- Try using `mvnd` (Maven Daemon) for ~2x faster resolves.
|
|
293
|
-
|
|
294
|
-
**Lock timeout errors**
|
|
295
|
-
- If a process was killed with SIGKILL while scanning, locks become stale after 60 seconds.
|
|
296
|
-
- Another process can then acquire the lock. No action needed unless the problem persists.
|
|
297
|
-
|
|
298
|
-
**Cache problems**
|
|
299
|
-
- Call `scan_dependencies` with `forceRefresh: true` to clear cache and restart.
|
|
300
|
-
|
|
301
|
-
---
|
|
302
|
-
|
|
303
|
-
## Technical stack
|
|
304
|
-
|
|
305
|
-
| Layer | Technology |
|
|
306
|
-
|-------|------------|
|
|
307
|
-
| Language | TypeScript 5.7 |
|
|
308
|
-
| Runtime | Node.js 16+ |
|
|
309
|
-
| Protocol | Model Context Protocol (MCP) |
|
|
310
|
-
| Decompiler | Vineflower 1.11.2 (bundled) |
|
|
311
|
-
| JAR reader | yauzl (streaming, lazy entries) |
|
|
312
|
-
| Build tool | tsc |
|
|
313
|
-
| Package manager | npm |
|
|
314
|
-
| License | Apache-2.0 |
|
|
315
|
-
|
|
316
|
-
---
|
|
317
|
-
|
|
318
|
-
## Performance Test Results
|
|
319
|
-
|
|
320
|
-
### Spring AI Project Test (April 2026)
|
|
321
|
-
|
|
322
|
-
**Test Environment:** Windows, Maven Daemon (`mvnd`)
|
|
323
|
-
**Project:** Spring AI (multi-module project)
|
|
324
|
-
|
|
325
|
-
| Operation | Time |
|
|
326
|
-
|-----------|------|
|
|
327
|
-
| Maven classpath resolution (185 JARs) | 44.87s |
|
|
328
|
-
| Background scan (185 JARs, 30,612 classes) | 12.38s |
|
|
329
|
-
| Total initial scan | ~57s |
|
|
330
|
-
| analyze_class (UserMessage) | <1s |
|
|
331
|
-
| decompile_class (UserMessage) | <1s |
|
|
332
|
-
| search_class (query: "UserMessage") | <1s |
|
|
333
|
-
|
|
334
|
-
**Notes:**
|
|
335
|
-
- First call triggers classpath resolution + background scan (non-blocking)
|
|
336
|
-
- Subsequent calls use cached index (in-memory Map)
|
|
337
|
-
- Cross-process locking prevents duplicate scans
|
|
212
|
+
The project is ES modules and emits JavaScript, declarations, and source maps to `dist/`.
|
|
338
213
|
|
|
339
214
|
## License
|
|
340
215
|
|
|
@@ -25,16 +25,19 @@ export interface HierarchyEntry {
|
|
|
25
25
|
}
|
|
26
26
|
export declare class JavaClassAnalyzer {
|
|
27
27
|
private scanner;
|
|
28
|
+
private superClassCache;
|
|
28
29
|
constructor();
|
|
29
30
|
/**
|
|
30
31
|
* Analyze Java class structure information
|
|
31
32
|
* @param verbose Use javap -v (default true). Set to false for lightweight superclass/interface checks.
|
|
32
33
|
*/
|
|
33
34
|
analyzeClass(className: string, projectPath: string, verbose?: boolean): Promise<ClassAnalysis>;
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
analyzeClassFromJar(className: string, jarPath: string, contextPath: string, verbose?: boolean): Promise<ClassAnalysis>;
|
|
36
|
+
analyzeClassFile(className: string, classFilePath: string, contextPath: string): Promise<ClassAnalysis>;
|
|
37
|
+
analyzeJdkClass(className: string, contextPath: string): Promise<ClassAnalysis>;
|
|
38
|
+
getBytecode(className: string, contextPath: string, jarPath?: string): Promise<string>;
|
|
39
|
+
getBytecodeFromClassFile(classFilePath: string, contextPath: string): Promise<string>;
|
|
40
|
+
private runJavap;
|
|
38
41
|
/**
|
|
39
42
|
* Use javap tool to analyze class structure in JAR package
|
|
40
43
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"JavaClassAnalyzer.d.ts","sourceRoot":"","sources":["../../src/analyzer/JavaClassAnalyzer.ts"],"names":[],"mappings":"AAQA,MAAM,WAAW,UAAU;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,EAAE,CAAC;CACvB;AAED,MAAM,WAAW,WAAW;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,SAAS,EAAE,MAAM,EAAE,CAAC;CACvB;AAED,MAAM,WAAW,aAAa;IAC1B,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,MAAM,EAAE,UAAU,EAAE,CAAC;IACrB,OAAO,EAAE,WAAW,EAAE,CAAC;CAC1B;AAED,MAAM,WAAW,cAAc;IAC3B,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,OAAO,CAAC;CACrB;AAED,qBAAa,iBAAiB;IAC1B,OAAO,CAAC,OAAO,CAAoB;;
|
|
1
|
+
{"version":3,"file":"JavaClassAnalyzer.d.ts","sourceRoot":"","sources":["../../src/analyzer/JavaClassAnalyzer.ts"],"names":[],"mappings":"AAQA,MAAM,WAAW,UAAU;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,EAAE,CAAC;CACvB;AAED,MAAM,WAAW,WAAW;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,SAAS,EAAE,MAAM,EAAE,CAAC;CACvB;AAED,MAAM,WAAW,aAAa;IAC1B,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,MAAM,EAAE,UAAU,EAAE,CAAC;IACrB,OAAO,EAAE,WAAW,EAAE,CAAC;CAC1B;AAED,MAAM,WAAW,cAAc;IAC3B,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,OAAO,CAAC;CACrB;AAED,qBAAa,iBAAiB;IAC1B,OAAO,CAAC,OAAO,CAAoB;IACnC,OAAO,CAAC,eAAe,CAAyC;;IAMhE;;;OAGG;IACG,YAAY,CAAC,SAAS,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,OAAO,GAAE,OAAc,GAAG,OAAO,CAAC,aAAa,CAAC;IA6BrG,mBAAmB,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,OAAO,GAAE,OAAc,GAAG,OAAO,CAAC,aAAa,CAAC;IAI7H,gBAAgB,CAAC,SAAS,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC;IAKvG,eAAe,CAAC,SAAS,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC;IAK/E,WAAW,CAAC,SAAS,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAOtF,wBAAwB,CAAC,aAAa,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;YAI7E,QAAQ;IAOtB;;OAEG;YACW,qBAAqB;IAkCnC;;MAEE;IACF,OAAO,CAAC,gBAAgB;IAyGxB;;OAEG;IACH,OAAO,CAAC,qBAAqB;IAiC7B;;OAEG;IACH,OAAO,CAAC,oBAAoB;IAqE5B;;OAEG;IACH,OAAO,CAAC,eAAe;IA6BvB;;OAEG;IACH,OAAO,CAAC,eAAe;IAYvB;;OAEG;IACG,uBAAuB,CAAC,SAAS,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC;CA8CnG"}
|
|
@@ -6,6 +6,7 @@ import { Logger } from '../utils/Logger.js';
|
|
|
6
6
|
const execFileAsync = promisify(execFile);
|
|
7
7
|
export class JavaClassAnalyzer {
|
|
8
8
|
scanner;
|
|
9
|
+
superClassCache = new Map();
|
|
9
10
|
constructor() {
|
|
10
11
|
this.scanner = DependencyScanner.getInstance();
|
|
11
12
|
}
|
|
@@ -39,27 +40,32 @@ export class JavaClassAnalyzer {
|
|
|
39
40
|
throw error;
|
|
40
41
|
}
|
|
41
42
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
async
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
43
|
+
async analyzeClassFromJar(className, jarPath, contextPath, verbose = true) {
|
|
44
|
+
return this.analyzeClassWithJavap(jarPath, className, verbose, Logger.get(contextPath));
|
|
45
|
+
}
|
|
46
|
+
async analyzeClassFile(className, classFilePath, contextPath) {
|
|
47
|
+
const output = await this.runJavap(['-v', '-p', classFilePath], Logger.get(contextPath));
|
|
48
|
+
return this.parseJavapOutput(output, className);
|
|
49
|
+
}
|
|
50
|
+
async analyzeJdkClass(className, contextPath) {
|
|
51
|
+
const output = await this.runJavap(['-v', className], Logger.get(contextPath));
|
|
52
|
+
return this.parseJavapOutput(output, className);
|
|
53
|
+
}
|
|
54
|
+
async getBytecode(className, contextPath, jarPath) {
|
|
55
|
+
const args = jarPath
|
|
56
|
+
? ['-c', '-l', '-p', '-s', '-cp', jarPath, className]
|
|
57
|
+
: ['-c', '-l', '-p', '-s', className];
|
|
58
|
+
return this.runJavap(args, Logger.get(contextPath));
|
|
59
|
+
}
|
|
60
|
+
async getBytecodeFromClassFile(classFilePath, contextPath) {
|
|
61
|
+
return this.runJavap(['-c', '-l', '-p', '-s', classFilePath], Logger.get(contextPath));
|
|
62
|
+
}
|
|
63
|
+
async runJavap(args, logger) {
|
|
64
|
+
const javapCmd = this.getJavapCommand(logger);
|
|
65
|
+
const { stdout, stderr } = await execFileAsync(javapCmd, args, { timeout: 10000, maxBuffer: 10 * 1024 * 1024 });
|
|
66
|
+
if (stderr?.trim())
|
|
67
|
+
logger?.warn(`[JAVAP] stderr: ${stderr}`);
|
|
68
|
+
return stdout;
|
|
63
69
|
}
|
|
64
70
|
/**
|
|
65
71
|
* Use javap tool to analyze class structure in JAR package
|
|
@@ -331,17 +337,30 @@ export class JavaClassAnalyzer {
|
|
|
331
337
|
const hierarchy = [];
|
|
332
338
|
let currentName = className;
|
|
333
339
|
let level = 0;
|
|
334
|
-
|
|
340
|
+
const visited = new Set();
|
|
341
|
+
const MAX_DEPTH = 20;
|
|
342
|
+
while (currentName && level < MAX_DEPTH) {
|
|
343
|
+
if (visited.has(currentName))
|
|
344
|
+
break;
|
|
345
|
+
visited.add(currentName);
|
|
335
346
|
let resolved = false;
|
|
336
347
|
let superClass;
|
|
337
|
-
|
|
338
|
-
|
|
348
|
+
const cached = this.superClassCache.get(currentName);
|
|
349
|
+
if (cached !== undefined) {
|
|
350
|
+
superClass = cached;
|
|
339
351
|
resolved = true;
|
|
340
|
-
superClass = analysis.superClass;
|
|
341
352
|
}
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
353
|
+
else {
|
|
354
|
+
try {
|
|
355
|
+
const analysis = await this.analyzeClass(currentName, projectPath, false);
|
|
356
|
+
resolved = true;
|
|
357
|
+
superClass = analysis.superClass;
|
|
358
|
+
this.superClassCache.set(currentName, superClass);
|
|
359
|
+
}
|
|
360
|
+
catch {
|
|
361
|
+
// Class not found in indexed dependencies
|
|
362
|
+
resolved = false;
|
|
363
|
+
}
|
|
345
364
|
}
|
|
346
365
|
hierarchy.unshift({ className: currentName, level: 0, resolved });
|
|
347
366
|
if (!superClass) {
|