@@ -3,6 +3,7 @@ import { KonveyorGUIWebviewViewProvider } from "./KonveyorGUIWebviewViewProvider
3
3
import { setupWebviewMessageListener } from "./webviewMessageHandler" ;
4
4
import { ExtensionState } from "./extensionState" ;
5
5
import { getWebviewContent } from "./webviewContent" ;
6
+ import { sourceOptions , targetOptions } from "./config/labels" ;
6
7
7
8
let fullScreenPanel : vscode . WebviewPanel | undefined ;
8
9
@@ -107,6 +108,177 @@ const commandsMap: (
107
108
extensionContext . subscriptions ,
108
109
) ;
109
110
} ,
111
+ "konveyor.overrideAnalyzerBinaries" : async ( ) => {
112
+ const options : vscode . OpenDialogOptions = {
113
+ canSelectMany : false ,
114
+ openLabel : 'Select Analyzer Binary' ,
115
+ filters : {
116
+ 'Executable Files' : [ 'exe' , 'sh' , 'bat' , '' ] ,
117
+ 'All Files' : [ '*' ]
118
+ }
119
+ } ;
120
+
121
+ const fileUri = await vscode . window . showOpenDialog ( options ) ;
122
+
123
+ if ( fileUri && fileUri [ 0 ] ) {
124
+ const filePath = fileUri [ 0 ] . fsPath ;
125
+
126
+ // Update the user settings
127
+ const config = vscode . workspace . getConfiguration ( 'konveyor' ) ;
128
+ await config . update ( 'analyzerPath' , filePath , vscode . ConfigurationTarget . Global ) ;
129
+
130
+ vscode . window . showInformationMessage ( `Analyzer binary path updated to: ${ filePath } ` ) ;
131
+ } else {
132
+ vscode . window . showInformationMessage ( 'No analyzer binary selected.' ) ;
133
+ }
134
+ } ,
135
+ "konveyor.configureCustomRules" : async ( ) => {
136
+ const options : vscode . OpenDialogOptions = {
137
+ canSelectMany : true ,
138
+ canSelectFolders : true ,
139
+ canSelectFiles : true ,
140
+ openLabel : 'Select Custom Rules' ,
141
+ filters : {
142
+ 'All Files' : [ '*' ]
143
+ }
144
+ } ;
145
+
146
+ const fileUris = await vscode . window . showOpenDialog ( options ) ;
147
+
148
+ if ( fileUris && fileUris . length > 0 ) {
149
+ const customRules = fileUris . map ( ( uri ) => uri . fsPath ) ;
150
+
151
+ // TODO(djzager): Should we verify the rules provided are valid?
152
+
153
+ // Update the user settings
154
+ const config = vscode . workspace . getConfiguration ( 'konveyor' ) ;
155
+ await config . update ( 'customRules' , customRules , vscode . ConfigurationTarget . Workspace ) ;
156
+
157
+ // Ask the user if they want to disable the default ruleset
158
+ const useDefaultRulesets = await vscode . window . showQuickPick (
159
+ [ 'Yes' , 'No' ] ,
160
+ {
161
+ placeHolder : 'Do you want to use the default rulesets?' ,
162
+ canPickMany : false
163
+ }
164
+ ) ;
165
+
166
+ if ( useDefaultRulesets === 'Yes' ) {
167
+ await config . update ( 'useDefaultRulesets' , true , vscode . ConfigurationTarget . Workspace ) ;
168
+ } else if ( useDefaultRulesets === 'No' ) {
169
+ await config . update ( 'useDefaultRulesets' , false , vscode . ConfigurationTarget . Workspace ) ;
170
+ }
171
+
172
+ vscode . window . showInformationMessage ( `Custom Rules Updated: ${ customRules } \nUse Default Rulesets: ${ useDefaultRulesets } ` ) ;
173
+ } else {
174
+ vscode . window . showInformationMessage ( 'No custom rules selected.' ) ;
175
+ }
176
+ } ,
177
+ "konveyor.configureSourcesTargets" : async ( ) => {
178
+ const config = vscode . workspace . getConfiguration ( 'konveyor' ) ;
179
+ const currentLabelSelector = config . get < string > ( 'labelSelector' , '' ) ;
180
+
181
+ // Function to extract values from label selector
182
+ const extractValuesFromSelector = ( selector : string , key : string ) : string [ ] => {
183
+ const regex = new RegExp ( `konveyor.io/${ key } =(.*?)(?:\\s|$)` , 'g' ) ;
184
+ const matches = selector . matchAll ( regex ) ;
185
+ const values = Array . from ( matches , match => match [ 1 ] ) ;
186
+ return values . flatMap ( value => value . split ( '|' ) ) ;
187
+ } ;
188
+
189
+ // Extract sources and targets from the current label selector
190
+ const currentSources = extractValuesFromSelector ( currentLabelSelector , 'source' ) ;
191
+ const currentTargets = extractValuesFromSelector ( currentLabelSelector , 'target' ) ;
192
+
193
+ const state : { sources : string [ ] ; targets : string [ ] ; labelSelector : string } = { sources : [ ] , targets : [ ] , labelSelector : '' } ;
194
+
195
+ // Function to show QuickPick for sources and targets
196
+ const showQuickPick = async ( title : string , placeholder : string , items : string [ ] , selectedItems : string [ ] ) : Promise < string [ ] | undefined > => {
197
+ const result = await vscode . window . showQuickPick (
198
+ items . map ( item => ( {
199
+ label : item ,
200
+ picked : selectedItems . includes ( item )
201
+ } ) ) ,
202
+ {
203
+ canPickMany : true ,
204
+ placeHolder : placeholder ,
205
+ title : title
206
+ }
207
+ ) ;
208
+ if ( result === undefined ) {
209
+ return undefined ;
210
+ }
211
+ return result . map ( item => item . label ) ;
212
+ } ;
213
+
214
+ // Show QuickPick for sources
215
+ const selectedSources = await showQuickPick (
216
+ 'Select Source Technologies' ,
217
+ 'Choose one or more source technologies' ,
218
+ sourceOptions ,
219
+ currentSources
220
+ ) ;
221
+ if ( selectedSources === undefined ) {
222
+ return ;
223
+ }
224
+ state . sources = selectedSources ;
225
+
226
+ // Show QuickPick for targets
227
+ const selectedTargets = await showQuickPick (
228
+ 'Select Target Technologies' ,
229
+ 'Choose one or more target technologies' ,
230
+ targetOptions ,
231
+ currentTargets
232
+ ) ;
233
+ if ( selectedTargets === undefined ) {
234
+ return ;
235
+ }
236
+ state . targets = selectedTargets ;
237
+
238
+ // Compute initial label selector
239
+ const sources = state . sources . map ( source => `konveyor.io/source=${ source } ` ) . join ( ' || ' ) ;
240
+ const targets = state . targets . map ( target => `konveyor.io/target=${ target } ` ) . join ( ' || ' ) ;
241
+ if ( sources === "" && targets === "" ) {
242
+ vscode . window . showInformationMessage ( "No sources or targets selected." ) ;
243
+ return ;
244
+ }
245
+
246
+ state . labelSelector = `(${ [ sources , targets ] . filter ( part => part !== "" ) . join ( ' && ' ) } ) || (discovery)` ;
247
+
248
+ // Show input box for modifying label selector
249
+ const modifiedLabelSelector = await vscode . window . showInputBox ( {
250
+ prompt : 'Modify the label selector if needed' ,
251
+ value : state . labelSelector ,
252
+ placeHolder : 'e.g., source=(java|spring) target=(quarkus)'
253
+ } ) ;
254
+
255
+ if ( modifiedLabelSelector === undefined ) {
256
+ return ;
257
+ }
258
+ state . labelSelector = modifiedLabelSelector ;
259
+
260
+ // Update the user settings
261
+ await config . update ( 'labelSelector' , state . labelSelector , vscode . ConfigurationTarget . Workspace ) ;
262
+
263
+ vscode . window . showInformationMessage ( `Configuration updated: Sources: ${ state . sources . join ( ', ' ) } , Targets: ${ state . targets . join ( ', ' ) } , Label Selector: ${ state . labelSelector } ` ) ;
264
+ } ,
265
+ "konveyor.configureLabelSelector" : async ( ) => {
266
+ const config = vscode . workspace . getConfiguration ( 'konveyor' ) ;
267
+ const currentLabelSelector = config . get < string > ( 'labelSelector' , '' ) ;
268
+
269
+ const modifiedLabelSelector = await vscode . window . showInputBox ( {
270
+ prompt : 'Modify the label selector if needed' ,
271
+ value : currentLabelSelector ,
272
+ placeHolder : 'e.g., source=(java|spring) target=(quarkus)'
273
+ } ) ;
274
+
275
+ if ( modifiedLabelSelector === undefined ) {
276
+ return ;
277
+ }
278
+
279
+ // Update the user settings
280
+ await config . update ( 'labelSelector' , modifiedLabelSelector , vscode . ConfigurationTarget . Workspace ) ;
281
+ } ,
110
282
} ;
111
283
} ;
112
284
0 commit comments