Author: julien_viet
Date: 2009-11-01 17:40:14 -0500 (Sun, 01 Nov 2009)
New Revision: 469
Modified:
portal/branches/performance/component/scripting/src/main/java/org/exoplatform/groovyscript/GroovyScript.java
portal/branches/performance/component/scripting/src/main/java/org/exoplatform/groovyscript/GroovyTemplate.java
portal/branches/performance/component/scripting/src/main/java/org/exoplatform/groovyscript/TemplateSection.java
portal/branches/performance/component/scripting/src/test/java/org/exoplatform/groovyscript/TestTemplateParser.java
portal/branches/performance/component/scripting/src/test/java/org/exoplatform/groovyscript/TestTemplateRendering.java
Log:
actually rewrite the full nested stack trace with script element when possible
Modified:
portal/branches/performance/component/scripting/src/main/java/org/exoplatform/groovyscript/GroovyScript.java
===================================================================
---
portal/branches/performance/component/scripting/src/main/java/org/exoplatform/groovyscript/GroovyScript.java 2009-11-01
13:58:21 UTC (rev 468)
+++
portal/branches/performance/component/scripting/src/main/java/org/exoplatform/groovyscript/GroovyScript.java 2009-11-01
22:40:14 UTC (rev 469)
@@ -84,8 +84,7 @@
}
else
{
- TextItem textItem = findOut(e);
- throw new TemplateRuntimeException(textItem, e);
+ throw buildRuntimeException(e);
}
}
catch (Throwable e)
@@ -94,30 +93,54 @@
{
throw ((Error)e);
}
- TextItem textItem = findOut(e);
- throw new TemplateRuntimeException(textItem, e);
+ throw buildRuntimeException(e);
}
//
script.flush();
}
- private TextItem findOut(Throwable t)
+ private TemplateRuntimeException buildRuntimeException(Throwable t)
{
- StackTraceElement[] elements = t.getStackTrace();
+ StackTraceElement[] trace = t.getStackTrace();
- // The index of the script based on the current stack trace
- int index = elements.length - Thread.currentThread().getStackTrace().length + 1;
+ //
+ TextItem firstItem = null;
- // Try to find the groovy script line
- if (index >= 0 && index < elements.length)
+ // Try to find the groovy script lines
+ for (int i = 0;i < trace.length;i++)
{
- int groovyLineNumber = elements[index].getLineNumber();
- return lineTable.get(groovyLineNumber);
+ StackTraceElement element = trace[i];
+ if (element.getClassName().equals(scriptClass.getName()))
+ {
+ int lineNumber = element.getLineNumber();
+ TextItem item = lineTable.get(lineNumber);
+ int templateLineNumber;
+ if (item != null)
+ {
+ templateLineNumber = item.getPosition().getLine();
+ if (firstItem == null)
+ {
+ firstItem = item;
+ }
+ }
+ else
+ {
+ templateLineNumber = -1;
+ }
+ element = new StackTraceElement(
+ element.getClassName(),
+ element.getMethodName(),
+ element.getFileName(),
+ templateLineNumber);
+ trace[i] = element;
+ }
}
- else
- {
- return null;
- }
+
+ //
+ t.setStackTrace(trace);
+
+ //
+ return new TemplateRuntimeException(firstItem, t);
}
}
Modified:
portal/branches/performance/component/scripting/src/main/java/org/exoplatform/groovyscript/GroovyTemplate.java
===================================================================
---
portal/branches/performance/component/scripting/src/main/java/org/exoplatform/groovyscript/GroovyTemplate.java 2009-11-01
13:58:21 UTC (rev 468)
+++
portal/branches/performance/component/scripting/src/main/java/org/exoplatform/groovyscript/GroovyTemplate.java 2009-11-01
22:40:14 UTC (rev 469)
@@ -89,6 +89,11 @@
return name;
}
+ public String getClassName()
+ {
+ return script.getScriptClass().getName();
+ }
+
public String getTemplateText()
{
return templateText;
Modified:
portal/branches/performance/component/scripting/src/main/java/org/exoplatform/groovyscript/TemplateSection.java
===================================================================
---
portal/branches/performance/component/scripting/src/main/java/org/exoplatform/groovyscript/TemplateSection.java 2009-11-01
13:58:21 UTC (rev 468)
+++
portal/branches/performance/component/scripting/src/main/java/org/exoplatform/groovyscript/TemplateSection.java 2009-11-01
22:40:14 UTC (rev 469)
@@ -75,7 +75,7 @@
//
from = to + 1;
lineNumber++;
- colNumber = 0;
+ colNumber = 1;
}
else
{
Modified:
portal/branches/performance/component/scripting/src/test/java/org/exoplatform/groovyscript/TestTemplateParser.java
===================================================================
---
portal/branches/performance/component/scripting/src/test/java/org/exoplatform/groovyscript/TestTemplateParser.java 2009-11-01
13:58:21 UTC (rev 468)
+++
portal/branches/performance/component/scripting/src/test/java/org/exoplatform/groovyscript/TestTemplateParser.java 2009-11-01
22:40:14 UTC (rev 469)
@@ -112,11 +112,11 @@
public void testPosition() throws IOException
{
List<TemplateSection> sections = parser.parse("a\nb<%= foo
%>d");
- assertEquals(new Position(0, 0), sections.get(0).getItems().get(0).getPosition());
- assertEquals(new Position(1, 0), sections.get(0).getItems().get(1).getPosition());
- assertEquals(new Position(0, 1), sections.get(0).getItems().get(2).getPosition());
- assertEquals(new Position(4, 1), sections.get(1).getItems().get(0).getPosition());
- assertEquals(new Position(11, 1),
sections.get(2).getItems().get(0).getPosition());
+ assertEquals(new Position(1, 1), sections.get(0).getItems().get(0).getPosition());
+ assertEquals(new Position(2, 1), sections.get(0).getItems().get(1).getPosition());
+ assertEquals(new Position(1, 2), sections.get(0).getItems().get(2).getPosition());
+ assertEquals(new Position(5, 2), sections.get(1).getItems().get(0).getPosition());
+ assertEquals(new Position(12, 2),
sections.get(2).getItems().get(0).getPosition());
}
}
Modified:
portal/branches/performance/component/scripting/src/test/java/org/exoplatform/groovyscript/TestTemplateRendering.java
===================================================================
---
portal/branches/performance/component/scripting/src/test/java/org/exoplatform/groovyscript/TestTemplateRendering.java 2009-11-01
13:58:21 UTC (rev 468)
+++
portal/branches/performance/component/scripting/src/test/java/org/exoplatform/groovyscript/TestTemplateRendering.java 2009-11-01
22:40:14 UTC (rev 469)
@@ -246,15 +246,26 @@
private void assertLineNumber(int expectedLineNumber, String expectedText, String
script) throws TemplateCompilationException, IOException
{
+ GroovyTemplate template = new GroovyTemplate(script);
try
{
- new GroovyTemplate(script).render();
+ template.render();
fail();
}
catch (TemplateRuntimeException t)
{
assertEquals(expectedText, t.getText());
assertEquals(expectedLineNumber, (Object)t.getLineNumber());
+ StackTraceElement scriptElt = null;
+ for (StackTraceElement elt : t.getCause().getStackTrace())
+ {
+ if (elt.getClassName().equals(template.getClassName()))
+ {
+ scriptElt = elt;
+ break;
+ }
+ }
+ assertEquals(expectedLineNumber, scriptElt.getLineNumber());
}
}