-
Notifications
You must be signed in to change notification settings - Fork 2
/
PluginManagerUI.bbj
496 lines (368 loc) · 19.5 KB
/
PluginManagerUI.bbj
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
use ::PluginManager/PluginManager.bbj::PluginManager
use ::PluginManager/src/Tag.bbj::Tag
use ::PluginManager/src/BBjPlugin.bbj::BBjPlugin
use ::PluginManager/src/RemoteBBjPlugin.bbj::RemoteBBjPlugin
use ::PluginManager/src/InstalledBBjPlugin.bbj::InstalledBBjPlugin
use ::PluginManager/src/gui/RemotePluginTab.bbj::RemotePluginTab
use ::PluginManager/src/gui/InstalledPluginTab.bbj::InstalledPluginTab
use ::PluginManager/src/gui/GithubCredentialWindow.bbj::GithubCredentialWindow
use ::PluginManager/src/gui/ConfigurePluginProjectURLsWindow.bbj::ConfigurePluginProjectURLsWindow
use java.util.Iterator
use java.util.ArrayList
use java.util.HashMap
use java.text.SimpleDateFormat
use ::PluginManager/src/PluginManagerDeployer.bbj::PluginManagerDeployer
class public PluginManagerUI
field public static String RUN_DEMO_PROGRAM! = "RUN_DEMO_PROGRAM"
field public static String ADD_CUSTOM_PLUGIN! = "ADD_CUSTOM_PLUGIN"
field public static String INSTALL_PLUGIN_END! = "INSTALL_PLUGIN_END"
field public static String INSTALL_PLUGIN_REQUEST! = "INSTALL_PLUGIN_REQUEST"
field public static String UPDATE_PLUGIN_END! = "UPDATE_PLUGIN_END"
field public static String UPDATE_PLUGIN_REQUEST! = "UPDATE_PLUGIN_REQUEST"
field public static String REMOVE_CUSTOM_PLUGIN! = "REMOVE_CUSTOM_PLUGIN"
field public static String UNINSTALL_PLUGIN_REQUEST! = "UNINSTALL_PLUGIN_REQUEST"
field public static String RUN_CONFIGURATION_PROGRAM! = "RUN_CONFIGURATION_PROGRAM"
field private PluginManager pluginManager!
field private BBjSysGui sysGui!
field private BBjTabCtrl tabCtrl!
field private BBjTopLevelWindow window!
field private BBjMenuBar mainWindowMenuBar!
field private RemotePluginTab remoteTab!
field private InstalledPluginTab installedTab!
field private GithubCredentialWindow credentialWindow!
field private ConfigurePluginProjectURLsWindow configurePluginProjectURLsWindow!
method public PluginManagerUI()
#pluginManager! = new PluginManager()
#configurePluginProjectURLsWindow! = new ConfigurePluginProjectURLsWindow(#pluginManager!, #this!)
#credentialWindow! = new GithubCredentialWindow()
#init()
methodend
method private void init()
print 'hide'
#sysGui! = BBjAPI().openSysGui("X0")
#sysGui!.setRepaintEnabled(0)
window_width = 1000
window_height = 650
declare java.awt.Rectangle screenBounds!
screenBounds! = #sysGui!.getSystemMetrics().getScreenBounds()
screen_width = screenBounds!.getWidth()
screen_height = screenBounds!.getHeight()
#window! = #sysGui!.addWindow(100, (screen_width/2 - window_width/2), (screen_height/2 - window_height/2), window_width, window_height, "Plugin Manager", $00000082$)
#window!.setCallback(BBjAPI.ON_CLOSE, #this!, "closeWindow")
window_next_id = #window!.getAvailableControlID()
#mainWindowMenuBar! = cast(BBjMenuBar, #window!.addMenuBar())
window_next_id = #window!.getAvailableControlID()
mainWindowMenuConfigure! = cast(BBjMenu, #mainWindowMenuBar!.addMenu(window_next_id, "Configure"))
REM window_next_id = #window!.getAvailableControlID()
REM menuItemImportPlugins! = cast(BBjMenuItem, mainWindowMenuConfigure!.addMenuItem(window_next_id, "Import Plugins"))
REM menuItemImportPlugins!.setEnabled(0)
REM
REM window_next_id = #window!.getAvailableControlID()
REM menuItemExportPlugins! = cast(BBjMenuItem, mainWindowMenuConfigure!.addMenuItem(window_next_id, "Export Installed Plugins"))
REM menuItemExportPlugins!.setEnabled(0)
REM mainWindowMenuConfigure!.insertSeparator(2)
window_next_id = #window!.getAvailableControlID()
menuItemCustomizePluginProjectURLs! = cast(BBjMenuItem, mainWindowMenuConfigure!.addMenuItem(window_next_id, "Customize Plugin Project URLs"))
menuItemCustomizePluginProjectURLs!.setCallback(BBjMenuItem.ON_MENU_ITEM_SELECT, #this!, "customizePluginProjectURLsMenuItemSelected")
row_x = 10
row_y = 50
tab_width = window_width-20
tab_height = window_height-row_y-10
window_next_id = #window!.getAvailableControlID()
#tabCtrl! = #window!.addTabCtrl(window_next_id, row_x, row_y, tab_width, tab_height)
#installedTab! = new InstalledPluginTab(#window!, #tabCtrl!.getWidth(), #tabCtrl!.getHeight(), #sysGui!)
#installedTab!.updateTabEntries(#pluginManager!.getInstalledPluginList())
#tabCtrl!.addTab("Installed Plugins", #installedTab!.getChildWindow())
bbjapi().setCustomEventCallback(#UPDATE_PLUGIN_REQUEST!, #this!, "updatePluginRequest")
bbjapi().setCustomEventCallback(#UNINSTALL_PLUGIN_REQUEST!, #this!, "uninstallPluginRequest")
#remoteTab! = new RemotePluginTab(#window!, #tabCtrl!.getWidth(), #tabCtrl!.getHeight(), #sysGui!)
#remoteTab!.updateTabEntries(#pluginManager!.getRemotePluginList(Boolean.TRUE))
#tabCtrl!.addTab("Available Plugins", #remoteTab!.getChildWindow())
declare BBjAPI bbjapi!
bbjapi! = BBjAPI()
bbjapi!.setCustomEventCallback(#INSTALL_PLUGIN_REQUEST!, #this!, "installPluginRequest")
bbjapi!.setCustomEventCallback(#RUN_DEMO_PROGRAM!, #this!, "runDemoProgram")
bbjapi!.setCustomEventCallback(#ADD_CUSTOM_PLUGIN!, #this!, "addCustomPlugin")
bbjapi!.setCustomEventCallback(#REMOVE_CUSTOM_PLUGIN!, #this!, "removeCustomRemotePlugin")
bbjapi!.setCustomEventCallback(#RUN_CONFIGURATION_PROGRAM!, #this!, "runConfigurationProgram")
#sysGui!.setRepaintEnabled(1)
methodend
method public void runConfigurationProgram(BBjCustomEvent event!)
declare InstalledBBjPlugin installedPlugin!
installedPlugin! = cast(InstalledBBjPlugin, event!.getObject())
rem TODO - If the plugin can have multiple configuration programs pass the selected one
#pluginManager!.runConfigurationProgram(installedPlugin!, "configure.bbj")
methodend
method public void removeCustomRemotePlugin(BBjCustomEvent event!)
declare RemoteBBjPlugin remotePlugin!
remotePlugin! = cast(RemoteBBjPlugin, event!.getObject())
#pluginManager!.removeCustomPluginRepository(remotePlugin!)
#configurePluginProjectURLsWindow!.update(#pluginManager!.getCustomRemoteBBjPluginList())
#installedTab!.updateTabEntries(#pluginManager!.getInstalledPluginList())
#remoteTab!.updateTabEntries(#pluginManager!.getRemotePluginList(Boolean.TRUE))
methodend
rem /**
rem * Gets called when a new custom plugin should be added to the list of plugins
rem */
method public void addCustomPlugin(BBjCustomEvent event!)
url! = str(event!.getObject())
rem first check if the Github credentials are set
if(!#pluginManager!.areGithubCredentialsSaved()) then
useCredentials! = Boolean.FALSE
rem if not, first check if the repo is public, if not prompt for the user credentials
if(!#pluginManager!.isPluginProjectAccessible(url!, Boolean.FALSE)) then
sb! = new StringBuilder("The provided project repository URL cannot be accessed(404).")
sb!.append("This indicates either that the URL is wrong or the repository is private.")
sb!.append($0A$)
sb!.append("If the repository is private, you'll need to provide valid Github credentials to access it.")
sb!.append("Do you want to add Github credentials ?")
answer = msgbox(sb!.toString(), 4)
if(answer <> 6) then
methodret
endif
invalidCredentials! = Boolean.TRUE
while(invalidCredentials!)
#credentialWindow!.open(#sysGui!)
if(#credentialWindow!.dialogCanceled()) then
methodret
endif
#pluginManager!.setGihubCredentials(#credentialWindow!.getUsername(), #credentialWindow!.getPassword(), #credentialWindow!.saveCredentials())
if(#pluginManager!.areGithubCredentialsValid()) then
invalidCredentials! = Boolean.FALSE
break
endif
a = msgbox("The entered Github Login Credentials are not valid.")
wend
if(!#pluginManager!.isPluginProjectAccessible(url!, Boolean.TRUE)) then
answer = msgbox("The BBj Plugin repository does not exist or is not accessible. Please verify that the provided URL is correct and the reporsitory is available and try again.")
#inpeProjectURL!.focus()
methodret
endif
useCredentials! = Boolean.TRUE
endif
else
useCredentials! = Boolean.TRUE
if(!#pluginManager!.isPluginProjectAccessible(url!, Boolean.TRUE)) then
answer = msgbox("The BBj Plugin repository does not exist or is not accessible. Please verify that the provided URL is correct and the reporsitory is available and try again.")
#inpeProjectURL!.focus()
methodret
endif
endif
rem TODO check if the plugin isn't already added to the list
#pluginManager!.addCustomBBjPluginRepository(url!, useCredentials!)
#configurePluginProjectURLsWindow!.update(#pluginManager!.getCustomRemoteBBjPluginList())
#installedTab!.updateTabEntries(#pluginManager!.getInstalledPluginList())
#remoteTab!.updateTabEntries(#pluginManager!.getRemotePluginList(Boolean.TRUE))
methodend
method public void runDemoProgram(BBjCustomEvent event!)
declare HashMap map!
map! = cast(HashMap, event!.getObject())
declare Iterator it!
it! = map!.entrySet().iterator()
declare InstalledBBjPlugin installedPlugin!
while(it!.hasNext())
entry! = it!.next()
installedPlugin! = cast(InstalledBBjPlugin, entry!.getKey())
demoProgramName! = entry!.getValue()
break
wend
#pluginManager!.runDemo(installedPlugin!, demoProgramName!)
methodend
method public void updatePluginRequest(BBjCustomEvent event!)
declare InstalledBBjPlugin installedPlugin!
installedPlugin! = cast(InstalledBBjPlugin, event!.getObject())
#pluginManager!.updatePlugin(installedPlugin!)
rem Throwing the event so that the UI can hide the progressbar
bbjapi().postCustomEvent(#UPDATE_PLUGIN_END!, "")
#installedTab!.updateTabEntries(#pluginManager!.getInstalledPluginList())
#remoteTab!.updateTabEntries(#pluginManager!.getRemotePluginList(Boolean.TRUE))
methodend
rem /**
rem * Uninstalls the plugin described in the given event! payload, and updates the tabs entries.
rem *
rem * @param event! The event with the plugin to uninstall.
rem */
method public void uninstallPluginRequest(BBjCustomEvent event!)
declare InstalledBBjPlugin installedPlugin!
installedPlugin! = cast(InstalledBBjPlugin, event!.getObject())
if(#pluginManager!.isDependency(installedPlugin!)) then
declare Iterator it!
declare ArrayList list!
declare StringBuilder sb!
declare InstalledBBjPlugin plugin!
sb! = new StringBuilder("The selected plugin is a dependency of the following plugins: " + $0A$ + $0A$)
list! = #pluginManager!.getDependentPlugins(installedPlugin!)
it! = list!.iterator()
while(it!.hasNext())
plugin! = cast(InstalledBBjPlugin, it!.next())
sb!.append(plugin!.getName() + $0A$)
wend
sb!.append($0A$ + "Uninstalling it may break the plugins listed above. Do you want to uninstall it anyway ?")
a = msgbox(sb!.toString(), 4)
if(a <> 6) then
methodret
endif
endif
#pluginManager!.uninstallPlugin(installedPlugin!)
#installedTab!.updateTabEntries(#pluginManager!.getInstalledPluginList())
#remoteTab!.updateTabEntries(#pluginManager!.getRemotePluginList(Boolean.TRUE))
methodend
method public void installPluginRequest(BBjCustomEvent event!)
declare HashMap map!
map! = cast(HashMap, event!.getObject())
declare RemoteBBjPlugin remotePlugin!
declare Tag tag!
declare Iterator it!
it! = map!.entrySet().iterator()
while(it!.hasNext())
entry! = it!.next()
remotePlugin! = cast(RemoteBBjPlugin, entry!.getKey())
tag! = cast(Tag, entry!.getValue())
#installPlugin(remotePlugin!, tag!)
wend
#installedTab!.updateTabEntries(#pluginManager!.getInstalledPluginList())
#remoteTab!.updateTabEntries(#pluginManager!.getRemotePluginList(Boolean.TRUE))
methodend
method public void installPlugin(RemoteBBjPlugin remotePlugin!, Tag tag!)
if(remotePlugin! = null() OR tag! = null()) then
print "Error: null value"
methodret
endif
if(#pluginManager!.hasDependencies(tag!)) then
if(#pluginManager!.hasBBjDependency(tag!)) then
if(!#pluginManager!.isBBjVersionValid(tag!)) then
a = msgbox("The installed BBj Version doesn't match the plugin's requirement."+ $0A$ + "The installed version is "+ str(REV) + $0A$ + "The plugin requires REV " + tag!.getBBjDependency() + " to run properly." + $0A$ + "Do want to install the plugin anyway ?", 4)
if(a <> 6) then
methodret
endif
endif
endif
if(#pluginManager!.hasDependenciesToBBjPlugins(tag!)) then
if(!#pluginManager!.areDependenciesInstalled(tag!)) then
rem TODO check if a dependency is installed but requires an update
declare StringBuilder sb!
sb! = new StringBuilder("The selected plugin requires the following plugins to be installed in order to run properly: " + $0A$ + $0A$)
declare HashMap dependencyMap!
dependencyMap! = tag!.getPluginDependencyMap()
declare Iterator it!
it! = dependencyMap!.entrySet().iterator()
while(it!.hasNext())
entry! = it!.next()
sb!.append("Plugin: " + cast(RemoteBBjPlugin, entry!.getKey()).getName() + ",Tag: " + cast(Tag, entry!.getValue()).getName() + $0A$)
wend
sb!.append($0A$ + "Do you want to install these plugins as well?")
a = msgbox(sb!.toString(),4)
if(a <> 6 AND a <> 7) then
methodret
endif
if(a = 6) then
declare Tag dependencyTag!
declare RemoteBBjPlugin remoteDependencyPlugin!
it! = dependencyMap!.entrySet().iterator()
while(it!.hasNext())
entry! = it!.next()
dependencyTag! = cast(Tag, entry!.getValue())
remoteDependencyPlugin! = cast(RemoteBBjPlugin, entry!.getKey())
#installPlugin(remoteDependencyPlugin!, cast(Tag, entry!.getValue()))
wend
endif
endif
endif
endif
#pluginManager!.installPlugin(remotePlugin!, tag!)
rem Throwing the event so that the UI can hide the progressbar
bbjapi().postCustomEvent(#INSTALL_PLUGIN_END!, "")
#installedTab!.updateTabEntries(#pluginManager!.getInstalledPluginList())
#remoteTab!.updateTabEntries(#pluginManager!.getRemotePluginList(Boolean.TRUE))
methodend
method public void customizePluginProjectURLsMenuItemSelected(BBjMenuItemSelectEvent event!)
#configurePluginProjectURLsWindow!.open(#sysGui!, #pluginManager!.getCustomRemoteBBjPluginList())
methodend
method public static String getDisplayDate(java.util.Date date!)
declare SimpleDateFormat sdf!
sdf! = new SimpleDateFormat("dd MMM yyyy HH:mm", java.util.Locale.ENGLISH)
rem sdf!.setTimeZone(java.util.TimeZone.getTimeZone("GMT"))
methodret sdf!.format(date!)
methodend
method public void closeWindow(BBjCloseEvent event!)
#window!.destroy()
bye
methodend
classend
print 'cs'
path! = BBjAPI().getFileSystem().resolvePath("PluginManagerLauncher.bbj", err=*next)
rem Adding the bbj/plugins folder to the session's prefix in case it hasn't been added yet
if(path! = null() OR path!.isEmpty()) then
declare java.io.File currentDirectory!
currentDirectory! = new java.io.File(dsk("") + dir(""))
prefix """" + currentDirectory!.getParentFile().getAbsolutePath() + """ " + pfx
endif
ok = 0; sys! = BBjAPI().openSysGui("X0", err=*next); ok = 1
if ok then
declare PluginManagerUI pmui!
pmui! = new PluginManagerUI()
process_events
release
endif
declare PluginManagerDeployer deployer!
deployer! = new PluginManagerDeployer()
print "The PluginManager needs a graphical user interface to run."
admin! = BBjAdminFactory.getBBjAdmin("admin", "admin123")
if admin! <> null() then
if deployer!.isPluginManagerDeployedAsBUI(admin!) then
buiApp! = deployer!.getPluginManagerBuiApplication(admin!)
print "The PluginManager was already deployed as BUI application."
print "To run it, open the following URL in your browser: "
print buiApp!.getUrl()
release
endif
endif
prompt_for_bui_app_creation:
print "Do you want to publish it as BUI application in order to run it in the browser ? (y/n) "
input userInput$
if userInput$ <> "y" then
if userInput$ = "n" then
release
endif
print "Invalid Input"
wait 2
goto prompt_for_bui_app_creation
endif
if admin! <> null() then
goto deploy_bui_app
endif
print "To deploy the PluginManager BUI application, a connection to the Basis admin base needs to be established."
prompt_for_bbj_admin_credentials:
credentialEnteringCounter = credentialEnteringCounter +1
print "Enter the BBj Enterprise Manager credentials: "
print "Username: ",
input username$
print 'EE', ; rem Disable the Echo Mode (Hiding what the user enters)
a = scall("stty -echo") ; rem Hiding the user input(Linux)
? "Password: ",
input password$
print 'BE', ; rem Enable the Echo Mode again
a = scall("stty echo") ; rem Enable the user input again
admin! = BBjAdminFactory.getBBjAdmin(username$, password$, err=*next)
if admin! = null() then
if credentialEnteringCounter > 3 then
print "Too many wrong attempts."
release
endif
print "Invalid BBj admin base credentials."
goto prompt_for_bbj_admin_credentials
endif
if deployer!.isPluginManagerDeployedAsBUI(admin!) then
buiApp! = deployer!.getPluginManagerBuiApplication(admin!)
print "The PluginManager was already deployed as BUI application."
print "To run it, open the following URL in your browser: "
print buiApp!.getUrl()
release
endif
deploy_bui_app:
rem Setting up the PluginManager BUI application
buiApp! = deployer!.deployPluginManagerBuiApp(admin!)
print "The PluginManager launcher script has been published as BUI application, and ca be accessed via the following URL: " + $0A$
print buiApp!.getUrl()
print $0A$
release