1
1
package org .lowcoder .api .framework .plugin ;
2
2
3
3
import java .util .ArrayList ;
4
+ import java .util .Arrays ;
4
5
import java .util .Comparator ;
6
+ import java .util .HashMap ;
5
7
import java .util .LinkedHashMap ;
6
8
import java .util .List ;
7
9
import java .util .Map ;
10
+ import java .util .stream .Collectors ;
11
+ import java .util .stream .StreamSupport ;
8
12
9
13
import org .apache .commons .collections4 .CollectionUtils ;
14
+ import org .apache .commons .lang3 .StringUtils ;
10
15
import org .lowcoder .plugin .api .LowcoderPlugin ;
11
16
import org .lowcoder .plugin .api .LowcoderServices ;
17
+ import org .springframework .core .env .AbstractEnvironment ;
18
+ import org .springframework .core .env .EnumerablePropertySource ;
19
+ import org .springframework .core .env .Environment ;
20
+ import org .springframework .core .env .MutablePropertySources ;
12
21
import org .springframework .stereotype .Component ;
13
22
14
23
import jakarta .annotation .PostConstruct ;
22
31
public class LowcoderPluginManager
23
32
{
24
33
private final LowcoderServices lowcoderServices ;
25
- private final PluginLoader pluginLoader ;
34
+ private final PluginLoader pluginLoader ;
35
+ private final Environment environment ;
26
36
27
37
private Map <String , LowcoderPlugin > plugins = new LinkedHashMap <>();
28
38
@@ -35,7 +45,7 @@ private void loadPlugins()
35
45
36
46
for (LowcoderPlugin plugin : sorted )
37
47
{
38
- PluginExecutor executor = new PluginExecutor (plugin , lowcoderServices );
48
+ PluginExecutor executor = new PluginExecutor (plugin , getPluginEnvironmentVariables ( plugin ), lowcoderServices );
39
49
executor .start ();
40
50
}
41
51
}
@@ -66,6 +76,29 @@ public List<PluginInfo> getLoadedPluginsInfo()
66
76
return infos ;
67
77
}
68
78
79
+ private Map <String , Object > getPluginEnvironmentVariables (LowcoderPlugin plugin )
80
+ {
81
+ Map <String , Object > env = new HashMap <>();
82
+
83
+ String varPrefix = "PLUGIN_" + plugin .pluginId ().toUpperCase ().replaceAll ("-" , "_" ) + "_" ;
84
+ MutablePropertySources propertySources = ((AbstractEnvironment ) environment ).getPropertySources ();
85
+ List <String > properties = StreamSupport .stream (propertySources .spliterator (), false )
86
+ .filter (propertySource -> propertySource instanceof EnumerablePropertySource )
87
+ .map (propertySource -> ((EnumerablePropertySource <?>) propertySource ).getPropertyNames ())
88
+ .flatMap (Arrays ::<String > stream )
89
+ .distinct ()
90
+ .sorted ()
91
+ .filter (prop -> prop .startsWith (varPrefix ))
92
+ .collect (Collectors .toList ());
93
+
94
+ for (String prop : properties )
95
+ {
96
+ env .put (StringUtils .removeStart (prop , varPrefix ), environment .getProperty (prop ));
97
+ }
98
+
99
+ return env ;
100
+ }
101
+
69
102
private void registerPlugins ()
70
103
{
71
104
List <LowcoderPlugin > loaded = pluginLoader .loadPlugins ();
0 commit comments