You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tapestry.apache.org by hl...@apache.org on 2012/01/26 18:33:30 UTC
svn commit: r1236311 - in /tapestry/tapestry5/trunk/tapestry-core/src:
main/java/org/apache/tapestry5/internal/transform/
main/java/org/apache/tapestry5/services/
test/groovy/org/apache/tapestry5/integration/app1/
test/java/org/apache/tapestry5/integra...
Author: hlship
Date: Thu Jan 26 17:33:29 2012
New Revision: 1236311
URL: http://svn.apache.org/viewvc?rev=1236311&view=rev
Log:
TAP5-1168: Add @Operation annotation that can be used to automatically track a component or service method invocation using the OperationTracker
Added:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/OperationWorker.java
tapestry/tapestry5/trunk/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/app1/MiscTests.groovy
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/OperationWorkerDemo.java
tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/integration/app1/pages/OperationWorkerDemo.tml
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/TapestryModule.java
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/Index.java
Added: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/OperationWorker.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/OperationWorker.java?rev=1236311&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/OperationWorker.java (added)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/OperationWorker.java Thu Jan 26 17:33:29 2012
@@ -0,0 +1,47 @@
+// Copyright 2012 The Apache Software Foundation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package org.apache.tapestry5.internal.transform;
+
+import org.apache.tapestry5.ioc.annotations.Operation;
+import org.apache.tapestry5.ioc.services.OperationAdvisor;
+import org.apache.tapestry5.model.MutableComponentModel;
+import org.apache.tapestry5.plastic.PlasticClass;
+import org.apache.tapestry5.plastic.PlasticMethod;
+import org.apache.tapestry5.services.transform.ComponentClassTransformWorker2;
+import org.apache.tapestry5.services.transform.TransformationSupport;
+
+/**
+ * Add support for the {@link org.apache.tapestry5.ioc.annotations.Operation} annotation on component class methods.
+ */
+public class OperationWorker implements ComponentClassTransformWorker2
+{
+ private final OperationAdvisor advisor;
+
+ public OperationWorker(OperationAdvisor advisor)
+ {
+ this.advisor = advisor;
+ }
+
+ @Override
+ public void transform(PlasticClass plasticClass, TransformationSupport support, MutableComponentModel model)
+ {
+ for (PlasticMethod method : plasticClass.getMethodsWithAnnotation(Operation.class))
+ {
+ Operation annotation = method.getAnnotation(Operation.class);
+
+ method.addAdvice(advisor.createAdvice(annotation.value()));
+ }
+ }
+}
Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/TapestryModule.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/TapestryModule.java?rev=1236311&r1=1236310&r2=1236311&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/TapestryModule.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/TapestryModule.java Thu Jan 26 17:33:29 2012
@@ -560,6 +560,7 @@ public final class TapestryModule
* <dt>Inject</dt>
* <dd>Used with the {@link org.apache.tapestry5.ioc.annotations.Inject} annotation, when a value is supplied</dd>
* </dl>
+ * <dd>Operation</dt> <dd>Support for the {@link Operation} method annotation</dd></dd>
*/
@Contribute(ComponentClassTransformWorker2.class)
@Primary
@@ -570,6 +571,10 @@ public final class TapestryModule
{
configuration.add("Property", new PropertyWorker());
+ // Order this one pretty early:
+
+ configuration.addInstance("Operation", OperationWorker.class);
+
configuration.add("RenderCommand", new RenderCommandWorker());
configuration.addInstance("OnEvent", OnEventWorker.class);
@@ -1534,7 +1539,6 @@ public final class TapestryModule
* A wrapper around {@link org.apache.tapestry5.internal.services.PageRenderQueue} used for
* partial page renders.
* Supports an ordered configuration of {@link org.apache.tapestry5.services.PartialMarkupRendererFilter}s.
- *
*/
public PartialMarkupRenderer buildPartialMarkupRenderer(Logger logger,
List<PartialMarkupRendererFilter> configuration, @Autobuild
Added: tapestry/tapestry5/trunk/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/app1/MiscTests.groovy
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/app1/MiscTests.groovy?rev=1236311&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/app1/MiscTests.groovy (added)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/app1/MiscTests.groovy Thu Jan 26 17:33:29 2012
@@ -0,0 +1,18 @@
+package org.apache.tapestry5.integration.app1
+
+import org.apache.tapestry5.integration.TapestryCoreTestCase
+import org.apache.tapestry5.test.TapestryTestConfiguration
+import org.testng.annotations.Test
+
+@TapestryTestConfiguration(webAppFolder = "src/test/app1")
+class MiscTests extends TapestryCoreTestCase {
+
+ @Test
+ void operation_tracking_via_annotation() {
+ openLinks "Operation Worker Demo", "throw exception"
+
+ assertTitle "Application Exception"
+
+ assertTextPresent "[Operation Description]"
+ }
+}
Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/Index.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/Index.java?rev=1236311&r1=1236310&r2=1236311&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/Index.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/Index.java Thu Jan 26 17:33:29 2012
@@ -1,4 +1,4 @@
-// Copyright 2006, 2007, 2008, 2009, 2010, 2011 The Apache Software Foundation
+// Copyright 2006, 2007, 2008, 2009, 2010, 2011, 2012 The Apache Software Foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -57,6 +57,8 @@ public class Index
private static final List<Item> ITEMS = CollectionFactory
.newList(
+ new Item("OperationWorkerDemo", "Operation Worker Demo", "Demonstrate use of @Operation annotation on component methods"),
+
new Item("MixinParameterDefault", "Mixin Parameter with Default", "Ensure that a mixin parameter with a default value is not reported as unbound."),
new Item("MixinVsInformalParameter", "Mixin Parameter vs. Informal Parameter", "Informal Paramters vs. Mixin parameter of same name"),
Added: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/OperationWorkerDemo.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/OperationWorkerDemo.java?rev=1236311&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/OperationWorkerDemo.java (added)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/OperationWorkerDemo.java Thu Jan 26 17:33:29 2012
@@ -0,0 +1,12 @@
+package org.apache.tapestry5.integration.app1.pages;
+
+import org.apache.tapestry5.ioc.annotations.Operation;
+
+public class OperationWorkerDemo
+{
+ @Operation("[Operation Description]")
+ void onActionFromThrowException()
+ {
+ throw new RuntimeException("An exception inside an operation tracked method.");
+ }
+}
Added: tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/integration/app1/pages/OperationWorkerDemo.tml
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/integration/app1/pages/OperationWorkerDemo.tml?rev=1236311&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/integration/app1/pages/OperationWorkerDemo.tml (added)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/integration/app1/pages/OperationWorkerDemo.tml Thu Jan 26 17:33:29 2012
@@ -0,0 +1,12 @@
+<html t:type="Border" xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd">
+ <h1>Operation Worker Demo</h1>
+
+
+ <p>
+ Click
+ <t:actionlink t:id="throwException">throw exception</t:actionlink>
+ for an exception inside an operation tracked component method.
+ </p>
+
+
+</html>