JBoss-OSGI SVN: r96299 - in projects/jboss-osgi/trunk: distribution/installer/src/main/resources/runtime/server/conf and 6 other directories.
by jboss-osgi-commits@lists.jboss.org
Author: thomas.diesler(a)jboss.com
Date: 2009-11-12 02:03:28 -0500 (Thu, 12 Nov 2009)
New Revision: 96299
Added:
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/service/internal/WebXMLVerifierInterceptor.java
Removed:
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/deployers/WebXMLVerifierInterceptor.java
Modified:
projects/jboss-osgi/trunk/distribution/installer/src/main/resources/jbossas/jboss-beans-jbossmc.xml
projects/jboss-osgi/trunk/distribution/installer/src/main/resources/runtime/server/conf/jboss-osgi-bootstrap.xml
projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/internal/LifecycleInterceptorServiceImpl.java
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/AbstractBundleState.java
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/service/internal/LifecycleInterceptorServiceImpl.java
projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/webapp/WebAppNegativeTestCase.java
projects/jboss-osgi/trunk/testsuite/example/src/test/resources/META-INF/jboss-osgi-bootstrap.xml
Log:
Restore PROPERTY_AUTO_START which is (currently) required for AS integration.
Fix bean based LifecycleInterceptor installation
Modified: projects/jboss-osgi/trunk/distribution/installer/src/main/resources/jbossas/jboss-beans-jbossmc.xml
===================================================================
--- projects/jboss-osgi/trunk/distribution/installer/src/main/resources/jbossas/jboss-beans-jbossmc.xml 2009-11-12 06:27:29 UTC (rev 96298)
+++ projects/jboss-osgi/trunk/distribution/installer/src/main/resources/jbossas/jboss-beans-jbossmc.xml 2009-11-12 07:03:28 UTC (rev 96299)
@@ -132,7 +132,6 @@
</bean>
<bean name="LifecycleInterceptorService" class="org.jboss.osgi.framework.service.internal.LifecycleInterceptorServiceImpl">
<constructor><parameter><inject bean="OSGiBundleManager" /></parameter></constructor>
- <incallback method="addBootstrapInterceptor" />
</bean>
<!--
@@ -155,7 +154,9 @@
********************************
-->
- <bean name="WebXMLVerifier" class="org.jboss.osgi.framework.deployers.WebXMLVerifierInterceptor"/>
+ <bean name="WebXMLVerifier" class="org.jboss.osgi.framework.service.internal.WebXMLVerifierInterceptor">
+ <constructor><parameter><inject bean="OSGiBundleManager" /></parameter></constructor>
+ </bean>
<!--
********************************
Modified: projects/jboss-osgi/trunk/distribution/installer/src/main/resources/runtime/server/conf/jboss-osgi-bootstrap.xml
===================================================================
--- projects/jboss-osgi/trunk/distribution/installer/src/main/resources/runtime/server/conf/jboss-osgi-bootstrap.xml 2009-11-12 06:27:29 UTC (rev 96298)
+++ projects/jboss-osgi/trunk/distribution/installer/src/main/resources/runtime/server/conf/jboss-osgi-bootstrap.xml 2009-11-12 07:03:28 UTC (rev 96299)
@@ -125,7 +125,6 @@
</bean>
<bean name="LifecycleInterceptorService" class="org.jboss.osgi.framework.service.internal.LifecycleInterceptorServiceImpl">
<constructor><parameter><inject bean="OSGiBundleManager" /></parameter></constructor>
- <incallback method="addBootstrapInterceptor" />
</bean>
<!--
@@ -136,7 +135,9 @@
********************************
-->
- <bean name="WebXMLVerifier" class="org.jboss.osgi.framework.deployers.WebXMLVerifierInterceptor"/>
+ <bean name="WebXMLVerifier" class="org.jboss.osgi.framework.service.internal.WebXMLVerifierInterceptor">
+ <constructor><parameter><inject bean="OSGiBundleManager" /></parameter></constructor>
+ </bean>
<!--
********************************
Modified: projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/internal/LifecycleInterceptorServiceImpl.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/internal/LifecycleInterceptorServiceImpl.java 2009-11-12 06:27:29 UTC (rev 96298)
+++ projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/internal/LifecycleInterceptorServiceImpl.java 2009-11-12 07:03:28 UTC (rev 96299)
@@ -53,18 +53,7 @@
return super.getInterceptorChain();
}
- protected void addBootstrapInterceptor(LifecycleInterceptor interceptor)
- {
- super.addInterceptor(interceptor);
- }
-
@Override
- protected void removeInterceptor(LifecycleInterceptor interceptor)
- {
- super.removeInterceptor(interceptor);
- }
-
- @Override
protected InvocationContext getInvocationContext(Bundle bundle)
{
DeploymentRegistryService service = getDeploymentRegistryService();
Modified: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/AbstractBundleState.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/AbstractBundleState.java 2009-11-12 06:27:29 UTC (rev 96298)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/AbstractBundleState.java 2009-11-12 07:03:28 UTC (rev 96299)
@@ -569,6 +569,11 @@
plugin.removeFrameworkListener(this, listener);
}
+ public Bundle installBundle(String location) throws BundleException
+ {
+ return installBundle(location, null);
+ }
+
public Bundle installBundle(String location, InputStream input) throws BundleException
{
checkValidBundleContext();
@@ -578,11 +583,6 @@
return bundleState.getBundleInternal();
}
- public Bundle installBundle(String location) throws BundleException
- {
- return installBundle(location, null);
- }
-
public Bundle installBundle(VirtualFile root) throws BundleException
{
checkValidBundleContext();
Modified: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java 2009-11-12 06:27:29 UTC (rev 96298)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java 2009-11-12 07:03:28 UTC (rev 96299)
@@ -21,6 +21,8 @@
*/
package org.jboss.osgi.framework.bundle;
+import static org.jboss.osgi.spi.OSGiConstants.PROPERTY_AUTO_START;
+
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
@@ -337,25 +339,46 @@
Class<?> clazz = plugin.getClass();
if (addPlugin(plugin, clazz) == false)
{
- Class<?> superclass = clazz.getSuperclass();
- if (Plugin.class.isAssignableFrom(superclass))
- addPlugin(plugin, superclass);
+ // If the plugin could not be added by Interface, use the clazz directly
+ log.debug("Add plugin: " + clazz.getName());
+ plugins.put(clazz, plugin);
}
+
+ // In case a service plugin gets added after the framework is started
+ boolean isFrameworkActive = systemBundle.getState() == Bundle.ACTIVE;
+ if (isFrameworkActive == true && plugin instanceof ServicePlugin)
+ {
+ ServicePlugin servicePlugin = (ServicePlugin)plugin;
+ servicePlugin.startService();
+ }
}
+ /**
+ * Add a plugin by scanning the interfaces for the given clazz.
+ * The plugin is added with the key of the first interface that extends Plugin.
+ */
private boolean addPlugin(Plugin plugin, Class<?> clazz)
{
- boolean pluginAdded = false;
+ // Scan the interfaces on the class
for (Class<?> interf : clazz.getInterfaces())
{
+ if (interf == Plugin.class || interf == ServicePlugin.class)
+ continue;
+
if (Plugin.class.isAssignableFrom(interf))
{
- log.debug("Add plugin: " + plugin.getClass().getName());
+ log.debug("Add plugin: " + interf.getName());
plugins.put(interf, plugin);
- pluginAdded = true;
+ return true;
}
}
- return pluginAdded;
+
+ // Interface not found, try the plugin's superclass
+ Class<?> superclass = clazz.getSuperclass();
+ if (Plugin.class.isAssignableFrom(superclass))
+ return addPlugin(plugin, superclass);
+
+ return false;
}
/**
@@ -399,7 +422,7 @@
{
if (url == null)
throw new BundleException("Null url");
-
+
return installBundle(url.toExternalForm(), null);
}
@@ -417,7 +440,7 @@
throw new BundleException("Null location");
URL locationURL;
-
+
// Get the location URL
if (input != null)
{
@@ -485,6 +508,7 @@
VFSDeployment deployment = VFSDeploymentFactory.getInstance().createVFSDeployment(root);
MutableAttachments att = (MutableAttachments)deployment.getPredeterminedManagedObjects();
att.addAttachment(PROPERTY_BUNDLE_LOCATION, location);
+ att.addAttachment(PROPERTY_AUTO_START, Boolean.FALSE);
deployerClient.deploy(deployment);
try
@@ -649,7 +673,7 @@
bundleState.setBundleManager(this);
bundles.add(bundleState);
-
+
// Add the bundle to the resolver
// [TODO] remove this restriction
if (bundleState.getBundleId() != 0)
@@ -657,9 +681,9 @@
ResolverPlugin bundleResolver = getPlugin(ResolverPlugin.class);
bundleResolver.addBundle(bundleState);
}
-
+
bundleState.changeState(Bundle.INSTALLED);
-
+
log.debug("Added: " + bundleState);
}
@@ -688,10 +712,11 @@
if (other.isSingleton() && metaData.isSingleton())
throw new IllegalStateException("Cannot install singleton " + bundleState + " another singleton is already installed: " + bundle.getLocation());
if (other.getBundleVersion().equals(metaData.getBundleVersion()))
- throw new IllegalStateException("Cannot install " + bundleState + " a bundle with that name and version is already installed: " + bundle.getLocation());
+ throw new IllegalStateException("Cannot install " + bundleState + " a bundle with that name and version is already installed: "
+ + bundle.getLocation());
}
}
-
+
List<PackageAttribute> importPackages = metaData.getImportPackages();
if (importPackages != null && importPackages.isEmpty() == false)
{
@@ -702,7 +727,7 @@
if (packages.contains(packageName))
throw new IllegalStateException("Duplicate import of package " + packageName + " for " + bundleState);
packages.add(packageName);
-
+
if (packageName.startsWith("java."))
throw new IllegalStateException("Not allowed to import java.* for " + bundleState);
@@ -712,7 +737,7 @@
throw new IllegalStateException(packageName + " version and specification version should be the same for " + bundleState);
}
}
-
+
List<PackageAttribute> exportPackages = metaData.getExportPackages();
if (exportPackages != null && exportPackages.isEmpty() == false)
{
@@ -738,11 +763,11 @@
bundleState.uninstallInternal();
bundleState.setBundleManager(null);
-
+
// Remove the bundle from the resolver
ResolverPlugin bundleResolver = getPlugin(ResolverPlugin.class);
bundleResolver.removeBundle(bundleState);
-
+
bundles.remove(bundleState);
log.debug("Removed " + bundleState.getCanonicalName());
}
@@ -867,7 +892,7 @@
result = aux;
break;
}
-
+
// Fallback to the deployment name
else if (aux instanceof OSGiBundleState)
{
@@ -970,7 +995,7 @@
Throwable cause = ex.getCause();
if (cause instanceof BundleException)
throw (BundleException)cause;
-
+
throw new BundleException("Error starting " + bundleState, (cause != null ? cause : ex));
}
}
@@ -1231,8 +1256,8 @@
public void initFramework()
{
// Log INFO about this implementation
- String implTitle = getClass().getPackage().getImplementationTitle();
- String implVersion = getClass().getPackage().getImplementationVersion();
+ String implTitle = getClass().getPackage().getImplementationTitle();
+ String implVersion = getClass().getPackage().getImplementationVersion();
log.info(implTitle + " - " + implVersion);
int state = systemBundle.getState();
Deleted: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/deployers/WebXMLVerifierInterceptor.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/deployers/WebXMLVerifierInterceptor.java 2009-11-12 06:27:29 UTC (rev 96298)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/deployers/WebXMLVerifierInterceptor.java 2009-11-12 07:03:28 UTC (rev 96299)
@@ -1,63 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This 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.1 of
- * the License, or (at your option) any later version.
- *
- * This software 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 software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.osgi.framework.deployers;
-
-//$Id$
-
-import org.jboss.osgi.deployment.interceptor.AbstractLifecycleInterceptor;
-import org.jboss.osgi.deployment.interceptor.InvocationContext;
-import org.jboss.osgi.deployment.interceptor.LifecycleInterceptor;
-import org.jboss.osgi.deployment.interceptor.LifecycleInterceptorException;
-import org.jboss.virtual.VirtualFile;
-import org.osgi.framework.Bundle;
-
-/**
- * The lifecycle interceptor that verifies that deployments ending in '.war'
- * have a WEB-INF/web.xml descriptor.
- *
- * @author thomas.diesler(a)jboss.com
- * @since 20-Oct-2009
- */
-public class WebXMLVerifierInterceptor extends AbstractLifecycleInterceptor implements LifecycleInterceptor
-{
- public void invoke(int state, InvocationContext context) throws LifecycleInterceptorException
- {
- if (state == Bundle.STARTING)
- {
- try
- {
- VirtualFile root = context.getRoot();
- VirtualFile webXML = root.getChild("/WEB-INF/web.xml");
- if (root.getName().endsWith(".war") && webXML == null)
- throw new LifecycleInterceptorException("Cannot obtain web.xml from: " + root.toURL());
- }
- catch (RuntimeException rte)
- {
- throw rte;
- }
- catch (Exception ex)
- {
- throw new LifecycleInterceptorException("Cannot check for web.xml", ex);
- }
- }
- }
-}
\ No newline at end of file
Modified: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/service/internal/LifecycleInterceptorServiceImpl.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/service/internal/LifecycleInterceptorServiceImpl.java 2009-11-12 06:27:29 UTC (rev 96298)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/service/internal/LifecycleInterceptorServiceImpl.java 2009-11-12 07:03:28 UTC (rev 96299)
@@ -23,14 +23,10 @@
//$Id$
-import java.util.HashSet;
-import java.util.Set;
-
import org.jboss.deployers.vfs.spi.structure.VFSDeploymentUnit;
import org.jboss.logging.Logger;
import org.jboss.osgi.deployment.interceptor.AbstractLifecycleInterceptorService;
import org.jboss.osgi.deployment.interceptor.InvocationContext;
-import org.jboss.osgi.deployment.interceptor.LifecycleInterceptor;
import org.jboss.osgi.deployment.interceptor.LifecycleInterceptorService;
import org.jboss.osgi.deployment.internal.InvocationContextImpl;
import org.jboss.osgi.framework.bundle.OSGiBundleManager;
@@ -53,7 +49,6 @@
// Provide logging
final Logger log = Logger.getLogger(LifecycleInterceptorServiceImpl.class);
- private Set<LifecycleInterceptor> bootstrapInterceptors = new HashSet<LifecycleInterceptor>();
private AbstractLifecycleInterceptorService delegate;
private ServiceRegistration registration;
@@ -88,12 +83,6 @@
}
};
- // Add bootstrap interceptors
- for (LifecycleInterceptor aux : bootstrapInterceptors)
- sysContext.registerService(LifecycleInterceptor.class.getName(), aux, null);
-
- bootstrapInterceptors.clear();
-
registration = sysContext.registerService(LifecycleInterceptorService.class.getName(), delegate, null);
}
@@ -107,11 +96,6 @@
}
}
- public void addBootstrapInterceptor(LifecycleInterceptor interceptor)
- {
- bootstrapInterceptors.add(interceptor);
- }
-
public void handleStateChange(int state, Bundle bundle)
{
if (delegate != null)
Copied: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/service/internal/WebXMLVerifierInterceptor.java (from rev 96285, projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/deployers/WebXMLVerifierInterceptor.java)
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/service/internal/WebXMLVerifierInterceptor.java (rev 0)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/service/internal/WebXMLVerifierInterceptor.java 2009-11-12 07:03:28 UTC (rev 96299)
@@ -0,0 +1,107 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This 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.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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 software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.osgi.framework.service.internal;
+
+//$Id$
+
+import java.util.Set;
+
+import org.jboss.osgi.deployment.interceptor.AbstractLifecycleInterceptor;
+import org.jboss.osgi.deployment.interceptor.InvocationContext;
+import org.jboss.osgi.deployment.interceptor.LifecycleInterceptor;
+import org.jboss.osgi.deployment.interceptor.LifecycleInterceptorException;
+import org.jboss.osgi.framework.bundle.OSGiBundleManager;
+import org.jboss.osgi.framework.plugins.internal.AbstractServicePlugin;
+import org.jboss.virtual.VirtualFile;
+import org.osgi.framework.Bundle;
+
+/**
+ * The lifecycle interceptor that verifies that deployments ending in '.war'
+ * have a WEB-INF/web.xml descriptor.
+ *
+ * @author thomas.diesler(a)jboss.com
+ * @since 20-Oct-2009
+ */
+public class WebXMLVerifierInterceptor extends AbstractServicePlugin implements LifecycleInterceptor
+{
+ private LifecycleInterceptor delegate;
+
+ public WebXMLVerifierInterceptor(OSGiBundleManager bundleManager)
+ {
+ super(bundleManager);
+ }
+
+ public void startService()
+ {
+ delegate = new AbstractLifecycleInterceptor()
+ {
+ public void invoke(int state, InvocationContext context) throws LifecycleInterceptorException
+ {
+ if (state == Bundle.STARTING)
+ {
+ try
+ {
+ VirtualFile root = context.getRoot();
+ VirtualFile webXML = root.getChild("/WEB-INF/web.xml");
+ if (root.getName().endsWith(".war") && webXML == null)
+ throw new LifecycleInterceptorException("Cannot obtain web.xml from: " + root.toURL());
+ }
+ catch (RuntimeException rte)
+ {
+ throw rte;
+ }
+ catch (Exception ex)
+ {
+ throw new LifecycleInterceptorException("Cannot check for web.xml", ex);
+ }
+ }
+ }
+ };
+
+ getSystemContext().registerService(LifecycleInterceptor.class.getName(), delegate, null);
+ }
+
+ public void stopService()
+ {
+ // do nothing
+ }
+
+ public Set<Class<?>> getInput()
+ {
+ return delegate.getInput();
+ }
+
+ public Set<Class<?>> getOutput()
+ {
+ return delegate.getOutput();
+ }
+
+ public int getRelativeOrder()
+ {
+ return delegate.getRelativeOrder();
+ }
+
+ public void invoke(int state, InvocationContext context) throws LifecycleInterceptorException
+ {
+ delegate.invoke(state, context);
+ }
+}
\ No newline at end of file
Modified: projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/webapp/WebAppNegativeTestCase.java
===================================================================
--- projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/webapp/WebAppNegativeTestCase.java 2009-11-12 06:27:29 UTC (rev 96298)
+++ projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/webapp/WebAppNegativeTestCase.java 2009-11-12 07:03:28 UTC (rev 96299)
@@ -23,6 +23,7 @@
// $Id$
+import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
@@ -34,6 +35,7 @@
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
+import org.osgi.framework.Bundle;
import org.osgi.framework.BundleException;
/**
@@ -66,6 +68,8 @@
public void testServletAccess() throws Exception
{
OSGiBundle bundle = runtime.installBundle("example-webapp-negative.war");
+ assertEquals(Bundle.INSTALLED, bundle.getState());
+
try
{
bundle.start();
Modified: projects/jboss-osgi/trunk/testsuite/example/src/test/resources/META-INF/jboss-osgi-bootstrap.xml
===================================================================
--- projects/jboss-osgi/trunk/testsuite/example/src/test/resources/META-INF/jboss-osgi-bootstrap.xml 2009-11-12 06:27:29 UTC (rev 96298)
+++ projects/jboss-osgi/trunk/testsuite/example/src/test/resources/META-INF/jboss-osgi-bootstrap.xml 2009-11-12 07:03:28 UTC (rev 96299)
@@ -107,7 +107,6 @@
</bean>
<bean name="LifecycleInterceptorService" class="org.jboss.osgi.framework.service.internal.LifecycleInterceptorServiceImpl">
<constructor><parameter><inject bean="OSGiBundleManager" /></parameter></constructor>
- <incallback method="addBootstrapInterceptor" />
</bean>
<!--
@@ -118,7 +117,9 @@
********************************
-->
- <bean name="WebXMLVerifier" class="org.jboss.osgi.framework.deployers.WebXMLVerifierInterceptor"/>
+ <bean name="WebXMLVerifier" class="org.jboss.osgi.framework.service.internal.WebXMLVerifierInterceptor">
+ <constructor><parameter><inject bean="OSGiBundleManager" /></parameter></constructor>
+ </bean>
<!--
********************************
14 years, 8 months
JBoss-OSGI SVN: r96287 - projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/smoke.
by jboss-osgi-commits@lists.jboss.org
Author: thomas.diesler(a)jboss.com
Date: 2009-11-11 19:41:49 -0500 (Wed, 11 Nov 2009)
New Revision: 96287
Modified:
projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/smoke/OSGiSmokeTestCase.java
Log:
[JBOSGI-203] Define non OSGi bundle handling by the Framework
Reference the JIRA issue from the disabled tests
Modified: projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/smoke/OSGiSmokeTestCase.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/smoke/OSGiSmokeTestCase.java 2009-11-12 00:34:53 UTC (rev 96286)
+++ projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/smoke/OSGiSmokeTestCase.java 2009-11-12 00:41:49 UTC (rev 96287)
@@ -56,13 +56,13 @@
public void testNoManifest() throws Exception
{
- // [TODO] discuss
+ // TODO [JBOSGI-203] Define non OSGi bundle handling by the Framework
// testBundle("smoke-no-manifest", Bundle.ACTIVE);
}
public void testNonOSGiManifest() throws Exception
{
- // [TODO] discuss
+ // TODO [JBOSGI-203] Define non OSGi bundle handling by the Framework
// testBundle("smoke-non-osgi-manifest", Bundle.ACTIVE);
}
@@ -90,13 +90,13 @@
public void testDeployedNoManifest() throws Exception
{
- // [TODO] discuss
+ // TODO [JBOSGI-203] Define non OSGi bundle handling by the Framework
// testDeployedBundle("smoke-no-manifest", Bundle.ACTIVE);
}
public void testDeployedNonOSGiManifest() throws Exception
{
- // [TODO] discuss
+ // TODO [JBOSGI-203] Define non OSGi bundle handling by the Framework
// testDeployedBundle("smoke-non-osgi-manifest", Bundle.ACTIVE);
}
@@ -129,8 +129,7 @@
public void testAssembledNonOSGiDeployment() throws Exception
{
- // [TODO] discuss
- /*
+ /* TODO [JBOSGI-203] Define non OSGi bundle handling by the Framework
Bundle bundle = deployBundle("smoke-non-osgi-deployment", A.class);
try
{
14 years, 8 months
JBoss-OSGI SVN: r96286 - in projects/jboss-osgi/trunk/reactor/framework/src: test/java/org/jboss/test/osgi/smoke and 1 other directory.
by jboss-osgi-commits@lists.jboss.org
Author: thomas.diesler(a)jboss.com
Date: 2009-11-11 19:34:53 -0500 (Wed, 11 Nov 2009)
New Revision: 96286
Modified:
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/deployers/OSGiBundleStateDeployer.java
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/deployers/OSGiDeployersWrapper.java
projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/smoke/OSGiSmokeTestCase.java
Log:
Restore PROPERTY_AUTO_START which is (currently) required for AS integration.
Revert to ignore non-osgi deployments since this also breaks AS integration.
Modified: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/deployers/OSGiBundleStateDeployer.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/deployers/OSGiBundleStateDeployer.java 2009-11-11 22:59:08 UTC (rev 96285)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/deployers/OSGiBundleStateDeployer.java 2009-11-12 00:34:53 UTC (rev 96286)
@@ -59,6 +59,7 @@
this.bundleManager = bundleManager;
this.requiredStage = DeploymentStages.DESCRIBE;
+ setInput(OSGiMetaData.class);
setOutput(OSGiBundleState.class);
setStage(DeploymentStages.POST_PARSE);
setTopLevelOnly(true);
@@ -73,8 +74,7 @@
protected void internalDeploy(DeploymentUnit unit) throws DeploymentException
{
// [TODO] look at manifest headers and persistent state for this
- if (unit.getAttachment(OSGiMetaData.class) != null)
- unit.setRequiredStage(requiredStage);
+ unit.setRequiredStage(requiredStage);
OSGiBundleState bundleState = bundleManager.addDeployment(unit);
unit.addAttachment(OSGiBundleState.class, bundleState);
Modified: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/deployers/OSGiDeployersWrapper.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/deployers/OSGiDeployersWrapper.java 2009-11-11 22:59:08 UTC (rev 96285)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/deployers/OSGiDeployersWrapper.java 2009-11-12 00:34:53 UTC (rev 96286)
@@ -21,6 +21,8 @@
*/
package org.jboss.osgi.framework.deployers;
+import static org.jboss.osgi.spi.OSGiConstants.PROPERTY_AUTO_START;
+
import java.util.Collection;
import java.util.List;
import java.util.Map;
@@ -128,8 +130,11 @@
OSGiBundleState bundle = unit.getAttachment(OSGiBundleState.class);
if (bundle == null)
continue;
-
- boolean autoStart = DeploymentStages.INSTALLED.equals(unit.getRequiredStage());
+
+ Boolean autoStart = (Boolean)unit.getAttachment(PROPERTY_AUTO_START);
+ if (autoStart == null)
+ autoStart = Boolean.TRUE;
+
if (autoStart == true && bundle.getState() == Bundle.INSTALLED)
{
unresolvedBundles.add(0, bundle);
Modified: projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/smoke/OSGiSmokeTestCase.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/smoke/OSGiSmokeTestCase.java 2009-11-11 22:59:08 UTC (rev 96285)
+++ projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/smoke/OSGiSmokeTestCase.java 2009-11-12 00:34:53 UTC (rev 96286)
@@ -56,12 +56,14 @@
public void testNoManifest() throws Exception
{
- testBundle("smoke-no-manifest", Bundle.ACTIVE);
+ // [TODO] discuss
+ // testBundle("smoke-no-manifest", Bundle.ACTIVE);
}
public void testNonOSGiManifest() throws Exception
{
- testBundle("smoke-non-osgi-manifest", Bundle.ACTIVE);
+ // [TODO] discuss
+ // testBundle("smoke-non-osgi-manifest", Bundle.ACTIVE);
}
public void testOSGiManifest() throws Exception
@@ -88,12 +90,14 @@
public void testDeployedNoManifest() throws Exception
{
- testDeployedBundle("smoke-no-manifest", Bundle.ACTIVE);
+ // [TODO] discuss
+ // testDeployedBundle("smoke-no-manifest", Bundle.ACTIVE);
}
public void testDeployedNonOSGiManifest() throws Exception
{
- testDeployedBundle("smoke-non-osgi-manifest", Bundle.ACTIVE);
+ // [TODO] discuss
+ // testDeployedBundle("smoke-non-osgi-manifest", Bundle.ACTIVE);
}
public void testDeployedOSGiManifest() throws Exception
@@ -125,6 +129,8 @@
public void testAssembledNonOSGiDeployment() throws Exception
{
+ // [TODO] discuss
+ /*
Bundle bundle = deployBundle("smoke-non-osgi-deployment", A.class);
try
{
@@ -137,6 +143,7 @@
{
bundle.uninstall();
}
+ */
}
protected void testBundle(String name, int expectedState) throws Exception
14 years, 8 months
JBoss-OSGI SVN: r96285 - in projects/jboss-osgi/trunk: distribution/installer/src/main/resources/runtime/server/conf and 3 other directories.
by jboss-osgi-commits@lists.jboss.org
Author: thomas.diesler(a)jboss.com
Date: 2009-11-11 17:59:08 -0500 (Wed, 11 Nov 2009)
New Revision: 96285
Modified:
projects/jboss-osgi/trunk/distribution/installer/src/main/resources/jbossas/jboss-beans-jbossmc.xml
projects/jboss-osgi/trunk/distribution/installer/src/main/resources/runtime/server/conf/jboss-osgi-bootstrap.xml
projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/internal/LifecycleInterceptorServiceImpl.java
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/service/internal/LifecycleInterceptorServiceImpl.java
projects/jboss-osgi/trunk/testsuite/example/src/test/resources/META-INF/jboss-osgi-bootstrap.xml
Log:
Fix the infinite loop issue with Interceptors
Modified: projects/jboss-osgi/trunk/distribution/installer/src/main/resources/jbossas/jboss-beans-jbossmc.xml
===================================================================
--- projects/jboss-osgi/trunk/distribution/installer/src/main/resources/jbossas/jboss-beans-jbossmc.xml 2009-11-11 22:35:35 UTC (rev 96284)
+++ projects/jboss-osgi/trunk/distribution/installer/src/main/resources/jbossas/jboss-beans-jbossmc.xml 2009-11-11 22:59:08 UTC (rev 96285)
@@ -132,8 +132,7 @@
</bean>
<bean name="LifecycleInterceptorService" class="org.jboss.osgi.framework.service.internal.LifecycleInterceptorServiceImpl">
<constructor><parameter><inject bean="OSGiBundleManager" /></parameter></constructor>
- <incallback method="addInterceptor" />
- <uncallback method="removeInterceptor" />
+ <incallback method="addBootstrapInterceptor" />
</bean>
<!--
Modified: projects/jboss-osgi/trunk/distribution/installer/src/main/resources/runtime/server/conf/jboss-osgi-bootstrap.xml
===================================================================
--- projects/jboss-osgi/trunk/distribution/installer/src/main/resources/runtime/server/conf/jboss-osgi-bootstrap.xml 2009-11-11 22:35:35 UTC (rev 96284)
+++ projects/jboss-osgi/trunk/distribution/installer/src/main/resources/runtime/server/conf/jboss-osgi-bootstrap.xml 2009-11-11 22:59:08 UTC (rev 96285)
@@ -125,8 +125,7 @@
</bean>
<bean name="LifecycleInterceptorService" class="org.jboss.osgi.framework.service.internal.LifecycleInterceptorServiceImpl">
<constructor><parameter><inject bean="OSGiBundleManager" /></parameter></constructor>
- <incallback method="addInterceptor" />
- <uncallback method="removeInterceptor" />
+ <incallback method="addBootstrapInterceptor" />
</bean>
<!--
Modified: projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/internal/LifecycleInterceptorServiceImpl.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/internal/LifecycleInterceptorServiceImpl.java 2009-11-11 22:35:35 UTC (rev 96284)
+++ projects/jboss-osgi/trunk/reactor/deployment/src/main/java/org/jboss/osgi/deployment/internal/LifecycleInterceptorServiceImpl.java 2009-11-11 22:59:08 UTC (rev 96285)
@@ -53,8 +53,7 @@
return super.getInterceptorChain();
}
- @Override
- protected void addInterceptor(LifecycleInterceptor interceptor)
+ protected void addBootstrapInterceptor(LifecycleInterceptor interceptor)
{
super.addInterceptor(interceptor);
}
Modified: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/service/internal/LifecycleInterceptorServiceImpl.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/service/internal/LifecycleInterceptorServiceImpl.java 2009-11-11 22:35:35 UTC (rev 96284)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/service/internal/LifecycleInterceptorServiceImpl.java 2009-11-11 22:59:08 UTC (rev 96285)
@@ -64,8 +64,8 @@
public void startService()
{
- BundleContext context = getSystemContext();
- delegate = new AbstractLifecycleInterceptorService(context)
+ BundleContext sysContext = getSystemContext();
+ delegate = new AbstractLifecycleInterceptorService(sysContext)
{
@Override
protected InvocationContext getInvocationContext(Bundle bundle)
@@ -87,12 +87,14 @@
return inv;
}
};
-
+
// Add bootstrap interceptors
for (LifecycleInterceptor aux : bootstrapInterceptors)
- addInterceptor(aux);
+ sysContext.registerService(LifecycleInterceptor.class.getName(), aux, null);
- registration = context.registerService(LifecycleInterceptorService.class.getName(), delegate, null);
+ bootstrapInterceptors.clear();
+
+ registration = sysContext.registerService(LifecycleInterceptorService.class.getName(), delegate, null);
}
public void stopService()
@@ -105,22 +107,11 @@
}
}
- public void addInterceptor(LifecycleInterceptor interceptor)
+ public void addBootstrapInterceptor(LifecycleInterceptor interceptor)
{
- if (delegate == null)
- {
- bootstrapInterceptors.add(interceptor);
- }
- else
- {
- getSystemContext().registerService(LifecycleInterceptor.class.getName(), interceptor, null);
- }
+ bootstrapInterceptors.add(interceptor);
}
- public void removeInterceptor(LifecycleInterceptor interceptor)
- {
- }
-
public void handleStateChange(int state, Bundle bundle)
{
if (delegate != null)
Modified: projects/jboss-osgi/trunk/testsuite/example/src/test/resources/META-INF/jboss-osgi-bootstrap.xml
===================================================================
--- projects/jboss-osgi/trunk/testsuite/example/src/test/resources/META-INF/jboss-osgi-bootstrap.xml 2009-11-11 22:35:35 UTC (rev 96284)
+++ projects/jboss-osgi/trunk/testsuite/example/src/test/resources/META-INF/jboss-osgi-bootstrap.xml 2009-11-11 22:59:08 UTC (rev 96285)
@@ -107,8 +107,7 @@
</bean>
<bean name="LifecycleInterceptorService" class="org.jboss.osgi.framework.service.internal.LifecycleInterceptorServiceImpl">
<constructor><parameter><inject bean="OSGiBundleManager" /></parameter></constructor>
- <incallback method="addInterceptor" />
- <uncallback method="removeInterceptor" />
+ <incallback method="addBootstrapInterceptor" />
</bean>
<!--
14 years, 8 months
JBoss-OSGI SVN: r96284 - projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/vfs.
by jboss-osgi-commits@lists.jboss.org
Author: alesj
Date: 2009-11-11 17:35:35 -0500 (Wed, 11 Nov 2009)
New Revision: 96284
Modified:
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/vfs/BundleHandler.java
Log:
Use string builder.
Modified: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/vfs/BundleHandler.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/vfs/BundleHandler.java 2009-11-11 22:31:21 UTC (rev 96283)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/vfs/BundleHandler.java 2009-11-11 22:35:35 UTC (rev 96284)
@@ -83,13 +83,13 @@
if (relativePath == null)
relativePath = AbstractStructureDeployer.getRelativePath(root, file);
- String path = relativePath;
- if (checkStart && path.startsWith("/") == false)
- path = "/" + path;
- if (checkEnd && path.endsWith("/") == false)
- path += "/";
+ StringBuilder path = new StringBuilder(relativePath);
+ if (checkStart && relativePath.startsWith("/") == false)
+ path.insert(0, '/');
+ if (checkEnd && relativePath.endsWith("/") == false)
+ path.append('/');
- return path;
+ return path.toString();
}
protected VirtualFileHandler createChildHandler(VirtualFile child) throws IOException
14 years, 8 months
JBoss-OSGI SVN: r96283 - projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/vfs.
by jboss-osgi-commits@lists.jboss.org
Author: alesj
Date: 2009-11-11 17:31:21 -0500 (Wed, 11 Nov 2009)
New Revision: 96283
Modified:
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/vfs/BundleHandler.java
Log:
Order vars.
Modified: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/vfs/BundleHandler.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/vfs/BundleHandler.java 2009-11-11 22:30:31 UTC (rev 96282)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/vfs/BundleHandler.java 2009-11-11 22:31:21 UTC (rev 96283)
@@ -52,8 +52,8 @@
private VirtualFile root; // bundle's root
private VirtualFile file;
private Bundle bundle;
+
private volatile String relativePath;
-
private volatile URI uri;
private volatile VirtualFileHandler handler;
14 years, 8 months
JBoss-OSGI SVN: r96282 - in projects/jboss-osgi/trunk/reactor/framework/src: main/java/org/jboss/osgi/framework/vfs and 5 other directories.
by jboss-osgi-commits@lists.jboss.org
Author: alesj
Date: 2009-11-11 17:30:31 -0500 (Wed, 11 Nov 2009)
New Revision: 96282
Added:
projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/FrameworkTest.java
projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/bundle/BundleVFSUnitTestCase.java
Removed:
projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/FrameworkTestCase.java
Modified:
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/AbstractBundleState.java
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/vfs/BundleHandler.java
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/vfs/BundleVFSContext.java
projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/bundle/BundleContextUnitTestCase.java
projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/bundle/BundleEntriesUnitTestCase.java
projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/bundle/BundleUnitTestCase.java
projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/bundle/SystemBundleUnitTestCase.java
projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/classloader/ExportImportPackageUnitTestCase.java
projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/classloader/RequireBundleUnitTestCase.java
projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/service/GetServiceReferencesUnitTestCase.java
projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/service/GetUnGetServiceUnitTestCase.java
projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/service/RegisterServiceUnitTestCase.java
projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/service/ServiceFactoryUnitTestCase.java
projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/service/ServiceReferenceUnitTestCase.java
projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/service/ServiceRegistrationUnitTestCase.java
projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/smoke/OSGiSmokeTestCase.java
Log:
Add bundle vfs tests.
Rename FrameworkTestCase to just Test, to be consistent.
Modified: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/AbstractBundleState.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/AbstractBundleState.java 2009-11-11 22:09:32 UTC (rev 96281)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/AbstractBundleState.java 2009-11-11 22:30:31 UTC (rev 96282)
@@ -216,7 +216,7 @@
return lastModified;
}
- public void modified()
+ void modified()
{
lastModified = System.currentTimeMillis();
}
Modified: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java 2009-11-11 22:09:32 UTC (rev 96281)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java 2009-11-11 22:30:31 UTC (rev 96282)
@@ -552,7 +552,7 @@
/**
* Uninstall a bundle
*
- * @param bundle the bundle
+ * @param bundleState the bundle
* @throws BundleException for any error
*/
public void uninstallBundle(OSGiBundleState bundleState) throws BundleException
Modified: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/vfs/BundleHandler.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/vfs/BundleHandler.java 2009-11-11 22:09:32 UTC (rev 96281)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/vfs/BundleHandler.java 2009-11-11 22:30:31 UTC (rev 96282)
@@ -26,6 +26,7 @@
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
+import java.net.MalformedURLException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@@ -35,6 +36,7 @@
import org.jboss.virtual.plugins.context.AbstractVirtualFileHandler;
import org.jboss.virtual.spi.VFSContext;
import org.jboss.virtual.spi.VirtualFileHandler;
+import org.jboss.deployers.vfs.spi.structure.helpers.AbstractStructureDeployer;
import org.osgi.framework.Bundle;
/**
@@ -46,19 +48,24 @@
{
/** The serialVersionUID */
private static final long serialVersionUID = 6650185906199900589L;
-
+
+ private VirtualFile root; // bundle's root
private VirtualFile file;
private Bundle bundle;
- private VirtualFileHandler handler;
+ private volatile String relativePath;
- public BundleHandler(VFSContext context, VirtualFile file, Bundle bundle) throws IOException
+ private volatile URI uri;
+ private volatile VirtualFileHandler handler;
+
+ public BundleHandler(VFSContext context, VirtualFile root, VirtualFile file, Bundle bundle) throws IOException
{
- this(context, LazyVirtualFileHandler.create(file.getParent()), file, bundle);
+ this(context, LazyVirtualFileHandler.create(file.getParent()), root, file, bundle);
}
- public BundleHandler(VFSContext context, VirtualFileHandler parent, VirtualFile file, Bundle bundle) throws IOException
+ private BundleHandler(VFSContext context, VirtualFileHandler parent, VirtualFile root, VirtualFile file, Bundle bundle) throws IOException
{
super(context, parent, file.getName());
+ this.root = root;
this.file = file;
this.bundle = bundle;
}
@@ -71,25 +78,31 @@
return handler;
}
- protected String getRelativePath(boolean checkEnd)
+ protected String getRelativePath(boolean checkStart, boolean checkEnd)
{
- String path = handler.getLocalPathName();
+ if (relativePath == null)
+ relativePath = AbstractStructureDeployer.getRelativePath(root, file);
+
+ String path = relativePath;
+ if (checkStart && path.startsWith("/") == false)
+ path = "/" + path;
if (checkEnd && path.endsWith("/") == false)
path += "/";
+
return path;
}
protected VirtualFileHandler createChildHandler(VirtualFile child) throws IOException
{
- if (handler == null)
- return new BundleHandler(getVFSContext(), child, bundle);
- else
- return new BundleHandler(getVFSContext(), handler, child, bundle);
+ return new BundleHandler(getVFSContext(), this, root, child, bundle);
}
public URI toURI() throws URISyntaxException
{
- return new URI("bundle", Long.toString(bundle.getBundleId()), getRelativePath(false), null);
+ if (uri == null)
+ uri = new URI("bundle", Long.toString(bundle.getBundleId()), getRelativePath(true, false), null);
+
+ return uri;
}
public long getLastModified() throws IOException
@@ -99,14 +112,14 @@
public InputStream openStream() throws IOException
{
- bundle.getResource(getRelativePath(false)); // permission check
+ bundle.getResource(getRelativePath(false, false)); // permission check
return file.openStream();
}
public List<VirtualFileHandler> getChildren(boolean ignoreErrors) throws IOException
{
- bundle.findEntries(getRelativePath(false), null, false); // permission check
+ bundle.findEntries(getRelativePath(false, false), null, false); // permission check
List<VirtualFile> children = file.getChildren();
if (children != null && children.isEmpty() == false)
@@ -123,7 +136,7 @@
public VirtualFileHandler getChild(String path) throws IOException
{
- String fullPath = getRelativePath(true) + path;
+ String fullPath = getRelativePath(false, true) + path;
URL entry = bundle.getEntry(fullPath); // permission check
if (entry == null)
return null;
@@ -134,6 +147,12 @@
//---------------------------------------------------------
+ @Override
+ protected URL toInternalVfsUrl() throws MalformedURLException, URISyntaxException
+ {
+ return toURI().toURL();
+ }
+
public long getSize() throws IOException
{
return file.getSize();
Modified: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/vfs/BundleVFSContext.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/vfs/BundleVFSContext.java 2009-11-11 22:09:32 UTC (rev 96281)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/vfs/BundleVFSContext.java 2009-11-11 22:30:31 UTC (rev 96282)
@@ -71,8 +71,9 @@
throw new IllegalArgumentException("Cannot handle non VFS deployments: " + unit);
VFSDeploymentUnit vdu = VFSDeploymentUnit.class.cast(unit);
- VirtualFile file = vdu.getFile(path); // should exist, resource != null
- root = new BundleHandler(this, file, bundleState);
+ VirtualFile duRoot = vdu.getRoot();
+ VirtualFile duFile = vdu.getFile(path); // should exist, resource != null
+ root = new BundleHandler(this, duRoot, duFile, bundleState);
}
public String getName()
Copied: projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/FrameworkTest.java (from rev 96278, projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/FrameworkTestCase.java)
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/FrameworkTest.java (rev 0)
+++ projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/FrameworkTest.java 2009-11-11 22:30:31 UTC (rev 96282)
@@ -0,0 +1,616 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This 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.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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 software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.osgi;
+
+import java.net.URL;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Enumeration;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.concurrent.CopyOnWriteArrayList;
+
+import org.jboss.classloader.plugins.ClassLoaderUtils;
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.osgi.framework.bundle.AbstractBundleState;
+import org.jboss.osgi.framework.bundle.OSGiBundleManager;
+import org.jboss.osgi.framework.metadata.OSGiMetaData;
+import org.jboss.osgi.spi.util.ConstantsHelper;
+import org.jboss.test.kernel.junit.MicrocontainerTest;
+import org.jboss.virtual.AssembledDirectory;
+import org.jboss.virtual.VirtualFile;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleEvent;
+import org.osgi.framework.BundleException;
+import org.osgi.framework.Constants;
+import org.osgi.framework.FrameworkEvent;
+import org.osgi.framework.FrameworkListener;
+import org.osgi.framework.ServiceEvent;
+import org.osgi.framework.ServiceListener;
+import org.osgi.framework.ServiceReference;
+import org.osgi.framework.SynchronousBundleListener;
+
+/**
+ * OSGiTestCase - Parent Test Case for OSGi tests.
+ *
+ * @author <a href="baileyje(a)gmail.com">John Bailey</a>
+ * @version $Revision: 87848 $
+ */
+public abstract class FrameworkTest extends MicrocontainerTest implements FrameworkListener, SynchronousBundleListener, ServiceListener
+{
+ private final List<FrameworkEvent> frameworkEvents = new CopyOnWriteArrayList<FrameworkEvent>();
+ private final List<BundleEvent> bundleEvents = new CopyOnWriteArrayList<BundleEvent>();
+ private final List<ServiceEvent> serviceEvents = new CopyOnWriteArrayList<ServiceEvent>();
+
+ /**
+ * Create a new OSGiTestCase.
+ *
+ * @param name the test name
+ */
+ public FrameworkTest(String name)
+ {
+ super(name);
+ }
+
+ public static FrameworkTestDelegate getDelegate(Class<?> clazz) throws Exception
+ {
+ return new FrameworkTestDelegate(clazz);
+ }
+
+ /**
+ * Get OSGiTestDelegate
+ */
+ protected FrameworkTestDelegate getDelegate()
+ {
+ return (FrameworkTestDelegate)super.getDelegate();
+ }
+
+ /**
+ * Get BundleManager from Delegate
+ *
+ * @return The BundleManager
+ */
+ protected OSGiBundleManager getBundleManager()
+ {
+ return getDelegate().getBundleManager();
+ }
+
+ /**
+ * Get the system bundle
+ *
+ * @return the system bundle
+ */
+ protected Bundle getSystemBundle()
+ {
+ return getBundleManager().getBundleById(0).getBundleInternal();
+ }
+
+ /**
+ * Add the base bundles
+ *
+ * @param expected the collection to add to
+ */
+ protected void addBaseBundles(Collection<Bundle> expected)
+ {
+ expected.add(getSystemBundle());
+ }
+
+ /**
+ * Create a bundle
+ *
+ * @param root the location of the location to deploy
+ * @param child the child to deploy
+ * @return Bundle for the deployment
+ * @throws Exception for any error
+ */
+ protected Bundle addBundle(String root, String child) throws Exception
+ {
+ return getDelegate().addBundle(root, child);
+ }
+
+ /**
+ * Create a bundle
+ *
+ * @param file the virtual file
+ * @return Bundle for the deployment
+ * @throws Exception for any error
+ */
+ protected Bundle addBundle(VirtualFile file) throws Exception
+ {
+ return getDelegate().addBundle(file);
+ }
+
+ /**
+ * Create a bundle
+ *
+ * @param root the location of the location to deploy
+ * @param child the child to deploy
+ * @return Bundle for the deployment
+ * @throws Exception for any error
+ */
+ protected Bundle deployBundle(String root, String child) throws Exception
+ {
+ return getDelegate().deployBundle(root, child);
+ }
+
+ /**
+ * Create a bundle
+ *
+ * @param file the virtual file
+ * @return Bundle for the deployment
+ * @throws Exception for any error
+ */
+ protected Bundle deployBundle(VirtualFile file) throws Exception
+ {
+ return getDelegate().deployBundle(file);
+ }
+
+ /**
+ * Remove a bundle
+ *
+ * @param bundle the bundle to remove
+ * @throws Exception for any error
+ */
+ protected void uninstall(Bundle bundle) throws Exception
+ {
+ getDelegate().uninstall(bundle);
+ }
+
+ protected DeploymentUnit getDeploymentUnit(Bundle bundle)
+ {
+ return getDelegate().getDeploymentUnit(bundle);
+ }
+
+ protected Bundle assembleBundle(String name, String resources, Class<?>... packages) throws Exception
+ {
+ return getDelegate().assembleBundle(name, new String[] { resources }, packages);
+ }
+
+ protected Bundle assembleBundle(String name, String[] resourcePaths, Class<?>... packages) throws Exception
+ {
+ return getDelegate().assembleBundle(name, resourcePaths, packages);
+ }
+
+ protected Bundle deployBundle(String name, Class<?>... packages) throws Exception
+ {
+ return getDelegate().deployBundle(name, null, (String[]) null, packages);
+ }
+
+ protected Bundle deployBundle(String name, String resourcePath, Class<?>... packages) throws Exception
+ {
+ return getDelegate().deployBundle(name, null, resourcePath, packages);
+ }
+
+ protected Bundle deployBundle(String name, String[] resourcePaths, Class<?>... packages) throws Exception
+ {
+ return getDelegate().deployBundle(name, null, resourcePaths, packages);
+ }
+
+ protected Bundle deployBundle(String name, OSGiMetaData metaData, Class<?>... packages) throws Exception
+ {
+ return getDelegate().deployBundle(name, metaData, (String[]) null, packages);
+ }
+
+ protected Bundle deployBundle(String name, OSGiMetaData metaData, String resourcePath, Class<?>... packages) throws Exception
+ {
+ return getDelegate().deployBundle(name, metaData, resourcePath, packages);
+ }
+
+ protected Bundle deployBundle(String name, OSGiMetaData metaData, String[] resourcePaths, Class<?>... packages) throws Exception
+ {
+ return getDelegate().deployBundle(name, metaData, resourcePaths, packages);
+ }
+
+ protected AssembledDirectory createAssembledDirectory(String name) throws Exception
+ {
+ return getDelegate().createAssembledDirectory(name, "");
+ }
+
+ protected AssembledDirectory createAssembledDirectory(String name, String rootName) throws Exception
+ {
+ return getDelegate().createAssembledDirectory(name, rootName);
+ }
+
+ protected void addPackage(AssembledDirectory dir, Class<?> reference) throws Exception
+ {
+ getDelegate().addPackage(dir, reference);
+ }
+
+ protected void addPath(final AssembledDirectory dir, String path, String name) throws Exception
+ {
+ getDelegate().addPath(dir, path, name);
+ }
+
+ protected void assertClassEquality(Class<?> expected, Class<?> actual)
+ {
+ assertTrue("Should be the same " + ClassLoaderUtils.classToString(expected) + " and " + ClassLoaderUtils.classToString(actual), expected == actual);
+ }
+
+ protected void assertNoClassEquality(Class<?> expected, Class<?> actual)
+ {
+ assertTrue("Should NOT be the same " + ClassLoaderUtils.classToString(expected) + " and " + ClassLoaderUtils.classToString(actual), expected != actual);
+ }
+
+ protected void assertClassLoader(Class<?> clazz, Bundle expected)
+ {
+ if (expected == null)
+ return;
+ ClassLoader cl = clazz.getClassLoader();
+ ClassLoader bundleClassLoader = getBundleClassLoader(expected);
+ boolean result = bundleClassLoader.equals(cl);
+ assertTrue(ClassLoaderUtils.classToString(clazz) + " should have expected classloader=" + expected, result);
+ }
+
+ protected ClassLoader getBundleClassLoader(Bundle expected)
+ {
+ return getDeploymentUnit(expected).getClassLoader();
+ }
+
+ protected Class<?> assertLoadClass(Bundle start, Class<?> reference) throws Exception
+ {
+ return assertLoadClass(start, reference, start);
+ }
+
+ protected Class<?> assertLoadClass(Bundle start, Class<?> reference, Bundle expected) throws Exception
+ {
+ return assertLoadClass(start, reference, expected, false);
+ }
+
+ protected Class<?> assertLoadClass(Bundle start, Class<?> reference, Bundle expected, boolean isReference) throws Exception
+ {
+ Class<?> result = assertLoadClass(reference.getName(), start, expected);
+ if (isReference)
+ assertClassEquality(reference, result);
+ else
+ assertNoClassEquality(reference, result);
+ return result;
+ }
+
+ protected Class<?> assertLoadClass(String name, Bundle bundle, Bundle expected)
+ {
+ Class<?> result = null;
+ try
+ {
+ result = bundle.loadClass(name);
+ getLog().debug("Got class: " + ClassLoaderUtils.classToString(result) + " for " + name + " from " + bundle);
+ }
+ catch (ClassNotFoundException e)
+ {
+ failure("Did not expect CNFE for " + name + " from " + bundle, e);
+ }
+ assertClassLoader(result, expected);
+ return result;
+ }
+
+ protected void assertLoadClassFail(Bundle start, Class<?> reference)
+ {
+ assertLoadClassFail(start, reference.getName());
+ }
+
+ protected void assertLoadClassFail(Bundle start, String name)
+ {
+ try
+ {
+ start.loadClass(name);
+ fail("Should not be here!");
+ }
+ catch (Exception expected)
+ {
+ checkThrowable(ClassNotFoundException.class, expected);
+ }
+ }
+
+ protected URL getBundleResource(Bundle bundle, String path)
+ {
+ return getDelegate().getBundleResource(bundle, path);
+ }
+
+ protected Enumeration<URL> getBundleResources(Bundle bundle, String path) throws Exception
+ {
+ return getDelegate().getBundleResources(bundle, path);
+ }
+
+ protected void assertNoAllReferences(BundleContext bundleContext, String clazz) throws Exception
+ {
+ assertNoAllReferences(bundleContext, clazz, null);
+ }
+
+ protected void assertNoAllReferences(BundleContext bundleContext, String clazz, String filter) throws Exception
+ {
+ ServiceReference[] actual = bundleContext.getAllServiceReferences(clazz, filter);
+ if (actual != null)
+ getLog().debug(bundleContext + " got " + Arrays.asList(actual) + " for clazz=" + clazz + " filter=" + filter);
+ else
+ getLog().debug(bundleContext + " got nothing for clazz=" + clazz + " filter=" + filter);
+ assertNull("Expected no references for clazz=" + clazz + " filter=" + filter, actual);
+ }
+
+ protected void assertAllReferences(BundleContext bundleContext, String clazz, ServiceReference... expected) throws Exception
+ {
+ assertAllReferences(bundleContext, clazz, null, expected);
+ }
+
+ protected void assertAllReferences(BundleContext bundleContext, String clazz, String filter, ServiceReference... expected) throws Exception
+ {
+ ServiceReference[] actual = bundleContext.getAllServiceReferences(clazz, filter);
+ if (actual != null)
+ getLog().debug(bundleContext + " got " + Arrays.asList(actual) + " for clazz=" + clazz + " filter=" + filter);
+ else
+ getLog().debug(bundleContext + " got nothing for clazz=" + clazz + " filter=" + filter);
+ assertEquals(bundleContext + " with clazz=" + clazz + " filter=" + filter, expected, actual);
+ }
+
+ protected void assertNoReferences(BundleContext bundleContext, String clazz) throws Exception
+ {
+ assertNoReferences(bundleContext, clazz, null);
+ }
+
+ protected void assertNoReferences(BundleContext bundleContext, String clazz, String filter) throws Exception
+ {
+ ServiceReference[] actual = bundleContext.getServiceReferences(clazz, filter);
+ if (actual != null)
+ getLog().debug(bundleContext + " got " + Arrays.asList(actual) + " for clazz=" + clazz + " filter=" + filter);
+ else
+ getLog().debug(bundleContext + " got nothing for clazz=" + clazz + " filter=" + filter);
+ assertNull("Expected no references for clazz=" + clazz + " filter=" + filter, actual);
+ }
+
+ protected void assertReferences(BundleContext bundleContext, String clazz, ServiceReference... expected) throws Exception
+ {
+ assertReferences(bundleContext, clazz, null, expected);
+ }
+
+ protected void assertReferences(BundleContext bundleContext, String clazz, String filter, ServiceReference... expected) throws Exception
+ {
+ ServiceReference[] actual = bundleContext.getServiceReferences(clazz, filter);
+ if (actual != null)
+ getLog().debug(bundleContext + " got " + Arrays.asList(actual) + " for clazz=" + clazz + " filter=" + filter);
+ else
+ getLog().debug(bundleContext + " got nothing for clazz=" + clazz + " filter=" + filter);
+ assertEquals(bundleContext + " with clazz=" + clazz + " filter=" + filter, expected, actual);
+ }
+
+ protected void assertNoGetReference(BundleContext bundleContext, String clazz) throws Exception
+ {
+ ServiceReference actual = bundleContext.getServiceReference(clazz);
+ if (actual != null)
+ getLog().debug(bundleContext + " got " + actual + " for clazz=" + clazz);
+ else
+ getLog().debug(bundleContext + " got nothing for clazz=" + clazz);
+ assertNull("Expected no references for clazz=" + clazz, actual);
+ }
+
+ protected void assertGetReference(BundleContext bundleContext, String clazz, ServiceReference expected) throws Exception
+ {
+ ServiceReference actual = bundleContext.getServiceReference(clazz);
+ if (actual != null)
+ getLog().debug(bundleContext + " got " + Arrays.asList(actual) + " for clazz=" + clazz);
+ else
+ getLog().debug(bundleContext + " got nothing for clazz=" + clazz);
+ assertEquals(bundleContext + " with clazz=" + clazz, expected, actual);
+ }
+
+ protected void assertUsingBundles(ServiceReference reference, Bundle... bundles)
+ {
+ Set<Bundle> expected = new HashSet<Bundle>();
+ expected.addAll(Arrays.asList(bundles));
+
+ Set<Bundle> actual = new HashSet<Bundle>();
+ Bundle[] users = reference.getUsingBundles();
+ if (users != null)
+ actual.addAll(Arrays.asList(users));
+
+ getLog().debug(reference + " users=" + actual);
+
+ assertEquals(expected, actual);
+ }
+
+ protected void assertObjectClass(String expected, ServiceReference reference)
+ {
+ assertObjectClass(new String[] { expected }, reference);
+ }
+
+ protected void assertObjectClass(String[] expected, ServiceReference reference)
+ {
+ Object actual = reference.getProperty(Constants.OBJECTCLASS);
+ if (actual == null)
+ fail("no object class???");
+ if (actual instanceof String[] == false)
+ fail(actual + " is not a string array??? " + actual.getClass().getName());
+ assertEquals(expected, (String[])actual);
+ }
+
+ public void frameworkEvent(FrameworkEvent event)
+ {
+ synchronized (frameworkEvents)
+ {
+ getLog().debug("FrameworkEvent type=" + ConstantsHelper.frameworkEvent(event.getType()) + " for " + event);
+ frameworkEvents.add(event);
+ frameworkEvents.notifyAll();
+ }
+ }
+
+ protected void assertNoFrameworkEvent() throws Exception
+ {
+ getLog().debug("frameworkEvents=" + frameworkEvents);
+ assertEquals(0, frameworkEvents.size());
+ }
+
+ protected void assertFrameworkEvent(int type) throws Exception
+ {
+ assertFrameworkEvent(type, getSystemBundle(), null);
+ }
+
+ protected void assertFrameworkEvent(int type, Class<? extends Throwable> expectedThrowable) throws Exception
+ {
+ assertFrameworkEvent(type, getSystemBundle(), expectedThrowable);
+ }
+
+ protected void assertFrameworkEvent(int type, Bundle bundle, Class<? extends Throwable> expectedThrowable) throws Exception
+ {
+ waitForEvent(frameworkEvents, type);
+ getLog().debug("frameworkEvents=" + frameworkEvents);
+ int size = frameworkEvents.size();
+ assertTrue("" + size, size > 0);
+ FrameworkEvent event = frameworkEvents.remove(0);
+ assertEquals(ConstantsHelper.frameworkEvent(type), ConstantsHelper.frameworkEvent(event.getType()));
+ Throwable t = event.getThrowable();
+ if (expectedThrowable == null)
+ {
+ if (t != null)
+ {
+ getLog().error("Unexpected error in Framework event: ", t);
+ fail("Unexpected throwable: " + t);
+ }
+ }
+ else
+ {
+ checkThrowable(BundleException.class, t);
+ checkDeepThrowable(expectedThrowable, t);
+ }
+ assertEquals(bundle, event.getSource());
+ assertEquals(bundle, event.getBundle());
+ }
+
+ public void bundleChanged(BundleEvent event)
+ {
+ synchronized (bundleEvents)
+ {
+ getLog().debug("BundleChanged type=" + ConstantsHelper.bundleEvent(event.getType()) + " for " + event);
+ bundleEvents.add(event);
+ bundleEvents.notifyAll();
+ }
+ }
+
+ protected void assertNoBundleEvent() throws Exception
+ {
+ getLog().debug("bundleEvents=" + bundleEvents);
+ assertEquals(0, bundleEvents.size());
+ }
+
+ protected void assertBundleEvent(int type, Bundle bundle) throws Exception
+ {
+ waitForEvent(bundleEvents, type);
+
+ getLog().debug("bundleEvents=" + bundleEvents);
+ int size = bundleEvents.size();
+ assertTrue("" + size, size > 0);
+
+ if (bundle instanceof AbstractBundleState)
+ bundle = ((AbstractBundleState)bundle).getBundle();
+
+ BundleEvent foundEvent = null;
+ for(int i=0; i < bundleEvents.size(); i++)
+ {
+ BundleEvent aux = bundleEvents.get(i);
+ if (type == aux.getType())
+ {
+ if (bundle.equals(aux.getSource()) && bundle.equals(aux.getBundle()))
+ {
+ bundleEvents.remove(aux);
+ foundEvent = aux;
+ break;
+ }
+ }
+ }
+
+ if (foundEvent == null)
+ fail("Cannot find event " + ConstantsHelper.bundleEvent(type) + " from " + bundle);
+ }
+
+ public void serviceChanged(ServiceEvent event)
+ {
+ synchronized (serviceEvents)
+ {
+ getLog().debug("ServiceChanged type=" + ConstantsHelper.serviceEvent(event.getType()) + " for " + event);
+ serviceEvents.add(event);
+ serviceEvents.notifyAll();
+ }
+ }
+
+ protected void assertNoServiceEvent() throws Exception
+ {
+ getLog().debug("serviceEvents=" + serviceEvents);
+ assertEquals(0, serviceEvents.size());
+ }
+
+ protected void assertServiceEvent(int type, ServiceReference reference) throws Exception
+ {
+ waitForEvent(serviceEvents, type);
+ getLog().debug("serviceEvents=" + serviceEvents);
+ int size = serviceEvents.size();
+ assertTrue("" + size, size > 0);
+ ServiceEvent event = serviceEvents.remove(0);
+ assertEquals(ConstantsHelper.serviceEvent(type), ConstantsHelper.serviceEvent(event.getType()));
+ assertEquals(reference, event.getSource());
+ assertEquals(reference, event.getServiceReference());
+ }
+
+ @SuppressWarnings({"unchecked", "SynchronizationOnLocalVariableOrMethodParameter"})
+ private void waitForEvent(List events, int type) throws InterruptedException
+ {
+ // Timeout for event delivery: 3 sec
+ int timeout = 30;
+
+ boolean eventFound = false;
+ while (eventFound == false && 0 < timeout)
+ {
+ synchronized (events)
+ {
+ events.wait(100);
+ for (Object aux : events)
+ {
+ if (aux instanceof BundleEvent)
+ {
+ BundleEvent event = (BundleEvent)aux;
+ if (type == event.getType())
+ {
+ eventFound = true;
+ break;
+ }
+ }
+ else if (aux instanceof ServiceEvent)
+ {
+ ServiceEvent event = (ServiceEvent)aux;
+ if (type == event.getType())
+ {
+ eventFound = true;
+ break;
+ }
+ }
+ else if (aux instanceof FrameworkEvent)
+ {
+ FrameworkEvent event = (FrameworkEvent)aux;
+ if (type == event.getType())
+ {
+ eventFound = true;
+ break;
+ }
+ }
+ }
+ }
+ timeout--;
+ }
+ }
+}
Deleted: projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/FrameworkTestCase.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/FrameworkTestCase.java 2009-11-11 22:09:32 UTC (rev 96281)
+++ projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/FrameworkTestCase.java 2009-11-11 22:30:31 UTC (rev 96282)
@@ -1,619 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2008, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This 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.1 of
- * the License, or (at your option) any later version.
- *
- * This software 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 software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-*/
-package org.jboss.test.osgi;
-
-import java.net.URL;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Enumeration;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-import java.util.concurrent.CopyOnWriteArrayList;
-
-import org.jboss.classloader.plugins.ClassLoaderUtils;
-import org.jboss.deployers.structure.spi.DeploymentUnit;
-import org.jboss.osgi.framework.bundle.AbstractBundleState;
-import org.jboss.osgi.framework.bundle.OSGiBundleManager;
-import org.jboss.osgi.framework.metadata.OSGiMetaData;
-import org.jboss.osgi.spi.util.ConstantsHelper;
-import org.jboss.test.kernel.junit.MicrocontainerTest;
-import org.jboss.virtual.AssembledDirectory;
-import org.jboss.virtual.VirtualFile;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.BundleEvent;
-import org.osgi.framework.BundleException;
-import org.osgi.framework.Constants;
-import org.osgi.framework.FrameworkEvent;
-import org.osgi.framework.FrameworkListener;
-import org.osgi.framework.ServiceEvent;
-import org.osgi.framework.ServiceListener;
-import org.osgi.framework.ServiceReference;
-import org.osgi.framework.SynchronousBundleListener;
-
-/**
- * OSGiTestCase - Parent Test Case for OSGi tests.
- *
- * @author <a href="baileyje(a)gmail.com">John Bailey</a>
- * @version $Revision: 87848 $
- */
-public abstract class FrameworkTestCase extends MicrocontainerTest implements FrameworkListener, SynchronousBundleListener, ServiceListener
-{
- private List<FrameworkEvent> frameworkEvents = new CopyOnWriteArrayList<FrameworkEvent>();
- private List<BundleEvent> bundleEvents = new CopyOnWriteArrayList<BundleEvent>();
- private List<ServiceEvent> serviceEvents = new CopyOnWriteArrayList<ServiceEvent>();
-
- /**
- * Create a new OSGiTestCase.
- *
- * @param name the test name
- */
- public FrameworkTestCase(String name)
- {
- super(name);
- }
-
- public static FrameworkTestDelegate getDelegate(Class<?> clazz) throws Exception
- {
- FrameworkTestDelegate delegate = new FrameworkTestDelegate(clazz);
- return delegate;
- }
-
- /**
- * Get OSGiTestDelegate
- */
- protected FrameworkTestDelegate getDelegate()
- {
- return (FrameworkTestDelegate)super.getDelegate();
- }
-
- /**
- * Get BundleManager from Delegate
- *
- * @return The BundleManager
- */
- protected OSGiBundleManager getBundleManager()
- {
- return getDelegate().getBundleManager();
- }
-
- /**
- * Get the system bundle
- *
- * @return the system bundle
- */
- protected Bundle getSystemBundle()
- {
- return getBundleManager().getBundleById(0).getBundleInternal();
- }
-
- /**
- * Add the base bundles
- *
- * @param expected the collection to add to
- */
- protected void addBaseBundles(Collection<Bundle> expected)
- {
- expected.add(getSystemBundle());
- }
-
- /**
- * Create a bundle
- *
- * @param root the location of the location to deploy
- * @param child the child to deploy
- * @return Bundle for the deployment
- * @throws Exception for any error
- */
- protected Bundle addBundle(String root, String child) throws Exception
- {
- return getDelegate().addBundle(root, child);
- }
-
- /**
- * Create a bundle
- *
- * @param file the virtual file
- * @return Bundle for the deployment
- * @throws Exception for any error
- */
- protected Bundle addBundle(VirtualFile file) throws Exception
- {
- return getDelegate().addBundle(file);
- }
-
- /**
- * Create a bundle
- *
- * @param root the location of the location to deploy
- * @param child the child to deploy
- * @return Bundle for the deployment
- * @throws Exception for any error
- */
- protected Bundle deployBundle(String root, String child) throws Exception
- {
- return getDelegate().deployBundle(root, child);
- }
-
- /**
- * Create a bundle
- *
- * @param file the virtual file
- * @return Bundle for the deployment
- * @throws Exception for any error
- */
- protected Bundle deployBundle(VirtualFile file) throws Exception
- {
- return getDelegate().deployBundle(file);
- }
-
- /**
- * Remove a bundle
- *
- * @param bundle the bundle to remove
- * @throws Exception for any error
- */
- protected void uninstall(Bundle bundle) throws Exception
- {
- getDelegate().uninstall(bundle);
- }
-
- protected DeploymentUnit getDeploymentUnit(Bundle bundle)
- {
- return getDelegate().getDeploymentUnit(bundle);
- }
-
- protected Bundle assembleBundle(String name, String resources, Class<?>... packages) throws Exception
- {
- return getDelegate().assembleBundle(name, new String[] { resources }, packages);
- }
-
- protected Bundle assembleBundle(String name, String[] resourcePaths, Class<?>... packages) throws Exception
- {
- return getDelegate().assembleBundle(name, resourcePaths, packages);
- }
-
- protected Bundle deployBundle(String name, Class<?>... packages) throws Exception
- {
- return getDelegate().deployBundle(name, null, (String[]) null, packages);
- }
-
- protected Bundle deployBundle(String name, String resourcePath, Class<?>... packages) throws Exception
- {
- return getDelegate().deployBundle(name, null, resourcePath, packages);
- }
-
- protected Bundle deployBundle(String name, String[] resourcePaths, Class<?>... packages) throws Exception
- {
- return getDelegate().deployBundle(name, null, resourcePaths, packages);
- }
-
- protected Bundle deployBundle(String name, OSGiMetaData metaData, Class<?>... packages) throws Exception
- {
- return getDelegate().deployBundle(name, metaData, (String[]) null, packages);
- }
-
- protected Bundle deployBundle(String name, OSGiMetaData metaData, String resourcePath, Class<?>... packages) throws Exception
- {
- return getDelegate().deployBundle(name, metaData, resourcePath, packages);
- }
-
- protected Bundle deployBundle(String name, OSGiMetaData metaData, String[] resourcePaths, Class<?>... packages) throws Exception
- {
- return getDelegate().deployBundle(name, metaData, resourcePaths, packages);
- }
-
- protected AssembledDirectory createAssembledDirectory(String name) throws Exception
- {
- return getDelegate().createAssembledDirectory(name, "");
- }
-
- protected AssembledDirectory createAssembledDirectory(String name, String rootName) throws Exception
- {
- return getDelegate().createAssembledDirectory(name, rootName);
- }
-
- protected void addPackage(AssembledDirectory dir, Class<?> reference) throws Exception
- {
- getDelegate().addPackage(dir, reference);
- }
-
- protected void addPath(final AssembledDirectory dir, String path, String name) throws Exception
- {
- getDelegate().addPath(dir, path, name);
- }
-
- protected void assertClassEquality(Class<?> expected, Class<?> actual)
- {
- assertTrue("Should be the same " + ClassLoaderUtils.classToString(expected) + " and " + ClassLoaderUtils.classToString(actual), expected == actual);
- }
-
- protected void assertNoClassEquality(Class<?> expected, Class<?> actual)
- {
- assertTrue("Should NOT be the same " + ClassLoaderUtils.classToString(expected) + " and " + ClassLoaderUtils.classToString(actual), expected != actual);
- }
-
- protected void assertClassLoader(Class<?> clazz, Bundle expected)
- {
- if (expected == null)
- return;
- ClassLoader cl = clazz.getClassLoader();
- ClassLoader bundleClassLoader = getBundleClassLoader(expected);
- boolean result = bundleClassLoader.equals(cl);
- assertTrue(ClassLoaderUtils.classToString(clazz) + " should have expected classloader=" + expected, result);
- }
-
- protected ClassLoader getBundleClassLoader(Bundle expected)
- {
- return getDeploymentUnit(expected).getClassLoader();
- }
-
- protected Class<?> assertLoadClass(Bundle start, Class<?> reference) throws Exception
- {
- return assertLoadClass(start, reference, start);
- }
-
- protected Class<?> assertLoadClass(Bundle start, Class<?> reference, Bundle expected) throws Exception
- {
- return assertLoadClass(start, reference, expected, false);
- }
-
- protected Class<?> assertLoadClass(Bundle start, Class<?> reference, Bundle expected, boolean isReference) throws Exception
- {
- Class<?> result = assertLoadClass(reference.getName(), start, expected);
- if (isReference)
- assertClassEquality(reference, result);
- else
- assertNoClassEquality(reference, result);
- return result;
- }
-
- protected Class<?> assertLoadClass(String name, Bundle bundle, Bundle expected)
- {
- Class<?> result = null;
- try
- {
- result = bundle.loadClass(name);
- getLog().debug("Got class: " + ClassLoaderUtils.classToString(result) + " for " + name + " from " + bundle);
- }
- catch (ClassNotFoundException e)
- {
- failure("Did not expect CNFE for " + name + " from " + bundle, e);
- }
- assertClassLoader(result, expected);
- return result;
- }
-
- protected void assertLoadClassFail(Bundle start, Class<?> reference)
- {
- assertLoadClassFail(start, reference.getName());
- }
-
- protected void assertLoadClassFail(Bundle start, String name)
- {
- try
- {
- start.loadClass(name);
- fail("Should not be here!");
- }
- catch (Exception expected)
- {
- checkThrowable(ClassNotFoundException.class, expected);
- }
- }
-
- protected URL getBundleResource(Bundle bundle, String path)
- {
- return getDelegate().getBundleResource(bundle, path);
- }
-
- protected Enumeration<URL> getBundleResources(Bundle bundle, String path) throws Exception
- {
- return getDelegate().getBundleResources(bundle, path);
- }
-
- protected void assertNoAllReferences(BundleContext bundleContext, String clazz) throws Exception
- {
- assertNoAllReferences(bundleContext, clazz, null);
- }
-
- protected void assertNoAllReferences(BundleContext bundleContext, String clazz, String filter) throws Exception
- {
- ServiceReference[] actual = bundleContext.getAllServiceReferences(clazz, filter);
- if (actual != null)
- getLog().debug(bundleContext + " got " + Arrays.asList(actual) + " for clazz=" + clazz + " filter=" + filter);
- else
- getLog().debug(bundleContext + " got nothing for clazz=" + clazz + " filter=" + filter);
- assertNull("Expected no references for clazz=" + clazz + " filter=" + filter, actual);
- }
-
- protected void assertAllReferences(BundleContext bundleContext, String clazz, ServiceReference... expected) throws Exception
- {
- assertAllReferences(bundleContext, clazz, null, expected);
- }
-
- protected void assertAllReferences(BundleContext bundleContext, String clazz, String filter, ServiceReference... expected) throws Exception
- {
- ServiceReference[] actual = bundleContext.getAllServiceReferences(clazz, filter);
- if (actual != null)
- getLog().debug(bundleContext + " got " + Arrays.asList(actual) + " for clazz=" + clazz + " filter=" + filter);
- else
- getLog().debug(bundleContext + " got nothing for clazz=" + clazz + " filter=" + filter);
- assertEquals(bundleContext + " with clazz=" + clazz + " filter=" + filter, expected, actual);
- }
-
- protected void assertNoReferences(BundleContext bundleContext, String clazz) throws Exception
- {
- assertNoReferences(bundleContext, clazz, null);
- }
-
- protected void assertNoReferences(BundleContext bundleContext, String clazz, String filter) throws Exception
- {
- ServiceReference[] actual = bundleContext.getServiceReferences(clazz, filter);
- if (actual != null)
- getLog().debug(bundleContext + " got " + Arrays.asList(actual) + " for clazz=" + clazz + " filter=" + filter);
- else
- getLog().debug(bundleContext + " got nothing for clazz=" + clazz + " filter=" + filter);
- assertNull("Expected no references for clazz=" + clazz + " filter=" + filter, actual);
- }
-
- protected void assertReferences(BundleContext bundleContext, String clazz, ServiceReference... expected) throws Exception
- {
- assertReferences(bundleContext, clazz, null, expected);
- }
-
- protected void assertReferences(BundleContext bundleContext, String clazz, String filter, ServiceReference... expected) throws Exception
- {
- ServiceReference[] actual = bundleContext.getServiceReferences(clazz, filter);
- if (actual != null)
- getLog().debug(bundleContext + " got " + Arrays.asList(actual) + " for clazz=" + clazz + " filter=" + filter);
- else
- getLog().debug(bundleContext + " got nothing for clazz=" + clazz + " filter=" + filter);
- assertEquals(bundleContext + " with clazz=" + clazz + " filter=" + filter, expected, actual);
- }
-
- protected void assertNoGetReference(BundleContext bundleContext, String clazz) throws Exception
- {
- ServiceReference actual = bundleContext.getServiceReference(clazz);
- if (actual != null)
- getLog().debug(bundleContext + " got " + actual + " for clazz=" + clazz);
- else
- getLog().debug(bundleContext + " got nothing for clazz=" + clazz);
- assertNull("Expected no references for clazz=" + clazz, actual);
- }
-
- protected void assertGetReference(BundleContext bundleContext, String clazz, ServiceReference expected) throws Exception
- {
- ServiceReference actual = bundleContext.getServiceReference(clazz);
- if (actual != null)
- getLog().debug(bundleContext + " got " + Arrays.asList(actual) + " for clazz=" + clazz);
- else
- getLog().debug(bundleContext + " got nothing for clazz=" + clazz);
- assertEquals(bundleContext + " with clazz=" + clazz, expected, actual);
- }
-
- protected void assertUsingBundles(ServiceReference reference, Bundle... bundles)
- {
- Set<Bundle> expected = new HashSet<Bundle>();
- for (Bundle bundle : bundles)
- expected.add(bundle);
-
- Set<Bundle> actual = new HashSet<Bundle>();
- Bundle[] users = reference.getUsingBundles();
- if (users != null)
- for (Bundle bundle : users)
- actual.add(bundle);
-
- getLog().debug(reference + " users=" + actual);
-
- assertEquals(expected, actual);
- }
-
- protected void assertObjectClass(String expected, ServiceReference reference)
- {
- assertObjectClass(new String[] { expected }, reference);
- }
-
- protected void assertObjectClass(String[] expected, ServiceReference reference)
- {
- Object actual = reference.getProperty(Constants.OBJECTCLASS);
- if (actual == null)
- fail("no object class???");
- if (actual instanceof String[] == false)
- fail(actual + " is not a string array??? " + actual.getClass().getName());
- assertEquals(expected, (String[])actual);
- }
-
- public void frameworkEvent(FrameworkEvent event)
- {
- synchronized (frameworkEvents)
- {
- getLog().debug("FrameworkEvent type=" + ConstantsHelper.frameworkEvent(event.getType()) + " for " + event);
- frameworkEvents.add(event);
- frameworkEvents.notifyAll();
- }
- }
-
- protected void assertNoFrameworkEvent() throws Exception
- {
- getLog().debug("frameworkEvents=" + frameworkEvents);
- assertEquals(0, frameworkEvents.size());
- }
-
- protected void assertFrameworkEvent(int type) throws Exception
- {
- assertFrameworkEvent(type, getSystemBundle(), null);
- }
-
- protected void assertFrameworkEvent(int type, Class<? extends Throwable> expectedThrowable) throws Exception
- {
- assertFrameworkEvent(type, getSystemBundle(), expectedThrowable);
- }
-
- protected void assertFrameworkEvent(int type, Bundle bundle, Class<? extends Throwable> expectedThrowable) throws Exception
- {
- waitForEvent(frameworkEvents, type);
- getLog().debug("frameworkEvents=" + frameworkEvents);
- int size = frameworkEvents.size();
- assertTrue("" + size, size > 0);
- FrameworkEvent event = frameworkEvents.remove(0);
- assertEquals(ConstantsHelper.frameworkEvent(type), ConstantsHelper.frameworkEvent(event.getType()));
- Throwable t = event.getThrowable();
- if (expectedThrowable == null)
- {
- if (t != null)
- {
- getLog().error("Unexpected error in Framework event: ", t);
- fail("Unexpected throwable: " + t);
- }
- }
- else
- {
- checkThrowable(BundleException.class, t);
- checkDeepThrowable(expectedThrowable, t);
- }
- assertEquals(bundle, event.getSource());
- assertEquals(bundle, event.getBundle());
- }
-
- public void bundleChanged(BundleEvent event)
- {
- synchronized (bundleEvents)
- {
- getLog().debug("BundleChanged type=" + ConstantsHelper.bundleEvent(event.getType()) + " for " + event);
- bundleEvents.add(event);
- bundleEvents.notifyAll();
- }
- }
-
- protected void assertNoBundleEvent() throws Exception
- {
- getLog().debug("bundleEvents=" + bundleEvents);
- assertEquals(0, bundleEvents.size());
- }
-
- protected void assertBundleEvent(int type, Bundle bundle) throws Exception
- {
- waitForEvent(bundleEvents, type);
-
- getLog().debug("bundleEvents=" + bundleEvents);
- int size = bundleEvents.size();
- assertTrue("" + size, size > 0);
-
- if (bundle instanceof AbstractBundleState)
- bundle = ((AbstractBundleState)bundle).getBundle();
-
- BundleEvent foundEvent = null;
- for(int i=0; i < bundleEvents.size(); i++)
- {
- BundleEvent aux = bundleEvents.get(i);
- if (type == aux.getType())
- {
- if (bundle.equals(aux.getSource()) && bundle.equals(aux.getBundle()))
- {
- bundleEvents.remove(aux);
- foundEvent = aux;
- break;
- }
- }
- }
-
- if (foundEvent == null)
- fail("Cannot find event " + ConstantsHelper.bundleEvent(type) + " from " + bundle);
- }
-
- public void serviceChanged(ServiceEvent event)
- {
- synchronized (serviceEvents)
- {
- getLog().debug("ServiceChanged type=" + ConstantsHelper.serviceEvent(event.getType()) + " for " + event);
- serviceEvents.add(event);
- serviceEvents.notifyAll();
- }
- }
-
- protected void assertNoServiceEvent() throws Exception
- {
- getLog().debug("serviceEvents=" + serviceEvents);
- assertEquals(0, serviceEvents.size());
- }
-
- protected void assertServiceEvent(int type, ServiceReference reference) throws Exception
- {
- waitForEvent(serviceEvents, type);
- getLog().debug("serviceEvents=" + serviceEvents);
- int size = serviceEvents.size();
- assertTrue("" + size, size > 0);
- ServiceEvent event = serviceEvents.remove(0);
- assertEquals(ConstantsHelper.serviceEvent(type), ConstantsHelper.serviceEvent(event.getType()));
- assertEquals(reference, event.getSource());
- assertEquals(reference, event.getServiceReference());
- }
-
- @SuppressWarnings("unchecked")
- private void waitForEvent(List events, int type) throws InterruptedException
- {
- // Timeout for event delivery: 3 sec
- int timeout = 30;
-
- boolean eventFound = false;
- while (eventFound == false && 0 < timeout)
- {
- synchronized (events)
- {
- events.wait(100);
- for (Object aux : events)
- {
- if (aux instanceof BundleEvent)
- {
- BundleEvent event = (BundleEvent)aux;
- if (type == event.getType())
- {
- eventFound = true;
- break;
- }
- }
- else if (aux instanceof ServiceEvent)
- {
- ServiceEvent event = (ServiceEvent)aux;
- if (type == event.getType())
- {
- eventFound = true;
- break;
- }
- }
- else if (aux instanceof FrameworkEvent)
- {
- FrameworkEvent event = (FrameworkEvent)aux;
- if (type == event.getType())
- {
- eventFound = true;
- break;
- }
- }
- }
- }
- timeout--;
- }
- }
-}
Modified: projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/bundle/BundleContextUnitTestCase.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/bundle/BundleContextUnitTestCase.java 2009-11-11 22:09:32 UTC (rev 96281)
+++ projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/bundle/BundleContextUnitTestCase.java 2009-11-11 22:30:31 UTC (rev 96282)
@@ -31,7 +31,7 @@
import junit.framework.Test;
-import org.jboss.test.osgi.FrameworkTestCase;
+import org.jboss.test.osgi.FrameworkTest;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleEvent;
@@ -48,7 +48,7 @@
* @author Thomas.Diesler(a)jboss.com
* @version $Revision: 1.1 $
*/
-public class BundleContextUnitTestCase extends FrameworkTestCase
+public class BundleContextUnitTestCase extends FrameworkTest
{
public static Test suite()
{
Modified: projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/bundle/BundleEntriesUnitTestCase.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/bundle/BundleEntriesUnitTestCase.java 2009-11-11 22:09:32 UTC (rev 96281)
+++ projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/bundle/BundleEntriesUnitTestCase.java 2009-11-11 22:30:31 UTC (rev 96282)
@@ -30,7 +30,7 @@
import junit.framework.Test;
-import org.jboss.test.osgi.FrameworkTestCase;
+import org.jboss.test.osgi.FrameworkTest;
import org.osgi.framework.Bundle;
/**
@@ -41,7 +41,7 @@
* @author <a href="adrian(a)jboss.com">Adrian Brock</a>
* @version $Revision: 1.1 $
*/
-public class BundleEntriesUnitTestCase extends FrameworkTestCase
+public class BundleEntriesUnitTestCase extends FrameworkTest
{
public static Test suite()
{
Modified: projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/bundle/BundleUnitTestCase.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/bundle/BundleUnitTestCase.java 2009-11-11 22:09:32 UTC (rev 96281)
+++ projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/bundle/BundleUnitTestCase.java 2009-11-11 22:30:31 UTC (rev 96282)
@@ -27,7 +27,7 @@
import junit.framework.Test;
-import org.jboss.test.osgi.FrameworkTestCase;
+import org.jboss.test.osgi.FrameworkTest;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleException;
@@ -40,7 +40,7 @@
* @author <a href="adrian(a)jboss.com">Adrian Brock</a>
* @version $Revision: 1.1 $
*/
-public class BundleUnitTestCase extends FrameworkTestCase
+public class BundleUnitTestCase extends FrameworkTest
{
public static Test suite()
{
Copied: projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/bundle/BundleVFSUnitTestCase.java (from rev 96278, projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/bundle/BundleEntriesUnitTestCase.java)
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/bundle/BundleVFSUnitTestCase.java (rev 0)
+++ projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/bundle/BundleVFSUnitTestCase.java 2009-11-11 22:30:31 UTC (rev 96282)
@@ -0,0 +1,233 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors.
+*
+* This 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.1 of
+* the License, or (at your option) any later version.
+*
+* This software 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 software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.osgi.bundle;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URI;
+import java.net.URL;
+import java.util.List;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import junit.framework.Test;
+
+import org.jboss.osgi.framework.vfs.BundleVFSContextFactory;
+import org.jboss.test.osgi.FrameworkTest;
+import org.jboss.virtual.VFS;
+import org.jboss.virtual.VirtualFile;
+import org.jboss.virtual.VirtualFileFilter;
+import org.jboss.virtual.VirtualFileVisitor;
+import org.jboss.virtual.VisitorAttributes;
+import org.osgi.framework.Bundle;
+
+/**
+ * BundleVFSUnitTestCase.
+ *
+ * TODO test security
+ * TODO test fragments
+ * @author <a href="ales.justin(a)jboss.org">Ales Justin</a>
+ */
+public class BundleVFSUnitTestCase extends FrameworkTest
+{
+ private BundleVFSContextFactory factory;
+
+ public static Test suite()
+ {
+ return suite(BundleVFSUnitTestCase.class);
+ }
+
+ public BundleVFSUnitTestCase(String name)
+ {
+ super(name);
+ }
+
+ @Override
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+
+ factory = new BundleVFSContextFactory(getBundleManager());
+ factory.start();
+ }
+
+ @Override
+ protected void tearDown() throws Exception
+ {
+ factory.stop();
+ factory = null;
+
+ super.tearDown();
+ }
+
+ public void testBasicOps() throws Exception
+ {
+ Bundle bundle = addBundle("/bundles/entries/", "entries-simple");
+ try
+ {
+ URI uri = createURI(bundle, null);
+ assertBundleByURI(uri, 0, true, "root.xml");
+
+ uri = createURI(bundle, "root.xml");
+ assertBundleByURI(uri, 0, false, null);
+
+ uri = createURI(bundle, "META-INF");
+ assertBundleByURI(uri, -1, true, "MANIFEST.MF");
+
+ uri = createURI(bundle, "META-INF/MANIFEST.MF");
+ assertBundleByURI(uri, 0, false, null);
+ }
+ finally
+ {
+ uninstall(bundle);
+ }
+ }
+
+ public void testBasicNavigation() throws Exception
+ {
+ Bundle bundle = addBundle("/bundles/entries/", "entries-simple");
+ try
+ {
+ URI uri = createURI(bundle, null);
+ VirtualFile root = VFS.getRoot(uri);
+ assertNotNull(root);
+
+ VirtualFile metainf = root.getChild("META-INF");
+ assertBundleByFile(metainf, -1, true, "MANIFEST.MF");
+ List<VirtualFile> children = metainf.getChildren();
+ assertTrue(children != null && children.size() == 1);
+ assertEquals(root, metainf.getParent());
+
+ VirtualFile manifest = metainf.getChild("MANIFEST.MF");
+ assertBundleByFile(manifest, 0, false, null);
+ }
+ finally
+ {
+ uninstall(bundle);
+ }
+ }
+
+ public void testVisitor() throws Exception
+ {
+ Bundle bundle = addBundle("/bundles/entries/", "entries-simple");
+ try
+ {
+ URI uri = createURI(bundle, null);
+ VirtualFile root = VFS.getRoot(uri);
+ assertNotNull(root);
+
+ List<VirtualFile> children = root.getChildren(new VirtualFileFilter()
+ {
+ public boolean accepts(VirtualFile file)
+ {
+ return file.getPathName().contains("META-INF");
+ }
+ });
+ assertTrue(children != null && children.size() == 1);
+
+ children = root.getChildrenRecursively(new VirtualFileFilter()
+ {
+ public boolean accepts(VirtualFile file)
+ {
+ return file.getPathName().contains("META-INF");
+ }
+ });
+ assertTrue(children != null && children.size() == 2);
+
+ final AtomicInteger counter = new AtomicInteger(0);
+ root.visit(new VirtualFileVisitor()
+ {
+ public VisitorAttributes getAttributes()
+ {
+ return VisitorAttributes.RECURSE_LEAVES_ONLY;
+ }
+
+ public void visit(VirtualFile file)
+ {
+ if (file.getName().equals("entry2.xml")) counter.incrementAndGet();
+ }
+ });
+ assertEquals(2, counter.get());
+ }
+ finally
+ {
+ uninstall(bundle);
+ }
+ }
+
+ protected URI createURI(Bundle bundle, String path) throws Exception
+ {
+ if (path == null)
+ path = "";
+ if (path != null && path.startsWith("/") == false)
+ path = "/" + path;
+
+ return new URI("bundle", Long.toString(bundle.getBundleId()), path, null);
+ }
+
+ protected void assertBundleByURI(URI uri, int available, boolean hasChildren, String path) throws Exception
+ {
+ VFS vfs = VFS.getVFS(uri);
+ assertNotNull(vfs);
+ VirtualFile file = vfs.getRoot();
+ assertNotNull(file);
+
+ URI bURI = file.toURI();
+ assertEquals(uri, bURI);
+ URL url = uri.toURL();
+ assertEquals(url, file.toURL());
+
+ assertBundleByFile(file, available, hasChildren, path);
+
+ // check url
+ file = VFS.getRoot(url);
+ assertBundleByFile(file, available, hasChildren, path);
+ }
+
+ protected void assertBundleByFile(VirtualFile file, int available, boolean hasChildren, String path) throws IOException
+ {
+ long lastModified = file.getLastModified();
+ assertTrue(lastModified >= 0);
+
+ InputStream is = file.openStream();
+ try
+ {
+ assertTrue(is.available() > available);
+ }
+ finally
+ {
+ is.close();
+ }
+
+ List<VirtualFile> children = file.getChildren();
+ assertEquals(hasChildren, children != null && children.isEmpty() == false);
+
+ String cp = path;
+ if (cp == null)
+ cp = "rubbish"; // :-)
+
+ VirtualFile child = file.getChild(cp);
+ assertEquals(path != null, child != null);
+
+ if (child != null)
+ assertEquals(file, child.getParent());
+ }
+}
\ No newline at end of file
Modified: projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/bundle/SystemBundleUnitTestCase.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/bundle/SystemBundleUnitTestCase.java 2009-11-11 22:09:32 UTC (rev 96281)
+++ projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/bundle/SystemBundleUnitTestCase.java 2009-11-11 22:30:31 UTC (rev 96282)
@@ -26,7 +26,7 @@
import junit.framework.Test;
-import org.jboss.test.osgi.FrameworkTestCase;
+import org.jboss.test.osgi.FrameworkTest;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleException;
import org.osgi.framework.Constants;
@@ -38,7 +38,7 @@
* @author <a href="adrian(a)jboss.com">Adrian Brock</a>
* @version $Revision: 1.1 $
*/
-public class SystemBundleUnitTestCase extends FrameworkTestCase
+public class SystemBundleUnitTestCase extends FrameworkTest
{
public SystemBundleUnitTestCase(String name)
{
Modified: projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/classloader/ExportImportPackageUnitTestCase.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/classloader/ExportImportPackageUnitTestCase.java 2009-11-11 22:09:32 UTC (rev 96281)
+++ projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/classloader/ExportImportPackageUnitTestCase.java 2009-11-11 22:30:31 UTC (rev 96282)
@@ -23,7 +23,7 @@
import junit.framework.Test;
-import org.jboss.test.osgi.FrameworkTestCase;
+import org.jboss.test.osgi.FrameworkTest;
import org.jboss.test.osgi.classloader.support.a.A;
import org.jboss.test.osgi.classloader.support.b.B;
import org.osgi.framework.Bundle;
@@ -41,7 +41,7 @@
* @author Thomas.Diesler(a)jboss.com
* @version $Revision: 1.1 $
*/
-public class ExportImportPackageUnitTestCase extends FrameworkTestCase
+public class ExportImportPackageUnitTestCase extends FrameworkTest
{
public static Test suite()
{
Modified: projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/classloader/RequireBundleUnitTestCase.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/classloader/RequireBundleUnitTestCase.java 2009-11-11 22:09:32 UTC (rev 96281)
+++ projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/classloader/RequireBundleUnitTestCase.java 2009-11-11 22:30:31 UTC (rev 96282)
@@ -23,7 +23,7 @@
import junit.framework.Test;
-import org.jboss.test.osgi.FrameworkTestCase;
+import org.jboss.test.osgi.FrameworkTest;
import org.jboss.test.osgi.classloader.support.a.A;
import org.jboss.test.osgi.classloader.support.b.B;
import org.osgi.framework.Bundle;
@@ -36,7 +36,7 @@
* @author <a href="adrian(a)jboss.com">Adrian Brock</a>
* @version $Revision: 1.1 $
*/
-public class RequireBundleUnitTestCase extends FrameworkTestCase
+public class RequireBundleUnitTestCase extends FrameworkTest
{
public RequireBundleUnitTestCase(String name)
{
Modified: projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/service/GetServiceReferencesUnitTestCase.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/service/GetServiceReferencesUnitTestCase.java 2009-11-11 22:09:32 UTC (rev 96281)
+++ projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/service/GetServiceReferencesUnitTestCase.java 2009-11-11 22:30:31 UTC (rev 96282)
@@ -26,7 +26,7 @@
import junit.framework.Test;
-import org.jboss.test.osgi.FrameworkTestCase;
+import org.jboss.test.osgi.FrameworkTest;
import org.jboss.test.osgi.service.support.a.A;
import org.jboss.test.osgi.service.support.b.B;
import org.osgi.framework.Bundle;
@@ -43,7 +43,7 @@
* @author <a href="adrian(a)jboss.com">Adrian Brock</a>
* @version $Revision: 1.1 $
*/
-public class GetServiceReferencesUnitTestCase extends FrameworkTestCase
+public class GetServiceReferencesUnitTestCase extends FrameworkTest
{
public static Test suite()
{
Modified: projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/service/GetUnGetServiceUnitTestCase.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/service/GetUnGetServiceUnitTestCase.java 2009-11-11 22:09:32 UTC (rev 96281)
+++ projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/service/GetUnGetServiceUnitTestCase.java 2009-11-11 22:30:31 UTC (rev 96282)
@@ -23,7 +23,7 @@
import junit.framework.Test;
-import org.jboss.test.osgi.FrameworkTestCase;
+import org.jboss.test.osgi.FrameworkTest;
import org.jboss.test.osgi.service.support.BrokenServiceFactory;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
@@ -37,7 +37,7 @@
* @author <a href="adrian(a)jboss.com">Adrian Brock</a>
* @version $Revision: 1.1 $
*/
-public class GetUnGetServiceUnitTestCase extends FrameworkTestCase
+public class GetUnGetServiceUnitTestCase extends FrameworkTest
{
static String OBJCLASS = BundleContext.class.getName();
Modified: projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/service/RegisterServiceUnitTestCase.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/service/RegisterServiceUnitTestCase.java 2009-11-11 22:09:32 UTC (rev 96281)
+++ projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/service/RegisterServiceUnitTestCase.java 2009-11-11 22:30:31 UTC (rev 96282)
@@ -26,7 +26,7 @@
import junit.framework.Test;
-import org.jboss.test.osgi.FrameworkTestCase;
+import org.jboss.test.osgi.FrameworkTest;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.Constants;
@@ -40,7 +40,7 @@
* @author <a href="adrian(a)jboss.com">Adrian Brock</a>
* @version $Revision: 1.1 $
*/
-public class RegisterServiceUnitTestCase extends FrameworkTestCase
+public class RegisterServiceUnitTestCase extends FrameworkTest
{
static String OBJCLASS = BundleContext.class.getName();
static String[] OBJCLASSES = new String[] { OBJCLASS };
Modified: projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/service/ServiceFactoryUnitTestCase.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/service/ServiceFactoryUnitTestCase.java 2009-11-11 22:09:32 UTC (rev 96281)
+++ projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/service/ServiceFactoryUnitTestCase.java 2009-11-11 22:30:31 UTC (rev 96282)
@@ -24,7 +24,7 @@
import junit.framework.Test;
import org.jboss.osgi.framework.bundle.OSGiBundleWrapper;
-import org.jboss.test.osgi.FrameworkTestCase;
+import org.jboss.test.osgi.FrameworkTest;
import org.jboss.test.osgi.service.support.SimpleServiceFactory;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
@@ -39,7 +39,7 @@
* @author Thomas.Diesler(a)jboss.com
* @version $Revision$
*/
-public class ServiceFactoryUnitTestCase extends FrameworkTestCase
+public class ServiceFactoryUnitTestCase extends FrameworkTest
{
static String OBJCLASS = BundleContext.class.getName();
static String[] OBJCLASSES = new String[] { OBJCLASS };
Modified: projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/service/ServiceReferenceUnitTestCase.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/service/ServiceReferenceUnitTestCase.java 2009-11-11 22:09:32 UTC (rev 96281)
+++ projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/service/ServiceReferenceUnitTestCase.java 2009-11-11 22:30:31 UTC (rev 96282)
@@ -30,7 +30,7 @@
import junit.framework.Test;
-import org.jboss.test.osgi.FrameworkTestCase;
+import org.jboss.test.osgi.FrameworkTest;
import org.jboss.test.osgi.service.support.a.A;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
@@ -45,7 +45,7 @@
* @author <a href="adrian(a)jboss.com">Adrian Brock</a>
* @version $Revision: 1.1 $
*/
-public class ServiceReferenceUnitTestCase extends FrameworkTestCase
+public class ServiceReferenceUnitTestCase extends FrameworkTest
{
public ServiceReferenceUnitTestCase(String name)
{
Modified: projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/service/ServiceRegistrationUnitTestCase.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/service/ServiceRegistrationUnitTestCase.java 2009-11-11 22:09:32 UTC (rev 96281)
+++ projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/service/ServiceRegistrationUnitTestCase.java 2009-11-11 22:30:31 UTC (rev 96282)
@@ -25,7 +25,7 @@
import junit.framework.Test;
-import org.jboss.test.osgi.FrameworkTestCase;
+import org.jboss.test.osgi.FrameworkTest;
import org.jboss.test.osgi.service.support.SimpleServiceFactory;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
@@ -40,7 +40,7 @@
* @author <a href="adrian(a)jboss.com">Adrian Brock</a>
* @version $Revision: 1.1 $
*/
-public class ServiceRegistrationUnitTestCase extends FrameworkTestCase
+public class ServiceRegistrationUnitTestCase extends FrameworkTest
{
public ServiceRegistrationUnitTestCase(String name)
{
Modified: projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/smoke/OSGiSmokeTestCase.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/smoke/OSGiSmokeTestCase.java 2009-11-11 22:09:32 UTC (rev 96281)
+++ projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/smoke/OSGiSmokeTestCase.java 2009-11-11 22:30:31 UTC (rev 96282)
@@ -30,7 +30,7 @@
import org.jboss.osgi.framework.metadata.OSGiMetaData;
import org.jboss.osgi.framework.metadata.internal.AbstractOSGiMetaData;
-import org.jboss.test.osgi.FrameworkTestCase;
+import org.jboss.test.osgi.FrameworkTest;
import org.jboss.test.osgi.smoke.support.a.A;
import org.jboss.test.osgi.smoke.support.a.b.B;
import org.jboss.test.osgi.smoke.support.c.C;
@@ -42,7 +42,7 @@
* @author <a href="adrian(a)jboss.com">Adrian Brock</a>
* @version $Revision: 1.1 $
*/
-public class OSGiSmokeTestCase extends FrameworkTestCase
+public class OSGiSmokeTestCase extends FrameworkTest
{
public static Test suite()
{
14 years, 8 months
JBoss-OSGI SVN: r96275 - in projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework: service/internal and 1 other directory.
by jboss-osgi-commits@lists.jboss.org
Author: adrian(a)jboss.org
Date: 2009-11-11 13:38:49 -0500 (Wed, 11 Nov 2009)
New Revision: 96275
Modified:
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleWrapper.java
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/service/internal/PackageAdminImpl.java
Log:
Don't leak implementation details through the wrapper
Modified: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java 2009-11-11 18:37:08 UTC (rev 96274)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java 2009-11-11 18:38:49 UTC (rev 96275)
@@ -829,6 +829,24 @@
}
/**
+ * Get the underlying bundle state for a bundle
+ *
+ * @param bundle the bundle
+ * @return the bundle state
+ * @throws IllegalArgumentException if it is an unrecognised bundle
+ */
+ public AbstractBundleState getBundleState(Bundle bundle)
+ {
+ if (bundle instanceof OSGiBundleWrapper)
+ bundle = ((OSGiBundleWrapper)bundle).getBundleState();
+
+ if (bundle instanceof AbstractBundleState == false)
+ throw new IllegalArgumentException("Cannot obtain bunde state from: " + bundle);
+
+ return (AbstractBundleState)bundle;
+ }
+
+ /**
* Get a bundle by location
*
* @param location the location of the bundle
Modified: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleWrapper.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleWrapper.java 2009-11-11 18:37:08 UTC (rev 96274)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleWrapper.java 2009-11-11 18:38:49 UTC (rev 96275)
@@ -65,7 +65,7 @@
*
* @return the bundle state
*/
- public AbstractBundleState getBundleState()
+ AbstractBundleState getBundleState()
{
return bundleState;
}
Modified: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/service/internal/PackageAdminImpl.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/service/internal/PackageAdminImpl.java 2009-11-11 18:37:08 UTC (rev 96274)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/service/internal/PackageAdminImpl.java 2009-11-11 18:38:49 UTC (rev 96275)
@@ -36,12 +36,11 @@
import org.jboss.osgi.framework.bundle.AbstractBundleState;
import org.jboss.osgi.framework.bundle.OSGiBundleManager;
import org.jboss.osgi.framework.bundle.OSGiBundleState;
-import org.jboss.osgi.framework.bundle.OSGiBundleWrapper;
-import org.jboss.osgi.framework.plugins.ResolverPlugin;
import org.jboss.osgi.framework.plugins.PackageAdminServicePlugin;
+import org.jboss.osgi.framework.plugins.ResolverPlugin;
import org.jboss.osgi.framework.plugins.internal.AbstractServicePlugin;
-import org.jboss.osgi.framework.resolver.Resolver;
import org.jboss.osgi.framework.resolver.Resolvable;
+import org.jboss.osgi.framework.resolver.Resolver;
import org.jboss.osgi.spi.NotImplementedException;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
@@ -109,7 +108,13 @@
public ExportedPackage[] getExportedPackages(Bundle bundle)
{
- OSGiBundleState bundleState = assertBundleState(bundle);
+ AbstractBundleState abstractBundleState = bundleManager.getBundleState(bundle);
+
+ // [TODO] exported packages for the system bundle
+ if (abstractBundleState instanceof OSGiBundleState == false)
+ throw new UnsupportedOperationException("FIXME: getExportedPackages for System bundle");
+
+ OSGiBundleState bundleState = (OSGiBundleState) abstractBundleState;
DeploymentUnit unit = bundleState.getDeploymentUnit();
ClassLoadingMetaData metaData = unit.getAttachment(ClassLoadingMetaData.class);
if (metaData == null)
@@ -194,7 +199,7 @@
Iterator<OSGiBundleState> it = resolvableBundles.iterator();
while (it.hasNext())
{
- OSGiBundleState bundleState = assertBundleState(it.next());
+ OSGiBundleState bundleState = it.next();
if (bundleManager.resolveBundle(bundleState, false))
{
it.remove();
@@ -210,17 +215,6 @@
return allResolved;
}
- private OSGiBundleState assertBundleState(Bundle bundle)
- {
- if (bundle instanceof OSGiBundleWrapper)
- bundle = ((OSGiBundleWrapper)bundle).getBundleState();
-
- if (bundle instanceof OSGiBundleState == false)
- throw new IllegalArgumentException("Cannot obtain bunde state from: " + bundle);
-
- return (OSGiBundleState)bundle;
- }
-
private static class ExportedPackageImpl implements ExportedPackage
{
private Bundle bundle;
14 years, 8 months
JBoss-OSGI SVN: r96271 - in projects/jboss-osgi/trunk/reactor/framework/src: main/java/org/jboss/osgi/framework/service/internal and 1 other directories.
by jboss-osgi-commits@lists.jboss.org
Author: thomas.diesler(a)jboss.com
Date: 2009-11-11 13:21:42 -0500 (Wed, 11 Nov 2009)
New Revision: 96271
Modified:
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/AbstractBundleState.java
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleState.java
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiSystemState.java
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/service/internal/PackageAdminImpl.java
projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/FrameworkTestDelegate.java
Log:
Constistent API with respect to bundle handing in install, start, stop, uninstall etc
startBundle(Bundle) instead of start(Bundle)
Modified: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/AbstractBundleState.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/AbstractBundleState.java 2009-11-11 17:57:51 UTC (rev 96270)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/AbstractBundleState.java 2009-11-11 18:21:42 UTC (rev 96271)
@@ -543,19 +543,6 @@
throw new UnsupportedOperationException("update");
}
- public void update(InputStream in) throws BundleException
- {
- checkAdminPermission(AdminPermission.LIFECYCLE); // [TODO] extension bundles
- // [TODO] update
- throw new UnsupportedOperationException("update");
- }
-
- public void uninstall() throws BundleException
- {
- checkAdminPermission(AdminPermission.LIFECYCLE); // [TODO] extension bundles
- getBundleManager().uninstall(this);
- }
-
void uninstallInternal()
{
changeState(Bundle.UNINSTALLED);
Modified: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java 2009-11-11 17:57:51 UTC (rev 96270)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java 2009-11-11 18:21:42 UTC (rev 96271)
@@ -555,15 +555,14 @@
* @param bundle the bundle
* @throws BundleException for any error
*/
- public void uninstall(Bundle bundle) throws BundleException
+ public void uninstallBundle(OSGiBundleState bundleState) throws BundleException
{
- long id = bundle.getBundleId();
+ long id = bundleState.getBundleId();
if (id == 0)
throw new IllegalArgumentException("Cannot uninstall system bundle");
- OSGiBundleState bundleState = (OSGiBundleState)getBundleById(id);
- if (bundleState == null)
- throw new BundleException(bundle + " not installed");
+ if (getBundleById(id) == null)
+ throw new BundleException(bundleState + " not installed");
DeploymentUnit unit = bundleState.getDeploymentUnit();
try
@@ -732,7 +731,7 @@
* @param bundleState the bundle state
* @throws IllegalArgumentException for a null bundle state
*/
- public void removeBundle(AbstractBundleState bundleState)
+ public void removeBundle(OSGiBundleState bundleState)
{
if (bundleState == null)
throw new IllegalArgumentException("Null bundle state");
@@ -899,7 +898,7 @@
* @param errorOnFail whether to throw an error if it cannot be resolved
* @return true when resolved
*/
- public boolean resolve(OSGiBundleState bundleState, boolean errorOnFail)
+ public boolean resolveBundle(OSGiBundleState bundleState, boolean errorOnFail)
{
int state = bundleState.getState();
if (state != Bundle.INSTALLED)
@@ -936,7 +935,7 @@
* @param bundleState the bundle state
* @throws BundleException the bundle exception
*/
- public void start(OSGiBundleState bundleState) throws BundleException
+ public void startBundle(OSGiBundleState bundleState) throws BundleException
{
// Resolve all INSTALLED bundles through the PackageAdmin
PackageAdmin packageAdmin = getPlugin(PackageAdminServicePlugin.class);
@@ -964,7 +963,7 @@
* @param bundleState the bundle state
* @throws BundleException the bundle exception
*/
- public void stop(OSGiBundleState bundleState) throws BundleException
+ public void stopBundle(OSGiBundleState bundleState) throws BundleException
{
try
{
Modified: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleState.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleState.java 2009-11-11 17:57:51 UTC (rev 96270)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleState.java 2009-11-11 18:21:42 UTC (rev 96271)
@@ -22,6 +22,7 @@
package org.jboss.osgi.framework.bundle;
import java.io.IOException;
+import java.io.InputStream;
import java.net.URL;
import java.util.Enumeration;
import java.util.Map;
@@ -251,7 +252,7 @@
if (getState() == ACTIVE)
return;
- getBundleManager().start(this);
+ getBundleManager().startBundle(this);
}
// [TODO] options
@@ -263,7 +264,7 @@
if (getState() != ACTIVE)
return;
- getBundleManager().stop(this);
+ getBundleManager().stopBundle(this);
}
/**
@@ -390,6 +391,19 @@
throw rethrow;
}
+ public void update(InputStream in) throws BundleException
+ {
+ checkAdminPermission(AdminPermission.LIFECYCLE); // [TODO] extension bundles
+ // [TODO] update
+ throw new UnsupportedOperationException("update");
+ }
+
+ public void uninstall() throws BundleException
+ {
+ checkAdminPermission(AdminPermission.LIFECYCLE); // [TODO] extension bundles
+ getBundleManager().uninstallBundle(this);
+ }
+
public static OSGiBundleState assertBundleState(Bundle bundle)
{
if (bundle == null)
Modified: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiSystemState.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiSystemState.java 2009-11-11 17:57:51 UTC (rev 96270)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiSystemState.java 2009-11-11 18:21:42 UTC (rev 96271)
@@ -155,13 +155,11 @@
});
}
- @Override
public void update(InputStream in) throws BundleException
{
throw new BundleException("The system bundle cannot be updated from a stream");
}
- @Override
public void uninstall() throws BundleException
{
throw new BundleException("The system bundle cannot be uninstalled");
Modified: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/service/internal/PackageAdminImpl.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/service/internal/PackageAdminImpl.java 2009-11-11 17:57:51 UTC (rev 96270)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/service/internal/PackageAdminImpl.java 2009-11-11 18:21:42 UTC (rev 96271)
@@ -195,7 +195,7 @@
while (it.hasNext())
{
OSGiBundleState bundleState = assertBundleState(it.next());
- if (bundleManager.resolve(bundleState, false))
+ if (bundleManager.resolveBundle(bundleState, false))
{
it.remove();
resolved++;
Modified: projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/FrameworkTestDelegate.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/FrameworkTestDelegate.java 2009-11-11 17:57:51 UTC (rev 96270)
+++ projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/FrameworkTestDelegate.java 2009-11-11 18:21:42 UTC (rev 96271)
@@ -70,7 +70,7 @@
{
super(clazz);
}
-
+
/**
* Deploys the jboss-osgi-bootstrap.xml bean descriptor to setup OSGi deployers
*/
@@ -90,13 +90,13 @@
{
undeploy();
if (t instanceof Exception)
- throw (Exception) t;
+ throw (Exception)t;
if (t instanceof Error)
- throw (Error) t;
+ throw (Error)t;
throw new RuntimeException("Error during deploy", t);
}
}
-
+
protected void undeploy()
{
undeployBundles();
@@ -117,24 +117,27 @@
}
}
- protected void undeployBundles()
+ protected void undeployBundles()
{
OSGiBundleManager bundleManager = getBundleManager();
Collection<AbstractBundleState> bundles = bundleManager.getBundles();
- for (AbstractBundleState bundleState : bundles)
+ for (AbstractBundleState aux : bundles)
{
try
{
- if (bundleState.getBundleId() != 0)
- bundleManager.uninstall(bundleState);
+ if (aux.getBundleId() != 0)
+ {
+ OSGiBundleState bundleState = (OSGiBundleState)aux;
+ bundleManager.uninstallBundle(bundleState);
+ }
}
catch (Throwable t)
{
- getLog().warn("Error undeploying bundle: " + bundleState, t);
+ getLog().warn("Error undeploying bundle: " + aux, t);
}
}
}
-
+
public OSGiBundleManager getBundleManager()
{
if (bundleManager == null)
@@ -198,9 +201,12 @@
public void uninstall(Bundle bundle) throws Exception
{
if (bundle.getState() != Bundle.UNINSTALLED)
- getBundleManager().uninstall(bundle);
+ {
+ OSGiBundleState bundleState = OSGiBundleState.assertBundleState(bundle);
+ getBundleManager().uninstallBundle(bundleState);
+ }
}
-
+
public DeploymentUnit getDeploymentUnit(Bundle bundle)
{
DeploymentUnit deploymentUnit = getBundleManager().getDeployment(bundle.getBundleId());
@@ -316,7 +322,7 @@
public AssembledDirectory createAssembledDirectory(String name) throws Exception
{
- return createAssembledDirectory(name, "");
+ return createAssembledDirectory(name, "");
}
public AssembledDirectory createAssembledDirectory(String name, String rootName) throws Exception
@@ -327,7 +333,7 @@
public void addPackage(AssembledDirectory dir, Class<?> reference) throws Exception
{
String packagePath = ClassLoaderUtils.packageNameToPath(reference.getName());
- dir.addResources(reference, new String[] { packagePath + "/*.class" } , new String[0]);
+ dir.addResources(reference, new String[] { packagePath + "/*.class" }, new String[0]);
}
public void addPath(final AssembledDirectory dir, String path, String name) throws Exception
@@ -341,12 +347,12 @@
SuffixesExcludeFilter noJars = new SuffixesExcludeFilter(JarUtils.getSuffixes());
dir.addPath(file, noJars);
}
-
+
public URL getBundleResource(Bundle bundle, String path)
{
return getDeploymentUnit(bundle).getResourceLoader().getResource(path);
}
-
+
public Enumeration<URL> getBundleResources(Bundle bundle, String path) throws Exception
{
return getDeploymentUnit(bundle).getResourceLoader().getResources(path);
14 years, 8 months
JBoss-OSGI SVN: r96270 - projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/deployers.
by jboss-osgi-commits@lists.jboss.org
Author: adrian(a)jboss.org
Date: 2009-11-11 12:57:51 -0500 (Wed, 11 Nov 2009)
New Revision: 96270
Modified:
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/deployers/OSGiDeployersWrapper.java
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/deployers/OSGiManifestParsingDeployer.java
Log:
PROPERTY_AUTO_START is unnecessary since DeploymentUnit.getRequiredStage() already controls this behaviour
Modified: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/deployers/OSGiDeployersWrapper.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/deployers/OSGiDeployersWrapper.java 2009-11-11 17:50:35 UTC (rev 96269)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/deployers/OSGiDeployersWrapper.java 2009-11-11 17:57:51 UTC (rev 96270)
@@ -21,8 +21,6 @@
*/
package org.jboss.osgi.framework.deployers;
-import static org.jboss.osgi.spi.OSGiConstants.PROPERTY_AUTO_START;
-
import java.util.Collection;
import java.util.List;
import java.util.Map;
@@ -130,11 +128,8 @@
OSGiBundleState bundle = unit.getAttachment(OSGiBundleState.class);
if (bundle == null)
continue;
-
- Boolean autoStart = (Boolean)unit.getAttachment(PROPERTY_AUTO_START);
- if (autoStart == null)
- autoStart = Boolean.TRUE;
-
+
+ boolean autoStart = DeploymentStages.INSTALLED.equals(unit.getRequiredStage());
if (autoStart == true && bundle.getState() == Bundle.INSTALLED)
{
unresolvedBundles.add(0, bundle);
Modified: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/deployers/OSGiManifestParsingDeployer.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/deployers/OSGiManifestParsingDeployer.java 2009-11-11 17:50:35 UTC (rev 96269)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/deployers/OSGiManifestParsingDeployer.java 2009-11-11 17:57:51 UTC (rev 96270)
@@ -21,8 +21,6 @@
*/
package org.jboss.osgi.framework.deployers;
-import static org.jboss.osgi.spi.OSGiConstants.PROPERTY_AUTO_START;
-
import java.util.jar.Manifest;
import java.util.jar.Attributes.Name;
@@ -73,9 +71,5 @@
// Add a marker that this is an OSGi deployment
unit.addAttachment(OSGiConstants.KEY_BUNDLE_SYMBOLIC_NAME, symbolicName);
-
- // Don't automatically start OSGi deployments.
- // [todo] this use the required stage processing
- unit.addAttachment(PROPERTY_AUTO_START, Boolean.FALSE);
}
}
14 years, 8 months