Author: radu Date: Mon Aug 29 16:25:06 2016 New Revision: 1758254 URL: http://svn.apache.org/viewvc?rev=1758254&view=rev Log: SLING-5978 - Make Sightly throw compilation errors when unknown data-sly-* plugins are used
* also improved other runtime errors reporting Modified: sling/trunk/bundles/scripting/sightly/compiler/src/main/java/org/apache/sling/scripting/sightly/compiler/SightlyCompiler.java sling/trunk/bundles/scripting/sightly/compiler/src/main/java/org/apache/sling/scripting/sightly/impl/compiler/PushStream.java sling/trunk/bundles/scripting/sightly/compiler/src/main/java/org/apache/sling/scripting/sightly/impl/compiler/debug/SanityChecker.java sling/trunk/bundles/scripting/sightly/compiler/src/main/java/org/apache/sling/scripting/sightly/impl/compiler/frontend/ExpressionWrapper.java sling/trunk/bundles/scripting/sightly/compiler/src/main/java/org/apache/sling/scripting/sightly/impl/html/dom/MarkupHandler.java sling/trunk/bundles/scripting/sightly/compiler/src/main/java/org/apache/sling/scripting/sightly/impl/plugin/AttributePlugin.java sling/trunk/bundles/scripting/sightly/compiler/src/main/java/org/apache/sling/scripting/sightly/impl/plugin/CallPlugin.java sling/trunk/bundles/scripting/sightly/compiler/src/main/java/org/apache/sling/scripting/sightly/impl/plugin/TemplatePlugin.java Modified: sling/trunk/bundles/scripting/sightly/compiler/src/main/java/org/apache/sling/scripting/sightly/compiler/SightlyCompiler.java URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/sightly/compiler/src/main/java/org/apache/sling/scripting/sightly/compiler/SightlyCompiler.java?rev=1758254&r1=1758253&r2=1758254&view=diff ============================================================================== --- sling/trunk/bundles/scripting/sightly/compiler/src/main/java/org/apache/sling/scripting/sightly/compiler/SightlyCompiler.java (original) +++ sling/trunk/bundles/scripting/sightly/compiler/src/main/java/org/apache/sling/scripting/sightly/compiler/SightlyCompiler.java Mon Aug 29 16:25:06 2016 @@ -145,7 +145,7 @@ public final class SightlyCompiler { backendCompiler.handle(optimizedStream); } frontend.compile(stream, scriptSource); - for (PushStream.Warning w : stream.getWarnings()) { + for (PushStream.StreamMessage w : stream.getWarnings()) { ScriptError warning = getScriptError(scriptSource, w.getCode(), 0, 0, w.getMessage()); compilationResult.getWarnings().add(new CompilerMessageImpl(scriptName, warning.errorMessage, warning.lineNumber, warning .column)); Modified: sling/trunk/bundles/scripting/sightly/compiler/src/main/java/org/apache/sling/scripting/sightly/impl/compiler/PushStream.java URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/sightly/compiler/src/main/java/org/apache/sling/scripting/sightly/impl/compiler/PushStream.java?rev=1758254&r1=1758253&r2=1758254&view=diff ============================================================================== --- sling/trunk/bundles/scripting/sightly/compiler/src/main/java/org/apache/sling/scripting/sightly/impl/compiler/PushStream.java (original) +++ sling/trunk/bundles/scripting/sightly/compiler/src/main/java/org/apache/sling/scripting/sightly/impl/compiler/PushStream.java Mon Aug 29 16:25:06 2016 @@ -21,6 +21,7 @@ package org.apache.sling.scripting.sight import java.util.LinkedList; import java.util.List; +import org.apache.sling.scripting.sightly.compiler.SightlyCompilerException; import org.apache.sling.scripting.sightly.compiler.commands.Command; import org.apache.sling.scripting.sightly.compiler.commands.CommandHandler; import org.apache.sling.scripting.sightly.compiler.commands.CommandStream; @@ -34,7 +35,7 @@ public final class PushStream implements private BroadcastHandler handler = new BroadcastHandler(); private boolean closed; private List<Command> commands = new LinkedList<>(); - private List<Warning> warnings = new LinkedList<>(); + private List<StreamMessage> warnings = new LinkedList<>(); @Override public void addHandler(CommandHandler handler) { @@ -46,7 +47,7 @@ public final class PushStream implements return commands; } - public List<Warning> getWarnings() { + public List<StreamMessage> getWarnings() { return warnings; } @@ -85,15 +86,15 @@ public final class PushStream implements this.handler.onDone(); } - public void write(Warning warning) { + public void warn(StreamMessage warning) { warnings.add(warning); } - public static class Warning { + public static class StreamMessage { private String message; private String code; - public Warning(String message, String code) { + public StreamMessage(String message, String code) { this.message = message; this.code = code; } Modified: sling/trunk/bundles/scripting/sightly/compiler/src/main/java/org/apache/sling/scripting/sightly/impl/compiler/debug/SanityChecker.java URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/sightly/compiler/src/main/java/org/apache/sling/scripting/sightly/impl/compiler/debug/SanityChecker.java?rev=1758254&r1=1758253&r2=1758254&view=diff ============================================================================== --- sling/trunk/bundles/scripting/sightly/compiler/src/main/java/org/apache/sling/scripting/sightly/impl/compiler/debug/SanityChecker.java (original) +++ sling/trunk/bundles/scripting/sightly/compiler/src/main/java/org/apache/sling/scripting/sightly/impl/compiler/debug/SanityChecker.java Mon Aug 29 16:25:06 2016 @@ -20,6 +20,7 @@ package org.apache.sling.scripting.sight import java.util.Stack; +import org.apache.sling.scripting.sightly.compiler.SightlyCompilerException; import org.apache.sling.scripting.sightly.compiler.commands.AbstractCommandVisitor; import org.apache.sling.scripting.sightly.compiler.commands.Command; import org.apache.sling.scripting.sightly.compiler.commands.CommandHandler; @@ -55,7 +56,7 @@ public final class SanityChecker extends @Override public void onError(String errorMessage) { - throw new RuntimeException(errorMessage); + throw new SightlyCompilerException(errorMessage); } @Override Modified: sling/trunk/bundles/scripting/sightly/compiler/src/main/java/org/apache/sling/scripting/sightly/impl/compiler/frontend/ExpressionWrapper.java URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/sightly/compiler/src/main/java/org/apache/sling/scripting/sightly/impl/compiler/frontend/ExpressionWrapper.java?rev=1758254&r1=1758253&r2=1758254&view=diff ============================================================================== --- sling/trunk/bundles/scripting/sightly/compiler/src/main/java/org/apache/sling/scripting/sightly/impl/compiler/frontend/ExpressionWrapper.java (original) +++ sling/trunk/bundles/scripting/sightly/compiler/src/main/java/org/apache/sling/scripting/sightly/impl/compiler/frontend/ExpressionWrapper.java Mon Aug 29 16:25:06 2016 @@ -61,7 +61,7 @@ public class ExpressionWrapper { //context must not be calculated by merging options.remove(Syntax.CONTEXT_OPTION); } - return new Expression(root, options); + return new Expression(root, options, interpolation.getContent()); } private Expression applyFilters(Expression expression, ExpressionContext expressionContext) { Modified: sling/trunk/bundles/scripting/sightly/compiler/src/main/java/org/apache/sling/scripting/sightly/impl/html/dom/MarkupHandler.java URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/sightly/compiler/src/main/java/org/apache/sling/scripting/sightly/impl/html/dom/MarkupHandler.java?rev=1758254&r1=1758253&r2=1758254&view=diff ============================================================================== --- sling/trunk/bundles/scripting/sightly/compiler/src/main/java/org/apache/sling/scripting/sightly/impl/html/dom/MarkupHandler.java (original) +++ sling/trunk/bundles/scripting/sightly/compiler/src/main/java/org/apache/sling/scripting/sightly/impl/html/dom/MarkupHandler.java Mon Aug 29 16:25:06 2016 @@ -25,6 +25,7 @@ import java.util.Stack; import org.apache.commons.lang.StringUtils; import org.apache.sling.scripting.sightly.compiler.RuntimeFunction; +import org.apache.sling.scripting.sightly.compiler.SightlyCompilerException; import org.apache.sling.scripting.sightly.compiler.commands.Conditional; import org.apache.sling.scripting.sightly.compiler.commands.OutText; import org.apache.sling.scripting.sightly.compiler.commands.OutputVariable; @@ -363,7 +364,7 @@ public class MarkupHandler { String currentTag = currentElementTag(); String warningMessage = String.format("Element %s requires that all expressions have an explicit context specified. " + "The expression will be replaced with an empty string.", currentTag); - stream.write(new PushStream.Warning(warningMessage, fragment.getExpression().getRawText())); + stream.warn(new PushStream.StreamMessage(warningMessage, fragment.getExpression().getRawText())); addedFragment = new Fragment.Expr(new Expression(StringConstant.EMPTY)); } } @@ -384,7 +385,7 @@ public class MarkupHandler { if (!expression.containsOption(Syntax.CONTEXT_OPTION)) { String warningMessage = String.format("Expressions within the value of attribute %s need to have an explicit context " + "option. The expression will be replaced with an empty string.", attributeName); - stream.write(new PushStream.Warning(warningMessage, expression.getRawText())); + stream.warn(new PushStream.StreamMessage(warningMessage, expression.getRawText())); addedFragment = new Fragment.Text(""); } } @@ -433,7 +434,8 @@ public class MarkupHandler { private Plugin obtainPlugin(String name) { Plugin plugin = pluginRegistry.get(name); if (plugin == null) { - throw new UnsupportedOperationException(String.format("Plugin %s does not exist", name)); + throw new SightlyCompilerException(String.format("None of the registered plugins can handle the data-sly-%s block element.", + name), "data-sly-" + name); } return plugin; } Modified: sling/trunk/bundles/scripting/sightly/compiler/src/main/java/org/apache/sling/scripting/sightly/impl/plugin/AttributePlugin.java URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/sightly/compiler/src/main/java/org/apache/sling/scripting/sightly/impl/plugin/AttributePlugin.java?rev=1758254&r1=1758253&r2=1758254&view=diff ============================================================================== --- sling/trunk/bundles/scripting/sightly/compiler/src/main/java/org/apache/sling/scripting/sightly/impl/plugin/AttributePlugin.java (original) +++ sling/trunk/bundles/scripting/sightly/compiler/src/main/java/org/apache/sling/scripting/sightly/impl/plugin/AttributePlugin.java Mon Aug 29 16:25:06 2016 @@ -63,7 +63,7 @@ public class AttributePlugin extends Abs String attributeName = decodeAttributeName(callInfo); if (attributeName != null && MarkupUtils.isSensitiveAttribute(attributeName)) { String warningMessage = String.format("Refusing to generate attribute '%s' for security reasons.", attributeName); - compilerContext.getPushStream().write(new PushStream.Warning(warningMessage, expression.getRawText())); + compilerContext.getPushStream().warn(new PushStream.StreamMessage(warningMessage, expression.getRawText())); return new DefaultPluginInvoke(); //no-op invocation } return (attributeName != null) Modified: sling/trunk/bundles/scripting/sightly/compiler/src/main/java/org/apache/sling/scripting/sightly/impl/plugin/CallPlugin.java URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/sightly/compiler/src/main/java/org/apache/sling/scripting/sightly/impl/plugin/CallPlugin.java?rev=1758254&r1=1758253&r2=1758254&view=diff ============================================================================== --- sling/trunk/bundles/scripting/sightly/compiler/src/main/java/org/apache/sling/scripting/sightly/impl/plugin/CallPlugin.java (original) +++ sling/trunk/bundles/scripting/sightly/compiler/src/main/java/org/apache/sling/scripting/sightly/impl/plugin/CallPlugin.java Mon Aug 29 16:25:06 2016 @@ -39,7 +39,7 @@ public class CallPlugin extends Abstract final PluginCallInfo callInfo, final CompilerContext compilerContext) { if (callInfo.getArguments().length > 0) { - throw new SightlyCompilerException("Call plugin should have no arguments"); + throw new SightlyCompilerException("Call plugin should have no arguments.", "data-sly-call." + callInfo.getArguments()[0]); } return new DefaultPluginInvoke() { Modified: sling/trunk/bundles/scripting/sightly/compiler/src/main/java/org/apache/sling/scripting/sightly/impl/plugin/TemplatePlugin.java URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/sightly/compiler/src/main/java/org/apache/sling/scripting/sightly/impl/plugin/TemplatePlugin.java?rev=1758254&r1=1758253&r2=1758254&view=diff ============================================================================== --- sling/trunk/bundles/scripting/sightly/compiler/src/main/java/org/apache/sling/scripting/sightly/impl/plugin/TemplatePlugin.java (original) +++ sling/trunk/bundles/scripting/sightly/compiler/src/main/java/org/apache/sling/scripting/sightly/impl/plugin/TemplatePlugin.java Mon Aug 29 16:25:06 2016 @@ -84,7 +84,7 @@ public class TemplatePlugin extends Abst private String decodeName() { String[] arguments = callInfo.getArguments(); if (arguments.length == 0) { - throw new SightlyCompilerException("Template name was not provided"); + throw new SightlyCompilerException("Template name was not provided.", "data-sly-template="); } return arguments[0]; }