Skip to content

Commit f9c9e49

Browse files
committed
Revert "Automatically register VMInstalls for the JDKs installed on the local machine (#3251)"
This reverts commit 6cc071a.
1 parent d24fb2c commit f9c9e49

9 files changed

Lines changed: 40 additions & 122 deletions

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1529,7 +1529,7 @@
15291529
"fs-extra": "^8.1.0",
15301530
"glob": "^7.1.3",
15311531
"htmlparser2": "6.0.1",
1532-
"jdk-utils": "^0.5.0",
1532+
"jdk-utils": "^0.4.4",
15331533
"react": "^17.0.2",
15341534
"react-dom": "^17.0.2",
15351535
"semver": "^7.5.2",

src/extension.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ export function activate(context: ExtensionContext): Promise<ExtensionAPI> {
163163
initializationOptions: {
164164
bundles: collectJavaExtensions(extensions.all),
165165
workspaceFolders: workspace.workspaceFolders ? workspace.workspaceFolders.map(f => f.uri.toString()) : null,
166-
settings: { java: await getJavaConfig(requirements.java_home) },
166+
settings: { java: getJavaConfig(requirements.java_home) },
167167
extendedClientCapabilities: {
168168
classFileContentsSupport: true,
169169
overrideMethodsPromptSupport: true,
@@ -192,7 +192,7 @@ export function activate(context: ExtensionContext): Promise<ExtensionAPI> {
192192
didChangeConfiguration: async () => {
193193
await standardClient.getClient().sendNotification(DidChangeConfigurationNotification.type, {
194194
settings: {
195-
java: await getJavaConfig(requirements.java_home),
195+
java: getJavaConfig(requirements.java_home),
196196
}
197197
});
198198
}
@@ -275,7 +275,7 @@ export function activate(context: ExtensionContext): Promise<ExtensionAPI> {
275275
// the promise is resolved
276276
// no need to pass `resolve` into any code past this point,
277277
// since `resolve` is a no-op from now on
278-
const serverOptions = prepareExecutable(requirements, syntaxServerWorkspacePath, context, true);
278+
const serverOptions = prepareExecutable(requirements, syntaxServerWorkspacePath, getJavaConfig(requirements.java_home), context, true);
279279
if (requireSyntaxServer) {
280280
if (process.env['SYNTAXLS_CLIENT_PORT']) {
281281
syntaxClient.initialize(requirements, clientOptions);

src/javaServerStarter.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export const HEAP_DUMP = '-XX:+HeapDumpOnOutOfMemoryError';
3434
const DEPENDENCY_COLLECTOR_IMPL= '-Daether.dependencyCollector.impl=';
3535
const DEPENDENCY_COLLECTOR_IMPL_BF= 'bf';
3636

37-
export function prepareExecutable(requirements: RequirementsData, workspacePath, context: ExtensionContext, isSyntaxServer: boolean): Executable {
37+
export function prepareExecutable(requirements: RequirementsData, workspacePath, javaConfig, context: ExtensionContext, isSyntaxServer: boolean): Executable {
3838
const executable: Executable = Object.create(null);
3939
const options: ExecutableOptions = Object.create(null);
4040
options.env = Object.assign({ syntaxserver : isSyntaxServer }, process.env);
@@ -47,7 +47,7 @@ export function prepareExecutable(requirements: RequirementsData, workspacePath,
4747
}
4848
executable.options = options;
4949
executable.command = path.resolve(`${requirements.tooling_jre}/bin/java`);
50-
executable.args = prepareParams(requirements, workspacePath, context, isSyntaxServer);
50+
executable.args = prepareParams(requirements, javaConfig, workspacePath, context, isSyntaxServer);
5151
logger.info(`Starting Java server with: ${executable.command} ${executable.args.join(' ')}`);
5252
return executable;
5353
}
@@ -68,7 +68,7 @@ export function awaitServerConnection(port): Thenable<StreamInfo> {
6868
});
6969
}
7070

71-
function prepareParams(requirements: RequirementsData, workspacePath, context: ExtensionContext, isSyntaxServer: boolean): string[] {
71+
function prepareParams(requirements: RequirementsData, javaConfiguration, workspacePath, context: ExtensionContext, isSyntaxServer: boolean): string[] {
7272
const params: string[] = [];
7373
if (DEBUG) {
7474
const port = isSyntaxServer ? 1045 : 1044;
@@ -117,9 +117,6 @@ function prepareParams(requirements: RequirementsData, workspacePath, context: E
117117
} else {
118118
vmargs = '';
119119
}
120-
if (vmargs.indexOf('-DDetectVMInstallationsJob.disabled=') < 0) {
121-
params.push('-DDetectVMInstallationsJob.disabled=true');
122-
}
123120
const encodingKey = '-Dfile.encoding=';
124121
if (vmargs.indexOf(encodingKey) < 0) {
125122
params.push(encodingKey + getJavaEncoding());

src/jdkUtils.ts

Lines changed: 0 additions & 57 deletions
This file was deleted.

src/requirements.ts

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@
22

33
import * as expandHomeDir from 'expand-home-dir';
44
import * as fse from 'fs-extra';
5-
import { getRuntime, getSources, JAVAC_FILENAME, JAVA_FILENAME } from 'jdk-utils';
5+
import { findRuntimes, getRuntime, getSources, IJavaRuntime, JAVAC_FILENAME, JAVA_FILENAME } from 'jdk-utils';
66
import * as path from 'path';
77
import { env, ExtensionContext, Uri, window, workspace } from 'vscode';
88
import { Commands } from './commands';
99
import { logger } from './log';
1010
import { checkJavaPreferences } from './settings';
11-
import { listJdks, sortJdksBySource, sortJdksByVersion } from './jdkUtils';
1211

1312
const REQUIRED_JDK_VERSION = 17;
1413
/* eslint-disable @typescript-eslint/naming-convention */
@@ -71,7 +70,7 @@ export async function resolveRequirements(context: ExtensionContext): Promise<Re
7170
}
7271

7372
// search valid JDKs from env.JAVA_HOME, env.PATH, SDKMAN, jEnv, jabba, Common directories
74-
const javaRuntimes = await listJdks();
73+
const javaRuntimes = await findRuntimes({ checkJavac: true, withVersion: true, withTags: true });
7574
if (!toolingJre) { // universal version
7675
// as latest version as possible.
7776
sortJdksByVersion(javaRuntimes);
@@ -160,6 +159,27 @@ async function findDefaultRuntimeFromSettings(): Promise<string | undefined> {
160159
return undefined;
161160
}
162161

162+
export function sortJdksBySource(jdks: IJavaRuntime[]) {
163+
const rankedJdks = jdks as Array<IJavaRuntime & { rank: number }>;
164+
const sources = ["JDK_HOME", "JAVA_HOME", "PATH"];
165+
for (const [index, source] of sources.entries()) {
166+
for (const jdk of rankedJdks) {
167+
if (jdk.rank === undefined && getSources(jdk).includes(source)) {
168+
jdk.rank = index;
169+
}
170+
}
171+
}
172+
rankedJdks.filter(jdk => jdk.rank === undefined).forEach(jdk => jdk.rank = sources.length);
173+
rankedJdks.sort((a, b) => a.rank - b.rank);
174+
}
175+
176+
/**
177+
* Sort by major version in descend order.
178+
*/
179+
export function sortJdksByVersion(jdks: IJavaRuntime[]) {
180+
jdks.sort((a, b) => (b.version?.major ?? 0) - (a.version?.major ?? 0));
181+
}
182+
163183
export function parseMajorVersion(version: string): number {
164184
if (!version) {
165185
return 0;

src/standardLanguageClient.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
'use strict';
22

3+
import * as fse from 'fs-extra';
4+
import { findRuntimes } from "jdk-utils";
35
import * as net from 'net';
46
import * as path from 'path';
57
import { CancellationToken, CodeActionKind, commands, ConfigurationTarget, DocumentSelector, EventEmitter, ExtensionContext, extensions, languages, Location, ProgressLocation, TextEditor, Uri, ViewColumn, window, workspace } from "vscode";
@@ -22,7 +24,7 @@ import { collectBuildFilePattern, onExtensionChange } from "./plugin";
2224
import { pomCodeActionMetadata, PomCodeActionProvider } from "./pom/pomCodeActionProvider";
2325
import { ActionableNotification, BuildProjectParams, BuildProjectRequest, CompileWorkspaceRequest, CompileWorkspaceStatus, EventNotification, EventType, ExecuteClientCommandRequest, FeatureStatus, FindLinks, GradleCompatibilityInfo, LinkLocation, ProgressKind, ProgressNotification, ServerNotification, SourceAttachmentAttribute, SourceAttachmentRequest, SourceAttachmentResult, SourceInvalidatedEvent, StatusNotification, UpgradeGradleWrapperInfo } from "./protocol";
2426
import * as refactorAction from './refactorAction';
25-
import { getJdkUrl, RequirementsData } from "./requirements";
27+
import { getJdkUrl, RequirementsData, sortJdksBySource, sortJdksByVersion } from "./requirements";
2628
import { serverStatus, ServerStatusKind } from "./serverStatus";
2729
import { serverStatusBarProvider } from "./serverStatusBarProvider";
2830
import { activationProgressNotification, serverTaskPresenter } from "./serverTaskPresenter";
@@ -39,7 +41,6 @@ import { Telemetry } from "./telemetry";
3941
import { TelemetryEvent } from "@redhat-developer/vscode-redhat-telemetry/lib";
4042
import { registerDocumentValidationListener } from './diagnostic';
4143
import { registerSmartSemicolonDetection } from './smartSemicolonDetection';
42-
import { listJdks, sortJdksBySource, sortJdksByVersion } from './jdkUtils';
4344

4445
const extensionName = 'Language Support for Java';
4546
const GRADLE_CHECKSUM = "gradle/checksum/prompt";
@@ -90,7 +91,7 @@ export class StandardLanguageClient {
9091
if (!port) {
9192
const lsPort = process.env['JDTLS_CLIENT_PORT'];
9293
if (!lsPort) {
93-
serverOptions = prepareExecutable(requirements, workspacePath, context, false);
94+
serverOptions = prepareExecutable(requirements, workspacePath, getJavaConfig(requirements.java_home), context, false);
9495
} else {
9596
serverOptions = () => {
9697
const socket = net.connect(lsPort);
@@ -216,7 +217,7 @@ export class StandardLanguageClient {
216217
const options: string[] = [];
217218
const info = notification.data as GradleCompatibilityInfo;
218219
const highestJavaVersion = Number(info.highestJavaVersion);
219-
let runtimes = await listJdks(true);
220+
let runtimes = await findRuntimes({ checkJavac: true, withVersion: true, withTags: true });
220221
runtimes = runtimes.filter(runtime => {
221222
return runtime.version.major <= highestJavaVersion;
222223
});

src/syntaxLanguageClient.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export class SyntaxLanguageClient {
2828
didChangeConfiguration: async () => {
2929
await this.languageClient.sendNotification(DidChangeConfigurationNotification.type, {
3030
settings: {
31-
java: await getJavaConfig(requirements.java_home),
31+
java: getJavaConfig(requirements.java_home),
3232
}
3333
});
3434
}

src/utils.ts

Lines changed: 1 addition & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ import * as fs from 'fs';
44
import * as path from 'path';
55
import { workspace, WorkspaceConfiguration, commands, Uri, version } from 'vscode';
66
import { Commands } from './commands';
7-
import { IJavaRuntime } from 'jdk-utils';
8-
import { listJdks, sortJdksBySource, sortJdksByVersion } from './jdkUtils';
97

108
export function getJavaConfiguration(): WorkspaceConfiguration {
119
return workspace.getConfiguration('java');
@@ -178,7 +176,7 @@ function getDirectoriesByBuildFile(inclusions: string[], exclusions: string[], f
178176
}
179177

180178

181-
export async function getJavaConfig(javaHome: string) {
179+
export function getJavaConfig(javaHome: string) {
182180
const origConfig = getJavaConfiguration();
183181
const javaConfig = JSON.parse(JSON.stringify(origConfig));
184182
javaConfig.home = javaHome;
@@ -217,46 +215,5 @@ export async function getJavaConfig(javaHome: string) {
217215
}
218216

219217
javaConfig.telemetry = { enabled: workspace.getConfiguration('redhat.telemetry').get('enabled', false) };
220-
const userConfiguredJREs: any[] = javaConfig.configuration.runtimes;
221-
javaConfig.configuration.runtimes = await addAutoDetectedJdks(userConfiguredJREs);
222218
return javaConfig;
223219
}
224-
225-
async function addAutoDetectedJdks(configuredJREs: any[]): Promise<any[]> {
226-
// search valid JDKs from env.JAVA_HOME, env.PATH, SDKMAN, jEnv, jabba, Common directories
227-
const autoDetectedJREs: IJavaRuntime[] = await listJdks();
228-
sortJdksByVersion(autoDetectedJREs);
229-
sortJdksBySource(autoDetectedJREs);
230-
const addedJreNames: Set<string> = new Set<string>();
231-
for (const jre of configuredJREs) {
232-
if (jre.name) {
233-
addedJreNames.add(jre.name);
234-
}
235-
}
236-
for (const jre of autoDetectedJREs) {
237-
const majorVersion: number = jre.version?.major ?? 0;
238-
if (!majorVersion) {
239-
continue;
240-
}
241-
242-
let jreName: string = `JavaSE-${majorVersion}`;
243-
if (majorVersion <= 5) {
244-
jreName = `J2SE-1.${majorVersion}`;
245-
} else if (majorVersion <= 8) {
246-
jreName = `JavaSE-1.${majorVersion}`;
247-
}
248-
249-
if (addedJreNames.has(jreName)) {
250-
continue;
251-
}
252-
253-
configuredJREs.push({
254-
name: jreName,
255-
path: jre.homedir,
256-
});
257-
258-
addedJreNames.add(jreName);
259-
}
260-
261-
return configuredJREs;
262-
}

0 commit comments

Comments
 (0)