Skip to content

Commit 8b5c36f

Browse files
Merge pull request #3 from Talexs/develop
@initial 7.0.0-preview.402.1 PluginScanner
2 parents 3634f57 + c01277d commit 8b5c36f

18 files changed

Lines changed: 579 additions & 116 deletions

src/main/java/com/talexframe/frame/config/RedisConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public class RedisConfig {
1212

1313
// @Bean
1414
// @ConditionalOnMissingBean
15-
// public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory connectionFactory) {
15+
// adapt RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory connectionFactory) {
1616
//
1717
// RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>();
1818
//

src/main/java/com/talexframe/frame/core/function/command/BaseCommand.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* @date 2022/1/20 10:56 <br /> Project: TalexFrame <br />
1313
*/
1414
@Getter
15-
public abstract class BaseCommand implements ICommand {
15+
public abstract class BaseCommand extends FrameCreator implements ICommand {
1616

1717
public static final String DIVIDER = "---------------------------";
1818
protected final TFrame tframe = TFrame.tframe;
@@ -32,6 +32,8 @@ public abstract class BaseCommand implements ICommand {
3232
*/
3333
public BaseCommand(FrameCreator creator, String label, String[] alias, String description) {
3434

35+
super("COMMAND", label);
36+
3537
this.owner = creator;
3638

3739
this.label = label;

src/main/java/com/talexframe/frame/core/function/command/CommandManager.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public void processCommand(ISender sender, String wholeCmd) {
6565
String cmdLabel = entry.getKey();
6666
BaseCommand cmd = entry.getValue();
6767

68-
if ( cmdLabel.equalsIgnoreCase(label) || Arrays.stream(cmd.getAlias()).anyMatch(s -> s.equalsIgnoreCase(label)) ) {
68+
if ( cmd.getLabel().equalsIgnoreCase(label) || cmdLabel.equalsIgnoreCase(label) || Arrays.stream(cmd.getAlias()).anyMatch(s -> s.equalsIgnoreCase(label)) ) {
6969

7070
match = true;
7171

@@ -262,4 +262,17 @@ public boolean setCommandExecutor(String label, BaseCommand command) {
262262

263263
}
264264

265+
/**
266+
*
267+
* 删除指令的执行器
268+
*
269+
* @param label 指令标识符
270+
* @return 返回是否成功 返回假一般代表没有此命令
271+
*/
272+
public boolean removeCommandExecutor(String label) {
273+
274+
return this.commands.remove(label) != null;
275+
276+
}
277+
265278
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package com.talexframe.frame.core.function.command;
2+
3+
import com.talexframe.frame.core.modules.plugins.adapt.PluginCompAdapter;
4+
import com.talexframe.frame.core.modules.plugins.addon.PluginScanner;
5+
import com.talexframe.frame.core.modules.plugins.core.WebPlugin;
6+
import com.talexframe.frame.core.talex.FrameCreator;
7+
import lombok.SneakyThrows;
8+
9+
import java.util.concurrent.atomic.AtomicBoolean;
10+
11+
/**
12+
* {@link com.talexframe.frame.core.modules.application Package }
13+
*
14+
* @author TalexDreamSoul 22/04/02 下午 08:44 Project: TalexFrame
15+
*/
16+
public class TCmdCompAdapter extends PluginCompAdapter<BaseCommand> {
17+
18+
private final CommandManager cmdManager = CommandManager.INSTANCE;
19+
20+
@SneakyThrows
21+
@Override
22+
public boolean injectWithInstance(PluginScanner scanner, WebPlugin webPlugin, BaseCommand instance) {
23+
24+
return cmdManager.setCommandExecutor(instance.getLabel(), instance);
25+
26+
}
27+
28+
@Override
29+
public boolean logoutInstance(PluginScanner scanner, WebPlugin webPlugin, Class<? extends FrameCreator> clazz) {
30+
31+
final AtomicBoolean success = new AtomicBoolean(false);
32+
33+
cmdManager.getCommands().values().forEach(baseCommand -> {
34+
35+
if( baseCommand.getClass().equals(clazz) ) {
36+
37+
cmdManager.removeCommandExecutor(baseCommand.getLabel());
38+
39+
success.set(true);
40+
41+
}
42+
43+
});
44+
45+
return success.get();
46+
47+
}
48+
49+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package com.talexframe.frame.core.modules.application;
2+
3+
import com.talexframe.frame.core.modules.plugins.adapt.PluginCompAdapter;
4+
import com.talexframe.frame.core.modules.plugins.addon.PluginScanner;
5+
import com.talexframe.frame.core.modules.plugins.core.WebPlugin;
6+
import com.talexframe.frame.core.talex.FrameCreator;
7+
import lombok.SneakyThrows;
8+
9+
/**
10+
* {@link com.talexframe.frame.core.modules.application Package }
11+
*
12+
* @author TalexDreamSoul 22/04/02 下午 08:44 Project: TalexFrame
13+
*/
14+
public class TAppCompAdapter extends PluginCompAdapter<TApp> {
15+
16+
private final TAppManager appManager = tframe.getAppManager();
17+
18+
@Override
19+
public int getPriority() {
20+
21+
return 100;
22+
}
23+
24+
@SneakyThrows
25+
@Override
26+
public boolean injectWithInstance(PluginScanner scanner, WebPlugin webPlugin, TApp instance) {
27+
28+
return appManager.registerController( webPlugin, instance );
29+
30+
}
31+
32+
@Override
33+
public boolean logoutInstance(PluginScanner scanner, WebPlugin webPlugin, Class<? extends FrameCreator> clazz) {
34+
35+
return appManager.unRegisterController( webPlugin, appManager.getControllers().get(clazz));
36+
37+
}
38+
39+
}

src/main/java/com/talexframe/frame/core/modules/handler/TNamingStrategy.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,33 +14,33 @@
1414
public class TNamingStrategy /*implements PhysicalNamingStrategy*/ {
1515

1616
// @Override
17-
// public Identifier toPhysicalCatalogName(Identifier name,
17+
// adapt Identifier toPhysicalCatalogName(Identifier name,
1818
// JdbcEnvironment jdbcEnvironment) {
1919
// return apply(name, jdbcEnvironment);
2020
// }
2121
//
2222
// @Override
23-
// public Identifier toPhysicalSchemaName(Identifier name,
23+
// adapt Identifier toPhysicalSchemaName(Identifier name,
2424
// JdbcEnvironment jdbcEnvironment) {
2525
// return apply(name, jdbcEnvironment);
2626
// }
2727
//
2828
// @Override
29-
// public Identifier toPhysicalTableName(Identifier name,
29+
// adapt Identifier toPhysicalTableName(Identifier name,
3030
// JdbcEnvironment jdbcEnvironment) {
3131
// Identifier identifier = apply(name, jdbcEnvironment);
3232
// String tbName = "t_" + identifier.toString();
3333
// return new Identifier(tbName, identifier.isQuoted());
3434
// }
3535
//
3636
// @Override
37-
// public Identifier toPhysicalSequenceName(Identifier name,
37+
// adapt Identifier toPhysicalSequenceName(Identifier name,
3838
// JdbcEnvironment jdbcEnvironment) {
3939
// return apply(name, jdbcEnvironment);
4040
// }
4141
//
4242
// @Override
43-
// public Identifier toPhysicalColumnName(Identifier name,
43+
// adapt Identifier toPhysicalColumnName(Identifier name,
4444
// JdbcEnvironment jdbcEnvironment) {
4545
// return apply(name, jdbcEnvironment);
4646
// }
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
package com.talexframe.frame.core.modules.plugins.adapt;
2+
3+
import com.talexframe.frame.core.modules.plugins.addon.PluginScanner;
4+
import com.talexframe.frame.core.modules.plugins.core.WebPlugin;
5+
import com.talexframe.frame.core.pojo.FrameBuilder;
6+
import com.talexframe.frame.core.talex.FrameCreator;
7+
import com.talexframe.frame.core.talex.TFrame;
8+
import lombok.SneakyThrows;
9+
10+
import java.lang.reflect.ParameterizedType;
11+
12+
/**
13+
* {@link com.talexframe.frame.core.modules.plugins.adapt Package }
14+
*
15+
* @author TalexDreamSoul 22/04/02 下午 08:20 Project: TalexFrame
16+
*/
17+
public abstract class PluginCompAdapter<T extends FrameCreator> extends FrameBuilder {
18+
19+
protected final TFrame tframe = TFrame.tframe;
20+
private final Class<?> templateClass = (Class<T>) ( (ParameterizedType) this.getClass().getGenericSuperclass() ).getActualTypeArguments()[0];;
21+
22+
public PluginCompAdapter() {
23+
24+
super("ComponentAdapter");
25+
26+
PluginScanner.adapt( this );
27+
28+
}
29+
30+
/** GetPriority **/
31+
public int getPriority() {
32+
33+
return 1000;
34+
35+
}
36+
37+
/**
38+
*
39+
* For true for access, for false for deny
40+
*
41+
*/
42+
public boolean shouldAccess(Class<? extends FrameCreator> clazz) {
43+
44+
return templateClass.isAssignableFrom(clazz);
45+
46+
}
47+
48+
@SneakyThrows
49+
public boolean inject( PluginScanner scanner, WebPlugin webPlugin, Object obj ) {
50+
51+
// Method method = this.getClass().getMethod("injectWithInstance", PluginScanner.class, WebPlugin.class, templateClass);
52+
53+
// method.invoke( this, scanner, webPlugin, (T) obj );
54+
55+
return this.injectWithInstance(scanner, webPlugin, (T) obj);
56+
57+
}
58+
59+
/**
60+
*
61+
* Trigger after all class scanned
62+
*
63+
* @param scanner For the plugin scanner
64+
* @param webPlugin For the own plugin
65+
* @param instance For the instance
66+
*
67+
* @return should return a signal of provided instance, if the signal is false, it will have a warning if mode is DEBUG
68+
*
69+
*/
70+
protected abstract boolean injectWithInstance(PluginScanner scanner, WebPlugin webPlugin, T instance );
71+
72+
/**
73+
*
74+
* Trigger when plugin disabled
75+
*
76+
* @param scanner For the plugin scanner
77+
* @param webPlugin For the own plugin
78+
* @param clazz For the class
79+
*
80+
* @return If you return false, the frame will be crashed
81+
*/
82+
public abstract boolean logoutInstance( PluginScanner scanner, WebPlugin webPlugin, Class<? extends FrameCreator> clazz );
83+
84+
}

0 commit comments

Comments
 (0)