22// Licensed under the MIT license.
33
44import { commands , ExtensionContext , extensions , window } from "vscode" ;
5+ import * as semver from "semver" ;
56import { UpgradeReason , type IUpgradeIssuesRenderer , type UpgradeIssue } from "../type" ;
6- import { buildCVENotificationMessage , buildFixPrompt , buildNotificationMessage } from "../utility" ;
7+ import { buildCVENotificationMessage , buildFixPrompt , buildNotificationMessage , type ExtensionState } from "../utility" ;
78import { Commands } from "../../commands" ;
89import { Settings } from "../../settings" ;
910import { instrumentOperation , sendInfo } from "vscode-extension-telemetry-wrapper" ;
10- import { ExtensionName } from "../../constants" ;
11+ import { ExtensionName , Upgrade } from "../../constants" ;
1112import { CveUpgradeIssue } from "../cve" ;
1213
1314const KEY_PREFIX = 'javaupgrade.notificationManager' ;
@@ -17,6 +18,8 @@ const BUTTON_TEXT_UPGRADE = "Upgrade Now";
1718const BUTTON_TEXT_FIX_CVE = "Fix Now" ;
1819const BUTTON_TEXT_INSTALL_AND_UPGRADE = "Install Extension and Upgrade" ;
1920const BUTTON_TEXT_INSTALL_AND_FIX_CVE = "Install Extension and Fix" ;
21+ const BUTTON_TEXT_UPDATE_AND_UPGRADE = "Update Extension and Upgrade" ;
22+ const BUTTON_TEXT_UPDATE_AND_FIX_CVE = "Update Extension and Fix" ;
2023const BUTTON_TEXT_NOT_NOW = "Not Now" ;
2124
2225const SECONDS_IN_A_DAY = 24 * 60 * 60 ;
@@ -26,6 +29,19 @@ function getNowTs() {
2629 return Number ( new Date ( ) ) / 1000 ;
2730}
2831
32+ function getExtensionState ( ) : ExtensionState {
33+ const ext = extensions . getExtension ( ExtensionName . APP_MODERNIZATION_UPGRADE_FOR_JAVA ) ;
34+ if ( ! ext ) {
35+ return "not-installed" ;
36+ }
37+ const version = ext . packageJSON ?. version ;
38+ if ( version && semver . gte ( version , Upgrade . MIN_APPMOD_VERSION ) ) {
39+ return "up-to-date" ;
40+ }
41+ // Treat missing version as outdated (conservative)
42+ return "outdated" ;
43+ }
44+
2945class NotificationManager implements IUpgradeIssuesRenderer {
3046 private hasShown = false ;
3147 private context ?: ExtensionContext ;
@@ -61,18 +77,33 @@ class NotificationManager implements IUpgradeIssuesRenderer {
6177 }
6278 this . hasShown = true ;
6379
64- const hasExtension = ! ! extensions . getExtension ( ExtensionName . APP_MODERNIZATION_UPGRADE_FOR_JAVA ) ;
80+ const extensionState = getExtensionState ( ) ;
6581 const prompt = buildFixPrompt ( issue ) ;
6682
6783 let notificationMessage = "" ;
6884
6985 if ( hasCVEIssue ) {
70- notificationMessage = buildCVENotificationMessage ( cveIssues , hasExtension ) ;
86+ notificationMessage = buildCVENotificationMessage ( cveIssues , extensionState ) ;
7187 } else {
72- notificationMessage = buildNotificationMessage ( issue , hasExtension ) ;
88+ notificationMessage = buildNotificationMessage ( issue , extensionState ) ;
89+ }
90+
91+ let upgradeButtonText : string ;
92+ let fixCVEButtonText : string ;
93+ switch ( extensionState ) {
94+ case "up-to-date" :
95+ upgradeButtonText = BUTTON_TEXT_UPGRADE ;
96+ fixCVEButtonText = BUTTON_TEXT_FIX_CVE ;
97+ break ;
98+ case "outdated" :
99+ upgradeButtonText = BUTTON_TEXT_UPDATE_AND_UPGRADE ;
100+ fixCVEButtonText = BUTTON_TEXT_UPDATE_AND_FIX_CVE ;
101+ break ;
102+ case "not-installed" :
103+ upgradeButtonText = BUTTON_TEXT_INSTALL_AND_UPGRADE ;
104+ fixCVEButtonText = BUTTON_TEXT_INSTALL_AND_FIX_CVE ;
105+ break ;
73106 }
74- const upgradeButtonText = hasExtension ? BUTTON_TEXT_UPGRADE : BUTTON_TEXT_INSTALL_AND_UPGRADE ;
75- const fixCVEButtonText = hasExtension ? BUTTON_TEXT_FIX_CVE : BUTTON_TEXT_INSTALL_AND_FIX_CVE ;
76107 sendInfo ( operationId , {
77108 operationName : "java.dependency.upgradeNotification.show" ,
78109 } ) ;
0 commit comments