Author: rmannibucau
Date: Tue Mar 13 12:28:57 2018
New Revision: 1826625

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

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

Modified: openwebbeans/branches/owb_1.7.x/distribution/pom.xml
URL: 
http://svn.apache.org/viewvc/openwebbeans/branches/owb_1.7.x/distribution/pom.xml?rev=1826625&r1=1826624&r2=1826625&view=diff
==============================================================================
--- openwebbeans/branches/owb_1.7.x/distribution/pom.xml (original)
+++ openwebbeans/branches/owb_1.7.x/distribution/pom.xml Tue Mar 13 12:28:57 
2018
@@ -145,7 +145,7 @@
         </dependency>
         <dependency>
             <groupId>org.apache.xbean</groupId>
-            <artifactId>xbean-asm5-shaded</artifactId>
+            <artifactId>xbean-asm6-shaded</artifactId>
         </dependency>
 
 

Modified: 
openwebbeans/branches/owb_1.7.x/distribution/src/assembly/dist-binary.xml
URL: 
http://svn.apache.org/viewvc/openwebbeans/branches/owb_1.7.x/distribution/src/assembly/dist-binary.xml?rev=1826625&r1=1826624&r2=1826625&view=diff
==============================================================================
--- openwebbeans/branches/owb_1.7.x/distribution/src/assembly/dist-binary.xml 
(original)
+++ openwebbeans/branches/owb_1.7.x/distribution/src/assembly/dist-binary.xml 
Tue Mar 13 12:28:57 2018
@@ -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/branches/owb_1.7.x/pom.xml
URL: 
http://svn.apache.org/viewvc/openwebbeans/branches/owb_1.7.x/pom.xml?rev=1826625&r1=1826624&r2=1826625&view=diff
==============================================================================
--- openwebbeans/branches/owb_1.7.x/pom.xml (original)
+++ openwebbeans/branches/owb_1.7.x/pom.xml Tue Mar 13 12:28:57 2018
@@ -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>1.2.8.Final</cdi.tck.version>
         <httpclient.version>4.5.2</httpclient.version>
@@ -574,7 +574,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/branches/owb_1.7.x/webbeans-impl/pom.xml
URL: 
http://svn.apache.org/viewvc/openwebbeans/branches/owb_1.7.x/webbeans-impl/pom.xml?rev=1826625&r1=1826624&r2=1826625&view=diff
==============================================================================
--- openwebbeans/branches/owb_1.7.x/webbeans-impl/pom.xml (original)
+++ openwebbeans/branches/owb_1.7.x/webbeans-impl/pom.xml Tue Mar 13 12:28:57 
2018
@@ -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/branches/owb_1.7.x/webbeans-impl/src/main/java/org/apache/webbeans/proxy/AbstractProxyFactory.java
URL: 
http://svn.apache.org/viewvc/openwebbeans/branches/owb_1.7.x/webbeans-impl/src/main/java/org/apache/webbeans/proxy/AbstractProxyFactory.java?rev=1826625&r1=1826624&r2=1826625&view=diff
==============================================================================
--- 
openwebbeans/branches/owb_1.7.x/webbeans-impl/src/main/java/org/apache/webbeans/proxy/AbstractProxyFactory.java
 (original)
+++ 
openwebbeans/branches/owb_1.7.x/webbeans-impl/src/main/java/org/apache/webbeans/proxy/AbstractProxyFactory.java
 Tue Mar 13 12:28:57 2018
@@ -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/branches/owb_1.7.x/webbeans-impl/src/main/java/org/apache/webbeans/proxy/InterceptorDecoratorProxyFactory.java
URL: 
http://svn.apache.org/viewvc/openwebbeans/branches/owb_1.7.x/webbeans-impl/src/main/java/org/apache/webbeans/proxy/InterceptorDecoratorProxyFactory.java?rev=1826625&r1=1826624&r2=1826625&view=diff
==============================================================================
--- 
openwebbeans/branches/owb_1.7.x/webbeans-impl/src/main/java/org/apache/webbeans/proxy/InterceptorDecoratorProxyFactory.java
 (original)
+++ 
openwebbeans/branches/owb_1.7.x/webbeans-impl/src/main/java/org/apache/webbeans/proxy/InterceptorDecoratorProxyFactory.java
 Tue Mar 13 12:28:57 2018
@@ -25,11 +25,11 @@ import org.apache.webbeans.exception.Web
 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.Bean;
 import java.io.ObjectStreamException;

Modified: 
openwebbeans/branches/owb_1.7.x/webbeans-impl/src/main/java/org/apache/webbeans/proxy/NormalScopeProxyFactory.java
URL: 
http://svn.apache.org/viewvc/openwebbeans/branches/owb_1.7.x/webbeans-impl/src/main/java/org/apache/webbeans/proxy/NormalScopeProxyFactory.java?rev=1826625&r1=1826624&r2=1826625&view=diff
==============================================================================
--- 
openwebbeans/branches/owb_1.7.x/webbeans-impl/src/main/java/org/apache/webbeans/proxy/NormalScopeProxyFactory.java
 (original)
+++ 
openwebbeans/branches/owb_1.7.x/webbeans-impl/src/main/java/org/apache/webbeans/proxy/NormalScopeProxyFactory.java
 Tue Mar 13 12:28:57 2018
@@ -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/branches/owb_1.7.x/webbeans-impl/src/main/java/org/apache/webbeans/proxy/SubclassProxyFactory.java
URL: 
http://svn.apache.org/viewvc/openwebbeans/branches/owb_1.7.x/webbeans-impl/src/main/java/org/apache/webbeans/proxy/SubclassProxyFactory.java?rev=1826625&r1=1826624&r2=1826625&view=diff
==============================================================================
--- 
openwebbeans/branches/owb_1.7.x/webbeans-impl/src/main/java/org/apache/webbeans/proxy/SubclassProxyFactory.java
 (original)
+++ 
openwebbeans/branches/owb_1.7.x/webbeans-impl/src/main/java/org/apache/webbeans/proxy/SubclassProxyFactory.java
 Tue Mar 13 12:28:57 2018
@@ -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/branches/owb_1.7.x/webbeans-impl/src/main/resources/META-INF/openwebbeans/openwebbeans.properties
URL: 
http://svn.apache.org/viewvc/openwebbeans/branches/owb_1.7.x/webbeans-impl/src/main/resources/META-INF/openwebbeans/openwebbeans.properties?rev=1826625&r1=1826624&r2=1826625&view=diff
==============================================================================
--- 
openwebbeans/branches/owb_1.7.x/webbeans-impl/src/main/resources/META-INF/openwebbeans/openwebbeans.properties
 (original)
+++ 
openwebbeans/branches/owb_1.7.x/webbeans-impl/src/main/resources/META-INF/openwebbeans/openwebbeans.properties
 Tue Mar 13 12:28:57 2018
@@ -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
 
################################################################################################
 
 


Reply via email to