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
25 changes: 12 additions & 13 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import * as requirements from './requirements';
import { initialize as initializeRecommendation } from './recommendation';
import { Commands } from './commands';
import { ExtensionAPI, ClientStatus } from './extension.api';
import { getJavaConfiguration, deleteDirectory, getBuildFilePatterns, getInclusionPatternsFromNegatedExclusion, convertToGlob, getExclusionBlob } from './utils';
import { getJavaConfiguration, deleteDirectory, getBuildFilePatterns, getInclusionPatternsFromNegatedExclusion, convertToGlob, getExclusionBlob, ensureExists } from './utils';
import { onConfigurationChange, getJavaServerMode, ServerMode, ACTIVE_BUILD_TOOL_STATE } from './settings';
import { logger, initializeLogFile } from './log';
import glob = require('glob');
Expand Down Expand Up @@ -610,9 +610,7 @@ async function cleanWorkspace(workspacePath) {
const doIt = 'Restart and delete';
window.showWarningMessage('Are you sure you want to clean the Java language server workspace?', 'Cancel', doIt).then(selection => {
if (selection === doIt) {
if (!fs.existsSync(workspacePath)) {
fs.mkdirSync(workspacePath);
}
ensureExists(workspacePath);
const file = path.join(workspacePath, cleanWorkspaceFileName);
fs.closeSync(fs.openSync(file, 'w'));
commands.executeCommand(Commands.RELOAD_WINDOW);
Expand Down Expand Up @@ -690,9 +688,7 @@ async function openFormatter(extensionPath) {
relativePath = fileName;
} else {
const root = path.join(extensionPath, '..', 'redhat.java');
if (!fs.existsSync(root)) {
fs.mkdirSync(root);
}
ensureExists(root);
file = path.join(root, fileName);
}
if (!fs.existsSync(file)) {
Expand Down Expand Up @@ -765,9 +761,7 @@ async function addFormatter(extensionPath, formatterUrl, defaultFormatter, relat
relativePath = fileName;
} else {
const root = path.join(extensionPath, '..', 'redhat.java');
if (!fs.existsSync(root)) {
fs.mkdirSync(root);
}
ensureExists(root);
f = path.join(root, fileName);
}
} else {
Expand All @@ -780,9 +774,14 @@ async function addFormatter(extensionPath, formatterUrl, defaultFormatter, relat
const action = 'Yes';
window.showWarningMessage(msg, action, 'No').then((selection) => {
if (action === selection) {
fs.createReadStream(defaultFormatter)
.pipe(fs.createWriteStream(f))
.on('finish', () => openDocument(extensionPath, f, defaultFormatter, relativePath));
try {
ensureExists(path.dirname(f));
fs.createReadStream(defaultFormatter)
.pipe(fs.createWriteStream(f))
.on('finish', () => openDocument(extensionPath, f, defaultFormatter, relativePath));
} catch (error) {
window.showErrorMessage(`Failed to create ${f}: ${error}`);
}
}
});
} else {
Expand Down
6 changes: 4 additions & 2 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,11 @@ export function getTimestamp(file) {
}

export function ensureExists(folder) {
if (!fs.existsSync(folder)) {
fs.mkdirSync(folder);
if (fs.existsSync(folder)) {
return;
}
ensureExists(path.dirname(folder));
fs.mkdirSync(folder);
}

export function getBuildFilePatterns(): string[] {
Expand Down