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 2014/05/06 17:06:49 UTC
svn commit: r1592771 - in /felix/trunk/ipojo:
manipulator/online-manipulator/src/main/java/org/apache/felix/ipojo/online/manipulator/
runtime/api/src/main/java/org/apache/felix/ipojo/api/
runtime/composite/src/main/java/org/apache/felix/ipojo/composite...
Author: clement
Date: Tue May 6 15:06:48 2014
New Revision: 1592771
URL: http://svn.apache.org/r1592771
Log:
Migrate the composite support, iPOJO API and Online manipulator to the new manipulator API (FELIX-4509).
The iPOJO API build a classloader around the given bundle context.
The composite use the class's classloader (should not be used anyway as the generated code is pretty simple)
The online manipulaotr use a bridge loading classes from the original bundle (under deployment) and from the set of deployed bundles
Added:
felix/trunk/ipojo/manipulator/online-manipulator/src/main/java/org/apache/felix/ipojo/online/manipulator/BridgeClassLoader.java
Modified:
felix/trunk/ipojo/manipulator/online-manipulator/src/main/java/org/apache/felix/ipojo/online/manipulator/IPOJOURLHandler.java
felix/trunk/ipojo/runtime/api/src/main/java/org/apache/felix/ipojo/api/PrimitiveComponentType.java
felix/trunk/ipojo/runtime/composite/src/main/java/org/apache/felix/ipojo/composite/service/provides/CompositionMetadata.java
Added: felix/trunk/ipojo/manipulator/online-manipulator/src/main/java/org/apache/felix/ipojo/online/manipulator/BridgeClassLoader.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/manipulator/online-manipulator/src/main/java/org/apache/felix/ipojo/online/manipulator/BridgeClassLoader.java?rev=1592771&view=auto
==============================================================================
--- felix/trunk/ipojo/manipulator/online-manipulator/src/main/java/org/apache/felix/ipojo/online/manipulator/BridgeClassLoader.java (added)
+++ felix/trunk/ipojo/manipulator/online-manipulator/src/main/java/org/apache/felix/ipojo/online/manipulator/BridgeClassLoader.java Tue May 6 15:06:48 2014
@@ -0,0 +1,65 @@
+/*
+ * 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.felix.ipojo.online.manipulator;
+
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+
+import java.io.File;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLClassLoader;
+
+/**
+ * A classloader trying to load classes from a given jar files and then from bundles.
+ * This classloader must only be used for the iPOJO manipulator (in order to compute bytecode frames).
+ */
+public class BridgeClassLoader extends ClassLoader {
+
+ private final URLClassLoader m_loader;
+ private final BundleContext m_context;
+
+ public BridgeClassLoader(File original, BundleContext context) throws MalformedURLException {
+ m_loader = new URLClassLoader(new URL[]{original.toURI().toURL()}, null);
+ m_context = context;
+ }
+
+ @Override
+ public Class<?> loadClass(String name) throws ClassNotFoundException {
+ // Try to load it using the url classloader
+ try {
+ return m_loader.loadClass(name);
+ } catch (ClassNotFoundException e) {
+ // Not there, try somewhere else.
+ }
+
+ for (Bundle bundle : m_context.getBundles()) {
+ if (bundle.getState() >= Bundle.RESOLVED) {
+ try {
+ return bundle.loadClass(name);
+ } catch (ClassNotFoundException e) {
+ // Try next one.
+ }
+ }
+ }
+
+ // Still nothing, delegate to parent
+ return super.loadClass(name);
+ }
+}
Modified: felix/trunk/ipojo/manipulator/online-manipulator/src/main/java/org/apache/felix/ipojo/online/manipulator/IPOJOURLHandler.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/manipulator/online-manipulator/src/main/java/org/apache/felix/ipojo/online/manipulator/IPOJOURLHandler.java?rev=1592771&r1=1592770&r2=1592771&view=diff
==============================================================================
--- felix/trunk/ipojo/manipulator/online-manipulator/src/main/java/org/apache/felix/ipojo/online/manipulator/IPOJOURLHandler.java (original)
+++ felix/trunk/ipojo/manipulator/online-manipulator/src/main/java/org/apache/felix/ipojo/online/manipulator/IPOJOURLHandler.java Tue May 6 15:06:48 2014
@@ -212,10 +212,11 @@ public class IPOJOURLHandler extends Abs
composite.addMetadataProvider(provider);
}
+ ClassLoader classloader = new BridgeClassLoader(original, m_context);
// Pojoization
Pojoization pojoizator = new Pojoization(createModuleProvider());
try {
- pojoizator.pojoization(store, composite, createVisitor(store, reporter));
+ pojoizator.pojoization(store, composite, createVisitor(store, reporter), classloader);
} catch (Exception e) {
if (!pojoizator.getErrors().isEmpty()) {
throw new IOException("Errors occurred during the manipulation : " + pojoizator.getErrors(), e);
Modified: felix/trunk/ipojo/runtime/api/src/main/java/org/apache/felix/ipojo/api/PrimitiveComponentType.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/api/src/main/java/org/apache/felix/ipojo/api/PrimitiveComponentType.java?rev=1592771&r1=1592770&r2=1592771&view=diff
==============================================================================
--- felix/trunk/ipojo/runtime/api/src/main/java/org/apache/felix/ipojo/api/PrimitiveComponentType.java (original)
+++ felix/trunk/ipojo/runtime/api/src/main/java/org/apache/felix/ipojo/api/PrimitiveComponentType.java Tue May 6 15:06:48 2014
@@ -448,7 +448,16 @@ public class PrimitiveComponentType exte
* @return the manipulated class
*/
private byte[] manipulate() {
- Manipulator manipulator = new Manipulator();
+ Manipulator manipulator = new Manipulator(new ClassLoader() {
+ @Override
+ public Class<?> loadClass(String name) throws ClassNotFoundException {
+ try {
+ return m_context.getBundle().loadClass(name);
+ } catch (ClassNotFoundException e) {
+ return this.getClass().getClassLoader().loadClass(name);
+ }
+ }
+ });
try {
byte[] array = getClassByteArray();
Modified: felix/trunk/ipojo/runtime/composite/src/main/java/org/apache/felix/ipojo/composite/service/provides/CompositionMetadata.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/composite/src/main/java/org/apache/felix/ipojo/composite/service/provides/CompositionMetadata.java?rev=1592771&r1=1592770&r2=1592771&view=diff
==============================================================================
--- felix/trunk/ipojo/runtime/composite/src/main/java/org/apache/felix/ipojo/composite/service/provides/CompositionMetadata.java (original)
+++ felix/trunk/ipojo/runtime/composite/src/main/java/org/apache/felix/ipojo/composite/service/provides/CompositionMetadata.java Tue May 6 15:06:48 2014
@@ -234,7 +234,7 @@ public class CompositionMetadata {
return null;
}
byte[] pojo = POJOWriter.dump(clazz, m_name, getFieldList(), getMethodList(), m_handler);
- Manipulator manipulator = new Manipulator();
+ Manipulator manipulator = new Manipulator(this.getClass().getClassLoader());
try {
manipulator.prepare(pojo);
byte[] newclazz = manipulator.manipulate(pojo);