Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: support extending jar directories for plugin class loader #3108

Merged
merged 3 commits into from
Jan 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 21 additions & 8 deletions src/main/java/run/halo/app/plugin/PluginAutoConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,17 +107,30 @@ protected PluginLoader createPluginLoader() {
} else {
return new CompoundPluginLoader()
.add(new DevelopmentPluginLoader(this) {

@Override
public ClassLoader loadPlugin(Path pluginPath,
protected PluginClassLoader createPluginClassLoader(Path pluginPath,
PluginDescriptor pluginDescriptor) {
PluginClassLoader pluginClassLoader =
new PluginClassLoader(pluginManager, pluginDescriptor,
getClass().getClassLoader(), ClassLoadingStrategy.APD);

loadClasses(pluginPath, pluginClassLoader);
loadJars(pluginPath, pluginClassLoader);
return new PluginClassLoader(pluginManager, pluginDescriptor,
getClass().getClassLoader(), ClassLoadingStrategy.APD);
}

return pluginClassLoader;
@Override
public ClassLoader loadPlugin(Path pluginPath,
PluginDescriptor pluginDescriptor) {
if (pluginProperties.getClassesDirectories() != null) {
for (String classesDirectory :
pluginProperties.getClassesDirectories()) {
pluginClasspath.addClassesDirectories(classesDirectory);
}
}
if (pluginProperties.getLibDirectories() != null) {
for (String libDirectory :
pluginProperties.getLibDirectories()) {
pluginClasspath.addJarsDirectories(libDirectory);
}
}
return super.loadPlugin(pluginPath, pluginDescriptor);
}
}, this::isDevelopment)
.add(new JarPluginLoader(this) {
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/run/halo/app/plugin/PluginProperties.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
@Data
@ConfigurationProperties(prefix = "halo.plugin")
public class PluginProperties {
public static final String GRADLE_LIBS_DIR = "build/libs";

/**
* Auto start plugin when main app is ready.
Expand Down Expand Up @@ -53,7 +54,7 @@ public class PluginProperties {
/**
* Extended Plugin Jar Directory.
*/
private List<String> libDirectories = new ArrayList<>();
private List<String> libDirectories = new ArrayList<>(List.of(GRADLE_LIBS_DIR));

/**
* Runtime Mode:development/deployment.
Expand Down
5 changes: 0 additions & 5 deletions src/main/resources/application-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,6 @@ halo:
super-admin-password: admin
plugin:
runtime-mode: development # development, deployment
classes-directories:
- "build/classes"
- "build/resources"
lib-directories:
- "libs"
work-dir: ${user.home}/halo2-dev
logging:
level:
Expand Down