Skip to content

Commit 4c16f2a

Browse files
snjezafbricon
authored andcommitted
Display a warning about the impending requirement of Java 11 to run the extension
Signed-off-by: Snjezana Peco <snjezana.peco@redhat.com>
1 parent 380cc39 commit 4c16f2a

3 files changed

Lines changed: 35 additions & 4 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ New in 0.60.0:
159159
* `java.sources.organizeImports.starThreshold`: Specifies the number of imports added before a star-import declaration is used, default is 99.
160160
* `java.sources.organizeImports.staticStarThreshold`: Specifies the number of static imports added before a star-import declaration is used, default is 99.
161161
* `java.semanticHighlighting.enabled`: Enable/disable the [semantic highlighting](https://github.com/microsoft/vscode/wiki/Semantic-Highlighting-Overview). Defaults to `true`.
162+
`java.requirements.JDK11Warning`: Enable/disable a warning about the impending requirement of Java 11. Defaults to `true`.
162163

163164
Semantic Highlighting
164165
===============

package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,12 @@
533533
"default": true,
534534
"description": "Enable/disable the semantic highlighting.",
535535
"scope": "window"
536+
},
537+
"java.requirements.JDK11Warning": {
538+
"type": "boolean",
539+
"description": "Enable/disable a warning about the impending requirement of Java 11.",
540+
"default": true,
541+
"scope": "window"
536542
}
537543
}
538544
},

src/requirements.ts

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import * as expandHomeDir from 'expand-home-dir';
88
import findJavaHome = require("find-java-home");
99
import { Commands } from './commands';
1010
import { checkJavaPreferences } from './settings';
11+
import { getJavaConfiguration } from './utils';
1112

1213
const isWindows = process.platform.indexOf('win') === 0;
1314
const JAVAC_FILENAME = 'javac' + (isWindows ? '.exe' : '');
@@ -87,6 +88,24 @@ function checkJavaVersion(javaHome: string): Promise<number> {
8788
if (javaVersion < 8) {
8889
openJDKDownload(reject, 'Java 8 or more recent is required to run. Please download and install a recent JDK');
8990
} else {
91+
if (javaVersion < 11) {
92+
const section = "requirements.JDK11Warning";
93+
const dontShowAgain = "Don't Show Again";
94+
const getJDK = "Get the Java Development Kit";
95+
const jdkWarning = getJavaConfiguration().get(section);
96+
if (jdkWarning) {
97+
const message = `Java 11, or more recent, [will soon be required](https://github.com/redhat-developer/vscode-java/wiki/JDK-Requirements) to run. Consider installing a recent JDK`;
98+
window.showInformationMessage(`${message}`, getJDK, dontShowAgain)
99+
.then(selection => {
100+
if (selection === dontShowAgain) {
101+
getJavaConfiguration().update(section, false, ConfigurationTarget.Global);
102+
}
103+
if (selection === getJDK) {
104+
commands.executeCommand(Commands.OPEN_BROWSER, Uri.parse(getJdkUrl()));
105+
}
106+
});
107+
}
108+
}
90109
resolve(javaVersion);
91110
}
92111
});
@@ -116,10 +135,7 @@ export function parseMajorVersion(content: string): number {
116135
}
117136

118137
function openJDKDownload(reject, cause) {
119-
let jdkUrl = 'https://developers.redhat.com/products/openjdk/download/?sc_cid=701f2000000RWTnAAO';
120-
if (process.platform === 'darwin') {
121-
jdkUrl = 'http://www.oracle.com/technetwork/java/javase/downloads/index.html';
122-
}
138+
const jdkUrl = getJdkUrl();
123139
reject({
124140
message: cause,
125141
label: 'Get the Java Development Kit',
@@ -128,6 +144,14 @@ function openJDKDownload(reject, cause) {
128144
});
129145
}
130146

147+
function getJdkUrl() {
148+
let jdkUrl = 'https://developers.redhat.com/products/openjdk/download/?sc_cid=701f2000000RWTnAAO';
149+
if (process.platform === 'darwin') {
150+
jdkUrl = 'https://adoptopenjdk.net/';
151+
}
152+
return jdkUrl;
153+
}
154+
131155
function invalidJavaHome(reject, cause: string) {
132156
if (cause.indexOf("java.home") > -1) {
133157
reject({

0 commit comments

Comments
 (0)