Author: clement
Date: Tue Sep 9 10:20:14 2008
New Revision: 693520
URL: http://svn.apache.org/viewvc?rev=693520&view=rev
Log:
Fix the issue Felix-697
Check the unicity of method flag field.
Add the tests case provided by Loris in the test suite.
Added:
felix/trunk/ipojo/tests/manipulator/manipulation/src/main/java/org/apache/felix/ipojo/test/scenarios/component/PlopImpl.java
felix/trunk/ipojo/tests/manipulator/manipulation/src/main/java/org/apache/felix/ipojo/test/scenarios/manipulation/DuplicateMethod.java
felix/trunk/ipojo/tests/manipulator/manipulation/src/main/java/org/apache/felix/ipojo/test/scenarios/manipulation/service/Plop.java
Modified:
felix/trunk/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/MethodCreator.java
felix/trunk/ipojo/tests/manipulator/manipulation/pom.xml
felix/trunk/ipojo/tests/manipulator/manipulation/src/main/java/org/apache/felix/ipojo/test/scenarios/manipulation/ManipulationTestSuite.java
felix/trunk/ipojo/tests/manipulator/manipulation/src/main/resources/metadata.xml
Modified:
felix/trunk/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/MethodCreator.java
URL:
http://svn.apache.org/viewvc/felix/trunk/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/MethodCreator.java?rev=693520&r1=693519&r2=693520&view=diff
==============================================================================
---
felix/trunk/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/MethodCreator.java
(original)
+++
felix/trunk/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/MethodCreator.java
Tue Sep 9 10:20:14 2008
@@ -106,6 +106,12 @@
* This set contains method id.
*/
private List m_methods = new ArrayList(); // Contains method id.
+
+ /**
+ * List of fields injected as method flag in the class.
+ * This set contains field name generate from method id.
+ */
+ private List m_methodFlags = new ArrayList();
/**
* Constructor.
@@ -155,8 +161,6 @@
if (name.equals("<clinit>") || name.equals("class$")) { return
super.visitMethod(access, name, desc, signature, exceptions); }
// The constructor is manipulated separately
if (name.equals("<init>")) {
- //TODO : do not manipulate non matching constructor.
-
// 1) change the constructor descriptor (add a component manager
arg as first argument)
String newDesc = desc.substring(1);
@@ -185,8 +189,14 @@
if ((access & ACC_STATIC) == ACC_STATIC) { return
super.visitMethod(access, name, desc, signature, exceptions); }
generateMethodHeader(access, name, desc, signature, exceptions);
- FieldVisitor flagField = cv.visitField(Opcodes.ACC_PRIVATE,
generateMethodFlag(name, desc), "Z", null, null);
- flagField.visitEnd();
+
+
+ String id = generateMethodFlag(name, desc);
+ if (! m_methodFlags.contains(id)) {
+ FieldVisitor flagField = cv.visitField(Opcodes.ACC_PRIVATE, id,
"Z", null, null);
+ flagField.visitEnd();
+ m_methodFlags.add(id);
+ }
MethodVisitor mv = super.visitMethod(ACC_PRIVATE, PREFIX + name, desc,
signature, exceptions);
return new MethodCodeAdapter(mv, m_owner, ACC_PRIVATE, PREFIX + name,
desc, m_fields);
@@ -382,7 +392,7 @@
* Generate a method flag name.
* @param name : method name.
* @param desc : method descriptor.
- * @return the method flag name.
+ * @return the method flag name
*/
private String generateMethodFlag(String name, String desc) {
return METHOD_FLAG_PREFIX + generateMethodId(name, desc);
@@ -473,6 +483,7 @@
createGetComponentInstanceMethod();
m_methods.clear();
+ m_methodFlags.clear();
cv.visitEnd();
}
Modified: felix/trunk/ipojo/tests/manipulator/manipulation/pom.xml
URL:
http://svn.apache.org/viewvc/felix/trunk/ipojo/tests/manipulator/manipulation/pom.xml?rev=693520&r1=693519&r2=693520&view=diff
==============================================================================
--- felix/trunk/ipojo/tests/manipulator/manipulation/pom.xml (original)
+++ felix/trunk/ipojo/tests/manipulator/manipulation/pom.xml Tue Sep 9
10:20:14 2008
@@ -93,8 +93,8 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
- <source>1.4</source>
- <target>1.4</target>
+ <source>1.5</source>
+ <target>1.5</target>
</configuration>
</plugin>
</plugins>
Added:
felix/trunk/ipojo/tests/manipulator/manipulation/src/main/java/org/apache/felix/ipojo/test/scenarios/component/PlopImpl.java
URL:
http://svn.apache.org/viewvc/felix/trunk/ipojo/tests/manipulator/manipulation/src/main/java/org/apache/felix/ipojo/test/scenarios/component/PlopImpl.java?rev=693520&view=auto
==============================================================================
---
felix/trunk/ipojo/tests/manipulator/manipulation/src/main/java/org/apache/felix/ipojo/test/scenarios/component/PlopImpl.java
(added)
+++
felix/trunk/ipojo/tests/manipulator/manipulation/src/main/java/org/apache/felix/ipojo/test/scenarios/component/PlopImpl.java
Tue Sep 9 10:20:14 2008
@@ -0,0 +1,11 @@
+package org.apache.felix.ipojo.test.scenarios.component;
+
+import org.apache.felix.ipojo.test.scenarios.manipulation.service.Plop;
+//TODO this test requires source compatibility 1.5
+public class PlopImpl implements Plop {
+
+ public String getPlop() {
+ return "plop";
+ }
+
+}
Added:
felix/trunk/ipojo/tests/manipulator/manipulation/src/main/java/org/apache/felix/ipojo/test/scenarios/manipulation/DuplicateMethod.java
URL:
http://svn.apache.org/viewvc/felix/trunk/ipojo/tests/manipulator/manipulation/src/main/java/org/apache/felix/ipojo/test/scenarios/manipulation/DuplicateMethod.java?rev=693520&view=auto
==============================================================================
---
felix/trunk/ipojo/tests/manipulator/manipulation/src/main/java/org/apache/felix/ipojo/test/scenarios/manipulation/DuplicateMethod.java
(added)
+++
felix/trunk/ipojo/tests/manipulator/manipulation/src/main/java/org/apache/felix/ipojo/test/scenarios/manipulation/DuplicateMethod.java
Tue Sep 9 10:20:14 2008
@@ -0,0 +1,22 @@
+package org.apache.felix.ipojo.test.scenarios.manipulation;
+
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.junit4osgi.OSGiTestCase;
+import org.apache.felix.ipojo.test.scenarios.manipulation.service.Plop;
+import org.apache.felix.ipojo.test.scenarios.util.Utils;
+import org.osgi.framework.ServiceReference;
+
+public class DuplicateMethod extends OSGiTestCase {
+
+
+ public void testDuplicateMethod() {
+ ComponentInstance instance = Utils.getComponentInstanceByName(context,
"plopimpl", "plop");
+ ServiceReference ref = Utils.getServiceReferenceByName(context,
Plop.class.getName(), "plop");
+ assertNotNull("Check plop", ref);
+ Plop plop = (Plop) context.getService(ref);
+ Object o = plop.getPlop();
+ assertEquals("Check result", "plop", o);
+ context.ungetService(ref);
+ instance.dispose();
+ }
+}
Modified:
felix/trunk/ipojo/tests/manipulator/manipulation/src/main/java/org/apache/felix/ipojo/test/scenarios/manipulation/ManipulationTestSuite.java
URL:
http://svn.apache.org/viewvc/felix/trunk/ipojo/tests/manipulator/manipulation/src/main/java/org/apache/felix/ipojo/test/scenarios/manipulation/ManipulationTestSuite.java?rev=693520&r1=693519&r2=693520&view=diff
==============================================================================
---
felix/trunk/ipojo/tests/manipulator/manipulation/src/main/java/org/apache/felix/ipojo/test/scenarios/manipulation/ManipulationTestSuite.java
(original)
+++
felix/trunk/ipojo/tests/manipulator/manipulation/src/main/java/org/apache/felix/ipojo/test/scenarios/manipulation/ManipulationTestSuite.java
Tue Sep 9 10:20:14 2008
@@ -35,6 +35,7 @@
ots.addTestSuite(ExceptionTest.class);
ots.addTestSuite(POJOCreation.class);
ots.addTestSuite(NestedClassesTests.class);
+ ots.addTestSuite(DuplicateMethod.class);
return ots;
}
Added:
felix/trunk/ipojo/tests/manipulator/manipulation/src/main/java/org/apache/felix/ipojo/test/scenarios/manipulation/service/Plop.java
URL:
http://svn.apache.org/viewvc/felix/trunk/ipojo/tests/manipulator/manipulation/src/main/java/org/apache/felix/ipojo/test/scenarios/manipulation/service/Plop.java?rev=693520&view=auto
==============================================================================
---
felix/trunk/ipojo/tests/manipulator/manipulation/src/main/java/org/apache/felix/ipojo/test/scenarios/manipulation/service/Plop.java
(added)
+++
felix/trunk/ipojo/tests/manipulator/manipulation/src/main/java/org/apache/felix/ipojo/test/scenarios/manipulation/service/Plop.java
Tue Sep 9 10:20:14 2008
@@ -0,0 +1,7 @@
+package org.apache.felix.ipojo.test.scenarios.manipulation.service;
+
+public interface Plop {
+
+ Object getPlop();
+
+}
Modified:
felix/trunk/ipojo/tests/manipulator/manipulation/src/main/resources/metadata.xml
URL:
http://svn.apache.org/viewvc/felix/trunk/ipojo/tests/manipulator/manipulation/src/main/resources/metadata.xml?rev=693520&r1=693519&r2=693520&view=diff
==============================================================================
---
felix/trunk/ipojo/tests/manipulator/manipulation/src/main/resources/metadata.xml
(original)
+++
felix/trunk/ipojo/tests/manipulator/manipulation/src/main/resources/metadata.xml
Tue Sep 9 10:20:14 2008
@@ -115,4 +115,9 @@
<property field="publicInt"/>
</provides>
</component>
+
+ <!-- Check duplicate method issue -->
+ <component
classname="org.apache.felix.ipojo.test.scenarios.component.PlopImpl"
name="plopimpl">
+ <provides></provides>
+ </component>
</ipojo>