You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by cl...@apache.org on 2012/09/20 11:01:51 UTC

svn commit: r1387915 - in /felix/trunk/ipojo/manipulator/manipulator: ./ src/main/java/org/apache/felix/ipojo/manipulation/ src/main/java/org/apache/felix/ipojo/manipulator/store/ src/test/java/org/apache/felix/ipojo/manipulation/

Author: clement
Date: Thu Sep 20 09:01:50 2012
New Revision: 1387915

URL: http://svn.apache.org/viewvc?rev=1387915&view=rev
Log:
Fix FELIX-3621
Correct computation of multi-dimension array:
- method id computation
- right arguments in the method metadata (element)
- add tests

Modified:
    felix/trunk/ipojo/manipulator/manipulator/pom.xml
    felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/ClassChecker.java
    felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/MethodCreator.java
    felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/MethodDescriptor.java
    felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/store/DirectoryResourceStore.java
    felix/trunk/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulation/ManipulatorTest.java

Modified: felix/trunk/ipojo/manipulator/manipulator/pom.xml
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/manipulator/manipulator/pom.xml?rev=1387915&r1=1387914&r2=1387915&view=diff
==============================================================================
--- felix/trunk/ipojo/manipulator/manipulator/pom.xml (original)
+++ felix/trunk/ipojo/manipulator/manipulator/pom.xml Thu Sep 20 09:01:50 2012
@@ -94,6 +94,7 @@
                     <obrRepository>NONE</obrRepository>
                 </configuration>
             </plugin>
+
             <plugin>
                 <groupId>org.codehaus.mojo</groupId>
                 <artifactId>rat-maven-plugin</artifactId>
@@ -111,6 +112,7 @@
                     </excludes>
                 </configuration>
             </plugin>
+
             <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-checkstyle-plugin</artifactId>

Modified: felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/ClassChecker.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/ClassChecker.java?rev=1387915&r1=1387914&r2=1387915&view=diff
==============================================================================
--- felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/ClassChecker.java (original)
+++ felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/ClassChecker.java Thu Sep 20 09:01:50 2012
@@ -645,7 +645,7 @@ public class ClassChecker extends EmptyV
          * Visits the content of the array. This method is called for
          * nested arrays (arrays contained in the array).
          * @param arg0 <code>null</code>
-         * @return an {@link ArrayDescriptor} which creates a copy of
+         * @return an {@link AnnotationVisitor} which creates a copy of
          * the contained array.
          * @see org.objectweb.asm.AnnotationVisitor#visitArray(String)
          */

Modified: felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/MethodCreator.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/MethodCreator.java?rev=1387915&r1=1387914&r2=1387915&view=diff
==============================================================================
--- felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/MethodCreator.java (original)
+++ felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/MethodCreator.java Thu Sep 20 09:01:50 2012
@@ -523,8 +523,13 @@ public class MethodCreator extends Class
         for (int i = 0; i < args.length; i++) {
             String arg = args[i].getClassName();
             if (arg.endsWith("[]")) {
-                arg = arg.substring(0, arg.length() - 2);
-                id.append("$" + arg.replace('.', '_') + "__");
+                // We have to replace all []
+                String acc = "";
+                while (arg.endsWith("[]")) {
+                    arg = arg.substring(0, arg.length() - 2);
+                    acc += "__";
+                }
+                id.append("$" + arg.replace('.', '_') + acc);
             } else {
                 id.append("$" + arg.replace('.', '_'));
             }

Modified: felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/MethodDescriptor.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/MethodDescriptor.java?rev=1387915&r1=1387914&r2=1387915&view=diff
==============================================================================
--- felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/MethodDescriptor.java (original)
+++ felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/MethodDescriptor.java Thu Sep 20 09:01:50 2012
@@ -183,8 +183,13 @@ public class MethodDescriptor {
     private String getType(Type type) {
         switch (type.getSort()) {
             case Type.ARRAY:
+                // Append brackets.
+                String brackets = "";
+                for (int i = 0; i < type.getDimensions(); i++) {
+                    brackets += "[]";
+                }
                 Type elemType = type.getElementType();
-                return getType(elemType) + "[]";
+                return getType(elemType) + brackets;
             case Type.BOOLEAN:
                 return "boolean";
             case Type.BYTE:

Modified: felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/store/DirectoryResourceStore.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/store/DirectoryResourceStore.java?rev=1387915&r1=1387914&r2=1387915&view=diff
==============================================================================
--- felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/store/DirectoryResourceStore.java (original)
+++ felix/trunk/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/store/DirectoryResourceStore.java Thu Sep 20 09:01:50 2012
@@ -130,15 +130,7 @@ public class DirectoryResourceStore impl
         Manifest updated = m_manifestBuilder.build(m_manifest);
         
         // Write it to disk
-        File outputFile = m_manifest_file;
-        // In case it's forgot to be set in Pojoization.
-        if(outputFile == null)
-        {
-        	outputFile = new File( m_source, "META-INF" );
-        	outputFile = new File( outputFile, "MANIFEST.MF" );
-        }
-        
-        OutputStream os = new FileOutputStream( outputFile );
+        OutputStream os = new FileOutputStream(m_manifest_file);
         try {
             updated.write(os);
         } finally {

Modified: felix/trunk/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulation/ManipulatorTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulation/ManipulatorTest.java?rev=1387915&r1=1387914&r2=1387915&view=diff
==============================================================================
--- felix/trunk/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulation/ManipulatorTest.java (original)
+++ felix/trunk/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulation/ManipulatorTest.java Thu Sep 20 09:01:50 2012
@@ -336,6 +336,62 @@ public class ManipulatorTest extends Tes
         Assert.assertEquals("toto", f.get(o));
      }
 
+    /**
+     * https://issues.apache.org/jira/browse/FELIX-3621
+     */
+    public void testManipulatingDoubleArray() throws Exception {
+        Manipulator manipulator = new Manipulator();
+        byte[] clazz = manipulator.manipulate(getBytesFromFile(new File("target/test-classes/test/DoubleArray.class")
+        ));
+        ManipulatedClassLoader classloader = new ManipulatedClassLoader("test.DoubleArray", clazz);
+        Class cl = classloader.findClass("test.DoubleArray");
+        Assert.assertNotNull(cl);
+        Assert.assertNotNull(manipulator.getManipulationMetadata());
+
+        System.out.println(manipulator.getManipulationMetadata());
+        Assert.assertTrue(manipulator.getManipulationMetadata().toString().contains("arguments=\"{int[][]}\""));
+
+        // The manipulation add stuff to the class.
+        Assert.assertTrue(clazz.length > getBytesFromFile(new File("target/test-classes/test/DoubleArray.class")).length);
+
+
+        boolean found = false;
+        Constructor cst = null;
+        Constructor[] csts = cl.getDeclaredConstructors();
+        for(int i = 0; i < csts.length; i++) {
+            System.out.println(Arrays.asList(csts[i].getParameterTypes()));
+            if (csts[i].getParameterTypes().length == 1  &&
+                    csts[i].getParameterTypes()[0].equals(InstanceManager.class)) {
+                found = true;
+                cst = csts[i];
+            }
+        }
+        Assert.assertTrue(found);
+
+        // We still have the empty constructor
+        found = false;
+        csts = cl.getDeclaredConstructors();
+        for (int i = 0; i < csts.length; i++) {
+            System.out.println(Arrays.asList(csts[i].getParameterTypes()));
+            if (csts[i].getParameterTypes().length == 0) {
+                found = true;
+            }
+        }
+        Assert.assertTrue(found);
+
+        // Check the POJO interface
+        Assert.assertTrue(Arrays.asList(cl.getInterfaces()).contains(Pojo.class));
+
+        cst.setAccessible(true);
+        Object pojo = cst.newInstance(new Object[] {new InstanceManager()});
+        Assert.assertNotNull(pojo);
+        Assert.assertTrue(pojo instanceof Pojo);
+
+        Method method = cl.getMethod("start", new Class[0]);
+        Assert.assertTrue(((Boolean) method.invoke(pojo, new Object[0])).booleanValue());
+
+    }
+
 
 
     public static byte[] getBytesFromFile(File file) throws IOException {