Skip to content

Commit

Permalink
Support starting the Java Language Server with JDK 9. Fixes eclipse-j…
Browse files Browse the repository at this point in the history
…dtls#43

Signed-off-by: Fred Bricon <fbricon@gmail.com>
  • Loading branch information
fbricon committed Mar 30, 2017
1 parent b908ac6 commit 0328a62
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
7 changes: 7 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ function runJavaServer() : Thenable<StreamInfo> {
// suspend=y is the default. Use this form if you need to debug the server startup code:
// params.push('-agentlib:jdwp=transport=dt_socket,server=y,address=1044');
}
if (requirements.java_version > 8) {
params.push('--add-modules=ALL-SYSTEM');
params.push('--add-opens');
params.push('java.base/java.util=ALL-UNNAMED');
params.push('--add-opens');
params.push('java.base/java.lang=ALL-UNNAMED');
}
params.push('-Declipse.application=org.eclipse.jdt.ls.core.id1');
params.push('-Dosgi.bundles.defaultStartLevel=4');
params.push('-Declipse.product=org.eclipse.jdt.ls.core.product');
Expand Down
11 changes: 7 additions & 4 deletions src/requirements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const JAVAC_FILENAME = 'javac' + (isWindows?'.exe':'');

interface RequirementsData {
java_home: string;
java_version: number;
}

interface ErrorData {
Expand All @@ -31,9 +32,9 @@ interface ErrorData {
*/
export async function resolveRequirements(): Promise<RequirementsData> {
let java_home = await checkJavaRuntime();
await checkJavaVersion(java_home);
let javaVersion = await checkJavaVersion(java_home);
await checkServerInstalled();
return Promise.resolve({ 'java_home': java_home });
return Promise.resolve({ 'java_home': java_home, 'java_version': javaVersion});
}

function checkJavaRuntime(): Promise<any> {
Expand Down Expand Up @@ -81,11 +82,13 @@ function readJavaConfig() : string {
function checkJavaVersion(java_home: string): Promise<any> {
return new Promise((resolve, reject) => {
cp.execFile(java_home + '/bin/java', ['-version'], {}, (error, stdout, stderr) => {
if (stderr.indexOf('1.8') < 0){
if (stderr.indexOf('version "9') > -1){
resolve(9);
} if (stderr.indexOf('1.8') < 0){
openJDKDownload(reject, 'Java 8 is required to run. Please download and install a JDK 8.');
}
else{
resolve(true);
resolve(8);
}
});
});
Expand Down

0 comments on commit 0328a62

Please sign in to comment.