Author: clement
Date: Mon Mar 17 09:53:04 2008
New Revision: 637971
URL: http://svn.apache.org/viewvc?rev=637971&view=rev
Log:
Improve error handling
Fix a bug on bundle re-manipulation (which create an incorrect pojo class)
Remove some useless code
Modified:
felix/sandbox/clement/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/ClassChecker.java
felix/sandbox/clement/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/Manipulator.java
felix/sandbox/clement/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/MethodCreator.java
felix/sandbox/clement/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/Pojoization.java
Modified:
felix/sandbox/clement/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/ClassChecker.java
URL:
http://svn.apache.org/viewvc/felix/sandbox/clement/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/ClassChecker.java?rev=637971&r1=637970&r2=637971&view=diff
==============================================================================
---
felix/sandbox/clement/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/ClassChecker.java
(original)
+++
felix/sandbox/clement/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/ClassChecker.java
Mon Mar 17 09:53:04 2008
@@ -76,7 +76,7 @@
public FieldVisitor visitField(int access, String name, String desc,
String signature, Object value) {
- if (access == ACC_PRIVATE && name.equals("_cm")
+ if (access == ACC_PRIVATE && name.equals(MethodCreator.IM_FIELD)
&& desc.equals("Lorg/apache/felix/ipojo/InstanceManager;")) {
m_isAlreadyManipulated = true;
} else if (name.startsWith("class$")) { // Does not add class$* field
generated by 'x.class'
Modified:
felix/sandbox/clement/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/Manipulator.java
URL:
http://svn.apache.org/viewvc/felix/sandbox/clement/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/Manipulator.java?rev=637971&r1=637970&r2=637971&view=diff
==============================================================================
---
felix/sandbox/clement/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/Manipulator.java
(original)
+++
felix/sandbox/clement/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/Manipulator.java
Mon Mar 17 09:53:04 2008
@@ -19,11 +19,8 @@
package org.apache.felix.ipojo.manipulation;
import java.io.ByteArrayInputStream;
-import java.io.File;
-import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
-import java.net.URL;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
@@ -32,7 +29,6 @@
import org.apache.felix.ipojo.metadata.Element;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassWriter;
-import org.objectweb.asm.util.CheckClassAdapter;
/**
* iPOJO Byte code Manipulator.
@@ -59,74 +55,6 @@
* Pojo super class.
*/
private String m_superClass;
-
- /**
- * Manipulate the class.
- *
- * @param name : The name of the class
- * @param outputDirectory : output directory where the class if stored.
- * @return true if the class is correctly manipulated.
- * @throws Exception : occurs if the manipulation failed.
- */
- public boolean manipulate(String name, File outputDirectory) throws
Exception {
- // gets an input stream to read the byte code of the class
- String path = outputDirectory + "/" + name.replace('.', '/') +
".class";
- File clazz = new File(path);
-
- if (!clazz.exists()) {
- return false;
- }
-
- URL url = clazz.toURL();
-
- // if (url == null) { throw new ClassNotFoundException(name); }
- ManipulationProperty.getLogger().log(ManipulationProperty.INFO,
"Manipulate the class file : " + clazz.getAbsolutePath());
-
- InputStream is1 = url.openStream();
-
- // First check if the class is already manipulated :
- ClassReader ckReader = new ClassReader(is1);
- ClassChecker ck = new ClassChecker();
- ckReader.accept(ck, ClassReader.SKIP_FRAMES);
- is1.close();
-
- m_fields = ck.getFields(); // Get visited fields (contains only POJO
fields)
-
- // Get interfaces and super class.
- m_interfaces = ck.getInterfaces();
- m_superClass = ck.getSuperClass();
-
- // Get the methods list
- m_methods = ck.getMethods();
-
- if (!ck.isalreadyManipulated()) {
-
- // Manipulation ->
- // Add the _setComponentManager method
- // Instrument all fields
- InputStream is2 = url.openStream();
- ClassReader cr0 = new ClassReader(is2);
- ClassWriter cw0 = new ClassWriter(ClassWriter.COMPUTE_MAXS);
- MethodCreator preprocess = new MethodCreator(cw0, m_fields);
- CheckClassAdapter ch = new CheckClassAdapter(preprocess);
- cr0.accept(ch, ClassReader.SKIP_FRAMES);
- is2.close();
-
- try {
- FileOutputStream fos = new FileOutputStream(clazz);
-
- fos.write(cw0.toByteArray());
-
- fos.close();
-
ManipulationProperty.getLogger().log(ManipulationProperty.INFO, "Put the file "
+ clazz.getAbsolutePath() + " in the jar file");
- } catch (Exception e) {
- System.err.println("Problem to write the adapted class on the
file system " + " [ " + clazz.getAbsolutePath() + " ] " + e.getMessage());
- e.printStackTrace();
- }
- }
- // The file is in the bundle
- return true;
- }
/**
* Manipulate the given byte array.
Modified:
felix/sandbox/clement/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/MethodCreator.java
URL:
http://svn.apache.org/viewvc/felix/sandbox/clement/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/MethodCreator.java?rev=637971&r1=637970&r2=637971&view=diff
==============================================================================
---
felix/sandbox/clement/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/MethodCreator.java
(original)
+++
felix/sandbox/clement/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulation/MethodCreator.java
Mon Mar 17 09:53:04 2008
@@ -41,6 +41,11 @@
public class MethodCreator extends ClassAdapter implements Opcodes {
/**
+ * Instance Manager Field.
+ */
+ public static final String IM_FIELD = "__IM";
+
+ /**
* All POJO method will be renamed by using this prefix.
*/
private static final String PREFIX = "__";
@@ -59,11 +64,6 @@
* MEthof flag prefix.
*/
private static final String METHOD_FLAG_PREFIX = "__M";
-
- /**
- * Instance Manager Field.
- */
- private static final String IM_FIELD = "__IM";
/**
* onEntry method name.
Modified:
felix/sandbox/clement/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/Pojoization.java
URL:
http://svn.apache.org/viewvc/felix/sandbox/clement/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/Pojoization.java?rev=637971&r1=637970&r2=637971&view=diff
==============================================================================
---
felix/sandbox/clement/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/Pojoization.java
(original)
+++
felix/sandbox/clement/ipojo/manipulator/src/main/java/org/apache/felix/ipojo/manipulator/Pojoization.java
Mon Mar 17 09:53:04 2008
@@ -133,6 +133,9 @@
path = "/" + path;
}
m_metadata = parseXMLMetadata(path);
+ if (m_metadata == null) {
+ return;
+ }
}
JarFile inputJar;