You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ra...@apache.org on 2018/08/22 13:04:10 UTC
[sling-org-apache-sling-scripting-sightly] branch
experimental-scripting-resolver updated: optimised bindings handling and
handling of precompiled RenderUnit
This is an automated email from the ASF dual-hosted git repository.
radu pushed a commit to branch experimental-scripting-resolver
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-scripting-sightly.git
The following commit(s) were added to refs/heads/experimental-scripting-resolver by this push:
new b9dd154 optimised bindings handling and handling of precompiled RenderUnit
b9dd154 is described below
commit b9dd154880443c45a84d2a8ad60eb589cbcb831a
Author: Radu Cotescu <ra...@apache.org>
AuthorDate: Wed Aug 22 15:03:02 2018 +0200
optimised bindings handling and handling of precompiled RenderUnit
---
.../sightly/impl/engine/SightlyCompiledScript.java | 2 +-
.../sightly/impl/engine/SightlyScriptEngine.java | 60 +++++++++-------------
2 files changed, 25 insertions(+), 37 deletions(-)
diff --git a/src/main/java/org/apache/sling/scripting/sightly/impl/engine/SightlyCompiledScript.java b/src/main/java/org/apache/sling/scripting/sightly/impl/engine/SightlyCompiledScript.java
index cf2c9ea..c0ddbaf 100644
--- a/src/main/java/org/apache/sling/scripting/sightly/impl/engine/SightlyCompiledScript.java
+++ b/src/main/java/org/apache/sling/scripting/sightly/impl/engine/SightlyCompiledScript.java
@@ -45,7 +45,7 @@ public class SightlyCompiledScript extends CompiledScript {
}
@Override
- public Object eval(ScriptContext context) throws ScriptException {
+ public Object eval(ScriptContext context) {
Bindings bindings = context.getBindings(ScriptContext.ENGINE_SCOPE);
SlingBindings slingBindings = new SlingBindings();
slingBindings.putAll(bindings);
diff --git a/src/main/java/org/apache/sling/scripting/sightly/impl/engine/SightlyScriptEngine.java b/src/main/java/org/apache/sling/scripting/sightly/impl/engine/SightlyScriptEngine.java
index 1a9fb03..8c5e9ed 100644
--- a/src/main/java/org/apache/sling/scripting/sightly/impl/engine/SightlyScriptEngine.java
+++ b/src/main/java/org/apache/sling/scripting/sightly/impl/engine/SightlyScriptEngine.java
@@ -92,22 +92,17 @@ public class SightlyScriptEngine extends AbstractSlingScriptEngine implements Co
@Override
public Object eval(Reader reader, ScriptContext scriptContext) throws ScriptException {
checkArguments(reader, scriptContext);
- Bindings bindings = scriptContext.getBindings(ScriptContext.ENGINE_SCOPE);
- SlingBindings slingBindings = new SlingBindings();
- slingBindings.putAll(bindings);
- final SlingHttpServletRequest request = slingBindings.getRequest();
- if (request == null) {
- throw new SightlyException("Missing SlingHttpServletRequest from ScriptContext.");
- }
- final Object oldValue = request.getAttribute(SlingBindings.class.getName());
try {
- request.setAttribute(SlingBindings.class.getName(), slingBindings);
- SightlyCompiledScript compiledScript = internalCompile(reader, scriptContext);
+ Object renderUnit = scriptContext.getAttribute("precompiled.unit", SlingScriptConstants.SLING_SCOPE);
+ SightlyCompiledScript compiledScript;
+ if (renderUnit instanceof RenderUnit) {
+ compiledScript = new SightlyCompiledScript(this, (RenderUnit) renderUnit);
+ } else {
+ compiledScript = internalCompile(reader, scriptContext);
+ }
return compiledScript.eval(scriptContext);
} catch (Exception e) {
throw new ScriptException(e);
- } finally {
- request.setAttribute(SlingBindings.class.getName(), oldValue);
}
}
@@ -134,34 +129,27 @@ public class SightlyScriptEngine extends AbstractSlingScriptEngine implements Co
return script;
}
};
- Object renderUnit = null;
+ JavaClassBackendCompiler javaClassBackendCompiler = new JavaClassBackendCompiler(importsAnalyser);
+ GlobalShadowCheckBackendCompiler shadowCheckBackendCompiler = null;
if (scriptContext != null) {
- renderUnit = scriptContext.getAttribute("precompiled.unit", SlingScriptConstants.SLING_SCOPE);
+ Bindings bindings = scriptContext.getBindings(ScriptContext.ENGINE_SCOPE);
+ Set<String> globals = bindings.keySet();
+ shadowCheckBackendCompiler = new GlobalShadowCheckBackendCompiler(javaClassBackendCompiler, globals);
}
- if (renderUnit == null) {
- JavaClassBackendCompiler javaClassBackendCompiler = new JavaClassBackendCompiler(importsAnalyser);
- GlobalShadowCheckBackendCompiler shadowCheckBackendCompiler = null;
- if (scriptContext != null) {
- Bindings bindings = scriptContext.getBindings(ScriptContext.ENGINE_SCOPE);
- Set<String> globals = bindings.keySet();
- shadowCheckBackendCompiler = new GlobalShadowCheckBackendCompiler(javaClassBackendCompiler, globals);
- }
- CompilationResult result = shadowCheckBackendCompiler == null ? sightlyCompiler.compile(compilationUnit,
- javaClassBackendCompiler) : sightlyCompiler.compile(compilationUnit, shadowCheckBackendCompiler);
- if (result.getWarnings().size() > 0) {
- for (CompilerMessage warning : result.getWarnings()) {
- LOGGER.warn("Script {} {}:{}: {}", warning.getScriptName(), warning.getLine(), warning.getColumn(),
- warning.getMessage());
- }
+ CompilationResult result = shadowCheckBackendCompiler == null ? sightlyCompiler.compile(compilationUnit,
+ javaClassBackendCompiler) : sightlyCompiler.compile(compilationUnit, shadowCheckBackendCompiler);
+ if (result.getWarnings().size() > 0) {
+ for (CompilerMessage warning : result.getWarnings()) {
+ LOGGER.warn("Script {} {}:{}: {}", warning.getScriptName(), warning.getLine(), warning.getColumn(), warning.getMessage());
}
- if (result.getErrors().size() > 0) {
- CompilerMessage error = result.getErrors().get(0);
- throw new ScriptException(error.getMessage(), error.getScriptName(), error.getLine(), error.getColumn());
- }
- SourceIdentifier sourceIdentifier = new SourceIdentifier(configuration, scriptName);
- String javaSourceCode = javaClassBackendCompiler.build(sourceIdentifier);
- renderUnit = javaCompilerService.compileSource(sourceIdentifier, javaSourceCode);
}
+ if (result.getErrors().size() > 0) {
+ CompilerMessage error = result.getErrors().get(0);
+ throw new ScriptException(error.getMessage(), error.getScriptName(), error.getLine(), error.getColumn());
+ }
+ SourceIdentifier sourceIdentifier = new SourceIdentifier(configuration, scriptName);
+ String javaSourceCode = javaClassBackendCompiler.build(sourceIdentifier);
+ Object renderUnit = javaCompilerService.compileSource(sourceIdentifier, javaSourceCode);
if (renderUnit instanceof RenderUnit) {
return new SightlyCompiledScript(this, (RenderUnit) renderUnit);
} else {