Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit7a3b3e5

Browse files
committed
new: extend new plugin system
1 parent63d5dde commit7a3b3e5

File tree

6 files changed

+18
-479
lines changed

6 files changed

+18
-479
lines changed

‎server/api-service/lowcoder-server/pom.xml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@
215215
<version>0.11.5</version>
216216
<scope>runtime</scope>
217217
</dependency>
218+
<dependency>
218219
<groupId>org.springframework</groupId>
219220
<artifactId>spring-aspects</artifactId>
220221
</dependency>

‎server/api-service/lowcoder-server/src/main/java/org/lowcoder/api/framework/configuration/PluginConfiguration.java‎

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
importjava.util.ArrayList;
44

55
importorg.lowcoder.api.framework.plugin.LowcoderPluginManager;
6-
importorg.lowcoder.api.framework.plugin.PluginLoader;
7-
importorg.springframework.context.ApplicationContext;
6+
importorg.lowcoder.api.framework.plugin.endpoint.PluginEndpointHandler;
87
importorg.springframework.context.annotation.Bean;
98
importorg.springframework.context.annotation.Configuration;
109
importorg.springframework.context.annotation.DependsOn;
@@ -20,24 +19,17 @@
2019
@Configuration
2120
publicclassPluginConfiguration
2221
{
23-
//private final ApplicationContext applicationContext;
24-
//private final PluginLoader pluginLoader;
25-
//
26-
//public LowcoderPluginManager lowcoderPluginManager()
27-
//{
28-
//return new LowcoderPluginManager(applicationContext, pluginLoader);
29-
//}
3022

3123
@SuppressWarnings("unchecked")
3224
@Bean
3325
@DependsOn("lowcoderPluginManager")
34-
RouterFunction<?>pluginEndpoints(LowcoderPluginManagerpluginManager)
26+
RouterFunction<?>pluginEndpoints(LowcoderPluginManagerpluginManager,PluginEndpointHandlerpluginEndpointHandler)
3527
{
3628
RouterFunction<?>pluginsList =RouterFunctions.route()
3729
.GET(RequestPredicates.path("/plugins"),req ->ServerResponse.ok().body(Mono.just(pluginManager.getLoadedPluginsInfo()),ArrayList.class))
3830
.build();
3931

40-
RouterFunction<?>endpoints =pluginManager.getEndpoints().stream()
32+
RouterFunction<?>endpoints =pluginEndpointHandler.registeredEndpoints().stream()
4133
.map(r-> (RouterFunction<ServerResponse>)r)
4234
.reduce((o,r )-> (RouterFunction<ServerResponse>)o.andOther(r))
4335
.orElse(null);

‎server/api-service/lowcoder-server/src/main/java/org/lowcoder/api/framework/plugin/LowcoderPluginManager.java‎

Lines changed: 2 additions & 159 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,20 @@
11
packageorg.lowcoder.api.framework.plugin;
22

3-
importstaticorg.springframework.web.reactive.function.server.RequestPredicates.DELETE;
4-
importstaticorg.springframework.web.reactive.function.server.RequestPredicates.GET;
5-
importstaticorg.springframework.web.reactive.function.server.RequestPredicates.OPTIONS;
6-
importstaticorg.springframework.web.reactive.function.server.RequestPredicates.PATCH;
7-
importstaticorg.springframework.web.reactive.function.server.RequestPredicates.POST;
8-
importstaticorg.springframework.web.reactive.function.server.RequestPredicates.PUT;
9-
importstaticorg.springframework.web.reactive.function.server.RouterFunctions.route;
10-
11-
importjava.lang.reflect.InvocationTargetException;
12-
importjava.lang.reflect.Method;
133
importjava.util.ArrayList;
144
importjava.util.Comparator;
155
importjava.util.LinkedHashMap;
166
importjava.util.List;
177
importjava.util.Map;
188

199
importorg.apache.commons.collections4.CollectionUtils;
20-
importorg.apache.commons.lang3.StringUtils;
21-
importorg.lowcoder.api.framework.plugin.data.PluginServerRequest;
22-
importorg.lowcoder.plugin.api.EndpointExtension;
2310
importorg.lowcoder.plugin.api.LowcoderPlugin;
2411
importorg.lowcoder.plugin.api.LowcoderServices;
25-
importorg.lowcoder.plugin.api.PluginEndpoint;
26-
importorg.lowcoder.plugin.api.data.EndpointRequest;
27-
importorg.lowcoder.plugin.api.data.EndpointResponse;
28-
importorg.lowcoder.sdk.exception.BaseException;
29-
importorg.springframework.core.ResolvableType;
30-
importorg.springframework.http.ResponseCookie;
3112
importorg.springframework.stereotype.Component;
32-
importorg.springframework.web.reactive.function.server.RequestPredicate;
33-
importorg.springframework.web.reactive.function.server.RouterFunction;
34-
importorg.springframework.web.reactive.function.server.ServerResponse;
35-
importorg.springframework.web.reactive.function.server.ServerResponse.BodyBuilder;
3613

3714
importjakarta.annotation.PostConstruct;
3815
importjakarta.annotation.PreDestroy;
3916
importlombok.RequiredArgsConstructor;
4017
importlombok.extern.slf4j.Slf4j;
41-
importreactor.core.publisher.Mono;
4218

4319
@RequiredArgsConstructor
4420
@Component
@@ -49,7 +25,6 @@ public class LowcoderPluginManager
4925
privatefinalPluginLoaderpluginLoader;
5026

5127
privateMap<String,LowcoderPlugin>plugins =newLinkedHashMap<>();
52-
privateList<RouterFunction<ServerResponse>>routes =newArrayList<>();
5328

5429
@PostConstruct
5530
privatevoidloadPlugins()
@@ -60,11 +35,8 @@ private void loadPlugins()
6035

6136
for (LowcoderPluginplugin :sorted)
6237
{
63-
if (plugin.load(lowcoderServices))
64-
{
65-
log.info("Plugin [{}] loaded successfully.",plugin.pluginId());
66-
registerEndpoints(plugin);
67-
}
38+
PluginExecutorexecutor =newPluginExecutor(plugin,lowcoderServices);
39+
executor.start();
6840
}
6941
}
7042

@@ -84,11 +56,6 @@ public void unloadPlugins()
8456
}
8557
}
8658

87-
publicList<RouterFunction<ServerResponse>>getEndpoints()
88-
{
89-
returnthis.routes;
90-
}
91-
9259
publicList<PluginInfo>getLoadedPluginsInfo()
9360
{
9461
List<PluginInfo>infos =newArrayList<>();
@@ -121,130 +88,6 @@ private void registerPlugins()
12188
}
12289
}
12390

124-
125-
privatevoidregisterEndpoints(LowcoderPluginplugin)
126-
{
127-
if (CollectionUtils.isNotEmpty(plugin.endpoints()))
128-
{
129-
for (PluginEndpointendpoint :plugin.endpoints())
130-
{
131-
Method[]handlers =endpoint.getClass().getDeclaredMethods();
132-
if (handlers !=null &&handlers.length >0)
133-
{
134-
for (Methodhandler :handlers)
135-
{
136-
registerEndpointHandler(plugin,endpoint,handler);
137-
}
138-
}
139-
}
140-
}
141-
}
142-
143-
privatevoidregisterEndpointHandler(LowcoderPluginplugin,PluginEndpointendpoint,Methodhandler)
144-
{
145-
if (handler.isAnnotationPresent(EndpointExtension.class))
146-
{
147-
if (checkHandlerMethod(handler))
148-
{
149-
150-
EndpointExtensionendpointMeta =handler.getAnnotation(EndpointExtension.class);
151-
routes.add(route(createRequestPredicate(plugin,endpointMeta),req -> {
152-
Mono<ServerResponse>result =null;
153-
try
154-
{
155-
EndpointResponseresponse = (EndpointResponse)handler.invoke(endpoint,PluginServerRequest.fromServerRequest(req));
156-
result =createServerResponse(response);
157-
}
158-
catch (IllegalAccessException |InvocationTargetExceptioncause)
159-
{
160-
thrownewBaseException("Error running handler for [ " +endpointMeta.method() +": " +endpointMeta.uri() +"] !");
161-
}
162-
returnresult;
163-
})
164-
);
165-
log.info("Registered plugin endpoint: {} -> {} -> {}: {}",plugin.pluginId(),endpoint.getClass().getSimpleName(),endpointMeta.method(),endpointMeta.uri());
166-
}
167-
else
168-
{
169-
log.error("Cannot register plugin endpoint: {} -> {} -> {}! Handler method must be defined as: public Mono<ServerResponse> {}(ServerRequest request)",plugin.pluginId(),endpoint.getClass().getSimpleName(),handler.getName(),handler.getName());
170-
}
171-
}
172-
}
173-
174-
privateMono<ServerResponse>createServerResponse(EndpointResponsepluginResponse)
175-
{
176-
/** Create response with given status **/
177-
BodyBuilderbuilder =ServerResponse.status(pluginResponse.statusCode());
178-
179-
/** Set response headers **/
180-
if (pluginResponse.headers() !=null && !pluginResponse.headers().isEmpty())
181-
{
182-
pluginResponse.headers().entrySet()
183-
.forEach(entry -> {
184-
builder.header(entry.getKey(),entry.getValue().toArray(newString[] {}));
185-
});
186-
187-
}
188-
189-
/** Set cookies if available **/
190-
if (pluginResponse.cookies() !=null && !pluginResponse.cookies().isEmpty())
191-
{
192-
pluginResponse.cookies().values()
193-
.forEach(cookies -> {
194-
cookies.forEach(cookie -> {
195-
builder.cookie(ResponseCookie.from(cookie.getKey(),cookie.getValue()).build());
196-
});
197-
198-
});
199-
}
200-
201-
/** Set response body if available **/
202-
if (pluginResponse.body() !=null)
203-
{
204-
returnbuilder.bodyValue(pluginResponse.body());
205-
}
206-
207-
returnbuilder.build();
208-
}
209-
210-
privatebooleancheckHandlerMethod(Methodmethod)
211-
{
212-
ResolvableTypereturnType =ResolvableType.forMethodReturnType(method);
213-
214-
return (returnType.getRawClass().isAssignableFrom(EndpointResponse.class)
215-
&&method.getParameterCount() ==1
216-
&&method.getParameterTypes()[0].isAssignableFrom(EndpointRequest.class)
217-
);
218-
}
219-
220-
privateRequestPredicatecreateRequestPredicate(LowcoderPluginplugin,EndpointExtensionendpoint)
221-
{
222-
StringbasePath ="/plugins/" +plugin.pluginId();
223-
224-
switch(endpoint.method())
225-
{
226-
caseGET:
227-
returnGET(pluginEndpointUri(basePath,endpoint.uri()));
228-
casePOST:
229-
returnPOST(pluginEndpointUri(basePath,endpoint.uri()));
230-
casePUT:
231-
returnPUT(pluginEndpointUri(basePath,endpoint.uri()));
232-
casePATCH:
233-
returnPATCH(pluginEndpointUri(basePath,endpoint.uri()));
234-
caseDELETE:
235-
returnDELETE(pluginEndpointUri(basePath,endpoint.uri()));
236-
caseOPTIONS:
237-
returnOPTIONS(pluginEndpointUri(basePath,endpoint.uri()));
238-
}
239-
returnnull;
240-
}
241-
242-
privateStringpluginEndpointUri(StringbasePath,Stringuri)
243-
{
244-
returnStringUtils.join(basePath,StringUtils.prependIfMissing(uri,"/"));
245-
}
246-
247-
24891
privaterecordPluginInfo(
24992
Stringid,
25093
Stringdescription,

‎server/api-service/lowcoder-server/src/main/java/org/lowcoder/api/framework/plugin/PathBasedPluginLoader.java‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,12 @@ protected List<String> findPluginCandidates(Path pluginsDir)
9797
protectedList<LowcoderPlugin>loadPluginCandidates(StringpluginJar)
9898
{
9999
List<LowcoderPlugin>pluginCandidates =newArrayList<>();
100-
101-
PluginJarClassLoaderpluginClassLoader =null;
100+
102101
try
103102
{
104-
pluginClassLoader =newPluginJarClassLoader(getClass().getClassLoader(),Path.of(pluginJar));
103+
PathpluginPath =Path.of(pluginJar);
104+
PluginClassLoaderpluginClassLoader =newPluginClassLoader(pluginPath.getFileName().toString(),pluginPath);
105105

106-
107106
ServiceLoader<LowcoderPlugin>pluginServices =ServiceLoader.load(LowcoderPlugin.class,pluginClassLoader);
108107
if (pluginServices !=null )
109108
{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp