This is an automated email from the ASF dual-hosted git repository.

remm pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/tomcat.git


The following commit(s) were added to refs/heads/master by this push:
     new 5474fd4  JSP compatibility testing for Graal
5474fd4 is described below

commit 5474fd4faa5f7fe4bebf466d41d2e591de062311
Author: remm <r...@apache.org>
AuthorDate: Tue Jul 9 18:44:10 2019 +0200

    JSP compatibility testing for Graal
    
    The JSP runtime library needed "equivalent" simpler reflection code to
    work with Graal as java.beans.Introspector.getBeanInfo doesn't work for
    me. This will likely lead to some limitations for JSPs.
    Also add an Ant script to precompile JSPs and package them. The script
    uses a dependency on target/tomcat-maven-1.0.jar which is cyclic, for
    convenience (mvn package, precompile, mvn clean, mvn package again).
---
 .../apache/jasper/runtime/JspRuntimeLibrary.java   | 133 +++++++++++++++------
 res/tomcat-maven/graal-webapp.ant.xml              |  49 ++++++++
 2 files changed, 143 insertions(+), 39 deletions(-)

diff --git a/java/org/apache/jasper/runtime/JspRuntimeLibrary.java 
b/java/org/apache/jasper/runtime/JspRuntimeLibrary.java
index a44c046..cc8416b 100644
--- a/java/org/apache/jasper/runtime/JspRuntimeLibrary.java
+++ b/java/org/apache/jasper/runtime/JspRuntimeLibrary.java
@@ -56,6 +56,22 @@ import org.apache.tomcat.InstanceManager;
  */
 public class JspRuntimeLibrary {
 
+    private static final boolean GRAAL;
+
+    static {
+        boolean result = false;
+        try {
+            Class<?> nativeImageClazz = 
Class.forName("org.graalvm.nativeimage.ImageInfo");
+            result = nativeImageClazz.getMethod("inImageCode").invoke(null) != 
null;
+            // Note: This will also be true for the Graal substrate VM
+        } catch (ClassNotFoundException e) {
+            // Must be Graal
+        } catch (ReflectiveOperationException | IllegalArgumentException e) {
+            // Should never happen
+        }
+        GRAAL = result;
+    }
+
     /**
      * Returns the value of the javax.servlet.error.exception request
      * attribute value, if present, otherwise the value of the
@@ -291,17 +307,24 @@ public class JspRuntimeLibrary {
         Class<?> type = null;
         Class<?> propertyEditorClass = null;
         try {
-            java.beans.BeanInfo info
+            if (GRAAL) {
+                method = getWriteMethod(bean.getClass(), prop);
+                if (method.getParameterTypes().length > 0) {
+                    type = method.getParameterTypes()[0];
+                }
+            } else {
+                java.beans.BeanInfo info
                 = java.beans.Introspector.getBeanInfo(bean.getClass());
-            if ( info != null ) {
-                java.beans.PropertyDescriptor pd[]
-                    = info.getPropertyDescriptors();
-                for (int i = 0 ; i < pd.length ; i++) {
-                    if ( pd[i].getName().equals(prop) ) {
-                        method = pd[i].getWriteMethod();
-                        type   = pd[i].getPropertyType();
-                        propertyEditorClass = pd[i].getPropertyEditorClass();
-                        break;
+                if ( info != null ) {
+                    java.beans.PropertyDescriptor pd[]
+                            = info.getPropertyDescriptors();
+                    for (int i = 0 ; i < pd.length ; i++) {
+                        if ( pd[i].getName().equals(prop) ) {
+                            method = pd[i].getWriteMethod();
+                            type   = pd[i].getPropertyType();
+                            propertyEditorClass = 
pd[i].getPropertyEditorClass();
+                            break;
+                        }
                     }
                 }
             }
@@ -709,24 +732,48 @@ public class JspRuntimeLibrary {
         }
     }
 
+    /**
+     * Reverse of Introspector.decapitalize.
+     * @param name The name
+     * @return the capitalized string
+     */
+    public static String capitalize(String name) {
+        if (name == null || name.length() == 0) {
+            return name;
+        }
+        char chars[] = name.toCharArray();
+        chars[0] = Character.toUpperCase(chars[0]);
+        return new String(chars);
+    }
+
     public static Method getWriteMethod(Class<?> beanClass, String prop)
-    throws JasperException {
-        Method method = null;
+            throws JasperException {
+        Method result = null;
         Class<?> type = null;
-        try {
-            java.beans.BeanInfo info = 
java.beans.Introspector.getBeanInfo(beanClass);
-            java.beans.PropertyDescriptor pd[] = info.getPropertyDescriptors();
-            for (int i = 0 ; i < pd.length ; i++) {
-                if ( pd[i].getName().equals(prop) ) {
-                    method = pd[i].getWriteMethod();
-                    type = pd[i].getPropertyType();
-                    break;
+        if (GRAAL) {
+            String setter = "set" + capitalize(prop);
+            Method methods[] = beanClass.getMethods();
+            for (Method method : methods) {
+                if (setter.equals(method.getName())) {
+                    return method;
                 }
             }
-        } catch (Exception ex) {
-            throw new JasperException (ex);
+        } else {
+            try {
+                java.beans.BeanInfo info = 
java.beans.Introspector.getBeanInfo(beanClass);
+                java.beans.PropertyDescriptor pd[] = 
info.getPropertyDescriptors();
+                for (int i = 0 ; i < pd.length ; i++) {
+                    if ( pd[i].getName().equals(prop) ) {
+                        result = pd[i].getWriteMethod();
+                        type = pd[i].getPropertyType();
+                        break;
+                    }
+                }
+            } catch (Exception ex) {
+                throw new JasperException (ex);
+            }
         }
-        if (method == null) {
+        if (result == null) {
             if (type == null) {
                 throw new JasperException(Localizer.getMessage(
                         "jsp.error.beans.noproperty", prop, 
beanClass.getName()));
@@ -736,28 +783,37 @@ public class JspRuntimeLibrary {
                         prop, type.getName(), beanClass.getName()));
             }
         }
-        return method;
+        return result;
     }
 
     public static Method getReadMethod(Class<?> beanClass, String prop)
             throws JasperException {
-
-        Method method = null;
+        Method result = null;
         Class<?> type = null;
-        try {
-            java.beans.BeanInfo info = 
java.beans.Introspector.getBeanInfo(beanClass);
-            java.beans.PropertyDescriptor pd[] = info.getPropertyDescriptors();
-            for (int i = 0 ; i < pd.length ; i++) {
-                if (pd[i].getName().equals(prop)) {
-                    method = pd[i].getReadMethod();
-                    type = pd[i].getPropertyType();
-                    break;
+        if (GRAAL) {
+            String setter = "get" + capitalize(prop);
+            Method methods[] = beanClass.getMethods();
+            for (Method method : methods) {
+                if (setter.equals(method.getName())) {
+                    return method;
                 }
             }
-        } catch (Exception ex) {
-            throw new JasperException (ex);
+        } else {
+            try {
+                java.beans.BeanInfo info = 
java.beans.Introspector.getBeanInfo(beanClass);
+                java.beans.PropertyDescriptor pd[] = 
info.getPropertyDescriptors();
+                for (int i = 0 ; i < pd.length ; i++) {
+                    if (pd[i].getName().equals(prop)) {
+                        result = pd[i].getReadMethod();
+                        type = pd[i].getPropertyType();
+                        break;
+                    }
+                }
+            } catch (Exception ex) {
+                throw new JasperException (ex);
+            }
         }
-        if (method == null) {
+        if (result == null) {
             if (type == null) {
                 throw new JasperException(Localizer.getMessage(
                         "jsp.error.beans.noproperty", prop, 
beanClass.getName()));
@@ -766,8 +822,7 @@ public class JspRuntimeLibrary {
                         "jsp.error.beans.nomethod", prop, 
beanClass.getName()));
             }
         }
-
-        return method;
+        return result;
     }
 
     //*********************************************************************
diff --git a/res/tomcat-maven/graal-webapp.ant.xml 
b/res/tomcat-maven/graal-webapp.ant.xml
new file mode 100644
index 0000000..559b046
--- /dev/null
+++ b/res/tomcat-maven/graal-webapp.ant.xml
@@ -0,0 +1,49 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You 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.
+-->
+<project name="Webapp packaging for GraalVM" default="package" basedir=".">
+
+  <property name="webapp.name" value="examples" />
+
+  <typedef name="jasper" classname="org.apache.jasper.JspC">
+    <classpath>
+      <fileset file="${basedir}/target/tomcat-maven-1.0.jar" />
+      <fileset dir="${basedir}/webapps/${webapp.name}/WEB-INF/lib" 
includes="*.jar" />
+    </classpath>
+  </typedef>
+
+  <target name="package">
+
+    <!-- Will contain the webapp classes -->
+    <mkdir dir="${basedir}/src/main/java" />
+    <delete failonerror="false">
+        <fileset dir="${basedir}/src/main/java"/>
+    </delete>
+
+    <!-- JSP precompilation -->
+    <jasper validateXml="false" package="${webapp.name}.org.apache.jsp"
+            uriroot="${basedir}/webapps/${webapp.name}"
+            webXml="${basedir}/webapps/${webapp.name}/WEB-INF/tomcat-web.xml"
+            outputDir="${basedir}/src/main/java" />
+    <!-- Copy all webapp classes to the mvn compile location -->
+    <copy todir="${basedir}/src/main/java">
+        <fileset dir="${basedir}/webapps/${webapp.name}/WEB-INF/classes" 
includes="**/*.java"/>
+    </copy>
+
+  </target>
+
+</project>


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to