Skip to content

Commit 60ad33e

Browse files
committed
re-organize properties
1 parent 1814bfc commit 60ad33e

File tree

9 files changed

+70
-68
lines changed

9 files changed

+70
-68
lines changed

demo-app/src/main/resources/application.yml

+10-12
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,21 @@ spring:
44
username: postgres
55
driver-class-name: "org.postgresql.Driver"
66
sbp:
7-
runtimeMode: development
7+
runtime-mode: development
88
enabled: true
99
classes-directories:
1010
- "out/production/classes"
1111
- "out/production/resources"
1212
lib-directories:
1313
- "libs"
14+
plugin-properties:
15+
spring:
16+
jpa:
17+
properties:
18+
hibernate:
19+
temp:
20+
use_jdbc_metadata_defaults: false
21+
database-platform: org.hibernate.dialect.PostgreSQL9Dialect
1422
flyway:
1523
schemas:
1624
- demo_app
@@ -37,14 +45,4 @@ logging:
3745
level:
3846
org.hibernate.tool.schema.internal.ExceptionHandlerLoggedImpl: ERROR
3947
org.jooq: DEBUG
40-
org.jooq.Constants: ERROR
41-
42-
sbp-plugin:
43-
properties:
44-
spring:
45-
jpa:
46-
properties:
47-
hibernate:
48-
temp:
49-
use_jdbc_metadata_defaults: false
50-
database-platform: org.hibernate.dialect.PostgreSQL9Dialect
48+
org.jooq.Constants: ERROR

demo-app/src/test/resources/application.yml

+11-13
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,17 @@ spring:
1313
- "build/resources/main"
1414
lib-directories:
1515
- "libs"
16+
plugin-properties:
17+
spring:
18+
flyway:
19+
import-data: true
20+
clean-before-migrate: true
21+
jpa:
22+
properties:
23+
hibernate:
24+
temp:
25+
use_jdbc_metadata_defaults: false
26+
database-platform: org.hibernate.dialect.PostgreSQL9Dialect
1627
flyway:
1728
schemas:
1829
- demo_app
@@ -36,16 +47,3 @@ logging:
3647
org.hibernate.tool.schema.internal.ExceptionHandlerLoggedImpl: ERROR
3748
# org.jooq: DEBUG
3849
org.jooq.Constants: ERROR
39-
40-
sbp-plugin:
41-
properties:
42-
spring:
43-
flyway:
44-
import-data: true
45-
clean-before-migrate: true
46-
jpa:
47-
properties:
48-
hibernate:
49-
temp:
50-
use_jdbc_metadata_defaults: false
51-
database-platform: org.hibernate.dialect.PostgreSQL9Dialect

docs/configuration.md

+24-22
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,20 @@
11
### SbpProperties
22

3-
Configurations for main app (not plugin) to control PluginManager behavior.
3+
Configurations for main application's PluginManager.
44

55
##### `spring.sbp.enabled`
66
set to true to enable sbp. Default false.
77

8-
##### `spring.sbp.autoStartPlugin`
8+
##### `spring.sbp.auto-start-plugin`
99
auto start plugin when main app is ready. Default true
1010

11-
##### `spring.sbp.disabledPlugins`
11+
##### `spring.sbp.disabled-plugins`
1212
Plugins disabled by default
1313

14-
##### `spring.sbp.enabledPlugins`
15-
Plugins enabled by default, prior to `disabledPlugins`
14+
##### `spring.sbp.enabled-plugins`
15+
Plugins enabled by default, prior to `disabled-plugins`
1616

17-
##### `spring.sbp.profiles`:
18-
Specify Spring profiles to be used to create plugins' `ApplicationContext`.
19-
20-
##### `spring.sbp.classesDirectories`
17+
##### `spring.sbp.classes-directories`
2118
where to load plugin classes, relative to plugin folder.
2219
* for IDEA
2320
```
@@ -27,19 +24,29 @@ where to load plugin classes, relative to plugin folder.
2724
- "out/production/classes"
2825
- "out/production/resources"
2926
```
30-
##### `spring.sbp.libDirectories`
27+
##### `spring.sbp.lib-directories`
3128
where to load jar libs, relative to plugin folder.
3229

33-
##### `spring.sbp.runtimeMode`
30+
##### `spring.sbp.runtime-mode`
3431
with two options
3532
* DEPLOYMENT: load plugin in jar/zip format.
3633
* DEVELOPMENT: load plugin from build folder with Java class file.
3734

38-
##### `spring.sbp.pluginsRoot`
35+
##### `spring.sbp.plugins-root`
3936
plugins home folder, relative to project working DIR.
4037
Default `plusins`
4138

42-
##### `spring.sbp.systemVersion`
39+
##### `spring.sbp.plugin-profiles`:
40+
Specify Spring profiles to be used when creating plugins' `ApplicationContext` environment. With profile `plugin` by default.
41+
You could use it to config plugin globally.
42+
Check [Demo](../demo-app/src/main/resources/application.yml) for example.
43+
44+
##### `spring.sbp.plugin-properties`
45+
Specify properties to be used when creating plugins' `ApplicationContext` environment.
46+
You could use it to config plugin globally.
47+
Check [Demo](../demo-app/src/main/resources/application.yml) for example.
48+
49+
##### `spring.sbp.system-version`
4350
The system version used for comparisons to the plugin requires attribute.
4451

4552
##### `spring.sbp.controller.base-path`
@@ -50,14 +57,9 @@ Check [Demo](../demo-app/src/main/resources/application.yml) for example.
5057

5158
### SbpPluginProperties
5259

53-
Configurations to control how plugins are loaded by PluginManager.
54-
55-
##### `sbp-plugin.properties`
56-
properties define under this property will be passed to
57-
plugin `ApplicationContext` environment. You could use it to passed global plugin
58-
properties. Check [Demo](../demo-app/src/main/resources/application.yml) for example.
60+
Configurations for individual plugins.
5961

60-
##### `sbp-plugin.pluginFirstClasses`
62+
##### `sbp-plugin.plugin-first-classes`
6163
If a class file existed in app classpath and
6264
plugin classpath at the same time, `PluginClassLoader` will try to load it
6365
from plugin classpath first. This will cause `ClassCastException` when classes from
@@ -66,8 +68,8 @@ plugin classpath first to make sure classes come from same classloader.
6668
e.g. Spring Boot AutoConfiguration used in plugin only. See
6769
[JPA example](../plugins/demo-plugin-library/src/main/resources/application.yml).
6870

69-
##### `sbp-plugin.pluginOnlyResources`
70-
If a resources file (including resource) existed
71+
##### `sbp-plugin.plugin-only-resources`
72+
If a resource file (including resource) existed
7173
in app classpath and plugin classpath at the same time, `PluginClassLoader` scan all of
7274
them out when performing `ClassLoader.loadResources()`. This will potentially cause
7375
unexpected errors, e.g. loading wrong configuration file from the wrong place. Use this

plugins/demo-plugin-author/src/main/resources/application.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ spring:
1111
jooq:
1212
sql-dialect: postgres
1313

14-
plugin:
15-
pluginOnlyResources:
14+
sbp-plugin:
15+
plugin-only-resources:
1616
- plugin_only
1717

1818
logging:

plugins/demo-plugin-library/src/main/resources/application.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ spring:
2323
datasource:
2424
beanName: dataSource-library
2525

26-
plugin:
27-
pluginFirstClasses:
26+
sbp-plugin:
27+
plugin-first-classes:
2828
- org.springframework.boot.autoconfigure.data.*
2929
- org.springframework.boot.autoconfigure.orm.*
3030
- org.springframework.boot.orm.jpa.*

sbp-core/src/main/java/org/laxture/sbp/spring/boot/SpringBootstrap.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ protected void bindToSpringApplication(ConfigurableEnvironment environment) {
276276
String pluginFirstClassesProp = null;
277277
int i = 0;
278278
do {
279-
pluginFirstClassesProp = getProperties(environment, "plugin.pluginFirstClasses", i++);
279+
pluginFirstClassesProp = getProperties(environment, "pluginFirstClasses", i++);
280280
if (pluginFirstClassesProp != null) {
281281
pluginFirstClasses.add(pluginFirstClassesProp);
282282
}
@@ -286,7 +286,7 @@ protected void bindToSpringApplication(ConfigurableEnvironment environment) {
286286
String pluginOnlyResourcesProp = null;
287287
i = 0;
288288
do {
289-
pluginOnlyResourcesProp = getProperties(environment, "plugin.pluginOnlyResources", i++);
289+
pluginOnlyResourcesProp = getProperties(environment, "pluginOnlyResources", i++);
290290
if (pluginOnlyResourcesProp != null) {
291291
pluginOnlyResources.add(pluginOnlyResourcesProp);
292292
}
@@ -388,11 +388,11 @@ protected void registerBeanFromMainContext(AbstractApplicationContext applicatio
388388
}
389389

390390
private String getProperties(Environment env, String propName, int index) {
391-
String prop = env.getProperty(String.format("%s[%s]", propName, index));
392-
if (prop == null) prop = env.getProperty(String.format("%s.%s", propName, index));
393-
if (prop == null) prop = env.getProperty(String.format("%s[%s]",
391+
String prop = env.getProperty(String.format("sbp-plugin.%s[%s]", propName, index));
392+
if (prop == null) prop = env.getProperty(String.format("sbp-plugin.%s.%s", propName, index));
393+
if (prop == null) prop = env.getProperty(String.format("sbp-plugin.%s[%s]",
394394
String.join("-", StringUtils.splitByCharacterTypeCamelCase(propName)).toLowerCase(), index));
395-
if (prop == null) prop = env.getProperty(String.format("%s.%s",
395+
if (prop == null) prop = env.getProperty(String.format("sbp-plugin.%s.%s",
396396
String.join("-", StringUtils.splitByCharacterTypeCamelCase(propName)).toLowerCase(), index));
397397
return prop;
398398
}

sbp-spring-boot-starter/src/main/java/org/laxture/sbp/spring/boot/SbpAutoConfiguration.java

+3-4
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,7 @@ public PluginManagerController pluginManagerController() {
7777

7878
@Bean
7979
@ConditionalOnMissingBean
80-
public SpringBootPluginManager pluginManager(SbpProperties properties,
81-
SbpPluginProperties pluginProperties) {
80+
public SpringBootPluginManager pluginManager(SbpProperties properties) {
8281
// Setup RuntimeMode
8382
System.setProperty("pf4j.mode", properties.getRuntimeMode().toString());
8483

@@ -133,11 +132,11 @@ protected PluginStatusProvider createPluginStatusProvider() {
133132
}
134133
};
135134

136-
pluginManager.presetProperties(flatProperties(pluginProperties.properties));
135+
pluginManager.setProfiles(properties.getPluginProfiles());
136+
pluginManager.presetProperties(flatProperties(properties.getPluginProperties()));
137137
pluginManager.setExactVersionAllowed(properties.isExactVersionAllowed());
138138
pluginManager.setSystemVersion(properties.getSystemVersion());
139139
pluginManager.setAutoStartPlugin(properties.isAutoStartPlugin());
140-
pluginManager.setProfiles(properties.getProfiles());
141140

142141
return pluginManager;
143142
}

sbp-spring-boot-starter/src/main/java/org/laxture/sbp/spring/boot/SbpPluginProperties.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import lombok.Data;
1919
import org.springframework.boot.context.properties.ConfigurationProperties;
20+
import org.springframework.context.ApplicationContext;
2021

2122
import java.util.HashMap;
2223
import java.util.Map;
@@ -32,14 +33,11 @@ public class SbpPluginProperties {
3233

3334
public static final String PREFIX = "sbp-plugin";
3435

35-
Map<String, Object> properties = new HashMap<>();
36-
3736
/**
3837
* Load these classes from plugin classpath first,
3938
* e.g Spring Boot AutoConfiguration used in plugin only.
4039
*/
4140
public String[] pluginFirstClasses = {};
42-
4341
/**
4442
* Load these resource from plugin classpath only
4543
*/

sbp-spring-boot-starter/src/main/java/org/laxture/sbp/spring/boot/SbpProperties.java

+11-4
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
2121
import org.springframework.context.ApplicationContext;
2222

2323
import java.util.ArrayList;
24+
import java.util.HashMap;
2425
import java.util.List;
26+
import java.util.Map;
2527

2628
/**
2729
* Properties for Sbp main app
@@ -50,10 +52,6 @@ public class SbpProperties {
5052
* Plugins enabled by default, prior to `disabledPlugins`
5153
*/
5254
private String[] enabledPlugins;
53-
/**
54-
* Profile for plugin Spring {@link ApplicationContext}
55-
*/
56-
private String[] profiles = new String[] {"plugin"};
5755
/**
5856
* Set to true to allow requires expression to be exactly x.y.z. The default is
5957
* false, meaning that using an exact version x.y.z will implicitly mean the
@@ -77,6 +75,15 @@ public class SbpProperties {
7775
* should be an absolute directory address
7876
*/
7977
private String pluginsRoot = "plugins";
78+
/**
79+
* Profile for plugin Spring {@link ApplicationContext}
80+
*/
81+
private String[] pluginProfiles = new String[] {"plugin"};
82+
/**
83+
* properties define under this property will be passed to
84+
* plugin `ApplicationContext` environment.
85+
*/
86+
Map<String, Object> pluginProperties = new HashMap<>();
8087
/**
8188
* The system version used for comparisons to the plugin requires attribute.
8289
*/

0 commit comments

Comments
 (0)