|
1 | 1 | packageorg.lowcoder.api.framework.plugin;
|
2 | 2 |
|
3 |
| -importjava.util.ArrayList; |
4 |
| -importjava.util.Comparator; |
5 |
| -importjava.util.LinkedHashMap; |
6 |
| -importjava.util.List; |
7 | 3 | importjava.util.Map;
|
8 | 4 |
|
9 |
| -importorg.apache.commons.collections4.CollectionUtils; |
10 |
| -importorg.lowcoder.plugin.api.LowcoderPlugin; |
11 |
| -importorg.lowcoder.plugin.api.LowcoderServices; |
| 5 | +importorg.lowcoder.plugin.LowcoderPlugin; |
| 6 | +importorg.lowcoder.sdk.config.CommonConfig; |
| 7 | +importorg.springframework.boot.system.ApplicationHome; |
| 8 | +importorg.springframework.context.ConfigurableApplicationContext; |
12 | 9 | importorg.springframework.stereotype.Component;
|
13 | 10 |
|
14 | 11 | importjakarta.annotation.PostConstruct;
|
15 |
| -importjakarta.annotation.PreDestroy; |
16 | 12 | importlombok.RequiredArgsConstructor;
|
17 | 13 | importlombok.extern.slf4j.Slf4j;
|
18 | 14 |
|
|
21 | 17 | @Slf4j
|
22 | 18 | publicclassLowcoderPluginManager
|
23 | 19 | {
|
24 |
| -privatefinalLowcoderServiceslowcoderServices; |
25 |
| -privatefinalPluginLoaderpluginLoader; |
| 20 | +privatefinalConfigurableApplicationContextapplicationContext; |
| 21 | +privatefinalCommonConfigcommon; |
| 22 | +privatefinalApplicationHomeapplicationHome; |
| 23 | + |
| 24 | +privateMap<String,LowcoderPlugin>plugins; |
| 25 | + |
26 | 26 |
|
27 |
| -privateMap<String,LowcoderPlugin>plugins =newLinkedHashMap<>(); |
28 |
| - |
29 | 27 | @PostConstruct
|
30 | 28 | privatevoidloadPlugins()
|
31 | 29 | {
|
32 |
| -registerPlugins(); |
33 |
| -List<LowcoderPlugin>sorted =newArrayList<>(plugins.values()); |
34 |
| -sorted.sort(Comparator.comparing(LowcoderPlugin::loadOrder)); |
35 | 30 |
|
36 |
| -for (LowcoderPluginplugin :sorted) |
37 |
| -{ |
38 |
| -PluginExecutorexecutor =newPluginExecutor(plugin,lowcoderServices); |
39 |
| -executor.start(); |
40 |
| -} |
41 | 31 | }
|
42 |
| - |
43 |
| -@PreDestroy |
44 |
| -publicvoidunloadPlugins() |
45 |
| -{ |
46 |
| -for (LowcoderPluginplugin :plugins.values()) |
47 |
| -{ |
48 |
| -try |
49 |
| -{ |
50 |
| -plugin.unload(); |
51 |
| -} |
52 |
| -catch(Throwablecause) |
53 |
| -{ |
54 |
| -log.warn("Error unloading plugin: {}!",plugin.pluginId(),cause); |
55 |
| -} |
56 |
| -} |
57 |
| -} |
58 |
| - |
59 |
| -publicList<PluginInfo>getLoadedPluginsInfo() |
60 |
| -{ |
61 |
| -List<PluginInfo>infos =newArrayList<>(); |
62 |
| -for (LowcoderPluginplugin :plugins.values()) |
63 |
| -{ |
64 |
| -infos.add(newPluginInfo(plugin.pluginId(),plugin.description(),plugin.pluginInfo())); |
65 |
| -} |
66 |
| -returninfos; |
67 |
| -} |
68 |
| - |
69 |
| -privatevoidregisterPlugins() |
70 |
| -{ |
71 |
| -List<LowcoderPlugin>loaded =pluginLoader.loadPlugins(); |
72 |
| -if (CollectionUtils.isNotEmpty(loaded)) |
73 |
| -{ |
74 |
| -for (LowcoderPluginplugin :loaded) |
75 |
| -{ |
76 |
| -if (!plugins.containsKey(plugin.pluginId())) |
77 |
| -{ |
78 |
| -log.info("Registered plugin: {} ({})",plugin.pluginId(),plugin.getClass().getName()); |
79 |
| -plugins.put(plugin.pluginId(),plugin); |
80 |
| -} |
81 |
| -else |
82 |
| -{ |
83 |
| -log.warn("Plugin {} already registered (from: {}), skipping {}.",plugin.pluginId(), |
84 |
| -plugins.get(plugin.pluginId()).getClass().getName(), |
85 |
| -plugin.getClass().getName()); |
86 |
| -} |
87 |
| -} |
88 |
| -} |
89 |
| -} |
90 |
| - |
91 |
| -privaterecordPluginInfo( |
92 |
| -Stringid, |
93 |
| -Stringdescription, |
94 |
| -Objectinfo |
95 |
| -) {} |
96 | 32 |
|
97 | 33 | }
|