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);