@aws/lsp-codewhisperer 0.0.34 → 0.0.36
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/CHANGELOG.md +66 -0
- package/out/client/token/bearer-token-service.json +91 -225
- package/out/language-server/agenticChat/agenticChatController.js +82 -29
- package/out/language-server/agenticChat/agenticChatController.js.map +1 -1
- package/out/language-server/agenticChat/agenticChatResultStream.js +3 -0
- package/out/language-server/agenticChat/agenticChatResultStream.js.map +1 -1
- package/out/language-server/agenticChat/constants.d.ts +3 -0
- package/out/language-server/agenticChat/constants.js +4 -1
- package/out/language-server/agenticChat/constants.js.map +1 -1
- package/out/language-server/agenticChat/context/agenticChatTriggerContext.d.ts +3 -8
- package/out/language-server/agenticChat/context/agenticChatTriggerContext.js +9 -2
- package/out/language-server/agenticChat/context/agenticChatTriggerContext.js.map +1 -1
- package/out/language-server/agenticChat/context/contextUtils.d.ts +20 -0
- package/out/language-server/agenticChat/context/contextUtils.js +107 -0
- package/out/language-server/agenticChat/context/contextUtils.js.map +1 -1
- package/out/language-server/agenticChat/errors.d.ts +2 -1
- package/out/language-server/agenticChat/errors.js +4 -1
- package/out/language-server/agenticChat/errors.js.map +1 -1
- package/out/language-server/agenticChat/tabBarController.js +1 -1
- package/out/language-server/agenticChat/tabBarController.js.map +1 -1
- package/out/language-server/agenticChat/tools/chatDb/chatDb.js +3 -2
- package/out/language-server/agenticChat/tools/chatDb/chatDb.js.map +1 -1
- package/out/language-server/agenticChat/tools/fileSearch.js +1 -1
- package/out/language-server/agenticChat/tools/fileSearch.js.map +1 -1
- package/out/language-server/agenticChat/tools/listDirectory.js +5 -5
- package/out/language-server/agenticChat/tools/listDirectory.js.map +1 -1
- package/out/language-server/chat/chatController.js +1 -1
- package/out/language-server/chat/chatController.js.map +1 -1
- package/out/language-server/chat/chatSessionService.d.ts +5 -0
- package/out/language-server/chat/chatSessionService.js +4 -1
- package/out/language-server/chat/chatSessionService.js.map +1 -1
- package/out/language-server/chat/constants.d.ts +3 -1
- package/out/language-server/chat/constants.js +15 -2
- package/out/language-server/chat/constants.js.map +1 -1
- package/out/language-server/chat/contexts/triggerContext.d.ts +3 -1
- package/out/language-server/chat/contexts/triggerContext.js +14 -1
- package/out/language-server/chat/contexts/triggerContext.js.map +1 -1
- package/out/language-server/configuration/qConfigurationServer.d.ts +8 -1
- package/out/language-server/configuration/qConfigurationServer.js +107 -8
- package/out/language-server/configuration/qConfigurationServer.js.map +1 -1
- package/out/language-server/inline-completion/codeWhispererServer.js +15 -2
- package/out/language-server/inline-completion/codeWhispererServer.js.map +1 -1
- package/out/language-server/netTransform/resources/SupportedProjects.js +1 -7
- package/out/language-server/netTransform/resources/SupportedProjects.js.map +1 -1
- package/out/language-server/workspaceContext/artifactManager.d.ts +44 -0
- package/out/language-server/workspaceContext/artifactManager.js +496 -0
- package/out/language-server/workspaceContext/artifactManager.js.map +1 -0
- package/out/language-server/workspaceContext/client.d.ts +23 -0
- package/out/language-server/workspaceContext/client.js +172 -0
- package/out/language-server/workspaceContext/client.js.map +1 -0
- package/out/language-server/workspaceContext/dependency/dependencyDiscoverer.d.ts +15 -0
- package/out/language-server/workspaceContext/dependency/dependencyDiscoverer.js +129 -0
- package/out/language-server/workspaceContext/dependency/dependencyDiscoverer.js.map +1 -0
- package/out/language-server/workspaceContext/dependency/dependencyHandler/JSTSDependencyHandler.d.ts +18 -0
- package/out/language-server/workspaceContext/dependency/dependencyHandler/JSTSDependencyHandler.js +204 -0
- package/out/language-server/workspaceContext/dependency/dependencyHandler/JSTSDependencyHandler.js.map +1 -0
- package/out/language-server/workspaceContext/dependency/dependencyHandler/JavaDependencyHandler.d.ts +16 -0
- package/out/language-server/workspaceContext/dependency/dependencyHandler/JavaDependencyHandler.js +160 -0
- package/out/language-server/workspaceContext/dependency/dependencyHandler/JavaDependencyHandler.js.map +1 -0
- package/out/language-server/workspaceContext/dependency/dependencyHandler/LanguageDependencyHandler.d.ts +78 -0
- package/out/language-server/workspaceContext/dependency/dependencyHandler/LanguageDependencyHandler.js +255 -0
- package/out/language-server/workspaceContext/dependency/dependencyHandler/LanguageDependencyHandler.js.map +1 -0
- package/out/language-server/workspaceContext/dependency/dependencyHandler/LanguageDependencyHandlerFactory.d.ts +7 -0
- package/out/language-server/workspaceContext/dependency/dependencyHandler/LanguageDependencyHandlerFactory.js +23 -0
- package/out/language-server/workspaceContext/dependency/dependencyHandler/LanguageDependencyHandlerFactory.js.map +1 -0
- package/out/language-server/workspaceContext/dependency/dependencyHandler/PythonDependencyHandler.d.ts +46 -0
- package/out/language-server/workspaceContext/dependency/dependencyHandler/PythonDependencyHandler.js +233 -0
- package/out/language-server/workspaceContext/dependency/dependencyHandler/PythonDependencyHandler.js.map +1 -0
- package/out/language-server/workspaceContext/javaManager.d.ts +92 -0
- package/out/language-server/workspaceContext/javaManager.js +710 -0
- package/out/language-server/workspaceContext/javaManager.js.map +1 -0
- package/out/language-server/workspaceContext/util.d.ts +10 -0
- package/out/language-server/workspaceContext/util.js +72 -0
- package/out/language-server/workspaceContext/util.js.map +1 -0
- package/out/language-server/workspaceContext/workspaceContextServer.d.ts +2 -0
- package/out/language-server/workspaceContext/workspaceContextServer.js +414 -0
- package/out/language-server/workspaceContext/workspaceContextServer.js.map +1 -0
- package/out/language-server/workspaceContext/workspaceFolderManager.d.ts +113 -0
- package/out/language-server/workspaceContext/workspaceFolderManager.js +827 -0
- package/out/language-server/workspaceContext/workspaceFolderManager.js.map +1 -0
- package/out/shared/amazonQServiceManager/qDeveloperProfiles.js.map +1 -1
- package/out/shared/codeWhispererService.d.ts +13 -0
- package/out/shared/codeWhispererService.js +24 -0
- package/out/shared/codeWhispererService.js.map +1 -1
- package/out/shared/languageDetection.d.ts +27 -0
- package/out/shared/languageDetection.js +44 -1
- package/out/shared/languageDetection.js.map +1 -1
- package/out/shared/localProjectContextController.d.ts +1 -0
- package/out/shared/localProjectContextController.js +7 -9
- package/out/shared/localProjectContextController.js.map +1 -1
- package/out/shared/proxy-server.d.ts +1 -0
- package/out/shared/proxy-server.js +3 -1
- package/out/shared/proxy-server.js.map +1 -1
- package/out/shared/supplementalContextUtil/crossFileContextUtil.d.ts +4 -3
- package/out/shared/supplementalContextUtil/crossFileContextUtil.js +16 -5
- package/out/shared/supplementalContextUtil/crossFileContextUtil.js.map +1 -1
- package/out/shared/supplementalContextUtil/supplementalContextUtil.d.ts +2 -1
- package/out/shared/supplementalContextUtil/supplementalContextUtil.js +2 -2
- package/out/shared/supplementalContextUtil/supplementalContextUtil.js.map +1 -1
- package/out/shared/utils.d.ts +1 -0
- package/out/shared/utils.js +15 -1
- package/out/shared/utils.js.map +1 -1
- package/package.json +9 -3
|
@@ -0,0 +1,710 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EclipseConfigGenerator = exports.JavaProjectAnalyzer = void 0;
|
|
4
|
+
const fs = require("fs/promises");
|
|
5
|
+
const path = require("path");
|
|
6
|
+
const xml2js = require("xml2js");
|
|
7
|
+
const glob = require("fast-glob");
|
|
8
|
+
const xmlbuilder2_1 = require("xmlbuilder2");
|
|
9
|
+
const vscode_uri_1 = require("vscode-uri");
|
|
10
|
+
const IGNORE_PATTERNS = [
|
|
11
|
+
// Package management and git
|
|
12
|
+
'**/node_modules/**',
|
|
13
|
+
'**/.git/**',
|
|
14
|
+
// Build outputs
|
|
15
|
+
'**/dist/**',
|
|
16
|
+
'**/build/**',
|
|
17
|
+
'**/out/**',
|
|
18
|
+
// Test directories
|
|
19
|
+
'**/test/**',
|
|
20
|
+
'**/tests/**',
|
|
21
|
+
'**/coverage/**',
|
|
22
|
+
// Hidden directories and files
|
|
23
|
+
'**/.*/**',
|
|
24
|
+
'**/.*',
|
|
25
|
+
// Logs and temporary files
|
|
26
|
+
'**/logs/**',
|
|
27
|
+
'**/tmp/**',
|
|
28
|
+
// Environment and configuration
|
|
29
|
+
'**/env/**',
|
|
30
|
+
'**/venv/**',
|
|
31
|
+
'**/bin/**',
|
|
32
|
+
// Framework specific
|
|
33
|
+
'**/target/**', // Maven/Gradle builds
|
|
34
|
+
];
|
|
35
|
+
// Similar to Bemol's ClasspathAttribute enum
|
|
36
|
+
var ClasspathAttribute;
|
|
37
|
+
(function (ClasspathAttribute) {
|
|
38
|
+
ClasspathAttribute["MODULE"] = "module";
|
|
39
|
+
ClasspathAttribute["OPTIONAL"] = "optional";
|
|
40
|
+
ClasspathAttribute["TEST"] = "test";
|
|
41
|
+
ClasspathAttribute["JAVADOC_LOCATION"] = "javadoc_location";
|
|
42
|
+
ClasspathAttribute["IGNORE_OPTIONAL_PROBLEMS"] = "ignore_optional_problems";
|
|
43
|
+
})(ClasspathAttribute || (ClasspathAttribute = {}));
|
|
44
|
+
class JavaProjectAnalyzer {
|
|
45
|
+
workspacePath;
|
|
46
|
+
defaultMavenStructure = {
|
|
47
|
+
sources: 'src/main/java',
|
|
48
|
+
resources: 'src/main/resources',
|
|
49
|
+
tests: 'src/test/java',
|
|
50
|
+
testResources: 'src/test/resources',
|
|
51
|
+
generated: 'target/generated-sources',
|
|
52
|
+
generatedTest: 'target/generated-test-sources',
|
|
53
|
+
};
|
|
54
|
+
defaultGradleStructure = {
|
|
55
|
+
sources: 'src/main/java',
|
|
56
|
+
resources: 'src/main/resources',
|
|
57
|
+
tests: 'src/test/java',
|
|
58
|
+
testResources: 'src/test/resources',
|
|
59
|
+
generated: 'build/generated/sources/main',
|
|
60
|
+
generatedTest: 'build/generated/sources/test',
|
|
61
|
+
};
|
|
62
|
+
constructor(workspacePath) {
|
|
63
|
+
this.workspacePath = workspacePath;
|
|
64
|
+
}
|
|
65
|
+
async analyze() {
|
|
66
|
+
const buildSystem = await this.detectBuildSystem();
|
|
67
|
+
const [sourceDirectories, testDirectories, resourceDirectories, testResourceDirectories, javaVersion, dependencies, annotationProcessors,] = await Promise.all([
|
|
68
|
+
this.findSourceDirectories(buildSystem),
|
|
69
|
+
this.findTestDirectories(buildSystem),
|
|
70
|
+
this.findResourceDirectories(buildSystem),
|
|
71
|
+
this.findTestResourceDirectories(buildSystem),
|
|
72
|
+
this.detectJavaVersion(buildSystem),
|
|
73
|
+
this.analyzeDependencies(buildSystem),
|
|
74
|
+
this.findAnnotationProcessors(buildSystem),
|
|
75
|
+
]);
|
|
76
|
+
return {
|
|
77
|
+
sourceDirectories,
|
|
78
|
+
testDirectories,
|
|
79
|
+
resourceDirectories,
|
|
80
|
+
testResourceDirectories,
|
|
81
|
+
outputDirectory: this.getOutputDirectory(buildSystem),
|
|
82
|
+
testOutputDirectory: this.getTestOutputDirectory(buildSystem),
|
|
83
|
+
javaVersion,
|
|
84
|
+
dependencies,
|
|
85
|
+
annotationProcessors,
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
async detectBuildSystem() {
|
|
89
|
+
const hasPom = await this.fileExists('pom.xml');
|
|
90
|
+
if (hasPom)
|
|
91
|
+
return 'maven';
|
|
92
|
+
const hasGradle = (await this.fileExists('build.gradle')) || (await this.fileExists('build.gradle.kts'));
|
|
93
|
+
if (hasGradle)
|
|
94
|
+
return 'gradle';
|
|
95
|
+
return 'unknown';
|
|
96
|
+
}
|
|
97
|
+
async findSourceDirectories(buildSystem) {
|
|
98
|
+
const directories = [];
|
|
99
|
+
const seenPaths = new Set();
|
|
100
|
+
// Add default source directory based on build system
|
|
101
|
+
const defaultSource = buildSystem === 'maven' ? this.defaultMavenStructure.sources : this.defaultGradleStructure.sources;
|
|
102
|
+
if (await this.fileExists(defaultSource)) {
|
|
103
|
+
directories.push({
|
|
104
|
+
path: defaultSource,
|
|
105
|
+
isOptional: false,
|
|
106
|
+
});
|
|
107
|
+
seenPaths.add(defaultSource);
|
|
108
|
+
}
|
|
109
|
+
// Add generated sources
|
|
110
|
+
const generatedDir = buildSystem === 'maven' ? this.defaultMavenStructure.generated : this.defaultGradleStructure.generated;
|
|
111
|
+
if (await this.fileExists(generatedDir)) {
|
|
112
|
+
directories.push({
|
|
113
|
+
path: generatedDir,
|
|
114
|
+
isOptional: true,
|
|
115
|
+
isGenerated: true,
|
|
116
|
+
});
|
|
117
|
+
seenPaths.add(generatedDir);
|
|
118
|
+
}
|
|
119
|
+
// For Maven, parse pom.xml for additional source directories
|
|
120
|
+
if (buildSystem === 'maven') {
|
|
121
|
+
const additionalSources = await this.parseMavenSourceDirectories();
|
|
122
|
+
for (const source of additionalSources) {
|
|
123
|
+
if (!seenPaths.has(source.path)) {
|
|
124
|
+
directories.push(source);
|
|
125
|
+
seenPaths.add(source.path);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
// For Gradle, parse build.gradle for additional source directories
|
|
130
|
+
if (buildSystem === 'gradle') {
|
|
131
|
+
const additionalSources = await this.parseGradleSourceDirectories();
|
|
132
|
+
for (const source of additionalSources) {
|
|
133
|
+
if (!seenPaths.has(source.path)) {
|
|
134
|
+
directories.push(source);
|
|
135
|
+
seenPaths.add(source.path);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
// Always scan for potential source directories as a fallback
|
|
140
|
+
// This will help catch non-standard source locations
|
|
141
|
+
const potentialSources = await this.findPotentialSourceDirectories();
|
|
142
|
+
for (const source of potentialSources) {
|
|
143
|
+
if (!seenPaths.has(source.path)) {
|
|
144
|
+
directories.push(source);
|
|
145
|
+
seenPaths.add(source.path);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
return directories;
|
|
149
|
+
}
|
|
150
|
+
async findPotentialSourceDirectories() {
|
|
151
|
+
const potentialSources = [];
|
|
152
|
+
const seenPaths = new Set();
|
|
153
|
+
const patterns = [
|
|
154
|
+
'src/**/*.java',
|
|
155
|
+
'source/**/*.java',
|
|
156
|
+
'java/**/*.java',
|
|
157
|
+
'main/**/*.java',
|
|
158
|
+
'app/**/*.java',
|
|
159
|
+
'test/**/*.java',
|
|
160
|
+
];
|
|
161
|
+
for (const pattern of patterns) {
|
|
162
|
+
const javaFiles = await glob(pattern, {
|
|
163
|
+
cwd: this.workspacePath,
|
|
164
|
+
ignore: IGNORE_PATTERNS,
|
|
165
|
+
});
|
|
166
|
+
for (const file of javaFiles) {
|
|
167
|
+
// Find the directory containing the first package directory (usually 'com', 'org', etc.)
|
|
168
|
+
const fullPath = path.dirname(file);
|
|
169
|
+
const pathParts = fullPath.split(path.sep);
|
|
170
|
+
// Find index of first package directory (com, org, etc.)
|
|
171
|
+
const packageStartIndex = pathParts.findIndex(part => part === 'com' || part === 'org' || part === 'net' || part === 'java');
|
|
172
|
+
if (packageStartIndex > 0) {
|
|
173
|
+
// The source root is the directory containing the package root
|
|
174
|
+
const sourceDir = path.join(...pathParts.slice(0, packageStartIndex));
|
|
175
|
+
if (!seenPaths.has(sourceDir)) {
|
|
176
|
+
seenPaths.add(sourceDir);
|
|
177
|
+
const isTest = sourceDir.toLowerCase().includes('test') || sourceDir.toLowerCase().includes('tst');
|
|
178
|
+
const isGenerated = sourceDir.toLowerCase().includes('generated');
|
|
179
|
+
potentialSources.push({
|
|
180
|
+
path: sourceDir,
|
|
181
|
+
isOptional: isGenerated || isTest,
|
|
182
|
+
isGenerated,
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
// Validate directories
|
|
189
|
+
const validatedSources = [];
|
|
190
|
+
for (const source of potentialSources) {
|
|
191
|
+
const hasJavaFiles = await this.hasJavaFiles(source.path);
|
|
192
|
+
if (hasJavaFiles) {
|
|
193
|
+
validatedSources.push(source);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
return validatedSources;
|
|
197
|
+
}
|
|
198
|
+
async hasJavaFiles(directory) {
|
|
199
|
+
const javaFiles = await glob('**/*.java', {
|
|
200
|
+
cwd: path.join(this.workspacePath, directory),
|
|
201
|
+
});
|
|
202
|
+
return javaFiles.length > 0;
|
|
203
|
+
}
|
|
204
|
+
async findTestDirectories(buildSystem) {
|
|
205
|
+
const directories = [];
|
|
206
|
+
// Define default test paths based on build system
|
|
207
|
+
let defaultTestPath;
|
|
208
|
+
let generatedTestPath;
|
|
209
|
+
switch (buildSystem) {
|
|
210
|
+
case 'maven':
|
|
211
|
+
defaultTestPath = this.defaultMavenStructure.tests;
|
|
212
|
+
generatedTestPath = this.defaultMavenStructure.generatedTest;
|
|
213
|
+
break;
|
|
214
|
+
case 'gradle':
|
|
215
|
+
defaultTestPath = this.defaultGradleStructure.tests;
|
|
216
|
+
generatedTestPath = this.defaultGradleStructure.generatedTest;
|
|
217
|
+
break;
|
|
218
|
+
default:
|
|
219
|
+
defaultTestPath = 'test';
|
|
220
|
+
generatedTestPath = 'generated-test';
|
|
221
|
+
}
|
|
222
|
+
// Check main test directory
|
|
223
|
+
if (await this.fileExists(defaultTestPath)) {
|
|
224
|
+
directories.push({
|
|
225
|
+
path: defaultTestPath,
|
|
226
|
+
isOptional: false,
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
// Check generated test sources
|
|
230
|
+
if (await this.fileExists(generatedTestPath)) {
|
|
231
|
+
directories.push({
|
|
232
|
+
path: generatedTestPath,
|
|
233
|
+
isOptional: true,
|
|
234
|
+
isGenerated: true,
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
return directories;
|
|
238
|
+
}
|
|
239
|
+
async findResourceDirectories(buildSystem) {
|
|
240
|
+
const directories = [];
|
|
241
|
+
const resourcePaths = {
|
|
242
|
+
maven: this.defaultMavenStructure.resources,
|
|
243
|
+
gradle: this.defaultGradleStructure.resources,
|
|
244
|
+
unknown: ['resources', 'src/resources', 'conf'],
|
|
245
|
+
};
|
|
246
|
+
const paths = resourcePaths[buildSystem] || resourcePaths.unknown;
|
|
247
|
+
for (const resourcePath of paths) {
|
|
248
|
+
if (await this.fileExists(resourcePath)) {
|
|
249
|
+
directories.push({
|
|
250
|
+
path: resourcePath,
|
|
251
|
+
isOptional: true,
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
return directories;
|
|
256
|
+
}
|
|
257
|
+
async findTestResourceDirectories(buildSystem) {
|
|
258
|
+
const directories = [];
|
|
259
|
+
const defaultTestResources = buildSystem === 'maven'
|
|
260
|
+
? this.defaultMavenStructure.testResources
|
|
261
|
+
: this.defaultGradleStructure.testResources;
|
|
262
|
+
if (await this.fileExists(defaultTestResources)) {
|
|
263
|
+
directories.push({
|
|
264
|
+
path: defaultTestResources,
|
|
265
|
+
isOptional: true,
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
return directories;
|
|
269
|
+
}
|
|
270
|
+
async detectJavaVersion(buildSystem) {
|
|
271
|
+
if (buildSystem === 'maven') {
|
|
272
|
+
const pomContent = await this.readPomXml();
|
|
273
|
+
if (pomContent) {
|
|
274
|
+
const parsed = await xml2js.parseStringPromise(pomContent);
|
|
275
|
+
return (parsed?.project?.properties?.[0]?.['java.version']?.[0] ||
|
|
276
|
+
parsed?.project?.properties?.[0]?.['maven.compiler.source']?.[0] ||
|
|
277
|
+
'11'); // Default to Java 11 if not specified
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
if (buildSystem === 'gradle') {
|
|
281
|
+
const gradleContent = await this.readGradleFile();
|
|
282
|
+
if (gradleContent) {
|
|
283
|
+
const sourceCompatibilityMatch = gradleContent.match(/sourceCompatibility\s*=\s*['"](.+)['"]/);
|
|
284
|
+
if (sourceCompatibilityMatch) {
|
|
285
|
+
return sourceCompatibilityMatch[1];
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
return '11'; // Default to Java 11 if not detected
|
|
290
|
+
}
|
|
291
|
+
async analyzeDependencies(buildSystem) {
|
|
292
|
+
const dependencies = [];
|
|
293
|
+
if (buildSystem === 'maven') {
|
|
294
|
+
const pomContent = await this.readPomXml();
|
|
295
|
+
if (pomContent) {
|
|
296
|
+
const parsed = await xml2js.parseStringPromise(pomContent);
|
|
297
|
+
const mavenDeps = parsed?.project?.dependencies?.[0]?.dependency || [];
|
|
298
|
+
for (const dep of mavenDeps) {
|
|
299
|
+
const groupId = dep.groupId[0];
|
|
300
|
+
const artifactId = dep.artifactId[0];
|
|
301
|
+
const version = dep.version?.[0] || 'LATEST';
|
|
302
|
+
// Here you would need to resolve the actual JAR paths
|
|
303
|
+
// This is a simplified example
|
|
304
|
+
dependencies.push({
|
|
305
|
+
libraryPath: `${groupId}/${artifactId}/${version}/${artifactId}-${version}.jar`,
|
|
306
|
+
sourcesPath: `${groupId}/${artifactId}/${version}/${artifactId}-${version}-sources.jar`,
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
// Also check for local JARs in lib directory
|
|
312
|
+
const libPath = path.join(this.workspacePath, 'lib');
|
|
313
|
+
if (await this.fileExists(libPath)) {
|
|
314
|
+
const localJars = await glob('**/*.jar', { cwd: libPath });
|
|
315
|
+
for (const jar of localJars) {
|
|
316
|
+
dependencies.push({
|
|
317
|
+
libraryPath: path.join('lib', jar),
|
|
318
|
+
});
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
return dependencies;
|
|
322
|
+
}
|
|
323
|
+
async findAnnotationProcessors(buildSystem) {
|
|
324
|
+
const processors = [];
|
|
325
|
+
const options = {};
|
|
326
|
+
if (buildSystem === 'maven') {
|
|
327
|
+
const pomContent = await this.readPomXml();
|
|
328
|
+
if (pomContent) {
|
|
329
|
+
const parsed = await xml2js.parseStringPromise(pomContent);
|
|
330
|
+
// Parse annotation processors from maven-compiler-plugin configuration
|
|
331
|
+
const plugins = parsed?.project?.build?.[0]?.plugins?.[0]?.plugin || [];
|
|
332
|
+
for (const plugin of plugins) {
|
|
333
|
+
if (plugin.artifactId[0] === 'maven-compiler-plugin') {
|
|
334
|
+
const config = plugin.configuration?.[0];
|
|
335
|
+
if (config?.annotationProcessors) {
|
|
336
|
+
processors.push(...config.annotationProcessors[0].processor);
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
return { processors, options };
|
|
343
|
+
}
|
|
344
|
+
getOutputDirectory(buildSystem) {
|
|
345
|
+
switch (buildSystem) {
|
|
346
|
+
case 'maven':
|
|
347
|
+
return 'target/classes';
|
|
348
|
+
case 'gradle':
|
|
349
|
+
return 'build/classes/java/main';
|
|
350
|
+
case 'unknown':
|
|
351
|
+
return 'bin'; // Common default for basic Java projects
|
|
352
|
+
default:
|
|
353
|
+
return 'out'; // Fallback directory
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
getTestOutputDirectory(buildSystem) {
|
|
357
|
+
switch (buildSystem) {
|
|
358
|
+
case 'maven':
|
|
359
|
+
return 'target/test-classes';
|
|
360
|
+
case 'gradle':
|
|
361
|
+
return 'build/classes/java/test';
|
|
362
|
+
case 'unknown':
|
|
363
|
+
return 'bin/test'; // Common default for basic Java projects
|
|
364
|
+
default:
|
|
365
|
+
return 'out/test'; // Fallback directory
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
async fileExists(relativePath) {
|
|
369
|
+
try {
|
|
370
|
+
await fs.access(path.join(this.workspacePath, relativePath));
|
|
371
|
+
return true;
|
|
372
|
+
}
|
|
373
|
+
catch {
|
|
374
|
+
return false;
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
async readPomXml() {
|
|
378
|
+
try {
|
|
379
|
+
return await fs.readFile(path.join(this.workspacePath, 'pom.xml'), 'utf-8');
|
|
380
|
+
}
|
|
381
|
+
catch {
|
|
382
|
+
return null;
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
async readGradleFile() {
|
|
386
|
+
try {
|
|
387
|
+
const gradlePath = (await this.fileExists('build.gradle.kts')) ? 'build.gradle.kts' : 'build.gradle';
|
|
388
|
+
return await fs.readFile(path.join(this.workspacePath, gradlePath), 'utf-8');
|
|
389
|
+
}
|
|
390
|
+
catch {
|
|
391
|
+
return null;
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
async parseMavenSourceDirectories() {
|
|
395
|
+
const directories = [];
|
|
396
|
+
const pomContent = await this.readPomXml();
|
|
397
|
+
if (pomContent) {
|
|
398
|
+
const parsed = await xml2js.parseStringPromise(pomContent);
|
|
399
|
+
const build = parsed?.project?.build?.[0];
|
|
400
|
+
// Parse additional source directories from build/sourceDirectory
|
|
401
|
+
if (build?.sourceDirectory) {
|
|
402
|
+
directories.push({
|
|
403
|
+
path: build.sourceDirectory[0],
|
|
404
|
+
isOptional: false,
|
|
405
|
+
});
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
return directories;
|
|
409
|
+
}
|
|
410
|
+
async parseGradleSourceDirectories() {
|
|
411
|
+
const directories = [];
|
|
412
|
+
const gradleContent = await this.readGradleFile();
|
|
413
|
+
if (gradleContent) {
|
|
414
|
+
// Parse sourceSets from build.gradle
|
|
415
|
+
// This is a simplified implementation
|
|
416
|
+
const sourceSetMatches = gradleContent.matchAll(/sourceSets\s*{\s*main\s*{\s*java\s*{\s*srcDirs\s*=\s*\[(.*?)\]/gs);
|
|
417
|
+
for (const match of sourceSetMatches) {
|
|
418
|
+
const srcDirs = match[1]
|
|
419
|
+
.split(',')
|
|
420
|
+
.map(dir => dir.trim().replace(/['"]/g, ''))
|
|
421
|
+
.filter(dir => dir);
|
|
422
|
+
for (const dir of srcDirs) {
|
|
423
|
+
directories.push({
|
|
424
|
+
path: dir,
|
|
425
|
+
isOptional: false,
|
|
426
|
+
});
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
return directories;
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
exports.JavaProjectAnalyzer = JavaProjectAnalyzer;
|
|
434
|
+
class EclipseConfigGenerator {
|
|
435
|
+
workspaceFolder;
|
|
436
|
+
logging;
|
|
437
|
+
projectFiles;
|
|
438
|
+
initializationPromise = null;
|
|
439
|
+
workspacePath;
|
|
440
|
+
constructor(workspaceFolder, logging) {
|
|
441
|
+
this.workspaceFolder = workspaceFolder;
|
|
442
|
+
this.logging = logging;
|
|
443
|
+
this.projectFiles = new Map();
|
|
444
|
+
this.workspacePath = vscode_uri_1.URI.parse(workspaceFolder.uri).path;
|
|
445
|
+
this.initializeProjectFiles().catch(error => {
|
|
446
|
+
this.logging.warn(`Failed to initialize Java project files: ${error}`);
|
|
447
|
+
});
|
|
448
|
+
}
|
|
449
|
+
async generateDotClasspath(structure) {
|
|
450
|
+
await this.ensureInitialized();
|
|
451
|
+
const existingClasspaths = this.projectFiles.get('.classpath') || [];
|
|
452
|
+
if (existingClasspaths.length > 0) {
|
|
453
|
+
return existingClasspaths;
|
|
454
|
+
}
|
|
455
|
+
const builder = (0, xmlbuilder2_1.create)({ version: '1.0', encoding: 'UTF-8' });
|
|
456
|
+
const classpath = builder.ele('classpath');
|
|
457
|
+
// Add default output directory
|
|
458
|
+
const output = classpath.ele('classpathentry').att('kind', 'output').att('path', structure.outputDirectory);
|
|
459
|
+
// Add JRE container
|
|
460
|
+
const container = classpath
|
|
461
|
+
.ele('classpathentry')
|
|
462
|
+
.att('kind', 'con')
|
|
463
|
+
.att('path', `org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-${structure.javaVersion}`);
|
|
464
|
+
this.addAttribute(container, ClasspathAttribute.MODULE);
|
|
465
|
+
// Add source folders
|
|
466
|
+
for (const src of structure.sourceDirectories) {
|
|
467
|
+
const entry = classpath.ele('classpathentry').att('kind', 'src').att('path', this.normalizePath(src.path));
|
|
468
|
+
if (src.isOptional) {
|
|
469
|
+
this.addAttribute(entry, ClasspathAttribute.OPTIONAL);
|
|
470
|
+
}
|
|
471
|
+
if (src.isGenerated) {
|
|
472
|
+
this.addAttribute(entry, ClasspathAttribute.IGNORE_OPTIONAL_PROBLEMS);
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
// Add resource folders
|
|
476
|
+
for (const resource of structure.resourceDirectories) {
|
|
477
|
+
const entry = classpath
|
|
478
|
+
.ele('classpathentry')
|
|
479
|
+
.att('kind', 'src')
|
|
480
|
+
.att('path', this.normalizePath(resource.path))
|
|
481
|
+
.att('output', structure.outputDirectory);
|
|
482
|
+
if (resource.isOptional) {
|
|
483
|
+
this.addAttribute(entry, ClasspathAttribute.OPTIONAL);
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
// Add test source folders
|
|
487
|
+
for (const test of structure.testDirectories) {
|
|
488
|
+
const entry = classpath
|
|
489
|
+
.ele('classpathentry')
|
|
490
|
+
.att('kind', 'src')
|
|
491
|
+
.att('path', this.normalizePath(test.path))
|
|
492
|
+
.att('output', structure.testOutputDirectory);
|
|
493
|
+
this.addAttribute(entry, ClasspathAttribute.TEST);
|
|
494
|
+
if (test.isOptional) {
|
|
495
|
+
this.addAttribute(entry, ClasspathAttribute.OPTIONAL);
|
|
496
|
+
}
|
|
497
|
+
if (test.isGenerated) {
|
|
498
|
+
this.addAttribute(entry, ClasspathAttribute.IGNORE_OPTIONAL_PROBLEMS);
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
// Add test resource folders
|
|
502
|
+
for (const testResource of structure.testResourceDirectories) {
|
|
503
|
+
const entry = classpath
|
|
504
|
+
.ele('classpathentry')
|
|
505
|
+
.att('kind', 'src')
|
|
506
|
+
.att('path', this.normalizePath(testResource.path))
|
|
507
|
+
.att('output', structure.testOutputDirectory);
|
|
508
|
+
this.addAttribute(entry, ClasspathAttribute.TEST);
|
|
509
|
+
if (testResource.isOptional) {
|
|
510
|
+
this.addAttribute(entry, ClasspathAttribute.OPTIONAL);
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
// Add dependencies
|
|
514
|
+
for (const dep of structure.dependencies) {
|
|
515
|
+
const entry = classpath
|
|
516
|
+
.ele('classpathentry')
|
|
517
|
+
.att('kind', 'lib')
|
|
518
|
+
.att('path', this.normalizePath(dep.libraryPath));
|
|
519
|
+
if (dep.sourcesPath) {
|
|
520
|
+
entry.att('sourcepath', this.normalizePath(dep.sourcesPath));
|
|
521
|
+
}
|
|
522
|
+
if (dep.documentationPath) {
|
|
523
|
+
this.addAttribute(entry, ClasspathAttribute.JAVADOC_LOCATION, `file:${this.normalizePath(dep.documentationPath)}`);
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
// Add annotation processor generated source folders if needed
|
|
527
|
+
if (structure.annotationProcessors && structure.annotationProcessors.processors.length > 0) {
|
|
528
|
+
// Add generated sources output
|
|
529
|
+
const aptSrcEntry = classpath
|
|
530
|
+
.ele('classpathentry')
|
|
531
|
+
.att('kind', 'src')
|
|
532
|
+
.att('path', 'target/generated-sources/annotations')
|
|
533
|
+
.att('output', structure.outputDirectory);
|
|
534
|
+
this.addAttribute(aptSrcEntry, ClasspathAttribute.OPTIONAL);
|
|
535
|
+
this.addAttribute(aptSrcEntry, ClasspathAttribute.IGNORE_OPTIONAL_PROBLEMS);
|
|
536
|
+
// Add generated test sources output
|
|
537
|
+
const aptTestEntry = classpath
|
|
538
|
+
.ele('classpathentry')
|
|
539
|
+
.att('kind', 'src')
|
|
540
|
+
.att('path', 'target/generated-test-sources/test-annotations')
|
|
541
|
+
.att('output', structure.testOutputDirectory);
|
|
542
|
+
this.addAttribute(aptTestEntry, ClasspathAttribute.OPTIONAL);
|
|
543
|
+
this.addAttribute(aptTestEntry, ClasspathAttribute.TEST);
|
|
544
|
+
this.addAttribute(aptTestEntry, ClasspathAttribute.IGNORE_OPTIONAL_PROBLEMS);
|
|
545
|
+
}
|
|
546
|
+
const generatedContent = Buffer.from(builder.end({ prettyPrint: true }));
|
|
547
|
+
const relativePath = '.classpath';
|
|
548
|
+
const newClasspathFile = {
|
|
549
|
+
filePath: path.join(this.workspacePath, relativePath),
|
|
550
|
+
relativePath,
|
|
551
|
+
language: 'java',
|
|
552
|
+
contentLength: generatedContent.length,
|
|
553
|
+
lastModified: Date.now(),
|
|
554
|
+
content: generatedContent,
|
|
555
|
+
workspaceFolder: this.workspaceFolder,
|
|
556
|
+
};
|
|
557
|
+
return [newClasspathFile];
|
|
558
|
+
}
|
|
559
|
+
async generateDotProject(projectName, structure) {
|
|
560
|
+
await this.ensureInitialized();
|
|
561
|
+
const existingProjects = this.projectFiles.get('.project') || [];
|
|
562
|
+
if (existingProjects.length > 0) {
|
|
563
|
+
return existingProjects;
|
|
564
|
+
}
|
|
565
|
+
const builder = (0, xmlbuilder2_1.create)({ version: '1.0', encoding: 'UTF-8' });
|
|
566
|
+
const project = builder.ele('projectDescription');
|
|
567
|
+
project.ele('name').txt(projectName);
|
|
568
|
+
project.ele('comment').txt('Generated by Eclipse Project Generator');
|
|
569
|
+
// Add build specification
|
|
570
|
+
const buildSpec = project.ele('buildSpec');
|
|
571
|
+
const buildCommand = buildSpec.ele('buildCommand');
|
|
572
|
+
buildCommand.ele('name').txt('org.eclipse.jdt.core.javabuilder');
|
|
573
|
+
// Add project natures
|
|
574
|
+
const natures = project.ele('natures');
|
|
575
|
+
natures.ele('nature').txt('org.eclipse.jdt.core.javanature');
|
|
576
|
+
// Add linked resources if we have any generated sources
|
|
577
|
+
const hasGeneratedSources = structure.sourceDirectories.some(src => src.isGenerated) ||
|
|
578
|
+
structure.testDirectories.some(test => test.isGenerated);
|
|
579
|
+
if (hasGeneratedSources) {
|
|
580
|
+
const linkedResources = project.ele('linkedResources');
|
|
581
|
+
const link = linkedResources.ele('link');
|
|
582
|
+
link.ele('name').txt('.generated');
|
|
583
|
+
link.ele('type').txt('2'); // Type 2 is folder
|
|
584
|
+
link.ele('location').txt(path.resolve(process.cwd(), 'target/generated-sources'));
|
|
585
|
+
}
|
|
586
|
+
const generatedContent = Buffer.from(builder.end({ prettyPrint: true }));
|
|
587
|
+
const relativePath = '.project';
|
|
588
|
+
const newProjectFile = {
|
|
589
|
+
filePath: path.join(this.workspacePath, relativePath),
|
|
590
|
+
relativePath,
|
|
591
|
+
language: 'java',
|
|
592
|
+
contentLength: generatedContent.length,
|
|
593
|
+
lastModified: Date.now(),
|
|
594
|
+
content: generatedContent,
|
|
595
|
+
workspaceFolder: this.workspaceFolder,
|
|
596
|
+
};
|
|
597
|
+
return [newProjectFile];
|
|
598
|
+
}
|
|
599
|
+
async generateDotFactorypath(structure) {
|
|
600
|
+
// Only generate factorypath if we have annotation processors
|
|
601
|
+
if (!structure.annotationProcessors || structure.annotationProcessors.processors.length === 0) {
|
|
602
|
+
return '';
|
|
603
|
+
}
|
|
604
|
+
const builder = (0, xmlbuilder2_1.create)({ version: '1.0', encoding: 'UTF-8' });
|
|
605
|
+
const factorypath = builder.ele('factorypath');
|
|
606
|
+
// Add all dependencies that might contain annotation processors
|
|
607
|
+
for (const dep of structure.dependencies) {
|
|
608
|
+
const entry = factorypath
|
|
609
|
+
.ele('factorypathentry')
|
|
610
|
+
.att('kind', 'EXTJAR')
|
|
611
|
+
.att('id', this.normalizePath(dep.libraryPath))
|
|
612
|
+
.att('enabled', 'true')
|
|
613
|
+
.att('runInBatchMode', 'false');
|
|
614
|
+
}
|
|
615
|
+
return builder.end({ prettyPrint: true });
|
|
616
|
+
}
|
|
617
|
+
async generateDotSettings(structure) {
|
|
618
|
+
const settings = new Map();
|
|
619
|
+
// Generate JDT core preferences
|
|
620
|
+
const jdtCore = (0, xmlbuilder2_1.create)({ version: '1.0', encoding: 'UTF-8' });
|
|
621
|
+
const corePrefs = jdtCore.ele('properties');
|
|
622
|
+
corePrefs.ele('entry').att('key', 'eclipse.preferences.version').att('value', '1');
|
|
623
|
+
corePrefs
|
|
624
|
+
.ele('entry')
|
|
625
|
+
.att('key', 'org.eclipse.jdt.core.compiler.codegen.targetPlatform')
|
|
626
|
+
.att('value', structure.javaVersion);
|
|
627
|
+
corePrefs
|
|
628
|
+
.ele('entry')
|
|
629
|
+
.att('key', 'org.eclipse.jdt.core.compiler.compliance')
|
|
630
|
+
.att('value', structure.javaVersion);
|
|
631
|
+
corePrefs.ele('entry').att('key', 'org.eclipse.jdt.core.compiler.source').att('value', structure.javaVersion);
|
|
632
|
+
settings.set('org.eclipse.jdt.core.prefs', jdtCore.end({ prettyPrint: true }));
|
|
633
|
+
// Generate APT preferences if we have annotation processors
|
|
634
|
+
if (structure.annotationProcessors && structure.annotationProcessors.processors.length > 0) {
|
|
635
|
+
const jdtApt = (0, xmlbuilder2_1.create)({ version: '1.0', encoding: 'UTF-8' });
|
|
636
|
+
const aptPrefs = jdtApt.ele('properties');
|
|
637
|
+
aptPrefs.ele('entry').att('key', 'eclipse.preferences.version').att('value', '1');
|
|
638
|
+
aptPrefs.ele('entry').att('key', 'org.eclipse.jdt.apt.aptEnabled').att('value', 'true');
|
|
639
|
+
aptPrefs
|
|
640
|
+
.ele('entry')
|
|
641
|
+
.att('key', 'org.eclipse.jdt.apt.genSrcDir')
|
|
642
|
+
.att('value', 'target/generated-sources/annotations');
|
|
643
|
+
aptPrefs
|
|
644
|
+
.ele('entry')
|
|
645
|
+
.att('key', 'org.eclipse.jdt.apt.genTestSrcDir')
|
|
646
|
+
.att('value', 'target/generated-test-sources/test-annotations');
|
|
647
|
+
// Add annotation processor options
|
|
648
|
+
for (const [key, value] of Object.entries(structure.annotationProcessors.options)) {
|
|
649
|
+
aptPrefs.ele('entry').att('key', `org.eclipse.jdt.apt.processorOptions/${key}`).att('value', value);
|
|
650
|
+
}
|
|
651
|
+
settings.set('org.eclipse.jdt.apt.core.prefs', jdtApt.end({ prettyPrint: true }));
|
|
652
|
+
}
|
|
653
|
+
return settings;
|
|
654
|
+
}
|
|
655
|
+
async initializeProjectFiles() {
|
|
656
|
+
try {
|
|
657
|
+
const eclipseFiles = ['.project', '.classpath'];
|
|
658
|
+
for (const fileName of eclipseFiles) {
|
|
659
|
+
const pattern = path.join(this.workspacePath, '**', fileName);
|
|
660
|
+
const files = await glob(pattern, {
|
|
661
|
+
ignore: IGNORE_PATTERNS,
|
|
662
|
+
onlyFiles: true,
|
|
663
|
+
followSymbolicLinks: false,
|
|
664
|
+
dot: true,
|
|
665
|
+
});
|
|
666
|
+
const fileMetadataArray = [];
|
|
667
|
+
for (const file of files) {
|
|
668
|
+
try {
|
|
669
|
+
const content = await fs.readFile(file);
|
|
670
|
+
const relativePath = path.relative(this.workspacePath, file);
|
|
671
|
+
fileMetadataArray.push({
|
|
672
|
+
filePath: file,
|
|
673
|
+
relativePath,
|
|
674
|
+
language: 'java',
|
|
675
|
+
contentLength: content.length,
|
|
676
|
+
lastModified: (await fs.stat(file)).mtimeMs,
|
|
677
|
+
content,
|
|
678
|
+
workspaceFolder: this.workspaceFolder,
|
|
679
|
+
});
|
|
680
|
+
}
|
|
681
|
+
catch (error) {
|
|
682
|
+
this.logging.warn(`Error reading file ${file}: ${error}`);
|
|
683
|
+
}
|
|
684
|
+
}
|
|
685
|
+
this.projectFiles.set(fileName, fileMetadataArray);
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
catch (error) {
|
|
689
|
+
this.logging.warn(`Error initializing project files: ${error}`);
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
async ensureInitialized() {
|
|
693
|
+
if (!this.initializationPromise) {
|
|
694
|
+
this.initializationPromise = this.initializeProjectFiles();
|
|
695
|
+
}
|
|
696
|
+
await this.initializationPromise;
|
|
697
|
+
}
|
|
698
|
+
addAttribute(node, attribute, value = 'true') {
|
|
699
|
+
// Get existing attributes element or create a new one
|
|
700
|
+
let attrs = node.ele('attributes');
|
|
701
|
+
// Add the attribute directly
|
|
702
|
+
attrs.ele('attribute').att('name', attribute).att('value', value);
|
|
703
|
+
}
|
|
704
|
+
normalizePath(filePath) {
|
|
705
|
+
// Convert to forward slashes for Eclipse
|
|
706
|
+
return filePath.replace(/\\/g, '/');
|
|
707
|
+
}
|
|
708
|
+
}
|
|
709
|
+
exports.EclipseConfigGenerator = EclipseConfigGenerator;
|
|
710
|
+
//# sourceMappingURL=javaManager.js.map
|