Commit 016d6cfc authored by Munilla Christophe's avatar Munilla Christophe

- FraSCAtiOSGiTracker and OSGiResourceProcessor are dependent of the core and...

- FraSCAtiOSGiTracker and OSGiResourceProcessor are dependent of the core and used in frascati-in-osgi and osgi-in-frascati : those two classes are put in the core module
- fix AbstractResource getResource and getResources methods bugs
- configure binding-gcs-test
- bpel, gcs, velocity, widget are available in frascati-in-osgi
parent bb8cc427
......@@ -87,6 +87,31 @@
<version>${project.version}</version>
<scope>compile</scope>
</dependency>
<!-- TEST DEPENDENCIES -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.6</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.9.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-test-mockito-junit4</artifactId>
<version>1.4.10</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<version>1.4.10</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
......
......@@ -28,7 +28,7 @@ package org.ow2.frascati.osgi.api;
import java.io.File;
import org.objectweb.fractal.juliac.osgi.revision.api.BundleContextRevisionItf;
import org.ow2.frascati.osgi.resource.loader.AbstractResourceClassLoader;
import org.ow2.frascati.osgi.resource.AbstractResourceClassLoader;
import org.ow2.frascati.parser.api.ParsingContext;
/**
......
......@@ -51,7 +51,7 @@ 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.resource.AbstractResourceClassLoader;
import org.ow2.frascati.osgi.security.FraSCAtiOSGiSecurityManager;
import org.ow2.frascati.osgi.util.io.OSGiIOUtils;
......@@ -213,8 +213,10 @@ public class FraSCAtiOSGiContextImpl implements FraSCAtiOSGiContext
@Init
public void init()
{
LOGGER.info("init FraSCAtiOSGiContext");
if(LOGGER.isLoggable(Level.CONFIG))
{
LOGGER.log(Level.CONFIG, "init FraSCAtiOSGiContext");
}
getCacheDir();
configureSecurityManager();
}
......
......@@ -46,7 +46,7 @@ import org.ow2.frascati.assembly.factory.api.ManagerException;
import org.ow2.frascati.assembly.factory.api.ProcessingContext;
import org.ow2.frascati.osgi.api.FraSCAtiOSGiContext;
import org.ow2.frascati.osgi.api.FraSCAtiOSGiRegistry;
import org.ow2.frascati.osgi.resource.loader.AbstractResourceClassLoader;
import org.ow2.frascati.osgi.resource.AbstractResourceClassLoader;
import org.ow2.frascati.parser.api.ParsingContext;
import org.ow2.frascati.tinfi.TinfiComponentInterceptor;
import org.ow2.frascati.tinfi.api.IntentHandler;
......
......@@ -24,7 +24,7 @@
* Contributor(s):
*
*/
package org.ow2.frascati.osgi.resource.loader;
package org.ow2.frascati.osgi.resource;
import java.io.IOException;
import java.net.URL;
......
......@@ -24,35 +24,41 @@
* Contributor(s): Christophe Munilla
*
*/
package org.ow2.frascati.osgi.tracker;
package org.ow2.frascati.osgi.resource;
import org.objectweb.fractal.juliac.osgi.revision.api.BundleRevisionItf;
import org.objectweb.fractal.juliac.osgi.revision.event.BundleListenerRevisionItf;
import org.osoa.sca.annotations.Reference;
import org.ow2.frascati.osgi.api.FraSCAtiOSGiContext;
import org.ow2.frascati.osgi.api.service.FraSCAtiOSGiService;
import org.ow2.frascati.osgi.processor.OSGiResourceProcessor;
import org.ow2.frascati.osgi.resource.OSGiResourceProcessor;
import org.ow2.frascati.osgi.util.io.OSGiIOUtils;
import org.ow2.frascati.starter.api.AbstractInitializable;
import org.ow2.frascati.util.AbstractLoggeable;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
* A FraSCAtiOSGiTracker listen about Bundles changes and look
* for SCA Composite in nearly installed ones
*/
public class FraSCAtiOSGiTracker extends AbstractInitializable implements
BundleListenerRevisionItf
public class FraSCAtiOSGiTracker extends AbstractLoggeable
implements BundleListenerRevisionItf
{
@Reference(name = "frascati-osgi-service")
private FraSCAtiOSGiService service;
@Reference(name = "frascati-osgi-context")
private FraSCAtiOSGiContext context;
private OSGiResourceProcessor processor;
public void doInitialize()
public FraSCAtiOSGiTracker(FraSCAtiOSGiService service,
FraSCAtiOSGiContext context)
{
if(log.isLoggable(Level.CONFIG))
{
log.log(Level.CONFIG, "init FraSCAtiOSGiTracker");
}
this.service = service;
this.context = context;
context.getBundleContext().registerBundleListener(this);
processor = new OSGiResourceProcessor(service);
}
......
......@@ -24,7 +24,7 @@
* Contributors :
*
*/
package org.ow2.frascati.osgi.processor;
package org.ow2.frascati.osgi.resource;
import java.io.File;
import java.net.MalformedURLException;
......@@ -112,7 +112,7 @@ public class OSGiResourceProcessor extends AbstractLoggeable
List<String> unmanagedResources, ArrayList<String> compositesToProcess,
List<String> embeddedComposites)
{
if(log.isLoggable(Level.INFO))
if(log.isLoggable(Level.CONFIG))
{
StringBuilder messageBuilder = new StringBuilder();
for(String compositeToProcess : compositesToProcess)
......@@ -127,7 +127,7 @@ public class OSGiResourceProcessor extends AbstractLoggeable
{
messageBuilder.append("\n ... searched");
}
log.log(Level.INFO,messageBuilder.toString());
log.log(Level.CONFIG,messageBuilder.toString());
}
if (embeddedComposites.size() > 0)
{
......@@ -139,14 +139,15 @@ public class OSGiResourceProcessor extends AbstractLoggeable
{
log.log(Level.INFO,embeddedComposite + " processing ...");
}
String compositeName = null;
try
{
compositeName = service.loadSCA(resource.getResourceURL(),
service.loadSCA(resource.getResourceURL(),
embeddedComposite);
} catch (FraSCAtiOSGiNotFoundCompositeException e)
{
log.warning("Unable to find the '" + embeddedComposite + "' embedded composite");
log.warning("Unable to find the '" + embeddedComposite +
"' embedded composite");
}
if (!compositesToProcess.remove(embeddedComposite))
......@@ -157,17 +158,27 @@ public class OSGiResourceProcessor extends AbstractLoggeable
}
}
int compositesSize = compositesToProcess.size();
log.log(Level.INFO, compositesSize + " more Composite file(s) to process");
if(log.isLoggable(Level.CONFIG))
{
log.log(Level.CONFIG, compositesSize +
" more Composite file(s) to process");
}
if (embeddedComposites.size() > 0 && compositesSize == 0)
{
log.info("All required Composite files have been processed");
if(log.isLoggable(Level.INFO))
{
log.log(Level.INFO,"All required Composite files have been processed");
}
return;
}
List<String> embeddedJars = resource.getEmbeddedJars();
int jarsSize = embeddedJars.size();
if (jarsSize == 0 && compositesSize > 0)
{
log.warning("All declared composite files have not been found");
if(log.isLoggable(Level.WARNING))
{
log.log(Level.WARNING,"All declared composite files have not been found");
}
return;
}
int n = 0;
......@@ -234,14 +245,18 @@ public class OSGiResourceProcessor extends AbstractLoggeable
resource.setUnmanagedResourcesList(unmanagedResources);
resource.buildEntries();
} else
} else if(log.isLoggable(Level.WARNING))
{
log.warning("Error occured while trying to cache the bundle "
log.log(Level.WARNING,
"Error occured while trying to cache the bundle "
+ bundle);
}
} catch (MalformedURLException e)
{
if(log.isLoggable(Level.WARNING))
{
log.log(Level.WARNING,e.getMessage(),e);
}
}
}
processResource(resource, unmanagedResources, compositesToProcess,
......
......@@ -47,7 +47,8 @@ import org.ow2.frascati.osgi.api.service.FraSCAtiOSGiNotFoundCompositeException;
import org.ow2.frascati.osgi.api.service.FraSCAtiOSGiNotFoundServiceException;
import org.ow2.frascati.osgi.api.service.FraSCAtiOSGiNotRunnableServiceException;
import org.ow2.frascati.osgi.api.service.FraSCAtiOSGiService;
import org.ow2.frascati.osgi.resource.loader.AbstractResourceClassLoader;
import org.ow2.frascati.osgi.resource.AbstractResourceClassLoader;
import org.ow2.frascati.osgi.resource.FraSCAtiOSGiTracker;
import org.ow2.frascati.starter.api.AbstractInitializable;
import org.ow2.frascati.util.FrascatiException;
import org.ow2.frascati.util.reflect.ReflectionHelper;
......@@ -104,6 +105,11 @@ public class FraSCAtiOSGiServiceImpl extends AbstractInitializable implements
* Helper for Bundles
* */
private ReflectionHelper bundle;
/**
* Tracker of bundle-embedded composites in the BundleContext
*/
private FraSCAtiOSGiTracker tracker;
// ---------------------------------------------------------------------------
// Internal methods.
......@@ -275,7 +281,10 @@ public class FraSCAtiOSGiServiceImpl extends AbstractInitializable implements
@Init
public void init()
{
log.info("init FraSCAtiOSGiService");
if(log.isLoggable(Level.CONFIG))
{
log.log(Level.CONFIG,"init FraSCAtiOSGiService");
}
this.loaded = new ArrayList<String>();
}
......@@ -294,6 +303,8 @@ public class FraSCAtiOSGiServiceImpl extends AbstractInitializable implements
fServiceRegistration = foContext.getBundleContext().registerService(
FraSCAtiOSGiService.class.getCanonicalName(), this, null);
this.tracker = new FraSCAtiOSGiTracker(this,foContext);
} catch(Exception e)
{
log.log(Level.WARNING,e.getMessage(),e);
......
......@@ -53,7 +53,7 @@ import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
import org.objectweb.fractal.juliac.osgi.revision.api.BundleRevisionItf;
import org.ow2.frascati.osgi.api.service.FraSCAtiOSGiService;
import org.ow2.frascati.osgi.processor.OSGiResourceProcessor;
import org.ow2.frascati.osgi.resource.OSGiResourceProcessor;
import org.ow2.frascati.osgi.util.io.OSGiIOUtils;
import org.ow2.frascati.util.io.IOUtils;
import org.ow2.frascati.util.resource.AbstractResource;
......
......@@ -48,8 +48,8 @@ import org.objectweb.fractal.juliac.osgi.revision.api.BundleContextRevisionItf;
import org.objectweb.fractal.juliac.osgi.revision.event.BundleListenerRevisionItf;
import org.ow2.frascati.osgi.api.FraSCAtiOSGiContext;
import org.ow2.frascati.osgi.api.service.FraSCAtiOSGiService;
import org.ow2.frascati.osgi.processor.OSGiResourceProcessor;
import org.ow2.frascati.osgi.tracker.FraSCAtiOSGiTracker;
import org.ow2.frascati.osgi.resource.OSGiResourceProcessor;
import org.ow2.frascati.osgi.resource.FraSCAtiOSGiTracker;
import org.ow2.frascati.osgi.util.io.OSGiIOUtils;
import org.ow2.frascati.util.resource.AbstractResource;
import org.powermock.api.mockito.PowerMockito;
......@@ -124,21 +124,17 @@ public class FraSCAtiOSGiTrackerTest
});
tracker = new FraSCAtiOSGiTracker();
tracker = new FraSCAtiOSGiTracker(spiedService,spiedContext);
//Mocks injection to be able to test
PowerMockito.field(FraSCAtiOSGiTracker.class,"context").set(tracker, spiedContext);
PowerMockito.field(FraSCAtiOSGiTracker.class,"service").set(tracker, spiedService);
tracker.doInitialize();
OSGiResourceProcessor processor = (OSGiResourceProcessor) PowerMockito.field(
FraSCAtiOSGiTracker.class,"processor").get(tracker);
spiedProcessor = spy(processor);
PowerMockito.field(FraSCAtiOSGiTracker.class,"processor").set(tracker, spiedProcessor);
}
/**
......
......@@ -167,17 +167,18 @@ public class FraSCAtiOSGiClassLoader extends URLClassLoader
{
try
{
InputStream inputStream = classFileNameURL.openStream();
clazz = createClass(className, packageName, classFileNameURL,
classFileNameURL.openStream());
inputStream);
} catch (IOException e)
{
logg.log(Level.INFO, "Exception thrown while trying to create Class "
+ className + " with URL " + classFileNameURL);
} catch (Exception e)
} catch (Throwable throwable)
{
if(logg.isLoggable(Level.WARNING))
{
logg.log(Level.INFO, "Exception thrown while trying to create Class "
+ className + " with URL " + classFileNameURL);
+ className + " with URL " + classFileNameURL, throwable);
}
}
}
}
......@@ -223,8 +224,13 @@ public class FraSCAtiOSGiClassLoader extends URLClassLoader
try
{
is.close();
} catch (IOException e)
{
if(logg.isLoggable(Level.WARNING))
{
logg.log(Level.WARNING,e.getMessage(),e);
}
}
}
if (packageName != null)
......@@ -555,8 +561,8 @@ public class FraSCAtiOSGiClassLoader extends URLClassLoader
URL url = getResource(name);
try
{
InputStream is = url.openStream();
return is;
InputStream inputStream = url.openStream();
return inputStream;
} catch (Exception e)
{
......
......@@ -35,6 +35,11 @@ import java.util.Enumeration;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.logging.Level;
import java.util.logging.Logger;
......@@ -273,7 +278,7 @@ public class FraSCAtiOSGiClassLoaderManager
* The name of the searched class
* @return The searched class if it has been found. Null otherwise
*/
public URL getResource(String name)
public URL getResource(final String name)
{
URL resourceURL = null;
String entry = name.endsWith("/")?name.substring(0,name.length()-1):name;
......@@ -286,15 +291,56 @@ public class FraSCAtiOSGiClassLoaderManager
List<FraSCAtiOSGiClassLoader> loaders = packagesMap.get(packageName);
if(loaders != null)
{
for(FraSCAtiOSGiClassLoader loader : loaders)
int current = 0;
int size = loaders.size();
ExecutorService executor = Executors.newFixedThreadPool(size);
List<Future<URL>> futures = new ArrayList<Future<URL>>(size) ;
while(current < size)
{
resourceURL = loader.findResource(name);
if(resourceURL != null)
{
break;
}
final FraSCAtiOSGiClassLoader loader = loaders.get(current++);
futures.add(executor.submit(new Callable<URL>()
{
public URL call() throws Exception
{
return loader.findResource(name);
}
}));
}
}
executor.shutdown();
while(!executor.isTerminated())
{
try
{
Thread.sleep(10);
} catch(InterruptedException e)
{
Thread.interrupted();
}
}
for(Future<URL> future : futures)
{
URL result = null;
try
{
result = future.get();
} catch (InterruptedException e)
{
e.printStackTrace();
} catch (ExecutionException e)
{
e.printStackTrace();
}
if(result != null)
{
resourceURL = result;
break;
}
}
}
if(resourceURL == null)
{
resourceURL = bundleContext.getResource(name);
......@@ -309,7 +355,7 @@ public class FraSCAtiOSGiClassLoaderManager
* The name of the searched class
* @return The searched class if it has been found. Null otherwise
*/
public Enumeration<URL> getResources(String name)
public Enumeration<URL> getResources(final String name)
{
List<URL> resourcesURL = new ArrayList<URL>();
......@@ -324,16 +370,53 @@ public class FraSCAtiOSGiClassLoaderManager
if(loaders != null)
{
for(FraSCAtiOSGiClassLoader loader : loaders)
int current = 0;
int size = loaders.size();
ExecutorService executor = Executors.newFixedThreadPool(size);
List<Future<Enumeration<URL>>> futures = new ArrayList<Future<Enumeration<URL>>>(size) ;
while(current < size)
{
final FraSCAtiOSGiClassLoader loader = loaders.get(current++);
futures.add(executor.submit(new Callable<Enumeration<URL>>()
{
public Enumeration<URL> call() throws Exception
{
return loader.findResources(name);
}
}));
}
executor.shutdown();
while(!executor.isTerminated())
{
try
{
Thread.sleep(10);
} catch(InterruptedException e)
{
Thread.interrupted();
}
}
for(Future<Enumeration<URL>> future : futures)
{
Enumeration<URL> resources = loader.findResources(name);
if(resources != null)
{
while(resources.hasMoreElements())
{
resourcesURL.add(resources.nextElement());
}
}
Enumeration<URL> results = null;
try
{
results = future.get();
} catch (InterruptedException e)
{
e.printStackTrace();
} catch (ExecutionException e)
{
e.printStackTrace();
}
if(results != null)
{
resourcesURL.addAll(Collections.list(results));
}
}
}
return Collections.enumeration(resourcesURL);
......
......@@ -85,17 +85,11 @@
<dependency><groupId>org.ow2.frascati.osgi</groupId><artifactId>frascati-starter</artifactId><version>${project.version}</version><scope>runtime</scope></dependency>
<dependency><groupId>org.ow2.frascati.osgi</groupId><artifactId>frascati-dependent-osgi-util</artifactId><version>${project.version}</version><scope>runtime</scope></dependency>
<!-- TODO: the bundle-tracker doesn't work for all implementation (classloading issue (?)) -->
<!-- USE the SCA Component instead -->
<dependency><groupId>org.ow2.frascati.osgi</groupId><artifactId>frascati-osgi-tracker</artifactId><version>${project.version}</version><scope>runtime</scope></dependency>
<dependency><groupId>org.ow2.frascati.osgi</groupId><artifactId>frascati-osgi-processor</artifactId><version>${project.version}</version><scope>runtime</scope></dependency>
<dependency><groupId>org.ow2.frascati.tinfi</groupId><artifactId>frascati-tinfi-runtime-api</artifactId><version>${tinfi.version}</version><scope>runtime</scope></dependency>
<dependency><groupId>org.ow2.frascati.tinfi</groupId><artifactId>frascati-tinfi-runtime</artifactId><version>${tinfi.version}</version><scope>runtime</scope></dependency>
<dependency><groupId>org.ow2.frascati.tinfi</groupId><artifactId>frascati-tinfi-membranes-oo</artifactId><version>${tinfi.version}</version><scope>runtime</scope></dependency>
<dependency><groupId>org.ow2.frascati.tinfi</groupId><artifactId>frascati-tinfi-mixins</artifactId><version>${tinfi.version}</version><scope>runtime</scope></dependency>
<dependency><groupId>org.ow2.frascati.tinfi</groupId><artifactId>frascati-tinfi-oo</artifactId><version>${tinfi.version}</version><scope>runtime</scope></dependency>
<!-- -->
<dependency><groupId>org.beanshell</groupId><artifactId>bsh</artifactId><version>2.0b5</version><scope>runtime</scope></dependency>
<dependency><groupId>com.google.guava</groupId><artifactId>guava</artifactId><version>r07</version><scope>runtime</scope></dependency>
......
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
<properties>
<entry key="SYSTEM_PACKAGE_BASE">
javax.activation,
javax.annotation,