forked from microsoft/vscode-java-dependency
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutility.ts
More file actions
110 lines (93 loc) · 4.1 KB
/
utility.ts
File metadata and controls
110 lines (93 loc) · 4.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
import { commands, extensions, Uri, window } from "vscode";
import * as semver from "semver";
import { UpgradeReason, type UpgradeIssue } from "./type";
import { Upgrade } from "../constants";
function findEolDate(currentVersion: string, eolDate: Record<string, string>): string | null {
const currentVersionSemVer = semver.coerce(currentVersion);
if (!currentVersionSemVer) {
return null;
}
for (const [versionRange, date] of Object.entries(eolDate)) {
if (semver.satisfies(currentVersionSemVer, versionRange)) {
return date;
}
}
return null;
}
export function buildNotificationMessage(issue: UpgradeIssue): string {
const {
packageId,
currentVersion,
reason,
suggestedVersion: { name: suggestedVersionName, description: suggestedVersionDescription },
packageDisplayName
} = issue;
if (packageId === Upgrade.PACKAGE_ID_FOR_JAVA_RUNTIME) {
return `The current project is using an older Java runtime (${currentVersion}). Do you want to upgrade to the latest LTS version ${suggestedVersionName}?`;
}
switch (reason) {
case UpgradeReason.END_OF_LIFE: {
const { eolDate } = issue;
const versionEolDate = findEolDate(currentVersion, eolDate);
return `The current project is using ${packageDisplayName} ${currentVersion}, which has reached end of life${versionEolDate ? ` in ${versionEolDate}` : ""
}. Do you want to upgrade to ${suggestedVersionName} (${suggestedVersionDescription})?`;
}
case UpgradeReason.DEPRECATED:
default: {
return `The current project is using ${packageDisplayName} ${currentVersion}, which has been deprecated. Do you want to upgrade to ${suggestedVersionName} (${suggestedVersionDescription})?`;
}
}
}
export function buildFixPrompt(issue: UpgradeIssue): string {
const { packageDisplayName, reason } = issue;
switch (reason) {
case UpgradeReason.JRE_TOO_OLD: {
const { suggestedVersion: { name: suggestedVersionName } } = issue;
return `upgrade java runtime to the latest LTS version ${suggestedVersionName} using java upgrade tools`;
}
case UpgradeReason.END_OF_LIFE:
case UpgradeReason.DEPRECATED: {
const { suggestedVersion: { name: suggestedVersionName } } = issue;
return `upgrade ${packageDisplayName} to ${suggestedVersionName} using java upgrade tools`;
}
}
}
export function buildPackageId(groupId: string, artifactId: string): string {
return `${groupId}:${artifactId}`;
}
export function normalizePath(path: string): string {
return Uri.parse(path).toString();
}
export async function checkOrInstallExtension(extensionIdToCheck: string, extensionIdToInstall?: string): Promise<void> {
if (extensions.getExtension(extensionIdToCheck)) {
return;
}
const actualExtensionIdToInstall = extensionIdToInstall ?? extensionIdToCheck;
{
const BTN_TEXT = "Install extension";
const choice = await window.showInformationMessage(
"An extension is needed for the feature to work. Please install it and try again.",
BTN_TEXT
);
if (choice === BTN_TEXT) {
await commands.executeCommand("workbench.extensions.installExtension", actualExtensionIdToInstall);
}
}
if (extensions.getExtension(actualExtensionIdToInstall)) {
return;
}
// In this case the extension is disabled.
await commands.executeCommand("workbench.extensions.search", actualExtensionIdToInstall);
{
const BTN_TEXT = "Show extension in sidebar";
const choice = await window.showInformationMessage(
"An extension is needed for the feature to work but it seems disabled. Please enable it manually and try again.",
BTN_TEXT
);
if (choice === BTN_TEXT) {
await commands.executeCommand("workbench.extensions.search", actualExtensionIdToInstall);
}
}
}