Skip to content

Commit

Permalink
Update DynamicPlugin, change void doWithDynamicModules() to `Clos…
Browse files Browse the repository at this point in the history
…ure doWithDynamicModules()`
  • Loading branch information
rainboyan committed Aug 20, 2024
1 parent bd8edf1 commit 1df7852
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 25 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2021-2022 the original author or authors.
* Copyright 2021-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -31,27 +31,9 @@ abstract class DynamicPlugin extends Plugin {
* Invoked in a phase where plugins can add dynamic modules.
* Subclasses should override
*/
void doWithDynamicModules() {
Closure doWithDynamicModules() {
// TODO Implement registering dynamic modules to application (optional)
}

@Override
Object invokeMethod(String name, Object args) {
if (plugin !instanceof DynamicGrailsPlugin) {
return false
}

DynamicGrailsPlugin dynamicPlugin = (DynamicGrailsPlugin) plugin
Object[] array = (Object[]) args
if (array.length > 0) {
if (array.length > 1) {
dynamicPlugin.addModuleDescriptor(name, array[0] as Map<String, Object>, array[1] as Closure)
}
else {
dynamicPlugin.addModuleDescriptor(name, array[0] as Map<String, Object>)
}
}
true
null
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2021-2023 the original author or authors.
* Copyright 2021-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -74,7 +74,10 @@ private void evaluateProvidedModules() {
public void doWithDynamicModules() {
if (getInstance() instanceof DynamicPlugin) {
DynamicPlugin dynamicPlugin = (DynamicPlugin) getInstance();
dynamicPlugin.doWithDynamicModules();
Closure dynamicModules = dynamicPlugin.doWithDynamicModules();
dynamicModules.setResolveStrategy(Closure.DELEGATE_FIRST);
dynamicModules.setDelegate(this);
dynamicModules.call();
}
}

Expand Down Expand Up @@ -124,4 +127,18 @@ public <M> List<ModuleDescriptor<M>> getModuleDescriptorsByModuleClass(Class<M>
return result;
}

@Override
public Object invokeMethod(String name, Object args) {
Object[] array = (Object[]) args;
if (array.length > 0) {
if (array.length > 1) {
addModuleDescriptor(name, (Map<String, Object>) array[0], (Closure) array[1]);
}
else {
addModuleDescriptor(name, (Map<String, Object>) array[0]);
}
}
return true;
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2021-2023 the original author or authors.
* Copyright 2021-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -75,7 +75,10 @@ private void evaluateProvidedModules() {
public void doWithDynamicModules() {
if (getInstance() instanceof DynamicPlugin) {
DynamicPlugin dynamicPlugin = (DynamicPlugin) getInstance();
dynamicPlugin.doWithDynamicModules();
Closure dynamicModules = dynamicPlugin.doWithDynamicModules();
dynamicModules.setResolveStrategy(Closure.DELEGATE_FIRST);
dynamicModules.setDelegate(this);
dynamicModules.call();
}
}

Expand Down Expand Up @@ -125,4 +128,18 @@ public <M> List<ModuleDescriptor<M>> getModuleDescriptorsByModuleClass(Class<M>
return result;
}

@Override
public Object invokeMethod(String name, Object args) {
Object[] array = (Object[]) args;
if (array.length > 0) {
if (array.length > 1) {
addModuleDescriptor(name, (Map<String, Object>) array[0], (Closure) array[1]);
}
else {
addModuleDescriptor(name, (Map<String, Object>) array[0]);
}
}
return true;
}

}

0 comments on commit 1df7852

Please sign in to comment.