Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,8 @@ The following settings are supported:
* `java.symbols.includeSourceMethodDeclarations` : Include method declarations from source files in symbol search. Defaults to `false`.

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


Semantic Highlighting
Expand Down
10 changes: 10 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,16 @@
"description": "Specifies severity if the plugin execution is not covered by Maven build lifecycle.",
"scope": "window"
},
"java.configuration.workspaceCacheLimit": {
Comment thread
rgrunber marked this conversation as resolved.
"type": [
"null",
"integer"
],
"default": null,
"minimum": 1,
"description": "The number of days (if enabled) to keep unused workspace cache data. Beyond this limit, cached workspace data may be removed.",
"scope": "application"
},
"java.format.enabled": {
"type": "boolean",
"default": true,
Expand Down
33 changes: 31 additions & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ const standardClient: StandardLanguageClient = new StandardLanguageClient();
const jdtEventEmitter = new EventEmitter<Uri>();
const cleanWorkspaceFileName = '.cleanWorkspace';
const extensionName = 'Language Support for Java';
let clientLogFile;
let storagePath: string;
let clientLogFile: string;

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

let storagePath = context.storagePath;
storagePath = context.storagePath;
if (!storagePath) {
storagePath = getTempWorkspace();
}
Expand All @@ -133,6 +134,8 @@ export function activate(context: ExtensionContext): Promise<ExtensionAPI> {

initializeRecommendation(context);

cleanJavaWorkspaceStorage();

return requirements.resolveRequirements(context).catch(error => {
// show error
window.showErrorMessage(error.message, error.label).then((selection) => {
Expand Down Expand Up @@ -925,3 +928,29 @@ function isPrefix(parentPath: string, childPath: string): boolean {
const relative = path.relative(parentPath, childPath);
return !!relative && !relative.startsWith('..') && !path.isAbsolute(relative);
}
async function cleanJavaWorkspaceStorage() {
const configCacheLimit = getJavaConfiguration().get<number>("configuration.workspaceCacheLimit");

if (!storagePath || !configCacheLimit) {
return;
}

const limit: number = configCacheLimit * 86400000; // days to ms
const currTime = new Date().valueOf(); // ms since Epoch
// storage path is Code/User/workspaceStorage/${id}/redhat.java/
const wsRoot = path.dirname(path.dirname(storagePath));

// find all folders of the form "redhat.java/jdt_ws/" and delete "redhat.java/"
if (fs.existsSync(wsRoot)) {
new glob.Glob(`${wsRoot}/**/jdt_ws`, (_err, matches) => {
for (const javaWSCache of matches) {
const entry = path.dirname(javaWSCache);
const entryModTime = fs.statSync(entry).mtimeMs;
if ((currTime - entryModTime) > limit) {
logger.info(`Removing workspace storage folder : ${entry}`);
deleteDirectory(entry);
}
}
});
}
}