You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@polygene.apache.org by ni...@apache.org on 2017/06/07 04:34:29 UTC

[1/4] polygene-java git commit: Added method in Polygene API to check if an object is a Composite.

Repository: polygene-java
Updated Branches:
  refs/heads/develop c201ff52a -> 4f1527980


Added method in Polygene API to check if an object is a Composite.

Signed-off-by: niclas <ni...@hedhman.org>


Project: http://git-wip-us.apache.org/repos/asf/polygene-java/repo
Commit: http://git-wip-us.apache.org/repos/asf/polygene-java/commit/195da9f5
Tree: http://git-wip-us.apache.org/repos/asf/polygene-java/tree/195da9f5
Diff: http://git-wip-us.apache.org/repos/asf/polygene-java/diff/195da9f5

Branch: refs/heads/develop
Commit: 195da9f536b28323950b0d3166f4c499466a157a
Parents: c201ff5
Author: niclas <ni...@hedhman.org>
Authored: Wed Jun 7 08:58:22 2017 +0800
Committer: niclas <ni...@hedhman.org>
Committed: Wed Jun 7 08:58:22 2017 +0800

----------------------------------------------------------------------
 .../main/java/org/apache/polygene/api/PolygeneAPI.java |  8 ++++++--
 .../apache/polygene/runtime/PolygeneRuntimeImpl.java   | 13 +++++++++++++
 2 files changed, 19 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/polygene-java/blob/195da9f5/core/api/src/main/java/org/apache/polygene/api/PolygeneAPI.java
----------------------------------------------------------------------
diff --git a/core/api/src/main/java/org/apache/polygene/api/PolygeneAPI.java b/core/api/src/main/java/org/apache/polygene/api/PolygeneAPI.java
index a9958a6..2823cb6 100644
--- a/core/api/src/main/java/org/apache/polygene/api/PolygeneAPI.java
+++ b/core/api/src/main/java/org/apache/polygene/api/PolygeneAPI.java
@@ -20,7 +20,6 @@
 package org.apache.polygene.api;
 
 import java.lang.reflect.Field;
-import java.lang.reflect.InvocationHandler;
 import java.lang.reflect.Proxy;
 import java.util.function.Function;
 import org.apache.polygene.api.association.AbstractAssociation;
@@ -28,7 +27,6 @@ import org.apache.polygene.api.association.AssociationDescriptor;
 import org.apache.polygene.api.composite.Composite;
 import org.apache.polygene.api.composite.CompositeDescriptor;
 import org.apache.polygene.api.composite.CompositeInstance;
-import org.apache.polygene.api.composite.InvalidCompositeException;
 import org.apache.polygene.api.composite.ModelDescriptor;
 import org.apache.polygene.api.composite.TransientDescriptor;
 import org.apache.polygene.api.entity.EntityDescriptor;
@@ -139,6 +137,12 @@ public interface PolygeneAPI
      */
     AssociationDescriptor associationDescriptorFor( AbstractAssociation association );
 
+    /** Tests if the given object is a Composite
+     *
+     * @param object The Java object to be checked
+     * @return true if the given object is a Composite type.
+     */
+    boolean isComposite( Object object );
     /**
      * Function that returns the CompositeInstance of a Composite.
      */

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/195da9f5/core/runtime/src/main/java/org/apache/polygene/runtime/PolygeneRuntimeImpl.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/polygene/runtime/PolygeneRuntimeImpl.java b/core/runtime/src/main/java/org/apache/polygene/runtime/PolygeneRuntimeImpl.java
index 405ade0..9e3bf2d 100644
--- a/core/runtime/src/main/java/org/apache/polygene/runtime/PolygeneRuntimeImpl.java
+++ b/core/runtime/src/main/java/org/apache/polygene/runtime/PolygeneRuntimeImpl.java
@@ -20,6 +20,7 @@
 package org.apache.polygene.runtime;
 
 import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Proxy;
 import java.util.Arrays;
 import java.util.Map;
 import java.util.stream.Stream;
@@ -312,6 +313,18 @@ public final class PolygeneRuntimeImpl
         return (AssociationDescriptor) ( (AbstractAssociationInstance) association ).associationInfo();
     }
 
+    @Override
+    public boolean isComposite( Object object )
+    {
+        return isCompositeType( object );
+    }
+
+    public static boolean isCompositeType( Object object )
+    {
+        return Proxy.isProxyClass( object.getClass() )
+               && Proxy.getInvocationHandler( object ) instanceof CompositeInstance;
+    }
+
     // SPI
     @Override
     public EntityState entityStateOf( EntityComposite composite )


[2/4] polygene-java git commit: Do not allow Composites in @Uses.

Posted by ni...@apache.org.
Do not allow Composites in @Uses.

Signed-off-by: niclas <ni...@hedhman.org>


Project: http://git-wip-us.apache.org/repos/asf/polygene-java/repo
Commit: http://git-wip-us.apache.org/repos/asf/polygene-java/commit/002794fe
Tree: http://git-wip-us.apache.org/repos/asf/polygene-java/tree/002794fe
Diff: http://git-wip-us.apache.org/repos/asf/polygene-java/diff/002794fe

Branch: refs/heads/develop
Commit: 002794fed1e070cf0b0217c69067272be472ee7c
Parents: 195da9f
Author: niclas <ni...@hedhman.org>
Authored: Wed Jun 7 08:58:31 2017 +0800
Committer: niclas <ni...@hedhman.org>
Committed: Wed Jun 7 08:58:31 2017 +0800

----------------------------------------------------------------------
 .../apache/polygene/runtime/composite/UsesInstance.java  | 11 +++++++++++
 1 file changed, 11 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/polygene-java/blob/002794fe/core/runtime/src/main/java/org/apache/polygene/runtime/composite/UsesInstance.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/polygene/runtime/composite/UsesInstance.java b/core/runtime/src/main/java/org/apache/polygene/runtime/composite/UsesInstance.java
index 0fc8eb3..9d9632b 100644
--- a/core/runtime/src/main/java/org/apache/polygene/runtime/composite/UsesInstance.java
+++ b/core/runtime/src/main/java/org/apache/polygene/runtime/composite/UsesInstance.java
@@ -24,6 +24,8 @@ import java.util.Arrays;
 import java.util.Collections;
 import java.util.HashSet;
 import java.util.Set;
+import org.apache.polygene.api.common.ConstructionException;
+import org.apache.polygene.runtime.PolygeneRuntimeImpl;
 
 /**
  * JAVADOC
@@ -45,6 +47,15 @@ public final class UsesInstance
 
     public UsesInstance use( Object... objects )
     {
+        // Validate that there are no Composites in the list, since they are possibly not fully initialized yet.
+        // TODO: The reason for that is that Composites may not be fully initialized when reaching here, and the hashCode() call later will cause an NPE.
+        for( Object obj : objects )
+        {
+            if( PolygeneRuntimeImpl.isCompositeType( obj ) )
+            {
+                throw new ConstructionException( "Composites are not allowed as @Uses arguments: " + obj.toString() );
+            }
+        }
         HashSet<Object> useObjects = new HashSet<>();
         if( !uses.isEmpty() )
         {


[4/4] polygene-java git commit: Increased timeout a little bit.

Posted by ni...@apache.org.
Increased timeout a little bit.

Signed-off-by: niclas <ni...@hedhman.org>


Project: http://git-wip-us.apache.org/repos/asf/polygene-java/repo
Commit: http://git-wip-us.apache.org/repos/asf/polygene-java/commit/4f152798
Tree: http://git-wip-us.apache.org/repos/asf/polygene-java/tree/4f152798
Diff: http://git-wip-us.apache.org/repos/asf/polygene-java/diff/4f152798

Branch: refs/heads/develop
Commit: 4f1527980c92828ec2207795bc007295ba9cbe88
Parents: 630b785
Author: niclas <ni...@hedhman.org>
Authored: Wed Jun 7 12:13:41 2017 +0800
Committer: niclas <ni...@hedhman.org>
Committed: Wed Jun 7 12:13:41 2017 +0800

----------------------------------------------------------------------
 tools/generator-polygene/test/generator_test.js | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/polygene-java/blob/4f152798/tools/generator-polygene/test/generator_test.js
----------------------------------------------------------------------
diff --git a/tools/generator-polygene/test/generator_test.js b/tools/generator-polygene/test/generator_test.js
index 62b9347..99f9bdb 100644
--- a/tools/generator-polygene/test/generator_test.js
+++ b/tools/generator-polygene/test/generator_test.js
@@ -135,7 +135,8 @@ function test(appType, entityStore, indexing, caching, metrics, features) {
         var testDirName = testName.replace(new RegExp(' - ', 'g'), '_').replace(new RegExp(' ', 'g'), '_');
         it(testName,
             function () {
-                this.timeout(30000);
+                console.log( "\n\nTest: " + testName );
+                this.timeout(60000);
                 return helpers.run(path.join(__dirname, '../app'))
                     .inDir(path.join(__dirname, '../build/npm-test/' + testDirName))
                     .withPrompts({


[3/4] polygene-java git commit: Added test for "No Composites in @Uses"

Posted by ni...@apache.org.
Added test for "No Composites in @Uses"

Signed-off-by: niclas <ni...@hedhman.org>


Project: http://git-wip-us.apache.org/repos/asf/polygene-java/repo
Commit: http://git-wip-us.apache.org/repos/asf/polygene-java/commit/630b7856
Tree: http://git-wip-us.apache.org/repos/asf/polygene-java/tree/630b7856
Diff: http://git-wip-us.apache.org/repos/asf/polygene-java/diff/630b7856

Branch: refs/heads/develop
Commit: 630b7856b5478223b82d701222cf2acf1d3cb85f
Parents: 002794f
Author: niclas <ni...@hedhman.org>
Authored: Wed Jun 7 09:21:26 2017 +0800
Committer: niclas <ni...@hedhman.org>
Committed: Wed Jun 7 09:21:26 2017 +0800

----------------------------------------------------------------------
 .../composite/AbstractModifierModel.java        |  1 -
 .../runtime/composite/IsCompositeTest.java      | 55 ++++++++++++++++++++
 2 files changed, 55 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/polygene-java/blob/630b7856/core/runtime/src/main/java/org/apache/polygene/runtime/composite/AbstractModifierModel.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/polygene/runtime/composite/AbstractModifierModel.java b/core/runtime/src/main/java/org/apache/polygene/runtime/composite/AbstractModifierModel.java
index 4a00359..2b2f3d5 100644
--- a/core/runtime/src/main/java/org/apache/polygene/runtime/composite/AbstractModifierModel.java
+++ b/core/runtime/src/main/java/org/apache/polygene/runtime/composite/AbstractModifierModel.java
@@ -17,7 +17,6 @@
  *
  *
  */
-
 package org.apache.polygene.runtime.composite;
 
 import java.lang.reflect.Array;

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/630b7856/core/runtime/src/test/java/org/apache/polygene/runtime/composite/IsCompositeTest.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/test/java/org/apache/polygene/runtime/composite/IsCompositeTest.java b/core/runtime/src/test/java/org/apache/polygene/runtime/composite/IsCompositeTest.java
new file mode 100644
index 0000000..a7fe462
--- /dev/null
+++ b/core/runtime/src/test/java/org/apache/polygene/runtime/composite/IsCompositeTest.java
@@ -0,0 +1,55 @@
+/*
+ *  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.polygene.runtime.composite;
+
+import org.apache.polygene.api.common.ConstructionException;
+import org.apache.polygene.api.injection.scope.Uses;
+import org.apache.polygene.bootstrap.AssemblyException;
+import org.apache.polygene.bootstrap.ModuleAssembly;
+import org.apache.polygene.test.AbstractPolygeneTest;
+import org.junit.Test;
+
+public class IsCompositeTest extends AbstractPolygeneTest
+{
+
+    @Override
+    public void assemble( ModuleAssembly module )
+        throws AssemblyException
+    {
+        module.transients( MyTransient.class );
+        module.objects( MyObject.class );
+    }
+
+    @Test( expected = ConstructionException.class )
+    public void givenCompositeToUsesWhenInstantiatingExpectException()
+    {
+        MyTransient myTransient = transientBuilderFactory.newTransient( MyTransient.class );
+        objectFactory.newObject( MyObject.class, myTransient );
+    }
+
+    public interface MyTransient
+    {}
+
+    public static class MyObject
+    {
+        @Uses
+        MyTransient my;
+    }
+}