Skip to content

Commit dd1fe09

Browse files
committed
Clean unused Java workspace storage folders
- Clean unused workspace storage folders on startup - Create setting "java.configuration.workspaceCacheLimit" (disabled by default) to allow users to configure maximum number of days to preserve cached data - Fixes #2110 Signed-off-by: Roland Grunberg <[email protected]>
1 parent 78c8294 commit dd1fe09

File tree

3 files changed

+43
-3
lines changed

3 files changed

+43
-3
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,8 @@ The following settings are supported:
195195
* `java.symbols.includeSourceMethodDeclarations` : Include method declarations from source files in symbol search. Defaults to `false`.
196196

197197
New in 1.1.0:
198-
* `java.quickfix.showAt"` : Show quickfixes at the problem or line level.
198+
* `java.quickfix.showAt` : Show quickfixes at the problem or line level.
199+
* `java.configuration.workspaceCacheLimit` : The number of days (if enabled) to keep unused workspace cache data. Beyond this limit, cached workspace data may be removed.
199200

200201

201202
Semantic Highlighting

package.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,16 @@
343343
"description": "Specifies severity if the plugin execution is not covered by Maven build lifecycle.",
344344
"scope": "window"
345345
},
346+
"java.configuration.workspaceCacheLimit": {
347+
"type": [
348+
"null",
349+
"integer"
350+
],
351+
"default": null,
352+
"minimum": 1,
353+
"description": "The number of days (if enabled) to keep unused workspace cache data. Beyond this limit, cached workspace data may be removed.",
354+
"scope": "application"
355+
},
346356
"java.format.enabled": {
347357
"type": "boolean",
348358
"default": true,

src/extension.ts

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ const standardClient: StandardLanguageClient = new StandardLanguageClient();
3232
const jdtEventEmitter = new EventEmitter<Uri>();
3333
const cleanWorkspaceFileName = '.cleanWorkspace';
3434
const extensionName = 'Language Support for Java';
35-
let clientLogFile;
35+
let storagePath: string;
36+
let clientLogFile: string;
3637

3738
export class ClientErrorHandler implements ErrorHandler {
3839
private restarts: number[];
@@ -122,7 +123,7 @@ export function activate(context: ExtensionContext): Promise<ExtensionAPI> {
122123
markdownPreviewProvider.show(context.asAbsolutePath(path.join('document', `_java.notCoveredExecution.md`)), 'Not Covered Maven Plugin Execution', "", context);
123124
}));
124125

125-
let storagePath = context.storagePath;
126+
storagePath = context.storagePath;
126127
if (!storagePath) {
127128
storagePath = getTempWorkspace();
128129
}
@@ -133,6 +134,8 @@ export function activate(context: ExtensionContext): Promise<ExtensionAPI> {
133134

134135
initializeRecommendation(context);
135136

137+
cleanJavaWorkspaceStorage();
138+
136139
return requirements.resolveRequirements(context).catch(error => {
137140
// show error
138141
window.showErrorMessage(error.message, error.label).then((selection) => {
@@ -925,3 +928,29 @@ function isPrefix(parentPath: string, childPath: string): boolean {
925928
const relative = path.relative(parentPath, childPath);
926929
return !!relative && !relative.startsWith('..') && !path.isAbsolute(relative);
927930
}
931+
async function cleanJavaWorkspaceStorage() {
932+
const configCacheLimit = getJavaConfiguration().get<number>("configuration.workspaceCacheLimit");
933+
934+
if (!storagePath || !configCacheLimit) {
935+
return;
936+
}
937+
938+
const limit: number = configCacheLimit * 86400000; // days to ms
939+
const currTime = new Date().valueOf(); // ms since Epoch
940+
// storage path is Code/User/workspaceStorage/${id}/redhat.java/
941+
const wsRoot = path.dirname(path.dirname(storagePath));
942+
943+
// find all folders of the form "redhat.java/jdt_ws/" and delete "redhat.java/"
944+
if (fs.existsSync(wsRoot)) {
945+
new glob.Glob(`${wsRoot}/**/jdt_ws`, (_err, matches) => {
946+
for (const javaWSCache of matches) {
947+
const entry = path.dirname(javaWSCache);
948+
const entryModTime = fs.statSync(entry).mtimeMs;
949+
if ((currTime - entryModTime) > limit) {
950+
logger.info(`Removing workspace storage folder : ${entry}`);
951+
deleteDirectory(entry);
952+
}
953+
}
954+
});
955+
}
956+
}

0 commit comments

Comments
 (0)