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 @@
<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.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-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>
......
......@@ -64,5 +64,11 @@
<version>${juliac.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.osgi.core</artifactId>
<version>1.0.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
......@@ -27,15 +27,16 @@ package org.ow2.frascati.util.resource.cobundle;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Enumeration;
import java.util.jar.JarFile;
import java.util.logging.Level;
import java.util.zip.ZipEntry;
import org.objectweb.fractal.juliac.osgi.concierge.Concierge;
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.resource.AbstractResource;
......@@ -48,28 +49,12 @@ public class Resource extends AbstractResource
// ---------------------------------------------------------------------------
// Internal state.
// --------------------------------------------------------------------------
private BundleRevisionItf<?,?> bundleResource;
private URL jarFileUrl;
private JarFile jarFile;
// ---------------------------------------------------------------------------
// Internal methods.
// --------------------------------------------------------------------------
// ---------------------------------------------------------------------------
// Internal methods.
// --------------------------------------------------------------------------
private JarFile getJarFile() throws IOException
{
if(jarFile == null)
{
jarFile = Concierge.getInstance().getBundleJar(
this.bundleResource.getBundleId());
}
return jarFile;
}
/**
* {@inheritDoc}
......@@ -79,17 +64,9 @@ public class Resource extends AbstractResource
@Override
protected URL getEntry(String entry)
{
URL url = null;
try
{
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;
String formatEntry = entry.startsWith("/")?entry.substring(1):entry;
URL entryURL = bundleResource.getEntry(formatEntry);
return entryURL;
}
/**
......@@ -100,16 +77,7 @@ public class Resource extends AbstractResource
@Override
protected Enumeration<String> getResourceEntries()
{
try
{
JarFile jarFile = getJarFile();
return IOUtils.getJarEntries(jarFile, filter);
} catch (IOException e)
{
e.printStackTrace();
}
return null;
return OSGiIOUtils.getBundleEntries(bundleResource, filter);
}
/**
......@@ -146,30 +114,19 @@ public class Resource extends AbstractResource
try
{
bundleResource = (BundleRevisionItf<?,?>) resourceObject;
URL entryURL = bundleResource.getEntry("/META-INF");
String bundleURLStr = entryURL.toExternalForm().substring(0,
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);
URL metaURL = bundleResource.getEntry("META-INF");
String metaURLStr = metaURL.toExternalForm();
resourceURL = new URL(metaURLStr.substring(0,metaURLStr.lastIndexOf('/')));
} catch(ClassCastException e)
{
log.log(Level.CONFIG,e.getMessage(),e);
return false;
} catch (MalformedURLException e)
{
log.log(Level.WARNING,e.getMessage(),e);
e.printStackTrace();
return false;
}
return true;
}
......@@ -207,14 +164,7 @@ public class Resource extends AbstractResource
@Override
public AbstractResource getEmbeddedResource(String embeddedResourceName)
{
File tmpDir = IOUtils.getTmpDir();
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());
return cacheEmbeddedResource(embeddedResourceName,null);
}
......@@ -231,46 +181,7 @@ public class Resource extends AbstractResource
public AbstractResource cacheEmbeddedResource(String embeddedResourceName,
String cacheDirPath)
{
URL resURL = getEntry(embeddedResourceName);
if(resURL == null)
{
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;
AbstractResource resource = newResource(this,getEntry(embeddedResourceName));
return resource;
}
}
......@@ -8,10 +8,7 @@ public class Plugin extends AbstractPlugin
{
public void plug()
{
System.setProperty(AbstractResource.RESOURCE_PROP, "cobundle");
System.setProperty(AbstractResource.RESOURCE_FILTER_PROP,
"org.ow2.frascati.util.resource.cofilter.ResourceFilterImpl");
System.setProperty(AbstractResource.RESOURCE_PROP, "cobundle");
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;
import java.io.File;
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.Date;
import java.util.Hashtable;
import java.util.List;
import java.util.logging.Level;
......@@ -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.BundleContextRevisionItf;
import org.objectweb.fractal.juliac.osgi.revision.api.OSGiRevisionItf;
import org.osoa.sca.annotations.Init;
import org.osoa.sca.annotations.Reference;
import org.osoa.sca.annotations.Scope;
import org.ow2.frascati.assembly.factory.api.ClassLoaderManager;
import org.ow2.frascati.osgi.api.FraSCAtiOSGiContext;
import org.ow2.frascati.osgi.resource.loader.AbstractResourceClassLoader;
import org.ow2.frascati.osgi.security.FraSCAtiOSGiSecurityManager;
import org.ow2.frascati.osgi.util.io.OSGiIOUtils;
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.io.IOUtils;
import org.ow2.frascati.util.resource.AbstractResource;
......@@ -86,7 +90,7 @@ public class FraSCAtiOSGiContextImpl implements FraSCAtiOSGiContext
* the AbstractResourceClassLoader manager
*/
private AbstractResourceClassLoader clManager;
/**
* The required classloader manager.
*/
......@@ -160,23 +164,12 @@ public class FraSCAtiOSGiContextImpl implements FraSCAtiOSGiContext
private String packageDependencies(URLClassLoader cloader,
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>();
//prepare a ClassLoader using the juliac compiler way
ClassLoader currentClassLoader = cloader;
while(currentClassLoader!= null
&& (currentClassLoader instanceof URLClassLoader))
ClassLoader currentClassLoader = cloader;
while(currentClassLoader!= null && URLClassLoader.class.isAssignableFrom(
currentClassLoader.getClass()))
{
int index = 0;
URL[] parentURLs = ((URLClassLoader) currentClassLoader).getURLs();
......@@ -186,37 +179,15 @@ public class FraSCAtiOSGiContextImpl implements FraSCAtiOSGiContext
}
currentClassLoader = currentClassLoader.getParent();
}
// try
// {
// urls.add(jdependLib.toURI().toURL());
//
// } catch (MalformedURLException e)
// {
// LOGGER.log(Level.WARNING, e.getMessage(), e);
// }
URLClassLoader tmpClassLoader = new URLClassLoader(
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();
urls.toArray(new URL[0]), ClassLoader.getSystemClassLoader());
StringBuilder dynamicInterfacePackageName = new StringBuilder();
try
{
Class<?> interfaceClass = tmpClassLoader.loadClass(interfaceName);
Class<?>[] classes = interfaceClass.getDeclaredClasses();
Annotation[] annotations = interfaceClass.getAnnotations();
//
// jdepend.invoke("addPackage",
// new Class<?>[]{String.class},
// new Object[]{interfaceClass.getPackage().getName()});
//
for(Annotation annotation : annotations)
{
dynamicInterfacePackageName.append(
......@@ -230,24 +201,7 @@ public class FraSCAtiOSGiContextImpl implements FraSCAtiOSGiContext
} catch (ClassNotFoundException 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("*");
return dynamicInterfacePackageName.toString();
}
......@@ -277,6 +231,8 @@ public class FraSCAtiOSGiContextImpl implements FraSCAtiOSGiContext
public void registerBindedInterface(String interfaceName, String filter,
ParsingContext parsingContext)
{
long launchDuration = -1;
long startTime = new Date().getTime();
try
{
String normalizedFilter = normalizeFilter(filter);
......@@ -288,9 +244,9 @@ public class FraSCAtiOSGiContextImpl implements FraSCAtiOSGiContext
Class<?> interfaceClass = bundle.loadClass(interfaceName);
//needed by JDTCompiler
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
{
......@@ -318,6 +274,11 @@ public class FraSCAtiOSGiContextImpl implements FraSCAtiOSGiContext
{
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
*/
public void registerExportedInterface(String interfaceName,
String properties, ParsingContext parsingContext)
{
{
long launchDuration = -1;
long startTime = new Date().getTime();
String interfaceSimpleName = interfaceName.substring(
interfaceName.lastIndexOf('.') + 1);
String interfacePackageName = interfaceName.substring(0,
......@@ -373,11 +336,17 @@ public class FraSCAtiOSGiContextImpl implements FraSCAtiOSGiContext
} catch (ClassNotFoundException e)
{
LOGGER.log(Level.INFO, interfaceName + " not found in the BundleContext");
LOGGER.log(Level.WARNING, interfaceName + " not found in the BundleContext");
} catch(Exception e)
{
LOGGER.log(Level.INFO, interfaceName + " not found in the BundleContext");
LOGGER.log(Level.WARNING, e.getMessage());
} finally
{
launchDuration = new Date().getTime() - startTime;
LOGGER.log(Level.INFO, "Binded interface registration '" +
interfaceName + "' : " + launchDuration + " ms");
}
}
......@@ -407,12 +376,12 @@ public class FraSCAtiOSGiContextImpl implements FraSCAtiOSGiContext
{
FrascatiClassLoader loader = (FrascatiClassLoader) parsingContext.getClassLoader();
AbstractResource bundleResource = AbstractResource.newResource(null, bundle);
bundleResource.buildEntries();
bundleResource.buildEntries();
for(String embeddedJarName : bundleResource.getEmbeddedJars())
{
URL url = bundleResource.cacheEmbeddedResource(embeddedJarName,
getCacheDir().getAbsolutePath()).getResourceURL();
loader.addUrl(url);
}
}
......
......@@ -40,6 +40,5 @@
</component>
<wire source="sca-parser/frascati-osgi-context" target="frascati-osgi/frascati-osgi-context" />
<!--<wire source="assembly-factory/frascati-osgi-context" target="frascati-osgi/frascati-osgi-context" />-->
</composite>
......@@ -27,5 +27,5 @@
<reference name="frascati-osgi-context" promote="sca-parser/frascati-osgi-context">
<interface.java interface="org.ow2.frascati.osgi.api.FraSCAtiOSGiContext"/>
</reference>
</composite>
\ No newline at end of file
......@@ -72,7 +72,7 @@
<instructions>
<Bundle-SymbolicName>${pom.artifactId}</Bundle-SymbolicName>
<Embed-Dependency>*;scope=compile|runtime</Embed-Dependency>
<Embed-Directory>lib</Embed-Directory>
<Embed-Directory>.</Embed-Directory>
<Embed-Transitive>false</Embed-Transitive>
<_nouses>true</_nouses><_nodefaultversion>true</_nodefaultversion>
<_exportcontents>*</_exportcontents>
......
......@@ -47,14 +47,4 @@
<module>reconfig</module>
</modules>
<dependencies>
<!--
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.core</artifactId>
<version>4.2.0</version>
<scope>provided</scope>
</dependency>
-->
</dependencies>
</project>
\ No newline at end of file
<?xml version="1.0"?>
<!--
* OW2 FraSCAti OSGi
* Copyright (c) 2011 - 2012 Inria, University of Lille 1
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Contact: frascati@ow2.org
*
* Author: Christophe Munilla
*
* Contributor(s):
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"
>
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.ow2.frascati.osgi</groupId>
<artifactId>parent</artifactId>
<version>1.5-SNAPSHOT</version>
</parent>
<artifactId>frascati-dependent-osgi-util</artifactId>
<name>OW2 FraSCAti OSGi Utility Tools</name>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>org.ow2.frascati</groupId>
<artifactId>frascati-util</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.ow2.frascati.tinfi</groupId>
<artifactId>frascati-tinfi-runtime</artifactId>
<version>${tinfi.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
......@@ -50,7 +50,7 @@ public abstract class ServiceReferenceUtil
// Internal state.
// -------------------------------------------------------------------------
private static Logger logg = Logger.getLogger(ServiceReferenceUtil.class.getCanonicalName());
private static final Logger LOGGER = Logger.getLogger(ServiceReferenceUtil.class.getCanonicalName());
// -------------------------------------------------------------------------
// Internal methods.
......@@ -118,14 +118,14 @@ public abstract class ServiceReferenceUtil
}
catch(ClassCastException e)