[xwiki-devs] [proposal] Cancelable events and refactoring script macros
Hello, I'd like to refactor AbstractScriptMacro in order to be able to change script behavior in the future without fanout violations. Here is the plan emerged after several discussions with ThomasM: Introduce a notion of cancelable events. Such events can be canceled by the receiver (providing an optional reason), the actual canceling is performed by the sender. http://dev.xwiki.org/xwiki/bin/view/Design/CancelableEvents Send a cancelable event ScriptEvaluationStartsEvent in AbstractScriptMacro just before evaluating the script and a ScriptEvaluationFinishedEvent right after evaluation has finished (in finally block). Add the following 3 listeners to those events (into rendering.internal.macro.script) and move the corresponding code from AbstractScriptMacro there: ScriptClassLoaderHandlerListener * does class loader manipulations currently performed by AbstractScriptMacro#getClassLoader & Co PermissionCheckerListener * Aborts execution of scripts that need PR if the document is not saved with PR * To distinguish velocity and PR scripts, introduce a new interface PrivilegedScriptMacro extends ScriptMacro and let AbstractJSR223ScriptMacro implement it NestedScriptMacroValidatorListener * Replaces NestedScriptMacroValidator (ScriptMacroValidator component is removed completely) The refactoring will remove the following methods (breaks API): AbstractJSR223ScriptMacro: * protected boolean canExecuteScript() * public List execute(JSR223ScriptMacroParameters, String, MacroTransformationContext) AbstractScriptMacro: * protected boolean canHaveJarsParameters() * protected ClassLoader getClassLoader(String, ClassLoader) WDYT? Alex
On Mon, Aug 23, 2010 at 11:00, Alex Busenius <[email protected]> wrote:
Hello,
I'd like to refactor AbstractScriptMacro in order to be able to change script behavior in the future without fanout violations. Here is the plan emerged after several discussions with ThomasM:
Introduce a notion of cancelable events. Such events can be canceled by the receiver (providing an optional reason), the actual canceling is performed by the sender.
http://dev.xwiki.org/xwiki/bin/view/Design/CancelableEvents
Send a cancelable event ScriptEvaluationStartsEvent in AbstractScriptMacro just before evaluating the script and a ScriptEvaluationFinishedEvent right after evaluation has finished (in finally block).
Add the following 3 listeners to those events (into rendering.internal.macro.script) and move the corresponding code from AbstractScriptMacro there:
ScriptClassLoaderHandlerListener * does class loader manipulations currently performed by AbstractScriptMacro#getClassLoader & Co
Lets say +0,5 because it makes more difficult to understand the behavior of class loaders in script macros.
PermissionCheckerListener * Aborts execution of scripts that need PR if the document is not saved with PR
+1
* To distinguish velocity and PR scripts, introduce a new interface PrivilegedScriptMacro extends ScriptMacro and let AbstractJSR223ScriptMacro implement it
NestedScriptMacroValidatorListener * Replaces NestedScriptMacroValidator (ScriptMacroValidator component is removed completely)
+1
The refactoring will remove the following methods (breaks API):
AbstractJSR223ScriptMacro: * protected boolean canExecuteScript()
* public List execute(JSR223ScriptMacroParameters, String, MacroTransformationContext)
Removing this method does not break anything since it's just an override of AbstractScriptMacro#execute. Probably a clirr check bug or something.
AbstractScriptMacro: * protected boolean canHaveJarsParameters() * protected ClassLoader getClassLoader(String, ClassLoader)
WDYT?
+1, cancelable events is a very useful feature that we will be able to use in many places: validate document before saving it, etc.
Alex _______________________________________________ devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs
-- Thomas Mortagne
On 08/23/2010 11:00 AM, Alex Busenius wrote:
Hello,
I'd like to refactor AbstractScriptMacro in order to be able to change script behavior in the future without fanout violations. Here is the plan emerged after several discussions with ThomasM:
Introduce a notion of cancelable events. Such events can be canceled by the receiver (providing an optional reason), the actual canceling is performed by the sender.
http://dev.xwiki.org/xwiki/bin/view/Design/CancelableEvents
Send a cancelable event ScriptEvaluationStartsEvent in AbstractScriptMacro just before evaluating the script and a ScriptEvaluationFinishedEvent right after evaluation has finished (in finally block).
Add the following 3 listeners to those events (into rendering.internal.macro.script) and move the corresponding code from AbstractScriptMacro there:
ScriptClassLoaderHandlerListener * does class loader manipulations currently performed by AbstractScriptMacro#getClassLoader& Co
PermissionCheckerListener * Aborts execution of scripts that need PR if the document is not saved with PR * To distinguish velocity and PR scripts, introduce a new interface PrivilegedScriptMacro extends ScriptMacro and let AbstractJSR223ScriptMacro implement it
NestedScriptMacroValidatorListener * Replaces NestedScriptMacroValidator (ScriptMacroValidator component is removed completely)
The refactoring will remove the following methods (breaks API):
AbstractJSR223ScriptMacro: * protected boolean canExecuteScript() * public List execute(JSR223ScriptMacroParameters, String, MacroTransformationContext)
AbstractScriptMacro: * protected boolean canHaveJarsParameters() * protected ClassLoader getClassLoader(String, ClassLoader)
WDYT?
+1 for all. -- Sergiu Dumitriu http://purl.org/net/sergiu/
+1 Jerome. ----- Original Message ----- From: "Alex Busenius" <[email protected]> To: "XWiki Developers" <[email protected]> Sent: Monday, August 23, 2010 11:00:16 AM GMT +01:00 Amsterdam / Berlin / Bern / Rome / Stockholm / Vienna Subject: [xwiki-devs] [proposal] Cancelable events and refactoring script macros Hello, I'd like to refactor AbstractScriptMacro in order to be able to change script behavior in the future without fanout violations. Here is the plan emerged after several discussions with ThomasM: Introduce a notion of cancelable events. Such events can be canceled by the receiver (providing an optional reason), the actual canceling is performed by the sender. http://dev.xwiki.org/xwiki/bin/view/Design/CancelableEvents Send a cancelable event ScriptEvaluationStartsEvent in AbstractScriptMacro just before evaluating the script and a ScriptEvaluationFinishedEvent right after evaluation has finished (in finally block). Add the following 3 listeners to those events (into rendering.internal.macro.script) and move the corresponding code from AbstractScriptMacro there: ScriptClassLoaderHandlerListener * does class loader manipulations currently performed by AbstractScriptMacro#getClassLoader & Co PermissionCheckerListener * Aborts execution of scripts that need PR if the document is not saved with PR * To distinguish velocity and PR scripts, introduce a new interface PrivilegedScriptMacro extends ScriptMacro and let AbstractJSR223ScriptMacro implement it NestedScriptMacroValidatorListener * Replaces NestedScriptMacroValidator (ScriptMacroValidator component is removed completely) The refactoring will remove the following methods (breaks API): AbstractJSR223ScriptMacro: * protected boolean canExecuteScript() * public List execute(JSR223ScriptMacroParameters, String, MacroTransformationContext) AbstractScriptMacro: * protected boolean canHaveJarsParameters() * protected ClassLoader getClassLoader(String, ClassLoader) WDYT? Alex _______________________________________________ devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs
+1 Caleb Jerome Velociter wrote:
+1
Jerome.
----- Original Message ----- From: "Alex Busenius" <[email protected]> To: "XWiki Developers" <[email protected]> Sent: Monday, August 23, 2010 11:00:16 AM GMT +01:00 Amsterdam / Berlin / Bern / Rome / Stockholm / Vienna Subject: [xwiki-devs] [proposal] Cancelable events and refactoring script macros
Hello,
I'd like to refactor AbstractScriptMacro in order to be able to change script behavior in the future without fanout violations. Here is the plan emerged after several discussions with ThomasM:
Introduce a notion of cancelable events. Such events can be canceled by the receiver (providing an optional reason), the actual canceling is performed by the sender.
http://dev.xwiki.org/xwiki/bin/view/Design/CancelableEvents
Send a cancelable event ScriptEvaluationStartsEvent in AbstractScriptMacro just before evaluating the script and a ScriptEvaluationFinishedEvent right after evaluation has finished (in finally block).
Add the following 3 listeners to those events (into rendering.internal.macro.script) and move the corresponding code from AbstractScriptMacro there:
ScriptClassLoaderHandlerListener * does class loader manipulations currently performed by AbstractScriptMacro#getClassLoader & Co
PermissionCheckerListener * Aborts execution of scripts that need PR if the document is not saved with PR * To distinguish velocity and PR scripts, introduce a new interface PrivilegedScriptMacro extends ScriptMacro and let AbstractJSR223ScriptMacro implement it
NestedScriptMacroValidatorListener * Replaces NestedScriptMacroValidator (ScriptMacroValidator component is removed completely)
The refactoring will remove the following methods (breaks API):
AbstractJSR223ScriptMacro: * protected boolean canExecuteScript() * public List execute(JSR223ScriptMacroParameters, String, MacroTransformationContext)
AbstractScriptMacro: * protected boolean canHaveJarsParameters() * protected ClassLoader getClassLoader(String, ClassLoader)
WDYT?
Alex _______________________________________________ devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs _______________________________________________ devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs
+1 Thanks, Marius On 08/23/2010 12:00 PM, Alex Busenius wrote:
Hello,
I'd like to refactor AbstractScriptMacro in order to be able to change script behavior in the future without fanout violations. Here is the plan emerged after several discussions with ThomasM:
Introduce a notion of cancelable events. Such events can be canceled by the receiver (providing an optional reason), the actual canceling is performed by the sender.
http://dev.xwiki.org/xwiki/bin/view/Design/CancelableEvents
Send a cancelable event ScriptEvaluationStartsEvent in AbstractScriptMacro just before evaluating the script and a ScriptEvaluationFinishedEvent right after evaluation has finished (in finally block).
Add the following 3 listeners to those events (into rendering.internal.macro.script) and move the corresponding code from AbstractScriptMacro there:
ScriptClassLoaderHandlerListener * does class loader manipulations currently performed by AbstractScriptMacro#getClassLoader& Co
PermissionCheckerListener * Aborts execution of scripts that need PR if the document is not saved with PR * To distinguish velocity and PR scripts, introduce a new interface PrivilegedScriptMacro extends ScriptMacro and let AbstractJSR223ScriptMacro implement it
NestedScriptMacroValidatorListener * Replaces NestedScriptMacroValidator (ScriptMacroValidator component is removed completely)
The refactoring will remove the following methods (breaks API):
AbstractJSR223ScriptMacro: * protected boolean canExecuteScript() * public List execute(JSR223ScriptMacroParameters, String, MacroTransformationContext)
AbstractScriptMacro: * protected boolean canHaveJarsParameters() * protected ClassLoader getClassLoader(String, ClassLoader)
WDYT?
Alex _______________________________________________ devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs
Good, if nobody complains, I'll commit the change later today. Thanks, Alex On 08/23/2010 11:00 AM, Alex Busenius wrote:
Hello,
I'd like to refactor AbstractScriptMacro in order to be able to change script behavior in the future without fanout violations. Here is the plan emerged after several discussions with ThomasM:
Introduce a notion of cancelable events. Such events can be canceled by the receiver (providing an optional reason), the actual canceling is performed by the sender.
http://dev.xwiki.org/xwiki/bin/view/Design/CancelableEvents
Send a cancelable event ScriptEvaluationStartsEvent in AbstractScriptMacro just before evaluating the script and a ScriptEvaluationFinishedEvent right after evaluation has finished (in finally block).
Add the following 3 listeners to those events (into rendering.internal.macro.script) and move the corresponding code from AbstractScriptMacro there:
ScriptClassLoaderHandlerListener * does class loader manipulations currently performed by AbstractScriptMacro#getClassLoader & Co
PermissionCheckerListener * Aborts execution of scripts that need PR if the document is not saved with PR * To distinguish velocity and PR scripts, introduce a new interface PrivilegedScriptMacro extends ScriptMacro and let AbstractJSR223ScriptMacro implement it
NestedScriptMacroValidatorListener * Replaces NestedScriptMacroValidator (ScriptMacroValidator component is removed completely)
The refactoring will remove the following methods (breaks API):
AbstractJSR223ScriptMacro: * protected boolean canExecuteScript() * public List execute(JSR223ScriptMacroParameters, String, MacroTransformationContext)
AbstractScriptMacro: * protected boolean canHaveJarsParameters() * protected ClassLoader getClassLoader(String, ClassLoader)
WDYT?
Alex _______________________________________________ devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs
participants (6)
-
Alex Busenius -
Caleb James DeLisle -
Jerome Velociter -
Marius Dumitru Florea -
Sergiu Dumitriu -
Thomas Mortagne