You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by ah...@apache.org on 2018/05/19 14:26:55 UTC

[isis] branch master updated (bc6ab40 -> 49d3089)

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

ahuber pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/isis.git.


    from bc6ab40  ISIS-1949: cleanup default method filter
     new 4e85abb  ISIS-1949: move objenesis dependencies
     new c9f71c7  ISIS-1949: reinstate original behavior to not call noarg-constructor
     new 49d3089  ISIS-1949: comment: code does not ignore bridges

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 core/plugins/codegen-javassist/pom.xml             |   5 +
 .../codegen/ProxyFactoryPluginUsingJavassist.java  |  66 ++++++++---
 core/unittestsupport/pom.xml                       | 126 +++++++++------------
 .../jmocking/JavassistImposteriser.java            |  12 +-
 core/wrapper/pom.xml                               |   5 -
 .../isis/core/wrapper/internal/util/Util.java      |  53 ---------
 .../isis/core/wrapper/proxy/ProxyCreator.java      |  21 +++-
 7 files changed, 128 insertions(+), 160 deletions(-)
 delete mode 100644 core/wrapper/src/main/java/org/apache/isis/core/wrapper/internal/util/Util.java

-- 
To stop receiving notification emails like this one, please contact
ahuber@apache.org.

[isis] 02/03: ISIS-1949: reinstate original behavior to not call noarg-constructor

Posted by ah...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit c9f71c788107dffeee357d43a20968ebfd3b9b8e
Author: Andi Huber <ah...@apache.org>
AuthorDate: Sat May 19 16:20:42 2018 +0200

    ISIS-1949: reinstate original behavior to not call noarg-constructor
    
    Task-Url: https://issues.apache.org/jira/browse/ISIS-1949
---
 .../codegen/ProxyFactoryPluginUsingJavassist.java  | 66 ++++++++++++++++------
 1 file changed, 49 insertions(+), 17 deletions(-)

diff --git a/core/plugins/codegen-javassist/src/main/java/org/apache/isis/core/runtime/plugins/codegen/ProxyFactoryPluginUsingJavassist.java b/core/plugins/codegen-javassist/src/main/java/org/apache/isis/core/runtime/plugins/codegen/ProxyFactoryPluginUsingJavassist.java
index 1f156c0..f9d43e6 100644
--- a/core/plugins/codegen-javassist/src/main/java/org/apache/isis/core/runtime/plugins/codegen/ProxyFactoryPluginUsingJavassist.java
+++ b/core/plugins/codegen-javassist/src/main/java/org/apache/isis/core/runtime/plugins/codegen/ProxyFactoryPluginUsingJavassist.java
@@ -8,9 +8,13 @@ import java.util.function.Predicate;
 import org.apache.isis.applib.internal.base._Casts;
 import org.apache.isis.applib.internal.base._NullSafe;
 import org.apache.isis.core.commons.exceptions.IsisException;
+import org.objenesis.Objenesis;
+import org.objenesis.ObjenesisStd;
 
-public class ProxyFactoryPluginUsingJavassist implements ProxyFactoryPlugin {
+import javassist.util.proxy.ProxyObject;
 
+public class ProxyFactoryPluginUsingJavassist implements ProxyFactoryPlugin {
+	
 	@Override
 	public <T> ProxyFactory<T> factory(
 			final Class<T> base, 
@@ -19,6 +23,7 @@ public class ProxyFactoryPluginUsingJavassist implements ProxyFactoryPlugin {
 			final Class<?>[] constructorArgTypes) {
 		
         final javassist.util.proxy.ProxyFactory pfDelegate = new javassist.util.proxy.ProxyFactory();
+        final Objenesis objenesis = new ObjenesisStd();
 
         pfDelegate.setSuperclass(base);
         pfDelegate.setInterfaces(interfaces);
@@ -26,35 +31,62 @@ public class ProxyFactoryPluginUsingJavassist implements ProxyFactoryPlugin {
         if(methodFilter!=null) {
         	pfDelegate.setFilter(methodFilter::test);	
         }
-		
-        final int constructorArgCount = _NullSafe.size(constructorArgTypes);
         
 		return new ProxyFactory<T>() {
 
 			@Override
-			public T createInstance(final InvocationHandler handler, final Object[] constructorArgs) {
-				
-				final int constructorArgCountActual = _NullSafe.size(constructorArgTypes);
-				
-				if(constructorArgCount != constructorArgCountActual) {
-					throw new IllegalArgumentException(String.format("Contructor args expected %d, got %d.", 
-							constructorArgCount, constructorArgCountActual));
-				}
+			public T createInstance(InvocationHandler handler, Object[] constructorArgs) {
 				
+				ensureSameSize(constructorArgTypes, constructorArgs);
+
 				try {
-					return _Casts.uncheckedCast( pfDelegate.create(
-							constructorArgTypes, 
-							constructorArgs, 
-							(Object self, Method thisMethod, Method proceed, Object[] args)->{
-								return handler.invoke(self, thisMethod, args);
-							}));
+					
+					if(_NullSafe.isEmpty(constructorArgTypes)) {
+						return _Casts.uncheckedCast( createNotUsingConstructor(handler) );	
+					} else {
+						return _Casts.uncheckedCast( createUsingConstructor(handler, constructorArgs) );
+					}
+					
 				} catch (NoSuchMethodException | IllegalArgumentException | InstantiationException | 
 						IllegalAccessException | InvocationTargetException e) {
 					throw new IsisException(e);
 				}
 			}
+
+			private Object createNotUsingConstructor(InvocationHandler handler) {
+				final Class<?> proxyClass = pfDelegate.createClass();
+				
+				final Object object = objenesis.newInstance(proxyClass);
+				
+				((ProxyObject)object).setHandler((Object self, Method thisMethod, Method proceed, Object[] args)->{
+					return handler.invoke(self, thisMethod, args);
+				});
+				
+				return object;
+			}
+			
+			private Object createUsingConstructor(InvocationHandler handler, Object[] constructorArgs)
+				throws NoSuchMethodException, IllegalArgumentException, InstantiationException, 
+					IllegalAccessException, InvocationTargetException {
+				
+				return pfDelegate.create(
+						constructorArgTypes, 
+						constructorArgs, 
+						(Object self, Method thisMethod, Method proceed, Object[] args)->{
+							return handler.invoke(self, thisMethod, args);
+						});
+			}
 			
 		};
 	}
 
+	// -- HELPER
+	
+	private static void ensureSameSize(Class<?>[] a, Object[] b) {
+		if(_NullSafe.size(a) != _NullSafe.size(b)) {
+			throw new IllegalArgumentException(String.format("Contructor args expected %d, got %d.", 
+					_NullSafe.size(a), _NullSafe.size(b) ));
+		}
+	}
+
 }

-- 
To stop receiving notification emails like this one, please contact
ahuber@apache.org.

[isis] 01/03: ISIS-1949: move objenesis dependencies

Posted by ah...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 4e85abbde3d5aa19207325d8ba217ebbee345b5b
Author: Andi Huber <ah...@apache.org>
AuthorDate: Sat May 19 15:54:29 2018 +0200

    ISIS-1949: move objenesis dependencies
    
    Task-Url: https://issues.apache.org/jira/browse/ISIS-1949
---
 core/plugins/codegen-javassist/pom.xml             |   5 +
 core/unittestsupport/pom.xml                       | 126 +++++++++------------
 .../jmocking/JavassistImposteriser.java            |   8 +-
 core/wrapper/pom.xml                               |   5 -
 .../isis/core/wrapper/internal/util/Util.java      |  53 ---------
 .../isis/core/wrapper/proxy/ProxyCreator.java      |  21 +++-
 6 files changed, 77 insertions(+), 141 deletions(-)

diff --git a/core/plugins/codegen-javassist/pom.xml b/core/plugins/codegen-javassist/pom.xml
index 190059b..a0f7382 100644
--- a/core/plugins/codegen-javassist/pom.xml
+++ b/core/plugins/codegen-javassist/pom.xml
@@ -59,6 +59,11 @@
 			<groupId>org.javassist</groupId>
 			<artifactId>javassist</artifactId>
 		</dependency>
+		
+		<dependency>
+			<groupId>org.objenesis</groupId>
+			<artifactId>objenesis</artifactId>
+		</dependency>
 
 		<dependency>
 			<groupId>org.apache.isis.core</groupId>
diff --git a/core/unittestsupport/pom.xml b/core/unittestsupport/pom.xml
index 53ba654..a8d62d6 100644
--- a/core/unittestsupport/pom.xml
+++ b/core/unittestsupport/pom.xml
@@ -1,97 +1,81 @@
 <?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 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">
+<!-- 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 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>
 
 	<parent>
 		<groupId>org.apache.isis.core</groupId>
 		<artifactId>isis</artifactId>
-        <version>${revision}</version>
+		<version>${revision}</version>
 	</parent>
 
 	<artifactId>isis-core-unittestsupport</artifactId>
 	<name>Apache Isis Unit Test Support</name>
 
-    <properties>
-        <jar-plugin.automaticModuleName>org.apache.isis.core.unittestsupport</jar-plugin.automaticModuleName>
-        <git-plugin.propertiesDir>org/apache/isis/core/unittestsupport</git-plugin.propertiesDir>
-    </properties>
+	<properties>
+		<jar-plugin.automaticModuleName>org.apache.isis.core.unittestsupport</jar-plugin.automaticModuleName>
+		<git-plugin.propertiesDir>org/apache/isis/core/unittestsupport</git-plugin.propertiesDir>
+	</properties>
 
-    <description>
+	<description>
 		Support for writing unit tests; should be added as a dependency
 		with scope=test only
 	</description>
 
 	<dependencies>
-           <dependency>
-               <groupId>junit</groupId>
-               <artifactId>junit</artifactId>
-           </dependency>
+		<dependency>
+			<groupId>junit</groupId>
+			<artifactId>junit</artifactId>
+		</dependency>
 
-           <dependency>
-               <groupId>org.picocontainer</groupId>
-               <artifactId>picocontainer</artifactId>
-           </dependency>
+		<dependency>
+			<groupId>org.picocontainer</groupId>
+			<artifactId>picocontainer</artifactId>
+		</dependency>
 
-           <dependency>
-               <groupId>org.jmock</groupId>
-               <artifactId>jmock</artifactId>
-           </dependency>
+		<dependency>
+			<groupId>org.jmock</groupId>
+			<artifactId>jmock</artifactId>
+		</dependency>
 
-           <dependency>
-               <groupId>org.jmock</groupId>
-               <artifactId>jmock-junit4</artifactId>
-           </dependency>
+		<dependency>
+			<groupId>org.jmock</groupId>
+			<artifactId>jmock-junit4</artifactId>
+		</dependency>
 
 		<!-- JDO API (non transient, provided by plugin) -->
-        <dependency>
-            <groupId>javax.jdo</groupId>
-            <artifactId>jdo-api</artifactId>
-            <version>${jdo-api.version}</version>
-            <!-- provided by plugins -->
-            <scope>provided</scope>
-        </dependency>
+		<dependency>
+			<groupId>javax.jdo</groupId>
+			<artifactId>jdo-api</artifactId>
+			<version>${jdo-api.version}</version>
+			<!-- provided by plugins -->
+			<scope>provided</scope>
+		</dependency>
 
-
-            <dependency>
-                <groupId>org.objenesis</groupId>
-                <artifactId>objenesis</artifactId>
-                <!--<version>1.4</version>-->
-            </dependency>
-
-            <dependency>
-                <groupId>org.reflections</groupId>
-                <artifactId>reflections</artifactId>
-                <exclusions>
-                    <exclusion>
-                        <!--
-                        part of JDK 6+
-                        the version here does not provide getUserData(), setUserData(),
-                        as needed by xmlsnapshot functionality in isis-core-runtime.
-                        -->
-                        <groupId>xml-apis</groupId>
-                        <artifactId>xml-apis</artifactId>
-                    </exclusion>
-                </exclusions>
-                <optional>true</optional>
-            </dependency>
+		<dependency>
+			<groupId>org.reflections</groupId>
+			<artifactId>reflections</artifactId>
+			<exclusions>
+				<exclusion>
+					<!-- part of JDK 6+ the version here does not provide getUserData(), 
+						setUserData(), as needed by xmlsnapshot functionality in isis-core-runtime. -->
+					<groupId>xml-apis</groupId>
+					<artifactId>xml-apis</artifactId>
+				</exclusion>
+			</exclusions>
+			<optional>true</optional>
+		</dependency>
 
 	</dependencies>
 
diff --git a/core/unittestsupport/src/main/java/org/apache/isis/core/unittestsupport/jmocking/JavassistImposteriser.java b/core/unittestsupport/src/main/java/org/apache/isis/core/unittestsupport/jmocking/JavassistImposteriser.java
index fdeb449..75567c8 100644
--- a/core/unittestsupport/src/main/java/org/apache/isis/core/unittestsupport/jmocking/JavassistImposteriser.java
+++ b/core/unittestsupport/src/main/java/org/apache/isis/core/unittestsupport/jmocking/JavassistImposteriser.java
@@ -126,10 +126,6 @@ public class JavassistImposteriser implements Imposteriser {
         return proxyObject;
     }
 
-    private static Class<?>[] combine(Class<?> first, Class<?>... rest) {
-        Class<?>[] all = new Class<?>[rest.length+1];
-        all[0] = first;
-        System.arraycopy(rest, 0, all, 1, rest.length);
-        return all;
-    }
+    
+    
 }
diff --git a/core/wrapper/pom.xml b/core/wrapper/pom.xml
index 193cc5d..0a9a7dd 100644
--- a/core/wrapper/pom.xml
+++ b/core/wrapper/pom.xml
@@ -35,11 +35,6 @@
 			<groupId>org.apache.isis.core</groupId>
 			<artifactId>isis-core-runtime</artifactId>
 		</dependency>
-
-		<dependency>
-			<groupId>org.objenesis</groupId>
-			<artifactId>objenesis</artifactId>
-		</dependency>
 		
 		<!-- TEST -->
 
diff --git a/core/wrapper/src/main/java/org/apache/isis/core/wrapper/internal/util/Util.java b/core/wrapper/src/main/java/org/apache/isis/core/wrapper/internal/util/Util.java
deleted file mode 100644
index 7cfecbd..0000000
--- a/core/wrapper/src/main/java/org/apache/isis/core/wrapper/internal/util/Util.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- *  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.
- */
-
-package org.apache.isis.core.wrapper.internal.util;
-
-import java.lang.reflect.InvocationHandler;
-import java.lang.reflect.Proxy;
-
-import org.objenesis.ObjenesisHelper;
-
-public final class Util {
-
-    private Util(){}
-    
-    @SuppressWarnings("unchecked")
-    public static <T> T createInstance(final Class<T> toProxy, final InvocationHandler handler, final Class<?>... auxiliaryTypes) {
-        return (T) Proxy.newProxyInstance(toProxy.getClassLoader(), combine(toProxy, auxiliaryTypes) , handler);
-    }
- 
-    /**
-     * Return a new instance of the specified class. The recommended way is
-     * without calling any constructor. This is usually done by doing like
-     * <code>ObjectInputStream.readObject()</code> which is JVM specific.
-     */
-    @SuppressWarnings("unchecked")
-    public static <T> T createInstance(final Class<T> enhancedClass) {
-        return (T) ObjenesisHelper.newInstance(enhancedClass);
-    }
-    
-    private static Class<?>[] combine(Class<?> first, Class<?>... rest) {
-        Class<?>[] all = new Class<?>[rest.length+1];
-        all[0] = first;
-        System.arraycopy(rest, 0, all, 1, rest.length);
-        return all;
-    }
-
-}
diff --git a/core/wrapper/src/main/java/org/apache/isis/core/wrapper/proxy/ProxyCreator.java b/core/wrapper/src/main/java/org/apache/isis/core/wrapper/proxy/ProxyCreator.java
index 69c11f9..9222180 100644
--- a/core/wrapper/src/main/java/org/apache/isis/core/wrapper/proxy/ProxyCreator.java
+++ b/core/wrapper/src/main/java/org/apache/isis/core/wrapper/proxy/ProxyCreator.java
@@ -19,15 +19,17 @@
 
 package org.apache.isis.core.wrapper.proxy;
 
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Proxy;
 import java.util.Map;
 
 import org.apache.isis.applib.internal.base._Casts;
+import org.apache.isis.applib.internal.collections._Arrays;
 import org.apache.isis.applib.services.wrapper.WrappingObject;
 import org.apache.isis.core.commons.lang.ArrayExtensions;
 import org.apache.isis.core.metamodel.specloader.classsubstitutor.ProxyEnhanced;
 import org.apache.isis.core.runtime.plugins.codegen.ProxyFactory;
 import org.apache.isis.core.wrapper.handlers.DelegatingInvocationHandler;
-import org.apache.isis.core.wrapper.internal.util.Util;
 
 import com.google.common.collect.MapMaker;
 
@@ -51,16 +53,17 @@ public class ProxyCreator {
 
         final T toProxy = handler.getDelegate();
 
-        final Class<T> clazz = (Class<T>) toProxy.getClass();
+        final Class<T> base = (Class<T>) toProxy.getClass();
 
-        if (clazz.isInterface()) {
-        	//TODO [ahuber] move this logic to ProxyFactory
-            return Util.createInstance(clazz, handler, WrappingObject.class);
+        if (base.isInterface()) {
+            return createInstanceForInterface(base, handler, WrappingObject.class);
         } else {
-            final ProxyFactory<T> proxyFactory = proxyFactoryFor(clazz);
+            final ProxyFactory<T> proxyFactory = proxyFactoryFor(base);
             return proxyFactory.createInstance(handler);
         }
     }
+    
+    // -- HELPER
 
     private <T> ProxyFactory<T> proxyFactoryFor(final Class<T> toProxyClass) {
         ProxyFactory<T> proxyFactory = _Casts.uncheckedCast(proxyFactoryByClass.get(toProxyClass));
@@ -84,4 +87,10 @@ public class ProxyCreator {
         return proxyFactory;
     }
 
+    @SuppressWarnings("unchecked")
+    private static <T> T createInstanceForInterface(
+    		final Class<T> base, final InvocationHandler handler, final Class<?>... auxiliaryTypes) {
+        return (T) Proxy.newProxyInstance(base.getClassLoader(), _Arrays.combine(base, auxiliaryTypes) , handler);
+    }
+    
 }

-- 
To stop receiving notification emails like this one, please contact
ahuber@apache.org.

[isis] 03/03: ISIS-1949: comment: code does not ignore bridges

Posted by ah...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 49d3089e5fb7b1a0bacbb2e0ccccf74123117d74
Author: Andi Huber <ah...@apache.org>
AuthorDate: Sat May 19 16:26:16 2018 +0200

    ISIS-1949: comment: code does not ignore bridges
    
    Task-Url: https://issues.apache.org/jira/browse/ISIS-1949
---
 .../isis/core/unittestsupport/jmocking/JavassistImposteriser.java     | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/core/unittestsupport/src/main/java/org/apache/isis/core/unittestsupport/jmocking/JavassistImposteriser.java b/core/unittestsupport/src/main/java/org/apache/isis/core/unittestsupport/jmocking/JavassistImposteriser.java
index 75567c8..5f3efdc 100644
--- a/core/unittestsupport/src/main/java/org/apache/isis/core/unittestsupport/jmocking/JavassistImposteriser.java
+++ b/core/unittestsupport/src/main/java/org/apache/isis/core/unittestsupport/jmocking/JavassistImposteriser.java
@@ -101,8 +101,8 @@ public class JavassistImposteriser implements Imposteriser {
         proxyFactory.setFilter(new MethodFilter() {
             @Override
             public boolean isHandled(final Method m) {
-                // ignore finalize() and als bridge methods
-                return !m.getName().equals("finalize") || m.isBridge();
+                // ignore finalize() and also bridge methods
+                return !m.getName().equals("finalize") || m.isBridge(); //[ahuber] this code does not ignore bridges!
             }
         });
 

-- 
To stop receiving notification emails like this one, please contact
ahuber@apache.org.