[jboss-osgi-commits] JBoss-OSGI SVN: r92647 - in projects/jboss-osgi/trunk: reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/framework and 3 other directories.
jboss-osgi-commits at lists.jboss.org
jboss-osgi-commits at lists.jboss.org
Thu Aug 20 21:18:13 EDT 2009
Author: thomas.diesler at jboss.com
Date: 2009-08-20 21:18:12 -0400 (Thu, 20 Aug 2009)
New Revision: 92647
Modified:
projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/api/BundleLifecyclePlugin.java
projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/api/BundleStoragePlugin.java
projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/framework/BundleContextImpl.java
projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/framework/FrameworkImpl.java
projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/framework/plugins/BundleEventsPluginImpl.java
projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/framework/plugins/BundleLifecyclePluginImpl.java
projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/framework/plugins/BundleStoragePluginImpl.java
projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/framework/plugins/FrameworkEventsPluginImpl.java
projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/framework/plugins/ServiceEventsPluginImpl.java
projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/framework/resolver/RuntimeClassLoaderImpl.java
projects/jboss-osgi/trunk/testsuite/pom.xml
Log:
Expand bundle jars to storage area
Modified: projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/api/BundleLifecyclePlugin.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/api/BundleLifecyclePlugin.java 2009-08-21 01:15:31 UTC (rev 92646)
+++ projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/api/BundleLifecyclePlugin.java 2009-08-21 01:18:12 UTC (rev 92647)
@@ -34,6 +34,8 @@
*/
public interface BundleLifecyclePlugin extends AbstractPlugin
{
+ Bundle installBundle(String location) throws BundleException;
+
void start(Bundle bundle, int options) throws BundleException;
void stop(Bundle bundle, int options) throws BundleException;
Modified: projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/api/BundleStoragePlugin.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/api/BundleStoragePlugin.java 2009-08-21 01:15:31 UTC (rev 92646)
+++ projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/api/BundleStoragePlugin.java 2009-08-21 01:18:12 UTC (rev 92647)
@@ -35,5 +35,10 @@
*/
public interface BundleStoragePlugin extends AbstractPlugin
{
+ void cleanStorage(String propValue);
+
+ File getStorageDir(Bundle bundle);
+
File getDataFile(Bundle bundle, String filename);
+
}
\ No newline at end of file
Modified: projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/framework/BundleContextImpl.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/framework/BundleContextImpl.java 2009-08-21 01:15:31 UTC (rev 92646)
+++ projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/framework/BundleContextImpl.java 2009-08-21 01:18:12 UTC (rev 92647)
@@ -34,17 +34,15 @@
import org.jboss.logging.Logger;
import org.jboss.osgi.jbossmc.api.AbstractPlugin;
import org.jboss.osgi.jbossmc.api.BundleEventsPlugin;
-import org.jboss.osgi.jbossmc.api.BundleFactoryPlugin;
-import org.jboss.osgi.jbossmc.api.BundleStoragePlugin;
+import org.jboss.osgi.jbossmc.api.BundleLifecyclePlugin;
import org.jboss.osgi.jbossmc.api.BundleRegistryPlugin;
+import org.jboss.osgi.jbossmc.api.BundleStoragePlugin;
import org.jboss.osgi.jbossmc.api.FrameworkEventsPlugin;
-import org.jboss.osgi.jbossmc.api.ClassLoaderFactoryPlugin;
import org.jboss.osgi.jbossmc.api.ServiceEventsPlugin;
import org.jboss.osgi.jbossmc.api.ServiceRegistryPlugin;
import org.jboss.osgi.spi.NotImplementedException;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
-import org.osgi.framework.BundleEvent;
import org.osgi.framework.BundleException;
import org.osgi.framework.BundleListener;
import org.osgi.framework.Filter;
@@ -217,35 +215,8 @@
public Bundle installBundle(String location) throws BundleException
{
- // Convert location to a virtual file URL
- BundleFactoryPlugin bundleFactory = getPlugin(BundleFactoryPlugin.class);
- location = bundleFactory.getVirtualLocation(location);
-
- // 1. If a bundle containing the same location identifier is already installed, the Bundle object for that bundle is returned.
- BundleRegistryPlugin bundleRegistry = getPlugin(BundleRegistryPlugin.class);
- Bundle bundle = bundleRegistry.getBundleByLocation(location);
- if (bundle != null)
- return bundle;
-
- // 2. The bundle's content is read from the input stream. If this fails, a BundleException is thrown.
- // 3. The bundle's associated resources are allocated. The associated resources minimally consist of a unique identifier and a persistent storage area if the platform has file system support.
- bundle = bundleFactory.createBundle(location);
- bundleRegistry.registerBundle(bundle);
-
- // Initialize the bundle's runtime class loader
- BundleImpl bundleImpl = (BundleImpl)bundle;
- ClassLoaderFactoryPlugin factory = getPlugin(ClassLoaderFactoryPlugin.class);
- bundleImpl.setRuntimeClassLoader(factory.createClassLoader(bundle));
-
- // 4. The bundle's state is set to INSTALLED.
- bundleImpl.setState(Bundle.INSTALLED);
-
- // 5. A bundle event of type BundleEvent.INSTALLED is fired.
- BundleEventsPlugin eventManager = getPlugin(BundleEventsPlugin.class);
- eventManager.fireBundleEvent(new BundleEvent(BundleEvent.INSTALLED, bundle));
-
- // 6. The Bundle object for the newly or previously installed bundle is returned.
- return bundle;
+ BundleLifecyclePlugin plugin = getPlugin(BundleLifecyclePlugin.class);
+ return plugin.installBundle(location);
}
public Bundle installBundle(String location, InputStream input) throws BundleException
Modified: projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/framework/FrameworkImpl.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/framework/FrameworkImpl.java 2009-08-21 01:15:31 UTC (rev 92646)
+++ projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/framework/FrameworkImpl.java 2009-08-21 01:18:12 UTC (rev 92647)
@@ -39,6 +39,7 @@
import org.jboss.osgi.jbossmc.api.AutoInstallPlugin;
import org.jboss.osgi.jbossmc.api.BundleEventsPlugin;
import org.jboss.osgi.jbossmc.api.BundleRegistryPlugin;
+import org.jboss.osgi.jbossmc.api.BundleStoragePlugin;
import org.jboss.osgi.jbossmc.api.FrameworkEventsPlugin;
import org.jboss.osgi.jbossmc.api.ServiceEventsPlugin;
import org.jboss.osgi.jbossmc.api.ServiceRegistryPlugin;
@@ -57,6 +58,7 @@
import org.jboss.virtual.VirtualFile;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleException;
+import org.osgi.framework.Constants;
import org.osgi.framework.FrameworkEvent;
import org.osgi.framework.InvalidSyntaxException;
import org.osgi.framework.ServiceReference;
@@ -274,7 +276,21 @@
setStartLevel(0);
// Have event handling enabled
+ FrameworkEventsPlugin frameworkEvents = getPlugin(FrameworkEventsPlugin.class);
+ frameworkEvents.setEnabled(true);
+ BundleEventsPlugin bundleEvents = getPlugin(BundleEventsPlugin.class);
+ bundleEvents.setEnabled(true);
+ ServiceEventsPlugin serviceEvents = getPlugin(ServiceEventsPlugin.class);
+ serviceEvents.setEnabled(true);
+ // Cleanup the storage area
+ String storageClean = (String)getProperty(Constants.FRAMEWORK_STORAGE_CLEAN);
+ if (storageClean != null)
+ {
+ BundleStoragePlugin storage = getPlugin(BundleStoragePlugin.class);
+ storage.cleanStorage(storageClean);
+ }
+
// [TODO] Have reified Bundle objects for all installed bundles
// [TODO] Have registered any framework services
Modified: projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/framework/plugins/BundleEventsPluginImpl.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/framework/plugins/BundleEventsPluginImpl.java 2009-08-21 01:15:31 UTC (rev 92646)
+++ projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/framework/plugins/BundleEventsPluginImpl.java 2009-08-21 01:18:12 UTC (rev 92647)
@@ -45,7 +45,7 @@
final Logger log = Logger.getLogger(BundleEventsPluginImpl.class);
private List<BundleListener> listeners = new ArrayList<BundleListener>();
- private boolean enabled = true;
+ private boolean enabled;
public BundleEventsPluginImpl()
{
Modified: projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/framework/plugins/BundleLifecyclePluginImpl.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/framework/plugins/BundleLifecyclePluginImpl.java 2009-08-21 01:15:31 UTC (rev 92646)
+++ projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/framework/plugins/BundleLifecyclePluginImpl.java 2009-08-21 01:18:12 UTC (rev 92647)
@@ -25,9 +25,11 @@
import org.jboss.logging.Logger;
import org.jboss.osgi.jbossmc.api.BundleEventsPlugin;
+import org.jboss.osgi.jbossmc.api.BundleFactoryPlugin;
import org.jboss.osgi.jbossmc.api.BundleLifecyclePlugin;
import org.jboss.osgi.jbossmc.api.BundleRegistryPlugin;
import org.jboss.osgi.jbossmc.api.BundleResolverPlugin;
+import org.jboss.osgi.jbossmc.api.ClassLoaderFactoryPlugin;
import org.jboss.osgi.jbossmc.api.FrameworkEventsPlugin;
import org.jboss.osgi.jbossmc.framework.BundleContextImpl;
import org.jboss.osgi.jbossmc.framework.BundleImpl;
@@ -59,6 +61,39 @@
setFramework(framework);
}
+ public Bundle installBundle(String location) throws BundleException
+ {
+ // Convert location to a virtual file URL
+ BundleFactoryPlugin bundleFactory = getPlugin(BundleFactoryPlugin.class);
+ location = bundleFactory.getVirtualLocation(location);
+
+ // 1. If a bundle containing the same location identifier is already installed, the Bundle object for that bundle is returned.
+ BundleRegistryPlugin bundleRegistry = getPlugin(BundleRegistryPlugin.class);
+ Bundle bundle = bundleRegistry.getBundleByLocation(location);
+ if (bundle != null)
+ return bundle;
+
+ // 2. The bundle's content is read from the input stream. If this fails, a BundleException is thrown.
+ // 3. The bundle's associated resources are allocated. The associated resources minimally consist of a unique identifier and a persistent storage area if the platform has file system support.
+ bundle = bundleFactory.createBundle(location);
+ bundleRegistry.registerBundle(bundle);
+
+ // Initialize the bundle's runtime class loader
+ BundleImpl bundleImpl = (BundleImpl)bundle;
+ ClassLoaderFactoryPlugin factory = getPlugin(ClassLoaderFactoryPlugin.class);
+ bundleImpl.setRuntimeClassLoader(factory.createClassLoader(bundle));
+
+ // 4. The bundle's state is set to INSTALLED.
+ bundleImpl.setState(Bundle.INSTALLED);
+
+ // 5. A bundle event of type BundleEvent.INSTALLED is fired.
+ BundleEventsPlugin eventManager = getPlugin(BundleEventsPlugin.class);
+ eventManager.fireBundleEvent(new BundleEvent(BundleEvent.INSTALLED, bundle));
+
+ // 6. The Bundle object for the newly or previously installed bundle is returned.
+ return bundle;
+ }
+
public void start(Bundle bundle, int options) throws BundleException
{
// If this bundle's state is UNINSTALLED then an IllegalStateException is thrown.
Modified: projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/framework/plugins/BundleStoragePluginImpl.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/framework/plugins/BundleStoragePluginImpl.java 2009-08-21 01:15:31 UTC (rev 92646)
+++ projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/framework/plugins/BundleStoragePluginImpl.java 2009-08-21 01:18:12 UTC (rev 92647)
@@ -43,7 +43,9 @@
{
// Provide logging
final Logger log = Logger.getLogger(BundleStoragePluginImpl.class);
-
+
+ private String storageArea;
+
public BundleStoragePluginImpl()
{
}
@@ -53,34 +55,54 @@
setFramework(framework);
}
+ public void cleanStorage(String propValue)
+ {
+ // [TODO] Support values other than 'onFirstInit'
+ if (Constants.FRAMEWORK_STORAGE_CLEAN_ONFIRSTINIT.equals(propValue))
+ {
+ File storage = new File(getStorageArea());
+ storage.delete();
+ }
+ }
+
public File getDataFile(Bundle bundle, String filename)
{
- File bundleDir = getBundleStorageDir(bundle);
+ File bundleDir = getStorageDir(bundle);
File dataFile = new File(bundleDir.getAbsolutePath() + "/" + filename);
+ dataFile.getParentFile().mkdirs();
return dataFile;
}
- private File getBundleStorageDir(Bundle bundle)
+ public File getStorageDir(Bundle bundle)
{
- BundleContext context = getFramework().getBundleContext();
- String dirName = context.getProperty(Constants.FRAMEWORK_STORAGE);
- if (dirName == null)
+ File bundleDir = new File(getStorageArea() + "/bundle-" + bundle.getBundleId());
+ if (bundleDir.exists() == false)
+ bundleDir.mkdirs();
+
+ return bundleDir;
+ }
+
+ private String getStorageArea()
+ {
+ if (storageArea == null)
{
- try
+ BundleContext context = getFramework().getBundleContext();
+ String dirName = context.getProperty(Constants.FRAMEWORK_STORAGE);
+ if (dirName == null)
{
- File tmpFile = File.createTempFile("Constants.FRAMEWORK_STORAGE", null);
- dirName = tmpFile.getParent();
- tmpFile.delete();
+ try
+ {
+ File tmpFile = File.createTempFile("Constants.FRAMEWORK_STORAGE", null);
+ dirName = tmpFile.getParent();
+ tmpFile.delete();
+ }
+ catch (IOException ex)
+ {
+ throw new IllegalStateException("Cannot create temp storage file", ex);
+ }
}
- catch (IOException ex)
- {
- throw new IllegalStateException("Cannot create temp storage file", ex);
- }
+ storageArea = dirName;
}
-
- File bundleDir = new File(dirName + "/bundle-" + bundle.getBundleId());
- if (bundleDir.exists() == false)
- bundleDir.mkdirs();
- return bundleDir;
+ return storageArea;
}
}
\ No newline at end of file
Modified: projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/framework/plugins/FrameworkEventsPluginImpl.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/framework/plugins/FrameworkEventsPluginImpl.java 2009-08-21 01:15:31 UTC (rev 92646)
+++ projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/framework/plugins/FrameworkEventsPluginImpl.java 2009-08-21 01:18:12 UTC (rev 92647)
@@ -45,7 +45,7 @@
final Logger log = Logger.getLogger(FrameworkEventsPluginImpl.class);
private List<FrameworkListener> listeners = new ArrayList<FrameworkListener>();
- private boolean enabled = true;
+ private boolean enabled;
public FrameworkEventsPluginImpl()
{
Modified: projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/framework/plugins/ServiceEventsPluginImpl.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/framework/plugins/ServiceEventsPluginImpl.java 2009-08-21 01:15:31 UTC (rev 92646)
+++ projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/framework/plugins/ServiceEventsPluginImpl.java 2009-08-21 01:18:12 UTC (rev 92647)
@@ -51,7 +51,7 @@
final Logger log = Logger.getLogger(ServiceEventsPluginImpl.class);
private Map<ServiceListener, ListenerRegistration> listeners = new LinkedHashMap<ServiceListener, ListenerRegistration>();
- private boolean enabled = true;
+ private boolean enabled;
public ServiceEventsPluginImpl()
{
Modified: projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/framework/resolver/RuntimeClassLoaderImpl.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/framework/resolver/RuntimeClassLoaderImpl.java 2009-08-21 01:15:31 UTC (rev 92646)
+++ projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/framework/resolver/RuntimeClassLoaderImpl.java 2009-08-21 01:18:12 UTC (rev 92647)
@@ -23,6 +23,8 @@
//$Id: $
+import java.io.File;
+import java.io.FileOutputStream;
import java.io.IOException;
import java.net.URL;
import java.net.URLClassLoader;
@@ -31,10 +33,13 @@
import java.util.Set;
import org.jboss.logging.Logger;
+import org.jboss.osgi.jbossmc.api.BundleStoragePlugin;
import org.jboss.osgi.jbossmc.api.RuntimeClassLoader;
+import org.jboss.osgi.jbossmc.framework.BundleContextImpl;
import org.jboss.osgi.jbossmc.framework.BundleImpl;
import org.jboss.osgi.jbossmc.framework.FrameworkImpl;
import org.jboss.osgi.spi.NotImplementedException;
+import org.jboss.virtual.VFSUtils;
import org.jboss.virtual.VirtualFile;
import org.osgi.framework.Bundle;
import org.osgi.framework.launch.Framework;
@@ -52,13 +57,14 @@
private static GlobalFrameworkLoader globalClassLoader;
+ private Bundle bundle;
private VirtualFile vFile;
private ClassLoader parentClassLoader;
public RuntimeClassLoaderImpl(Framework framework, Bundle bundle)
{
- BundleImpl bundleImpl = (BundleImpl)bundle;
- vFile = bundleImpl.getVirtualFile();
+ this.bundle = bundle;
+ this.vFile = ((BundleImpl)bundle).getVirtualFile();
parentClassLoader = getClass().getClassLoader();
@@ -81,8 +87,13 @@
private void addClassLoaderURL(VirtualFile vFile) throws IOException
{
- URL url = failsafeURL(vFile);
- globalClassLoader.addURL(url);
+ BundleContextImpl context = (BundleContextImpl)bundle.getBundleContext();
+ BundleStoragePlugin storage = context.getPlugin(BundleStoragePlugin.class);
+
+ File storageFile = storage.getDataFile(bundle, "internal/" + vFile.getName());
+ VFSUtils.copyStreamAndClose(vFile.openStream(), new FileOutputStream(storageFile));
+
+ globalClassLoader.addURL(storageFile.toURL());
for (VirtualFile child : vFile.getChildren())
{
if (child.isArchive())
@@ -152,7 +163,7 @@
public Class<?> loadClass(String name) throws ClassNotFoundException
{
// System.out.println("gfl: " + name);
-
+
Class<?> clazz;
try
{
@@ -162,22 +173,8 @@
{
clazz = parent.loadClass(name);
}
-
+
return clazz;
}
}
-
- private URL failsafeURL(VirtualFile vFile)
- {
- URL url = null;
- try
- {
- url = vFile.toURL();
- }
- catch (Exception ex)
- {
- log.error("Cannot get URL from: " + vFile, ex);
- }
- return url;
- }
}
\ No newline at end of file
Modified: projects/jboss-osgi/trunk/testsuite/pom.xml
===================================================================
--- projects/jboss-osgi/trunk/testsuite/pom.xml 2009-08-21 01:15:31 UTC (rev 92646)
+++ projects/jboss-osgi/trunk/testsuite/pom.xml 2009-08-21 01:18:12 UTC (rev 92647)
@@ -184,7 +184,7 @@
</property>
</activation>
- <!-- default to jbossmc -->
+ <!-- default to jbossmc
<dependencies>
<dependency>
<groupId>org.jboss.osgi.runtime</groupId>
@@ -193,8 +193,9 @@
<scope>provided</scope>
</dependency>
</dependencies>
+ -->
- <!-- default to felix
+ <!-- default to felix -->
<dependencies>
<dependency>
<groupId>org.jboss.osgi</groupId>
@@ -203,7 +204,6 @@
<scope>provided</scope>
</dependency>
</dependencies>
- -->
</profile>
<!--
More information about the jboss-osgi-commits
mailing list