-
Notifications
You must be signed in to change notification settings - Fork 504
Add command to add JDK to settings #4162
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
e718b81
Add command to add JDK to settings
tsmaeder c54c6ec
Add java.runtimes.add command to test
tsmaeder d557c1e
Add new command to lighweght test suite
tsmaeder cbe1b37
Addressed review comments
tsmaeder b0ac00f
Addressing more review comments.
tsmaeder File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| import { getRuntime, IJavaRuntime } from "jdk-utils"; | ||
| import * as vscode from "vscode"; | ||
| import { getSupportedJreNames } from "./jdkUtils"; | ||
| import { Commands } from "./commands"; | ||
| import * as path from "path"; | ||
|
|
||
|
|
||
| export namespace JavaRuntimes { | ||
| function compatible(runtime: IJavaRuntime, jreName: string): boolean { | ||
| if (!runtime.version) { | ||
| return true; | ||
| } | ||
| const majorVersion = runtime.version.major; | ||
| if (majorVersion === 8) { | ||
| return jreName === 'JavaSE-1.8'; | ||
| } | ||
| const versionStrings = /[0-9]+/g.exec(jreName); | ||
| if (versionStrings && versionStrings.length > 0) { | ||
| return majorVersion >= parseInt(versionStrings[0]); | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| export async function initialize(context: vscode.ExtensionContext): Promise<void> { | ||
| context.subscriptions.push(vscode.commands.registerCommand(Commands.ADD_JAVA_RUNTIME, async () => { | ||
| const lastSelectedDirectory: vscode.Uri | undefined = context.workspaceState.get('java.runtimes.lastSelectedDirectory'); | ||
| const directory = await vscode.window.showOpenDialog({ | ||
| canSelectFiles: false, | ||
| canSelectFolders: true, | ||
| canSelectMany: false, | ||
| title: 'Select JDK Directory', | ||
| defaultUri: lastSelectedDirectory, | ||
| }); | ||
| if (directory) { | ||
fbricon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| context.workspaceState.update('java.runtimes.lastSelectedDirectory', vscode.Uri.file(path.dirname(directory[0].fsPath))); | ||
| const runtime = await getRuntime(directory[0].fsPath, {withVersion: true}); | ||
| if (runtime) { | ||
| const config = vscode.workspace.getConfiguration('java.configuration').get('runtimes'); | ||
| if (Array.isArray(config)) { | ||
| const candidates = getSupportedJreNames().filter(name => compatible(runtime, name)).reverse(); | ||
| if (candidates.length > 0) { | ||
| const name = await vscode.window.showQuickPick(candidates, { | ||
| title: 'Select Java Runtime', | ||
| }); | ||
| if (name) { | ||
| const newConfig = { | ||
| name: name, | ||
| path: directory[0].fsPath, | ||
| }; | ||
| const index = config.findIndex(r => r.name === name); | ||
| if (index >= 0) { | ||
| config[index] = newConfig; | ||
| } else { | ||
| config.push(newConfig); | ||
| } | ||
| vscode.workspace.getConfiguration('java.configuration').update('runtimes', config, vscode.ConfigurationTarget.Global); | ||
| vscode.window.showInformationMessage(`JDK Directory ${directory[0].fsPath} added`); | ||
| } | ||
| } else { | ||
| vscode.window.showErrorMessage('No compatible environment available'); | ||
| } | ||
| } | ||
| } else { | ||
| vscode.window.showErrorMessage(`Invalid JDK Directory ${directory[0].fsPath}`); | ||
| } | ||
| } | ||
| })); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.