@@ -29,6 +29,62 @@ function getNowTs() {
2929 return Number ( new Date ( ) ) / 1000 ;
3030}
3131
32+ export type ExtensionState = "up-to-date" | "outdated" | "not-installed" ;
33+
34+ export interface NotificationContent {
35+ message : string ;
36+ upgradeButtonText : string ;
37+ fixCVEButtonText : string ;
38+ }
39+
40+ export function getExtensionState ( extensionVersion : string | undefined ) : ExtensionState {
41+ if ( ! extensionVersion ) {
42+ return "not-installed" ;
43+ }
44+ if ( semver . gte ( extensionVersion , Upgrade . MIN_APPMOD_VERSION ) ) {
45+ return "up-to-date" ;
46+ }
47+ return "outdated" ;
48+ }
49+
50+ export function buildNotificationContent (
51+ issues : UpgradeIssue [ ] ,
52+ extensionState : ExtensionState ,
53+ ) : NotificationContent {
54+ const cveIssues = issues . filter (
55+ ( i ) : i is CveUpgradeIssue => i . reason === UpgradeReason . CVE
56+ ) ;
57+ const nonCVEIssues = issues . filter (
58+ ( i ) => i . reason !== UpgradeReason . CVE
59+ ) ;
60+ const hasCVEIssue = cveIssues . length > 0 ;
61+ const isReady = extensionState === "up-to-date" ;
62+
63+ const message = hasCVEIssue
64+ ? buildCVENotificationMessage ( cveIssues , isReady )
65+ : buildNotificationMessage ( nonCVEIssues [ 0 ] , isReady ) ;
66+
67+ let upgradeButtonText : string ;
68+ let fixCVEButtonText : string ;
69+
70+ switch ( extensionState ) {
71+ case "up-to-date" :
72+ upgradeButtonText = BUTTON_TEXT_UPGRADE ;
73+ fixCVEButtonText = BUTTON_TEXT_FIX_CVE ;
74+ break ;
75+ case "outdated" :
76+ upgradeButtonText = BUTTON_TEXT_UPDATE_AND_UPGRADE ;
77+ fixCVEButtonText = BUTTON_TEXT_UPDATE_AND_FIX_CVE ;
78+ break ;
79+ case "not-installed" :
80+ upgradeButtonText = BUTTON_TEXT_INSTALL_AND_UPGRADE ;
81+ fixCVEButtonText = BUTTON_TEXT_INSTALL_AND_FIX_CVE ;
82+ break ;
83+ }
84+
85+ return { message, upgradeButtonText, fixCVEButtonText } ;
86+ }
87+
3288class NotificationManager implements IUpgradeIssuesRenderer {
3389 private hasShown = false ;
3490 private context ?: ExtensionContext ;
@@ -45,16 +101,6 @@ class NotificationManager implements IUpgradeIssuesRenderer {
45101 return ;
46102 }
47103
48- // Filter to only CVE issues and cast to CveUpgradeIssue[]
49- const cveIssues = issues . filter (
50- ( i ) : i is CveUpgradeIssue => i . reason === UpgradeReason . CVE
51- ) ;
52- const nonCVEIssues = issues . filter (
53- ( i ) => i . reason !== UpgradeReason . CVE
54- ) ;
55- const hasCVEIssue = cveIssues . length > 0 ;
56- const issue = hasCVEIssue ? cveIssues [ 0 ] : nonCVEIssues [ 0 ] ;
57-
58104 if ( ! this . shouldShow ( ) ) {
59105 return ;
60106 }
@@ -65,35 +111,26 @@ class NotificationManager implements IUpgradeIssuesRenderer {
65111 this . hasShown = true ;
66112
67113 const ext = extensions . getExtension ( ExtensionName . APP_MODERNIZATION_UPGRADE_FOR_JAVA ) ;
68- const hasExtension = ! ! ext ;
69- const isExtensionUpToDate = hasExtension
70- && ! ! ext . packageJSON ?. version
71- && semver . gte ( ext . packageJSON . version , Upgrade . MIN_APPMOD_VERSION ) ;
72- const prompt = buildFixPrompt ( issue ) ;
114+ const extensionState = getExtensionState ( ext ?. packageJSON ?. version ) ;
115+ const { message, upgradeButtonText, fixCVEButtonText } = buildNotificationContent ( issues , extensionState ) ;
73116
74- let notificationMessage = "" ;
117+ const hasCVEIssue = issues . some ( i => i . reason === UpgradeReason . CVE ) ;
118+ const issue = hasCVEIssue
119+ ? issues . find ( ( i ) : i is CveUpgradeIssue => i . reason === UpgradeReason . CVE ) !
120+ : issues . find ( i => i . reason !== UpgradeReason . CVE ) ! ;
121+ const prompt = buildFixPrompt ( issue ) ;
75122
76- if ( hasCVEIssue ) {
77- notificationMessage = buildCVENotificationMessage ( cveIssues , isExtensionUpToDate ) ;
78- } else {
79- notificationMessage = buildNotificationMessage ( issue , isExtensionUpToDate ) ;
80- }
81- const upgradeButtonText = isExtensionUpToDate
82- ? BUTTON_TEXT_UPGRADE
83- : hasExtension ? BUTTON_TEXT_UPDATE_AND_UPGRADE : BUTTON_TEXT_INSTALL_AND_UPGRADE ;
84- const fixCVEButtonText = isExtensionUpToDate
85- ? BUTTON_TEXT_FIX_CVE
86- : hasExtension ? BUTTON_TEXT_UPDATE_AND_FIX_CVE : BUTTON_TEXT_INSTALL_AND_FIX_CVE ;
87123 sendInfo ( operationId , {
88124 operationName : "java.dependency.upgradeNotification.show" ,
125+ extensionState,
89126 } ) ;
90127
91128 const buttons = hasCVEIssue
92129 ? [ fixCVEButtonText , BUTTON_TEXT_NOT_NOW ]
93130 : [ upgradeButtonText , BUTTON_TEXT_NOT_NOW ] ;
94131
95132 const selection = await window . showInformationMessage (
96- notificationMessage ,
133+ message ,
97134 ...buttons
98135 ) ;
99136 sendInfo ( operationId , {
0 commit comments