Skip to content

Commit 5d4f8d5

Browse files
authored
Stop generating metadata files at project's root (#2153)
* Stop generating metadata files at project's root Signed-off-by: Sheng Chen <[email protected]>
1 parent b4f8b07 commit 5d4f8d5

File tree

7 files changed

+55
-6
lines changed

7 files changed

+55
-6
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ The following settings are supported:
197197
New in 1.1.0:
198198
* `java.quickfix.showAt` : Show quickfixes at the problem or line level.
199199
* `java.configuration.workspaceCacheLimit` : The number of days (if enabled) to keep unused workspace cache data. Beyond this limit, cached workspace data may be removed.
200+
* `java.import.generatesMetadataFilesAtProjectRoot` : Specify whether the project metadata files(.project, .classpath, .factorypath, .settings/) will be generated at the project root. Defaults to `false`.
200201

201202

202203
Semantic Highlighting
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Metadata Files Generation
2+
3+
We use the setting `java.import.generatesMetadataFilesAtProjectRoot` to control where the project metadata files(.project, .classpath, .factorypath, .settings/) will be generated:
4+
- `true`: Metadata files will be generated at the project's root.
5+
- `false`: Metadata files will be generated at the workspace storage. To be specifc, the path will be: `<WORKSPACE_STORAGE_PATH>/redhat.java/jdt_ws/.metadata/.plugins/org.eclipse.core.resources/.projects/<PROJECT_NAME>/`.
6+
7+
By default, the setting is set to `false`.
8+
9+
> If the metadata files exist in both the project root and the workspace storage, the extension will pick the files in the project root.
10+
11+
## Change the setting value
12+
13+
Depending on how you change the setting, some extra steps need to be taken to make the change take effect.
14+
15+
### Change from `false` to `true`
16+
You need to restart the client.
17+
18+
### Change from `true` to `false`
19+
1. Close the client.
20+
2. Remove the metadata files in the project by your own.
21+
3. Open the client.

package.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@
4444
"workspaceContains:build.gradle.kts",
4545
"workspaceContains:settings.gradle.kts",
4646
"workspaceContains:.classpath",
47-
"onCommand:_java.templateVariables"
47+
"onCommand:_java.templateVariables",
48+
"onCommand:_java.metadataFilesGeneration"
4849
],
4950
"main": "./dist/extension",
5051
"contributes": {
@@ -376,6 +377,12 @@
376377
],
377378
"scope": "window"
378379
},
380+
"java.import.generatesMetadataFilesAtProjectRoot": {
381+
"type": "boolean",
382+
"markdownDescription": "Specify whether the project metadata files(.project, .classpath, .factorypath, .settings/) will be generated at the project root. Click [HERE](command:_java.metadataFilesGeneration) to learn how to change the setting to make it take effect.",
383+
"default": false,
384+
"scope": "window"
385+
},
379386
"java.project.referencedLibraries": {
380387
"type": [
381388
"array",

src/commands.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,5 +241,7 @@ export namespace Commands {
241241

242242
export const NOT_COVERED_EXECUTION = '_java.notCoveredExecution';
243243

244+
export const MEATDATA_FILES_GENERATION = '_java.metadataFilesGeneration';
245+
244246
export const RUNTIME_VALIDATION_OPEN = 'java.runtimeValidation.open';
245247
}

src/extension.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,12 @@ import * as chokidar from 'chokidar';
3131
const syntaxClient: SyntaxLanguageClient = new SyntaxLanguageClient();
3232
const standardClient: StandardLanguageClient = new StandardLanguageClient();
3333
const jdtEventEmitter = new EventEmitter<Uri>();
34-
const cleanWorkspaceFileName = '.cleanWorkspace';
3534
const extensionName = 'Language Support for Java';
3635
let storagePath: string;
3736
let clientLogFile: string;
3837

38+
export const cleanWorkspaceFileName = '.cleanWorkspace';
39+
3940
export class ClientErrorHandler implements ErrorHandler {
4041
private restarts: number[];
4142

@@ -162,6 +163,9 @@ export function activate(context: ExtensionContext): Promise<ExtensionAPI> {
162163
}));
163164

164165
storagePath = context.storagePath;
166+
context.subscriptions.push(commands.registerCommand(Commands.MEATDATA_FILES_GENERATION, async () => {
167+
markdownPreviewProvider.show(context.asAbsolutePath(path.join('document', `_java.metadataFilesGeneration.md`)), 'Metadata Files Generation', "", context);
168+
}));
165169
if (!storagePath) {
166170
storagePath = getTempWorkspace();
167171
}
@@ -365,7 +369,7 @@ export function activate(context: ExtensionContext): Promise<ExtensionAPI> {
365369

366370
context.subscriptions.push(commands.registerCommand(Commands.CLEAN_WORKSPACE, () => cleanWorkspace(workspacePath)));
367371

368-
context.subscriptions.push(onConfigurationChange());
372+
context.subscriptions.push(onConfigurationChange(workspacePath));
369373

370374
/**
371375
* Command to switch the server mode. Currently it only supports switch from lightweight to standard.

src/javaServerStarter.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ function prepareParams(requirements: RequirementsData, javaConfiguration, worksp
7373
if (DEBUG) {
7474
params.push('-Dlog.level=ALL');
7575
}
76+
const metadataLocation = workspace.getConfiguration().get('java.import.generatesMetadataFilesAtProjectRoot');
77+
if (metadataLocation !== undefined) {
78+
params.push(`-Djava.import.generatesMetadataFilesAtProjectRoot=${metadataLocation}`);
79+
}
7680
let vmargsCheck = workspace.getConfiguration().inspect('java.jdt.ls.vmargs').workspaceValue;
7781
if (vmargsCheck !== undefined) {
7882
const isWorkspaceTrusted = (workspace as any).isTrusted; // keep compatibility for old engines < 1.56.0

src/settings.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
'use strict';
22

3+
import * as fs from 'fs';
34
import * as path from 'path';
45
import { window, Uri, workspace, WorkspaceConfiguration, commands, ConfigurationTarget, env, ExtensionContext, TextEditor, Range, Disposable, WorkspaceFolder } from 'vscode';
56
import { Commands } from './commands';
6-
import { getJavaConfiguration } from './utils';
7+
import { cleanWorkspaceFileName } from './extension';
8+
import { ensureExists, getJavaConfiguration } from './utils';
79

810
const DEFAULT_HIDDEN_FILES: string[] = ['**/.classpath', '**/.project', '**/.settings', '**/.factorypath'];
911
export const IS_WORKSPACE_JDK_ALLOWED = "java.ls.isJdkAllowed";
@@ -23,7 +25,7 @@ export const ORGANIZE_IMPORTS_ON_PASTE = 'actionsOnPaste.organizeImports'; // ja
2325
let oldConfig: WorkspaceConfiguration = getJavaConfiguration();
2426
const gradleWrapperPromptDialogs = [];
2527

26-
export function onConfigurationChange() {
28+
export function onConfigurationChange(workspacePath: string) {
2729
return workspace.onDidChangeConfiguration(params => {
2830
if (!params.affectsConfiguration('java')) {
2931
return;
@@ -32,7 +34,15 @@ export function onConfigurationChange() {
3234
if (newConfig.get(EXCLUDE_FILE_CONFIG)) {
3335
excludeProjectSettingsFiles();
3436
}
35-
if (hasJavaConfigChanged(oldConfig, newConfig)) {
37+
38+
const isFsModeChanged: boolean = hasConfigKeyChanged('import.generatesMetadataFilesAtProjectRoot', oldConfig, newConfig);
39+
if (isFsModeChanged) {
40+
// Changing the FS mode needs a clean restart.
41+
ensureExists(workspacePath);
42+
const file = path.join(workspacePath, cleanWorkspaceFileName);
43+
fs.closeSync(fs.openSync(file, 'w'));
44+
}
45+
if (isFsModeChanged || hasJavaConfigChanged(oldConfig, newConfig)) {
3646
const msg = `Java Language Server configuration changed, please restart ${env.appName}.`;
3747
const action = 'Restart Now';
3848
const restartId = Commands.RELOAD_WINDOW;

0 commit comments

Comments
 (0)