Commit 9b79c886 authored by Munilla Christophe's avatar Munilla Christophe

- update FraSCAti's juliac dependencies : move to juliac.2.4.3

- FraSCAtiOSGiContext : add registerOSGiImplementation to access osgi-revision libraries
- frascati-osgi-util becomes frascati-independent-osgi-util + frascati-dependent-osgi-util
- AbstractResource resources storage : use packages as key
- FraSCAtiOSGiClassLoader and FraSCAtiOSGiClassLoaderManager : update to use new AbstractResource storage strategy when loadClass, getResource,...etc are called  
- Embed libraries directly in the root of the bundles 
parent 7e0d7157
...@@ -372,7 +372,8 @@ ...@@ -372,7 +372,8 @@
<artifactItem><groupId>org.ow2.frascati.model</groupId><artifactId>tuscany-model</artifactId><version>2.0.1.3</version></artifactItem> <artifactItem><groupId>org.ow2.frascati.model</groupId><artifactId>tuscany-model</artifactId><version>2.0.1.3</version></artifactItem>
<artifactItem><groupId>org.ow2.frascati.model</groupId><artifactId>frascati-model</artifactId><version>2.0.1.3</version></artifactItem> <artifactItem><groupId>org.ow2.frascati.model</groupId><artifactId>frascati-model</artifactId><version>2.0.1.3</version></artifactItem>
<artifactItem><groupId>org.ow2.frascati.osgi</groupId><artifactId>frascati-starter</artifactId><version>${project.version}</version></artifactItem> <artifactItem><groupId>org.ow2.frascati.osgi</groupId><artifactId>frascati-starter</artifactId><version>${project.version}</version></artifactItem>
<artifactItem><groupId>org.ow2.frascati.osgi</groupId><artifactId>frascati-osgi-util</artifactId><version>${project.version}</version></artifactItem> <artifactItem><groupId>org.ow2.frascati.osgi</groupId><artifactId>frascati-dependent-osgi-util</artifactId><version>${project.version}</version></artifactItem>
<artifactItem><groupId>org.ow2.frascati.osgi</groupId><artifactId>frascati-independent-osgi-util</artifactId><version>${project.version}</version></artifactItem>
<artifactItem><groupId>org.ow2.frascati.nuxeo</groupId><artifactId>frascati-nuxeo-service</artifactId><version>${project.version}</version></artifactItem> <artifactItem><groupId>org.ow2.frascati.nuxeo</groupId><artifactId>frascati-nuxeo-service</artifactId><version>${project.version}</version></artifactItem>
<artifactItem><groupId>org.ow2.frascati.nuxeo</groupId><artifactId>frascati-metamodel-nuxeo</artifactId><version>${project.version}</version></artifactItem> <artifactItem><groupId>org.ow2.frascati.nuxeo</groupId><artifactId>frascati-metamodel-nuxeo</artifactId><version>${project.version}</version></artifactItem>
<artifactItem><groupId>org.ow2.frascati.nuxeo</groupId><artifactId>frascati-binding-nuxeo</artifactId><version>${project.version}</version></artifactItem> <artifactItem><groupId>org.ow2.frascati.nuxeo</groupId><artifactId>frascati-binding-nuxeo</artifactId><version>${project.version}</version></artifactItem>
......
...@@ -64,5 +64,11 @@ ...@@ -64,5 +64,11 @@
<version>${juliac.version}</version> <version>${juliac.version}</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.osgi.core</artifactId>
<version>1.0.0</version>
<scope>provided</scope>
</dependency>
</dependencies> </dependencies>
</project> </project>
...@@ -27,15 +27,16 @@ package org.ow2.frascati.util.resource.cobundle; ...@@ -27,15 +27,16 @@ package org.ow2.frascati.util.resource.cobundle;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
import java.util.Enumeration; import java.util.Enumeration;
import java.util.jar.JarFile; import java.util.jar.JarFile;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.zip.ZipEntry;
import org.objectweb.fractal.juliac.osgi.concierge.Concierge; import org.objectweb.fractal.juliac.osgi.concierge.Concierge;
import org.objectweb.fractal.juliac.osgi.revision.api.BundleRevisionItf; import org.objectweb.fractal.juliac.osgi.revision.api.BundleRevisionItf;
import org.ow2.frascati.osgi.util.io.OSGiIOUtils;
import org.ow2.frascati.util.io.IOUtils; import org.ow2.frascati.util.io.IOUtils;
import org.ow2.frascati.util.resource.AbstractResource; import org.ow2.frascati.util.resource.AbstractResource;
...@@ -48,28 +49,12 @@ public class Resource extends AbstractResource ...@@ -48,28 +49,12 @@ public class Resource extends AbstractResource
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
// Internal state. // Internal state.
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
private BundleRevisionItf<?,?> bundleResource; private BundleRevisionItf<?,?> bundleResource;
private URL jarFileUrl;
private JarFile jarFile;
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
// Internal methods. // Internal methods.
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
// ---------------------------------------------------------------------------
// Internal methods.
// --------------------------------------------------------------------------
private JarFile getJarFile() throws IOException
{
if(jarFile == null)
{
jarFile = Concierge.getInstance().getBundleJar(
this.bundleResource.getBundleId());
}
return jarFile;
}
/** /**
* {@inheritDoc} * {@inheritDoc}
...@@ -79,17 +64,9 @@ public class Resource extends AbstractResource ...@@ -79,17 +64,9 @@ public class Resource extends AbstractResource
@Override @Override
protected URL getEntry(String entry) protected URL getEntry(String entry)
{ {
URL url = null; String formatEntry = entry.startsWith("/")?entry.substring(1):entry;
try URL entryURL = bundleResource.getEntry(formatEntry);
{ return entryURL;
url = new URL(new StringBuilder(jarFileUrl.toExternalForm())
.append(entry.startsWith("/")?entry.substring(1):entry).toString());
} catch (MalformedURLException e)
{
log.log(Level.WARNING,e.getMessage(),e);
}
return url;
} }
/** /**
...@@ -100,16 +77,7 @@ public class Resource extends AbstractResource ...@@ -100,16 +77,7 @@ public class Resource extends AbstractResource
@Override @Override
protected Enumeration<String> getResourceEntries() protected Enumeration<String> getResourceEntries()
{ {
try return OSGiIOUtils.getBundleEntries(bundleResource, filter);
{
JarFile jarFile = getJarFile();
return IOUtils.getJarEntries(jarFile, filter);
} catch (IOException e)
{
e.printStackTrace();
}
return null;
} }
/** /**
...@@ -146,30 +114,19 @@ public class Resource extends AbstractResource ...@@ -146,30 +114,19 @@ public class Resource extends AbstractResource
try try
{ {
bundleResource = (BundleRevisionItf<?,?>) resourceObject; bundleResource = (BundleRevisionItf<?,?>) resourceObject;
URL metaURL = bundleResource.getEntry("META-INF");
URL entryURL = bundleResource.getEntry("/META-INF"); String metaURLStr = metaURL.toExternalForm();
String bundleURLStr = entryURL.toExternalForm().substring(0, resourceURL = new URL(metaURLStr.substring(0,metaURLStr.lastIndexOf('/')));
entryURL.toExternalForm().indexOf("/bundle")+7);
String protocol = entryURL.getProtocol();
String newProtocol = "jar".equals(protocol) ? "" : "jar:";
jarFileUrl = new URL(new StringBuilder(newProtocol)
.append(bundleURLStr).append("!/").toString());
String resourceURLStr = jarFileUrl.toExternalForm().substring(4);
resourceURLStr = new StringBuilder(resourceURLStr.startsWith("file:")?
"":"file:").append(resourceURLStr.substring(0,resourceURLStr.length()-2)).toString();
resourceURL = new URL(resourceURLStr);
} catch(ClassCastException e) } catch(ClassCastException e)
{ {
log.log(Level.CONFIG,e.getMessage(),e);
return false; return false;
} catch (MalformedURLException e) } catch (MalformedURLException e)
{ {
log.log(Level.WARNING,e.getMessage(),e); log.log(Level.WARNING,e.getMessage(),e);
e.printStackTrace(); return false;
} }
return true; return true;
} }
...@@ -207,14 +164,7 @@ public class Resource extends AbstractResource ...@@ -207,14 +164,7 @@ public class Resource extends AbstractResource
@Override @Override
public AbstractResource getEmbeddedResource(String embeddedResourceName) public AbstractResource getEmbeddedResource(String embeddedResourceName)
{ {
File tmpDir = IOUtils.getTmpDir(); return cacheEmbeddedResource(embeddedResourceName,null);
File conciergeTmpDir = new File(new StringBuilder(tmpDir.getAbsolutePath()).append(
File.separatorChar).append("concierge_resources").toString());
if(!conciergeTmpDir.exists() && !conciergeTmpDir.mkdir())
{
conciergeTmpDir = tmpDir;
}
return cacheEmbeddedResource(embeddedResourceName,conciergeTmpDir.getAbsolutePath());
} }
...@@ -231,46 +181,7 @@ public class Resource extends AbstractResource ...@@ -231,46 +181,7 @@ public class Resource extends AbstractResource
public AbstractResource cacheEmbeddedResource(String embeddedResourceName, public AbstractResource cacheEmbeddedResource(String embeddedResourceName,
String cacheDirPath) String cacheDirPath)
{ {
URL resURL = getEntry(embeddedResourceName); AbstractResource resource = newResource(this,getEntry(embeddedResourceName));
if(resURL == null) return resource;
{
resURL = getEntry("lib/" + embeddedResourceName);
}
if (resURL != null)
{
if (cacheDirPath == null)
{
cacheDirPath = IOUtils.getTmpDir().getAbsolutePath();
}
try
{
String simpleResourceName = IOUtils.pathLastPart(embeddedResourceName);
File resourceCopy = new File(new StringBuilder(cacheDirPath).append(
File.separatorChar).append(simpleResourceName).toString());
String resourceCopyPath = resourceCopy.getAbsolutePath();
JarFile jarFile = getJarFile();
InputStream is = jarFile.getInputStream(jarFile.getEntry(
embeddedResourceName));
IOUtils.copyFromStream(is, resourceCopyPath);
resURL = new URL("jar", "", new StringBuilder("file:")
.append(resourceCopyPath).append("!/").toString());
return newResource(this,resURL);
} catch (IOException e)
{
e.printStackTrace();
log.warning("Unable to cache embedded resource :"
+ embeddedResourceName);
}
} else
{
log.warning("Unable to find embedded resource :"
+ embeddedResourceName);
}
return null;
} }
} }
...@@ -8,10 +8,7 @@ public class Plugin extends AbstractPlugin ...@@ -8,10 +8,7 @@ public class Plugin extends AbstractPlugin
{ {
public void plug() public void plug()
{ {
System.setProperty(AbstractResource.RESOURCE_PROP, "cobundle"); System.setProperty(AbstractResource.RESOURCE_PROP, "cobundle");
System.setProperty(AbstractResource.RESOURCE_FILTER_PROP,
"org.ow2.frascati.util.resource.cofilter.ResourceFilterImpl");
LOGGER.log(Level.INFO, "AbstractResource adapter : Concierge Plugin plugged"); LOGGER.log(Level.INFO, "AbstractResource adapter : Concierge Plugin plugged");
} }
} }
\ No newline at end of file
...@@ -28,11 +28,11 @@ package org.ow2.frascati.osgi.context; ...@@ -28,11 +28,11 @@ package org.ow2.frascati.osgi.context;
import java.io.File; import java.io.File;
import java.lang.annotation.Annotation; import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
import java.net.URLClassLoader; import java.net.URLClassLoader;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date;
import java.util.Hashtable; import java.util.Hashtable;
import java.util.List; import java.util.List;
import java.util.logging.Level; import java.util.logging.Level;
...@@ -42,16 +42,20 @@ import org.objectweb.fractal.juliac.osgi.OSGiHelper; ...@@ -42,16 +42,20 @@ import org.objectweb.fractal.juliac.osgi.OSGiHelper;
import org.objectweb.fractal.juliac.osgi.revision.api.BundleRevisionItf; import org.objectweb.fractal.juliac.osgi.revision.api.BundleRevisionItf;
import org.objectweb.fractal.juliac.osgi.revision.api.BundleContextRevisionItf; import org.objectweb.fractal.juliac.osgi.revision.api.BundleContextRevisionItf;
import org.objectweb.fractal.juliac.osgi.revision.api.OSGiRevisionItf; import org.objectweb.fractal.juliac.osgi.revision.api.OSGiRevisionItf;
import org.osoa.sca.annotations.Init; import org.osoa.sca.annotations.Init;
import org.osoa.sca.annotations.Reference; import org.osoa.sca.annotations.Reference;
import org.osoa.sca.annotations.Scope; import org.osoa.sca.annotations.Scope;
import org.ow2.frascati.assembly.factory.api.ClassLoaderManager; import org.ow2.frascati.assembly.factory.api.ClassLoaderManager;
import org.ow2.frascati.osgi.api.FraSCAtiOSGiContext; import org.ow2.frascati.osgi.api.FraSCAtiOSGiContext;
import org.ow2.frascati.osgi.resource.loader.AbstractResourceClassLoader; import org.ow2.frascati.osgi.resource.loader.AbstractResourceClassLoader;
import org.ow2.frascati.osgi.security.FraSCAtiOSGiSecurityManager; import org.ow2.frascati.osgi.security.FraSCAtiOSGiSecurityManager;
import org.ow2.frascati.osgi.util.io.OSGiIOUtils; import org.ow2.frascati.osgi.util.io.OSGiIOUtils;
import org.ow2.frascati.parser.api.ParsingContext; import org.ow2.frascati.parser.api.ParsingContext;
import org.ow2.frascati.parser.core.ParsingContextImpl;
import org.ow2.frascati.util.FrascatiClassLoader; import org.ow2.frascati.util.FrascatiClassLoader;
import org.ow2.frascati.util.io.IOUtils; import org.ow2.frascati.util.io.IOUtils;
import org.ow2.frascati.util.resource.AbstractResource; import org.ow2.frascati.util.resource.AbstractResource;
...@@ -86,7 +90,7 @@ public class FraSCAtiOSGiContextImpl implements FraSCAtiOSGiContext ...@@ -86,7 +90,7 @@ public class FraSCAtiOSGiContextImpl implements FraSCAtiOSGiContext
* the AbstractResourceClassLoader manager * the AbstractResourceClassLoader manager
*/ */
private AbstractResourceClassLoader clManager; private AbstractResourceClassLoader clManager;
/** /**
* The required classloader manager. * The required classloader manager.
*/ */
...@@ -160,23 +164,12 @@ public class FraSCAtiOSGiContextImpl implements FraSCAtiOSGiContext ...@@ -160,23 +164,12 @@ public class FraSCAtiOSGiContextImpl implements FraSCAtiOSGiContext
private String packageDependencies(URLClassLoader cloader, private String packageDependencies(URLClassLoader cloader,
String packageName, String interfaceName) String packageName, String interfaceName)
{ {
// String jdependLibName = "jdepend.jar";
// String jdependLibPath = new StringBuilder(
// IOUtils.getTmpDir().getAbsolutePath()).append(
// File.separatorChar).append(jdependLibName).toString();
//
// InputStream inputStream = FraSCAtiOSGiContextImpl.class.getClassLoader(
// ).getResourceAsStream(jdependLibName);
//
// IOUtils.copyFromStream(inputStream,jdependLibPath);
//
// File jdependLib = new File(jdependLibPath);
List<URL> urls = new ArrayList<URL>(); List<URL> urls = new ArrayList<URL>();
//prepare a ClassLoader using the juliac compiler way //prepare a ClassLoader using the juliac compiler way
ClassLoader currentClassLoader = cloader; ClassLoader currentClassLoader = cloader;
while(currentClassLoader!= null while(currentClassLoader!= null && URLClassLoader.class.isAssignableFrom(
&& (currentClassLoader instanceof URLClassLoader)) currentClassLoader.getClass()))
{ {
int index = 0; int index = 0;
URL[] parentURLs = ((URLClassLoader) currentClassLoader).getURLs(); URL[] parentURLs = ((URLClassLoader) currentClassLoader).getURLs();
...@@ -186,37 +179,15 @@ public class FraSCAtiOSGiContextImpl implements FraSCAtiOSGiContext ...@@ -186,37 +179,15 @@ public class FraSCAtiOSGiContextImpl implements FraSCAtiOSGiContext
} }
currentClassLoader = currentClassLoader.getParent(); currentClassLoader = currentClassLoader.getParent();
} }
// try
// {
// urls.add(jdependLib.toURI().toURL());
//
// } catch (MalformedURLException e)
// {
// LOGGER.log(Level.WARNING, e.getMessage(), e);
// }
URLClassLoader tmpClassLoader = new URLClassLoader( URLClassLoader tmpClassLoader = new URLClassLoader(
urls.toArray(new URL[0]), ClassLoader.getSystemClassLoader()); urls.toArray(new URL[0]), ClassLoader.getSystemClassLoader());
// ReflectionHelper jdepend = new ReflectionHelper(tmpClassLoader,
// "jdepend.framework.JDepend");
// ReflectionHelper javaPackage = new ReflectionHelper(tmpClassLoader,
// "jdepend.framework.JavaPackage");
// ReflectionHelper efferentJavaPackage = new ReflectionHelper(
// javaPackage.getReflectedClass());
//
// jdepend.newInstance();
StringBuilder dynamicInterfacePackageName = new StringBuilder(); StringBuilder dynamicInterfacePackageName = new StringBuilder();
try try
{ {
Class<?> interfaceClass = tmpClassLoader.loadClass(interfaceName); Class<?> interfaceClass = tmpClassLoader.loadClass(interfaceName);
Class<?>[] classes = interfaceClass.getDeclaredClasses(); Class<?>[] classes = interfaceClass.getDeclaredClasses();
Annotation[] annotations = interfaceClass.getAnnotations(); Annotation[] annotations = interfaceClass.getAnnotations();
//
// jdepend.invoke("addPackage",
// new Class<?>[]{String.class},
// new Object[]{interfaceClass.getPackage().getName()});
//
for(Annotation annotation : annotations) for(Annotation annotation : annotations)
{ {
dynamicInterfacePackageName.append( dynamicInterfacePackageName.append(
...@@ -230,24 +201,7 @@ public class FraSCAtiOSGiContextImpl implements FraSCAtiOSGiContext ...@@ -230,24 +201,7 @@ public class FraSCAtiOSGiContextImpl implements FraSCAtiOSGiContext
} catch (ClassNotFoundException e) } catch (ClassNotFoundException e)
{ {
LOGGER.log(Level.WARNING, e.getMessage(), e); LOGGER.log(Level.WARNING, e.getMessage(), e);
} }
// javaPackage.set(jdepend.invoke("getPackage",
// new Class<?>[]{String.class},
// new Object[]{packageName}));
//
// if(javaPackage.get() != null)
// {
// Collection<?> efferents = (Collection<?>) javaPackage.invoke("getEfferents");
// if(efferents != null)
// {
// for (Object efferent : efferents)
// {
// efferentJavaPackage.set(efferent);
// dynamicInterfacePackageName.append(
// (String)efferentJavaPackage.invoke("getName")).append(",");
// }
// }
// }
dynamicInterfacePackageName.append("*"); dynamicInterfacePackageName.append("*");
return dynamicInterfacePackageName.toString(); return dynamicInterfacePackageName.toString();
} }
...@@ -277,6 +231,8 @@ public class FraSCAtiOSGiContextImpl implements FraSCAtiOSGiContext ...@@ -277,6 +231,8 @@ public class FraSCAtiOSGiContextImpl implements FraSCAtiOSGiContext
public void registerBindedInterface(String interfaceName, String filter, public void registerBindedInterface(String interfaceName, String filter,
ParsingContext parsingContext) ParsingContext parsingContext)
{ {
long launchDuration = -1;
long startTime = new Date().getTime();
try try
{ {
String normalizedFilter = normalizeFilter(filter); String normalizedFilter = normalizeFilter(filter);
...@@ -288,9 +244,9 @@ public class FraSCAtiOSGiContextImpl implements FraSCAtiOSGiContext ...@@ -288,9 +244,9 @@ public class FraSCAtiOSGiContextImpl implements FraSCAtiOSGiContext
Class<?> interfaceClass = bundle.loadClass(interfaceName); Class<?> interfaceClass = bundle.loadClass(interfaceName);
//needed by JDTCompiler //needed by JDTCompiler
String jarFilePath = OSGiIOUtils.cacheBundle(bundle,getCacheDir()); String jarFilePath = OSGiIOUtils.cacheBundle(bundle,getCacheDir());
if(LOGGER.isLoggable(Level.CONFIG)) if(LOGGER.isLoggable(Level.INFO))
{ {
LOGGER.log(Level.CONFIG, "bundle cached : " + jarFilePath); LOGGER.log(Level.INFO, "bundle cached : " + jarFilePath);
} }
try try
{ {
...@@ -318,6 +274,11 @@ public class FraSCAtiOSGiContextImpl implements FraSCAtiOSGiContext ...@@ -318,6 +274,11 @@ public class FraSCAtiOSGiContextImpl implements FraSCAtiOSGiContext
{ {
LOGGER.log(Level.WARNING,e.getMessage(), e); LOGGER.log(Level.WARNING,e.getMessage(), e);
} }
} finally
{
launchDuration = new Date().getTime() - startTime;
LOGGER.log(Level.INFO, "Binded interface registration '" +
interfaceName + "' : " + launchDuration + " ms");
} }
} }
...@@ -329,7 +290,9 @@ public class FraSCAtiOSGiContextImpl implements FraSCAtiOSGiContext ...@@ -329,7 +290,9 @@ public class FraSCAtiOSGiContextImpl implements FraSCAtiOSGiContext
*/ */
public void registerExportedInterface(String interfaceName, public void registerExportedInterface(String interfaceName,
String properties, ParsingContext parsingContext) String properties, ParsingContext parsingContext)
{ {
long launchDuration = -1;
long startTime = new Date().getTime();
String interfaceSimpleName = interfaceName.substring( String interfaceSimpleName = interfaceName.substring(
interfaceName.lastIndexOf('.') + 1); interfaceName.lastIndexOf('.') + 1);
String interfacePackageName = interfaceName.substring(0, String interfacePackageName = interfaceName.substring(0,
...@@ -373,11 +336,17 @@ public class FraSCAtiOSGiContextImpl implements FraSCAtiOSGiContext ...@@ -373,11 +336,17 @@ public class FraSCAtiOSGiContextImpl implements FraSCAtiOSGiContext
} catch (ClassNotFoundException e) } catch (ClassNotFoundException e)
{ {
LOGGER.log(Level.INFO, interfaceName + " not found in the BundleContext"); LOGGER.log(Level.WARNING, interfaceName + " not found in the BundleContext");