Skip to content

Commit 4065df7

Browse files
snjezafbricon
authored andcommitted
VS Code Java Cannot Run from Read-Only Location
Signed-off-by: Snjezana Peco <snjezana.peco@redhat.com>
1 parent 0726970 commit 4065df7

1 file changed

Lines changed: 32 additions & 1 deletion

File tree

src/javaServerStarter.ts

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import * as path from 'path';
33
import * as net from 'net';
44
import * as glob from 'glob';
55
import * as os from 'os';
6+
import * as fs from 'fs';
67
import { StreamInfo, Executable, ExecutableOptions } from 'vscode-languageclient';
78
import { RequirementsData } from './requirements';
89
import { getJavaEncoding, IS_WORKSPACE_VMARGS_ALLOWED, getKey, getJavaagentFlag } from './settings';
@@ -114,11 +115,41 @@ function prepareParams(requirements: RequirementsData, javaConfiguration, worksp
114115
} else if (process.platform === 'linux') {
115116
configDir = 'config_linux';
116117
}
117-
params.push('-configuration'); params.push(path.resolve(__dirname, '../server', configDir));
118+
params.push('-configuration'); params.push(resolveConfiguration(context, configDir));
118119
params.push('-data'); params.push(workspacePath);
119120
return params;
120121
}
121122

123+
function resolveConfiguration(context, configDir) {
124+
ensureExists(context.globalStoragePath);
125+
const extensionPath = path.resolve(context.extensionPath, "package.json");
126+
const packageFile = JSON.parse(fs.readFileSync(extensionPath, 'utf8'));
127+
let version;
128+
if (packageFile) {
129+
version = packageFile.version;
130+
}
131+
else {
132+
version = '0.0.0';
133+
}
134+
let configuration = path.resolve(context.globalStoragePath, version);
135+
ensureExists(configuration);
136+
configuration = path.resolve(configuration, configDir);
137+
ensureExists(configuration);
138+
const configIniName = "config.ini";
139+
const configIni = path.resolve(configuration, configIniName);
140+
if (!fs.existsSync(configIni)) {
141+
const ini = path.resolve(__dirname, '../server', configDir, configIniName);
142+
fs.copyFileSync(ini, configIni);
143+
}
144+
return configuration;
145+
}
146+
147+
function ensureExists(folder) {
148+
if (!fs.existsSync(folder)) {
149+
fs.mkdirSync(folder);
150+
}
151+
}
152+
122153
function startedInDebugMode(): boolean {
123154
const args = (process as any).execArgv;
124155
if (args) {

0 commit comments

Comments
 (0)