You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwebbeans.apache.org by rm...@apache.org on 2017/11/24 08:21:01 UTC

svn commit: r1816217 - in /openwebbeans/trunk: ./ distribution/ distribution/src/assembly/ webbeans-impl/ webbeans-impl/src/main/java/org/apache/webbeans/proxy/ webbeans-impl/src/main/resources/META-INF/openwebbeans/

Author: rmannibucau
Date: Fri Nov 24 08:21:01 2017
New Revision: 1816217

URL: http://svn.apache.org/viewvc?rev=1816217&view=rev
Log:
OWB-1221 asm 6 upgrade

Modified:
    openwebbeans/trunk/distribution/pom.xml
    openwebbeans/trunk/distribution/src/assembly/dist-binary.xml
    openwebbeans/trunk/pom.xml
    openwebbeans/trunk/webbeans-impl/pom.xml
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/AbstractProxyFactory.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/InterceptorDecoratorProxyFactory.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/NormalScopeProxyFactory.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/SubclassProxyFactory.java
    openwebbeans/trunk/webbeans-impl/src/main/resources/META-INF/openwebbeans/openwebbeans.properties

Modified: openwebbeans/trunk/distribution/pom.xml
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/distribution/pom.xml?rev=1816217&r1=1816216&r2=1816217&view=diff
==============================================================================
--- openwebbeans/trunk/distribution/pom.xml (original)
+++ openwebbeans/trunk/distribution/pom.xml Fri Nov 24 08:21:01 2017
@@ -145,7 +145,7 @@
         </dependency>
         <dependency>
             <groupId>org.apache.xbean</groupId>
-            <artifactId>xbean-asm5-shaded</artifactId>
+            <artifactId>xbean-asm6-shaded</artifactId>
         </dependency>
 
 

Modified: openwebbeans/trunk/distribution/src/assembly/dist-binary.xml
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/distribution/src/assembly/dist-binary.xml?rev=1816217&r1=1816216&r2=1816217&view=diff
==============================================================================
--- openwebbeans/trunk/distribution/src/assembly/dist-binary.xml (original)
+++ openwebbeans/trunk/distribution/src/assembly/dist-binary.xml Fri Nov 24 08:21:01 2017
@@ -73,7 +73,7 @@ under the License.
             <includes>
                 <include>org.apache.openwebbeans:openwebbeans-impl:jar</include>
                 <include>org.apache.xbean:xbean-finder-shaded:jar</include>
-                <include>org.apache.xbean:xbean-asm5-shaded:jar</include>
+                <include>org.apache.xbean:xbean-asm6-shaded:jar</include>
             </includes>
         </dependencySet>
 

Modified: openwebbeans/trunk/pom.xml
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/pom.xml?rev=1816217&r1=1816216&r2=1816217&view=diff
==============================================================================
--- openwebbeans/trunk/pom.xml (original)
+++ openwebbeans/trunk/pom.xml Fri Nov 24 08:21:01 2017
@@ -71,7 +71,7 @@
         <geronimo_validation.version>1.1</geronimo_validation.version>
         <tomcat7.version>7.0.73</tomcat7.version>
         <myfaces.version>2.2.12</myfaces.version>
-        <xbean.version>4.5</xbean.version>
+        <xbean.version>4.6</xbean.version>
         <arquillian.version>1.1.13.Final</arquillian.version>
         <cdi.tck.version>2.0.0.Final</cdi.tck.version>
         <httpclient.version>4.5.2</httpclient.version>
@@ -611,7 +611,7 @@
             </dependency>
             <dependency>
                 <groupId>org.apache.xbean</groupId>
-                <artifactId>xbean-asm5-shaded</artifactId>
+                <artifactId>xbean-asm6-shaded</artifactId>
                 <version>${xbean.version}</version>
             </dependency>
 

Modified: openwebbeans/trunk/webbeans-impl/pom.xml
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/pom.xml?rev=1816217&r1=1816216&r2=1816217&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/pom.xml (original)
+++ openwebbeans/trunk/webbeans-impl/pom.xml Fri Nov 24 08:21:01 2017
@@ -49,7 +49,7 @@
         </dependency>
         <dependency>
             <groupId>org.apache.xbean</groupId>
-            <artifactId>xbean-asm5-shaded</artifactId>
+            <artifactId>xbean-asm6-shaded</artifactId>
         </dependency>
 
         <dependency>

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/AbstractProxyFactory.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/AbstractProxyFactory.java?rev=1816217&r1=1816216&r2=1816217&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/AbstractProxyFactory.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/AbstractProxyFactory.java Fri Nov 24 08:21:01 2017
@@ -18,6 +18,9 @@
  */
 package org.apache.webbeans.proxy;
 
+import static org.apache.xbean.asm6.ClassReader.SKIP_DEBUG;
+
+import java.io.InputStream;
 import java.lang.reflect.Constructor;
 import java.lang.reflect.Field;
 import java.lang.reflect.InvocationTargetException;
@@ -34,10 +37,12 @@ import org.apache.webbeans.config.WebBea
 import org.apache.webbeans.exception.ProxyGenerationException;
 import org.apache.webbeans.exception.WebBeansException;
 import org.apache.webbeans.logger.WebBeansLoggerFacade;
-import org.apache.xbean.asm5.ClassWriter;
-import org.apache.xbean.asm5.MethodVisitor;
-import org.apache.xbean.asm5.Opcodes;
-import org.apache.xbean.asm5.Type;
+import org.apache.xbean.asm6.ClassReader;
+import org.apache.xbean.asm6.ClassWriter;
+import org.apache.xbean.asm6.MethodVisitor;
+import org.apache.xbean.asm6.Opcodes;
+import org.apache.xbean.asm6.Type;
+import org.apache.xbean.asm6.shade.commons.EmptyVisitor;
 
 /**
  * Base class for all OWB Proxy factories
@@ -82,31 +87,30 @@ public abstract class AbstractProxyFacto
     protected AbstractProxyFactory(WebBeansContext webBeansContext)
     {
         this.webBeansContext = webBeansContext;
-        javaVersion = determineJavaVersion();
+        javaVersion = determineDefaultJavaVersion();
         initializeUnsafe();
     }
 
-    private int determineJavaVersion()
+    private int determineDefaultJavaVersion()
     {
         String javaVersionProp = webBeansContext.getOpenWebBeansConfiguration().getGeneratorJavaVersion();
+        if (javaVersionProp == null)  // try to align on the runtime
+        {
+            javaVersionProp = System.getProperty("java.version");
+        }
         if (javaVersionProp != null)
         {
-            if (javaVersionProp.startsWith("1.7"))
-            {
-                return Opcodes.V1_7;
-            }
-            else if (javaVersionProp.startsWith("1.8"))
+            if (javaVersionProp.startsWith("1.8"))
             {
                 return Opcodes.V1_8;
             }
-            else if (javaVersionProp.startsWith("1.9"))
+            else if (javaVersionProp.startsWith("9") || javaVersionProp.startsWith("1.9"))
             {
-                // TODO upgrade to Java9 as soon as ASM really supports it!
-                return Opcodes.V1_8;
+                return Opcodes.V9;
             }
         }
 
-        // the fallback default is V1_6
+        // the fallback is the lowest one to ensure it supports all possible classes of current environments
         return Opcodes.V1_6;
     }
 
@@ -299,7 +303,7 @@ public abstract class AbstractProxyFacto
             superClassName = Type.getInternalName(Object.class);
         }
 
-        cw.visit(javaVersion, Opcodes.ACC_PUBLIC + Opcodes.ACC_SUPER + Opcodes.ACC_SYNTHETIC, proxyClassFileName, null, superClassName, interfaceNames);
+        cw.visit(findJavaVersion(classToProxy), Opcodes.ACC_PUBLIC + Opcodes.ACC_SUPER + Opcodes.ACC_SYNTHETIC, proxyClassFileName, null, superClassName, interfaceNames);
         cw.visitSource(classFileName + ".java", null);
 
         createInstanceVariables(cw, classToProxy, classFileName);
@@ -327,6 +331,31 @@ public abstract class AbstractProxyFacto
         return cw.toByteArray();
     }
 
+    private int findJavaVersion(final Class<?> from)
+    {
+        final String resource = from.getName().replace('.', '/') + ".class";
+        try (final InputStream stream = from.getClassLoader().getResourceAsStream(resource))
+        {
+            if (stream == null)
+            {
+                return javaVersion;
+            }
+            final ClassReader reader = new ClassReader(stream);
+            final VersionVisitor visitor = new VersionVisitor();
+            reader.accept(visitor, SKIP_DEBUG);
+            if (visitor.version != 0)
+            {
+                return visitor.version;
+            }
+        }
+        catch (final Exception e)
+        {
+            // no-op
+        }
+        // mainly for JVM classes - outside the classloader, find to fallback on the JVM version
+        return javaVersion;
+    }
+
 
     /**
      * The 'defineClass' method on the ClassLoader is protected, thus we need to invoke it via reflection.
@@ -863,4 +892,16 @@ public abstract class AbstractProxyFacto
     }
 
 
+    private static class VersionVisitor extends EmptyVisitor
+    {
+        private int version;
+
+        @Override
+        public void visit(final int version, final int access, final String name,
+                          final String signature, final String superName, final String[] interfaces)
+        {
+            super.visit(version, access, name, signature, superName, interfaces);
+            this.version = version;
+        }
+    }
 }

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/InterceptorDecoratorProxyFactory.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/InterceptorDecoratorProxyFactory.java?rev=1816217&r1=1816216&r2=1816217&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/InterceptorDecoratorProxyFactory.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/InterceptorDecoratorProxyFactory.java Fri Nov 24 08:21:01 2017
@@ -26,11 +26,11 @@ import org.apache.webbeans.intercept.Int
 import org.apache.webbeans.logger.WebBeansLoggerFacade;
 import org.apache.webbeans.util.Asserts;
 import org.apache.webbeans.util.ExceptionUtil;
-import org.apache.xbean.asm5.ClassWriter;
-import org.apache.xbean.asm5.Label;
-import org.apache.xbean.asm5.MethodVisitor;
-import org.apache.xbean.asm5.Opcodes;
-import org.apache.xbean.asm5.Type;
+import org.apache.xbean.asm6.ClassWriter;
+import org.apache.xbean.asm6.Label;
+import org.apache.xbean.asm6.MethodVisitor;
+import org.apache.xbean.asm6.Opcodes;
+import org.apache.xbean.asm6.Type;
 
 import javax.enterprise.inject.spi.AnnotatedType;
 import javax.enterprise.inject.spi.Bean;

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/NormalScopeProxyFactory.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/NormalScopeProxyFactory.java?rev=1816217&r1=1816216&r2=1816217&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/NormalScopeProxyFactory.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/NormalScopeProxyFactory.java Fri Nov 24 08:21:01 2017
@@ -41,10 +41,10 @@ import org.apache.webbeans.intercept.Nor
 import org.apache.webbeans.util.ClassUtil;
 import org.apache.webbeans.util.ExceptionUtil;
 import org.apache.webbeans.util.WebBeansUtil;
-import org.apache.xbean.asm5.ClassWriter;
-import org.apache.xbean.asm5.MethodVisitor;
-import org.apache.xbean.asm5.Opcodes;
-import org.apache.xbean.asm5.Type;
+import org.apache.xbean.asm6.ClassWriter;
+import org.apache.xbean.asm6.MethodVisitor;
+import org.apache.xbean.asm6.Opcodes;
+import org.apache.xbean.asm6.Type;
 
 /**
  * This factory creates proxies which delegate the
@@ -508,7 +508,7 @@ public class NormalScopeProxyFactory ext
      * if targetMethod is protected. Please see Java LangSpec 6.6.2 about the complex
      * rules for calling 'protected' methods.
      *
-     * @see #generateDelegationMethod(org.apache.xbean.asm5.ClassWriter, java.lang.reflect.Method, int, Class, String)
+     * @see #generateDelegationMethod(org.apache.xbean.asm6.ClassWriter, java.lang.reflect.Method, int, Class, String)
      */
     @SuppressWarnings("unused")
     public static Object delegateProtectedMethod(Method method, Object instance, Object[] params)

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/SubclassProxyFactory.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/SubclassProxyFactory.java?rev=1816217&r1=1816216&r2=1816217&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/SubclassProxyFactory.java (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/SubclassProxyFactory.java Fri Nov 24 08:21:01 2017
@@ -27,10 +27,10 @@ import org.apache.webbeans.config.WebBea
 import org.apache.webbeans.exception.ProxyGenerationException;
 import org.apache.webbeans.exception.WebBeansConfigurationException;
 import org.apache.webbeans.util.ClassUtil;
-import org.apache.xbean.asm5.ClassWriter;
-import org.apache.xbean.asm5.MethodVisitor;
-import org.apache.xbean.asm5.Opcodes;
-import org.apache.xbean.asm5.Type;
+import org.apache.xbean.asm6.ClassWriter;
+import org.apache.xbean.asm6.MethodVisitor;
+import org.apache.xbean.asm6.Opcodes;
+import org.apache.xbean.asm6.Type;
 
 import javax.enterprise.inject.spi.AnnotatedConstructor;
 import javax.enterprise.inject.spi.AnnotatedType;

Modified: openwebbeans/trunk/webbeans-impl/src/main/resources/META-INF/openwebbeans/openwebbeans.properties
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/resources/META-INF/openwebbeans/openwebbeans.properties?rev=1816217&r1=1816216&r2=1816217&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/resources/META-INF/openwebbeans/openwebbeans.properties (original)
+++ openwebbeans/trunk/webbeans-impl/src/main/resources/META-INF/openwebbeans/openwebbeans.properties Fri Nov 24 08:21:01 2017
@@ -140,7 +140,7 @@ org.apache.webbeans.web.eagerSessionInit
 # If "auto" then we will pick the version of the current JVM.
 # The default is set to "1.6" as some tools in jetty/tomcat/etc still
 # cannot properly handle Java8 (mostly due to older Eclipse JDT versions).
-org.apache.webbeans.generator.javaVersion=1.6
+# org.apache.webbeans.generator.javaVersion=1.6
 ################################################################################################