Skip to content

Commit 56084e6

Browse files
chore: centralize LATEST_JAVA_LTS_VESRION and SESSION_COUNT_BEFORE_NOTIFICATION_RESHOW to individual files
1 parent 76a8261 commit 56084e6

File tree

5 files changed

+16
-11
lines changed

5 files changed

+16
-11
lines changed

src/constants.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@ export namespace ExtensionName {
3939

4040
export namespace Upgrade {
4141
export const PACKAGE_ID_FOR_JAVA_RUNTIME = "java:*";
42-
export const LATEST_JAVA_LTS_VESRION = 21;
43-
export const SESSION_COUNT_BEFORE_NOTIFICATION_RESHOW = 3;
4442
}
4543

4644
/**

src/upgrade/dependency.data.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,27 @@
44
import { Upgrade } from "../constants";
55
import { UpgradeReason, type DependencyCheckMetadata } from "./type";
66

7+
const LATEST_JAVA_LTS_VESRION = 21;
8+
79
export const DEPENDENCY_JAVA_RUNTIME = {
810
"name": "Java Runtime",
911
"reason": UpgradeReason.JRE_TOO_OLD,
10-
"supportedVersion": `>=${Upgrade.LATEST_JAVA_LTS_VESRION}`,
12+
"supportedVersion": `>=${LATEST_JAVA_LTS_VESRION}`,
13+
"suggestedVersion": String(LATEST_JAVA_LTS_VESRION),
1114
} as const;
1215

1316
const DEPENDENCIES_TO_SCAN: DependencyCheckMetadata = {
1417
"org.springframework.boot:*": {
1518
"reason": UpgradeReason.END_OF_LIFE,
1619
"name": "Spring Boot",
1720
"supportedVersion": "2.7.x || >=3.2.x",
21+
"suggestedVersion": "6.2",
1822
},
1923
"org.springframework:*": {
2024
"reason": UpgradeReason.END_OF_LIFE,
2125
"name": "Spring Framework",
2226
"supportedVersion": "5.3.x || >=6.2.x",
27+
"suggestedVersion": "3.5"
2328
},
2429
"javax:javaee-api": {
2530
"reason": UpgradeReason.DEPRECATED,

src/upgrade/display/notificationManager.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { commands, ExtensionContext, window } from "vscode";
55
import type { UpgradeIssue } from "../type";
66
import { buildFixPrompt, buildNotificationMessage } from "../utility";
77
import { Commands } from "../../commands";
8-
import { Upgrade } from "../../constants";
98

109
const KEY_PREFIX = 'javaupgrade.notificationManager';
1110
const IS_CANDIDATE_KEY = `${KEY_PREFIX}.isCandidate`;
@@ -15,6 +14,8 @@ const BUTTON_TEXT_UPGRADE = "Upgrade Now";
1514
const BUTTON_TEXT_NOT_NOW = "Not Now";
1615
const BUTTON_TEXT_DONT_SHOW_AGAIN = "Don't Show Again";
1716

17+
const SESSION_COUNT_BEFORE_NOTIFICATION_RESHOW = 3;
18+
1819
class NotificationManager {
1920
private hasShown = false;
2021
private context?: ExtensionContext;
@@ -49,7 +50,7 @@ class NotificationManager {
4950
break;
5051
}
5152
case BUTTON_TEXT_NOT_NOW: {
52-
this.setSessionCount(-1 * Upgrade.SESSION_COUNT_BEFORE_NOTIFICATION_RESHOW);
53+
this.setSessionCount(-1 * SESSION_COUNT_BEFORE_NOTIFICATION_RESHOW);
5354
break;
5455
}
5556
case BUTTON_TEXT_DONT_SHOW_AGAIN: {

src/upgrade/type.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT license.
33
export type DependencyCheckItemBase = { name: string, reason: UpgradeReason };
4-
export type DependencyCheckItemEol = DependencyCheckItemBase & { reason: UpgradeReason.END_OF_LIFE | UpgradeReason.JRE_TOO_OLD, supportedVersion: string };
4+
export type DependencyCheckItemEol = DependencyCheckItemBase & { reason: UpgradeReason.END_OF_LIFE | UpgradeReason.JRE_TOO_OLD, supportedVersion: string, suggestedVersion: string };
55
export type DependencyCheckItemDeprecated = DependencyCheckItemBase & { reason: UpgradeReason.DEPRECATED, alternative: string };
66
export type DependencyCheckItem = (DependencyCheckItemEol | DependencyCheckItemDeprecated);
77
export type DependencyCheckMetadata = Record<string, DependencyCheckItem>;

src/upgrade/upgradeManager.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,18 @@ const DEFAULT_UPGRADE_PROMPT = "Upgrade Java project dependency to latest versio
2020

2121
function getJavaIssues(data: INodeData): UpgradeIssue[] {
2222
const javaVersion = data.metaData?.MaxSourceVersion as number | undefined;
23-
const javaSupportedVersionDefinition = DEPENDENCY_JAVA_RUNTIME;
23+
const { name, reason, supportedVersion, suggestedVersion } = DEPENDENCY_JAVA_RUNTIME;
2424
if (!javaVersion) {
2525
return [];
2626
}
27-
if (javaVersion < Upgrade.LATEST_JAVA_LTS_VESRION) {
27+
const currentSemVer = semver.coerce(javaVersion);
28+
if (currentSemVer && !semver.satisfies(currentSemVer, supportedVersion)) {
2829
return [{
2930
packageId: Upgrade.PACKAGE_ID_FOR_JAVA_RUNTIME,
30-
packageDisplayName: javaSupportedVersionDefinition.name,
31-
reason: javaSupportedVersionDefinition.reason,
31+
packageDisplayName: name,
3232
currentVersion: String(javaVersion),
33-
suggestedVersion: String(Upgrade.LATEST_JAVA_LTS_VESRION),
33+
reason,
34+
suggestedVersion,
3435
}];
3536
}
3637

0 commit comments

Comments
 (0)