Permalink
Browse files

rhart JSF plugin - modifications for Insight 1.9.2

  • Loading branch information...
1 parent 7f912aa commit d61f73aec53e1414553acd6c3d8430fcce5b6c74 Shachar Anchelovich committed Dec 3, 2012
Showing with 2,430 additions and 0 deletions.
  1. +137 −0 collection-plugins/jsf/pom.xml
  2. +158 −0 .../main/java/com/springsource/insight/plugin/jsf/AbstractActionListenerOperationCollectionAspect.aj
  3. +28 −0 ...ins/jsf/src/main/java/com/springsource/insight/plugin/jsf/AbstractJSFOperationCollectionAspect.aj
  4. +44 −0 ...ain/java/com/springsource/insight/plugin/jsf/AbstractRestoreViewPhaseOperationCollectionAspect.aj
  5. +37 −0 .../jsf/src/main/java/com/springsource/insight/plugin/jsf/ActionListenerOperationCollectionAspect.aj
  6. +68 −0 ...main/java/com/springsource/insight/plugin/jsf/ApplyRequestValuesPhaseOperationCollectionAspect.aj
  7. +39 −0 .../main/java/com/springsource/insight/plugin/jsf/InvokeApplicationPhaseOperationCollectionAspect.aj
  8. +62 −0 ...tion-plugins/jsf/src/main/java/com/springsource/insight/plugin/jsf/JSFActionEndPointAnalyzer.java
  9. +53 −0 ...ion-plugins/jsf/src/main/java/com/springsource/insight/plugin/jsf/JSFPluginRuntimeDescriptor.java
  10. +48 −0 ...c/main/java/com/springsource/insight/plugin/jsf/MyFacesActionListenerOperationCollectionAspect.aj
  11. +38 −0 ...main/java/com/springsource/insight/plugin/jsf/MyFacesRestoreViewPhaseOperationCollectionAspect.aj
  12. +45 −0 ...f/src/main/java/com/springsource/insight/plugin/jsf/NavigationHandlerOperationCollectionAspect.aj
  13. +49 −0 ...s/jsf/src/main/java/com/springsource/insight/plugin/jsf/PhaseListenerOperationCollectionAspect.aj
  14. +39 −0 ...main/java/com/springsource/insight/plugin/jsf/ProcessValidationsPhaseOperationCollectionAspect.aj
  15. +43 −0 ...src/main/java/com/springsource/insight/plugin/jsf/RenderResponsePhaseOperationCollectionAspect.aj
  16. +59 −0 ...sf/src/main/java/com/springsource/insight/plugin/jsf/RestoreViewPhaseOperationCollectionAspect.aj
  17. +39 −0 .../main/java/com/springsource/insight/plugin/jsf/UpdateModelValuesPhaseOperationCollectionAspect.aj
  18. +47 −0 ...ugins/jsf/src/main/java/com/springsource/insight/plugin/jsf/ValidatorOperationCollectionAspect.aj
  19. +34 −0 collection-plugins/jsf/src/main/resources/META-INF/insight-plugin-jsf.xml
  20. +12 −0 collection-plugins/jsf/src/main/resources/com/springsource/insight/plugin/jsf/action.ftl
  21. +19 −0 ...plugins/jsf/src/main/resources/com/springsource/insight/plugin/jsf/apply_request_values_phase.ftl
  22. +7 −0 ...n-plugins/jsf/src/main/resources/com/springsource/insight/plugin/jsf/invoke_application_phase.ftl
  23. +12 −0 collection-plugins/jsf/src/main/resources/com/springsource/insight/plugin/jsf/navigation.ftl
  24. +13 −0 collection-plugins/jsf/src/main/resources/com/springsource/insight/plugin/jsf/phase_listener.ftl
  25. +7 −0 ...-plugins/jsf/src/main/resources/com/springsource/insight/plugin/jsf/process_validations_phase.ftl
  26. +11 −0 ...tion-plugins/jsf/src/main/resources/com/springsource/insight/plugin/jsf/render_response_phase.ftl
  27. +12 −0 collection-plugins/jsf/src/main/resources/com/springsource/insight/plugin/jsf/restore_view_phase.ftl
  28. +7 −0 ...-plugins/jsf/src/main/resources/com/springsource/insight/plugin/jsf/update_model_values_phase.ftl
  29. +11 −0 collection-plugins/jsf/src/main/resources/com/springsource/insight/plugin/jsf/validator.ftl
  30. +332 −0 ...rc/test/java/com/springsource/insight/plugin/jsf/ActionListenerOperationCollectionAspectTest.java
  31. +69 −0 ...java/com/springsource/insight/plugin/jsf/InvokeApplicationPhaseOperationCollectionAspectTest.java
  32. +68 −0 ...plugins/jsf/src/test/java/com/springsource/insight/plugin/jsf/InvokeApplicationPhaseViewTest.java
  33. +105 −0 ...ection-plugins/jsf/src/test/java/com/springsource/insight/plugin/jsf/JSFEndPointAnalyzerTest.java
  34. +116 −0 ...src/test/java/com/springsource/insight/plugin/jsf/PhaseListenerOperationCollectionAspectTest.java
  35. +72 −0 collection-plugins/jsf/src/test/java/com/springsource/insight/plugin/jsf/PhaseListenerViewTest.java
  36. +69 −0 ...ava/com/springsource/insight/plugin/jsf/ProcessValidationsPhaseOperationCollectionAspectTest.java
  37. +68 −0 ...lugins/jsf/src/test/java/com/springsource/insight/plugin/jsf/ProcessValidationsPhaseViewTest.java
  38. +69 −0 ...java/com/springsource/insight/plugin/jsf/UpdateModelValuesPhaseOperationCollectionAspectTest.java
  39. +68 −0 ...plugins/jsf/src/test/java/com/springsource/insight/plugin/jsf/UpdateModelValuesPhaseViewTest.java
  40. +81 −0 ...jsf/src/test/java/com/springsource/insight/plugin/jsf/ValidatorOperationCollectionAspectTest.java
  41. +74 −0 collection-plugins/jsf/src/test/java/com/springsource/insight/plugin/jsf/ValidatorViewTest.java
  42. +17 −0 collection-plugins/jsf/src/test/resources/META-INF/test-app-context.xml
  43. +1 −0 collection-plugins/pom.xml
  44. +43 −0 parent/pom.xml
@@ -0,0 +1,137 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>com.springsource.insight.plugins</groupId>
+ <artifactId>insight-plugin-jsf</artifactId>
+ <version>1.9.2-CI-SNAPSHOT</version>
+ <name>com.springsource.insight.plugins:insight-plugin-jsf</name>
+ <packaging>jar</packaging>
+
+ <parent>
+ <groupId>com.springsource.insight</groupId>
+ <artifactId>community-plugins</artifactId>
+ <version>1.9.2-CI-SNAPSHOT</version>
+ <relativePath>..</relativePath>
+ </parent>
+
+ <dependencies>
+ <!-- Provided dependencies (part of the user application) -->
+ <dependency>
+ <groupId>javax.el</groupId>
+ <artifactId>javax.el-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>com.sun.faces</groupId>
+ <artifactId>jsf-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>com.sun.faces</groupId>
+ <artifactId>jsf-impl</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.myfaces.core</groupId>
+ <artifactId>myfaces-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.myfaces.core</groupId>
+ <artifactId>myfaces-impl</artifactId>
+ <scope>provided</scope>
+ </dependency>
+
+ <!-- Test dependencies -->
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-all</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.powermock</groupId>
+ <artifactId>powermock-module-junit4</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.powermock</groupId>
+ <artifactId>powermock-api-mockito</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-test</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>commons-logging</groupId>
+ <artifactId>commons-logging</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-webmvc</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-context-support</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.freemarker</groupId>
+ <artifactId>freemarker</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-jcl</artifactId>
+ <version>1.5.5</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.aspectj</groupId>
+ <artifactId>aspectjweaver</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jar-plugin</artifactId>
+ <configuration>
+ <archive>
+ <manifest>
+ <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
+ </manifest>
+ <manifestEntries>
+ <Insight-Plugin-Descriptor>com.springsource.insight.plugin.jsf.JSFPluginRuntimeDescriptor</Insight-Plugin-Descriptor>
+ </manifestEntries>
+ </archive>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>com.mycila.maven-license-plugin</groupId>
+ <artifactId>maven-license-plugin</artifactId>
+ <configuration>
+ <header>../../aslHeader.txt</header>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+
+</project>
@@ -0,0 +1,158 @@
+/**
+ * Copyright (c) 2009-2011 VMware, Inc. All Rights Reserved.
+ *
+ * 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 com.springsource.insight.plugin.jsf;
+
+import javax.el.ELContext;
+import javax.el.MethodExpression;
+import javax.el.MethodInfo;
+import javax.el.ValueExpression;
+import javax.faces.component.ActionSource;
+import javax.faces.component.ActionSource2;
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.el.MethodBinding;
+import javax.faces.event.ActionEvent;
+import javax.faces.event.MethodExpressionActionListener;
+
+import org.aspectj.lang.JoinPoint;
+
+import com.springsource.insight.intercept.operation.Operation;
+import com.springsource.insight.intercept.operation.OperationType;
+
+
+@SuppressWarnings("deprecation")
+public abstract aspect AbstractActionListenerOperationCollectionAspect extends AbstractJSFOperationCollectionAspect {
+
+ static final OperationType TYPE = OperationType.valueOf("jsf_action_listener_operation");
+
+ @Override
+ protected Operation createOperation(JoinPoint jp) {
+ ActionEvent actionEvent = (ActionEvent) jp.getArgs()[0];
+
+ FacesContext ctx = FacesContext.getCurrentInstance();
+ ELContext elContext = ctx.getELContext();
+
+ String fromAction = null;
+ MethodInfo methodInfo = null;
+ MethodExpression methodExpression = null;
+
+ if (jp.getTarget() instanceof MethodExpressionActionListener) {
+ MethodExpressionActionListener listener = (MethodExpressionActionListener) jp.getTarget();
+ Object state = listener.saveState(ctx);
+ if (state == null) {
+ state = loadState(ctx, listener);
+ }
+ if (state instanceof Object[]) {
+ Object[] expressions = (Object[]) state;
+ if (expressions.length > 0 && expressions[0] instanceof MethodExpression) {
+ methodExpression = (MethodExpression) expressions[0];
+ fromAction = methodExpression.getExpressionString();
+ methodInfo = methodExpression.getMethodInfo(elContext);
+ }
+ }
+ } else {
+ UIComponent component = actionEvent.getComponent();
+
+ if (component instanceof ActionSource2) {
+ // Must be an instance of ActionSource2, so don't look on action
+ // if the actionExpression is set
+ methodExpression = ((ActionSource2) component).getActionExpression();
+ if (methodExpression != null && !methodExpression.isLiteralText()) {
+ fromAction = methodExpression.getExpressionString();
+ methodInfo = methodExpression.getMethodInfo(elContext);
+ }
+ }
+ if (methodExpression == null && component instanceof ActionSource) {
+ // Backwards compatibility for pre-1.2.
+ MethodBinding methodBinding = ((ActionSource) component).getAction();
+ if (methodBinding != null && methodBinding.getExpressionString() != null
+ && methodBinding.getExpressionString().startsWith("#{")) {
+ fromAction = methodBinding.getExpressionString();
+ methodInfo = new MethodInfo(getBeanMethodName(fromAction), methodBinding.getType(ctx), null);
+ }
+ }
+ }
+
+ if (fromAction == null) {
+ fromAction = "No Action";
+ }
+
+ StringBuilder label = new StringBuilder("JSF Action [");
+ label.append(fromAction);
+ label.append("]");
+ Operation operation = super.createOperation(jp).type(TYPE).label(label.toString());
+ if (fromAction != null) {
+ Class<?> implementationClass = getBeanClass(ctx, elContext, fromAction);
+ operation.put("implementationClass", implementationClass != null ? implementationClass.getName() : "unknown")
+ .put("implementationClassMethod", methodInfo != null ? methodInfo.getName() : "unknown")
+ .put("implementationClassMethodSignature", methodInfo != null ? getBeanMethodSignature(methodInfo) : "unknown()")
+ .put("fromAction", fromAction);
+ }
+ return operation;
+ }
+
+ protected abstract Object loadState(FacesContext ctx, MethodExpressionActionListener listener);
+
+ protected Class<?> getBeanClass(FacesContext ctx, ELContext elContext, String expression) {
+ Class<?> toReturn = null;
+ int index = expression.lastIndexOf('.');
+
+ if (index > -1) {
+ String beanName = expression.substring(0, index);
+ ValueExpression valueExpression = ctx.getApplication().getExpressionFactory().createValueExpression(elContext, beanName + "}", Object.class);
+ Object bean = valueExpression.getValue(elContext);
+ toReturn = bean != null ? bean.getClass() : null;
+ }
+
+ return toReturn;
+ }
+
+ protected String getBeanMethodName(String expression) {
+ String result = null;
+ int index = expression.lastIndexOf('.');
+ if (index > -1) {
+ result = expression.substring(index + 1, expression.length() - 1);
+ }
+ return result;
+ }
+
+ protected String getBeanMethodSignature(MethodInfo methodInfo) {
+ StringBuilder result = new StringBuilder();
+ if (methodInfo.getReturnType() != null) {
+ result.append(methodInfo.getReturnType().getSimpleName());
+ } else {
+ result.append("void");
+ }
+ result.append(" ");
+ result.append(methodInfo.getName());
+ result.append("(");
+ if (methodInfo.getParamTypes() != null && methodInfo.getParamTypes().length > 0) {
+ for (int i = 0; i < methodInfo.getParamTypes().length; i++) {
+ result.append(methodInfo.getParamTypes()[i].getSimpleName());
+ if (i < methodInfo.getParamTypes().length - 1) {
+ result.append(",");
+ }
+ }
+ }
+ result.append(")");
+ return result.toString();
+ }
+
+ @Override
+ public boolean isEndpoint() {
+ return true;
+ }
+}
@@ -0,0 +1,28 @@
+/**
+ * Copyright (c) 2009-2011 VMware, Inc. All Rights Reserved.
+ *
+ * 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 com.springsource.insight.plugin.jsf;
+
+import com.springsource.insight.collection.method.MethodOperationCollectionAspect;
+
+
+public abstract aspect AbstractJSFOperationCollectionAspect extends MethodOperationCollectionAspect {
+
+ @Override
+ public String getPluginName() {
+ return JSFPluginRuntimeDescriptor.PLUGIN_NAME;
+ }
+
+}
@@ -0,0 +1,44 @@
+/**
+ * Copyright (c) 2009-2011 VMware, Inc. All Rights Reserved.
+ *
+ * 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 com.springsource.insight.plugin.jsf;
+
+import javax.faces.context.FacesContext;
+
+import org.aspectj.lang.JoinPoint;
+
+import com.springsource.insight.intercept.operation.Operation;
+import com.springsource.insight.intercept.operation.OperationType;
+
+public abstract aspect AbstractRestoreViewPhaseOperationCollectionAspect extends AbstractJSFOperationCollectionAspect {
+
+ static final OperationType TYPE = OperationType
+ .valueOf("restore_view_phase_operation");
+
+ @Override
+ protected Operation createOperation(JoinPoint jp) {
+ FacesContext facesContext = (FacesContext) jp.getArgs()[0];
+ String viewId = calculateViewId(facesContext);
+
+ StringBuilder label = new StringBuilder("JSF Restore View Phase [");
+ label.append(viewId);
+ label.append("]");
+ return super.createOperation(jp).type(TYPE).label(label.toString())
+ .put("viewId", viewId)
+ .put("isPostBack", facesContext.isPostback());
+ }
+
+ protected abstract String calculateViewId(FacesContext facesContext);
+}
Oops, something went wrong. Retry.

0 comments on commit d61f73a

Please sign in to comment.