Fix FELIX-3621
Correct computation of multi-dimension array:
- method id computation
- right arguments in the method metadata (element)
- add tests
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1387915 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/ipojo/manipulator/manipulator/pom.xml b/ipojo/manipulator/manipulator/pom.xml
index d4b0c99..35a5636 100644
--- a/ipojo/manipulator/manipulator/pom.xml
+++ b/ipojo/manipulator/manipulator/pom.xml
@@ -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>
diff --git a/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/ClassChecker.java b/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/ClassChecker.java
index cd804a6..b3630ff 100644
--- a/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/ClassChecker.java
+++ b/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/ClassChecker.java
@@ -645,7 +645,7 @@
* 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)
*/
diff --git a/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/MethodCreator.java b/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/MethodCreator.java
index d3401c4..f4ea9af 100644
--- a/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/MethodCreator.java
+++ b/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/MethodCreator.java
@@ -523,8 +523,13 @@
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('.', '_'));
}
diff --git a/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/MethodDescriptor.java b/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/MethodDescriptor.java
index 025dca3..879762d 100644
--- a/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/MethodDescriptor.java
+++ b/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/MethodDescriptor.java
@@ -183,8 +183,13 @@
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:
diff --git a/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/store/DirectoryResourceStore.java b/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/store/DirectoryResourceStore.java
index dfa8cfc..a38dc29 100644
--- a/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/store/DirectoryResourceStore.java
+++ b/ipojo/manipulator/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/store/DirectoryResourceStore.java
@@ -130,15 +130,7 @@
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 {
diff --git a/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulation/ManipulatorTest.java b/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulation/ManipulatorTest.java
index 9bd1b89..4aaa928 100644
--- a/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulation/ManipulatorTest.java
+++ b/ipojo/manipulator/manipulator/src/test/java/org/apache/felix/ipojo/manipulation/ManipulatorTest.java
@@ -336,6 +336,62 @@
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 {