FELIX-570 add "refreshPackages" parameter to request PackageAdmin.refreshPackages after update
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@657738 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/InstallAction.java b/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/InstallAction.java
index 1f1f6c4..bd8222f 100644
--- a/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/InstallAction.java
+++ b/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/InstallAction.java
@@ -33,6 +33,7 @@
import org.osgi.framework.BundleException;
import org.osgi.framework.Constants;
import org.osgi.service.log.LogService;
+import org.osgi.service.packageadmin.PackageAdmin;
import org.osgi.service.startlevel.StartLevel;
/**
@@ -50,6 +51,9 @@
public static final String FIELD_BUNDLEFILE = "bundlefile";
+ // set to ask for PackageAdmin.refreshPackages() after install/update
+ public static final String FIELD_REFRESH_PACKAGES = "refreshPackages";
+
public String getName() {
return NAME;
}
@@ -67,10 +71,11 @@
return true;
}
- FileItem startItem = this.getFileItem(params, FIELD_START, true);
- FileItem startLevelItem = this.getFileItem(params, FIELD_STARTLEVEL,
- true);
- FileItem bundleItem = this.getFileItem(params, FIELD_BUNDLEFILE, false);
+ FileItem startItem = getFileItem(params, FIELD_START, true);
+ FileItem startLevelItem = getFileItem(params, FIELD_STARTLEVEL, true);
+ FileItem bundleItem = getFileItem(params, FIELD_BUNDLEFILE, false);
+ FileItem refreshPackagesItem = getFileItem(params,
+ FIELD_REFRESH_PACKAGES, true);
// don't care any more if not bundle item
if (bundleItem == null || bundleItem.getSize() <= 0) {
@@ -78,7 +83,6 @@
}
// default values
- boolean start = startItem != null; // don't care for the value, as long
// it exists
int startLevel = -1;
String bundleLocation = "inputstream:";
@@ -114,15 +118,18 @@
// install or update the bundle now
if (tmpFile != null) {
+ // start, refreshPackages just needs to exist, don't care for value
+ boolean start = startItem != null;
+ boolean refreshPackages = refreshPackagesItem != null;
+
bundleLocation = "inputstream:" + bundleItem.getName();
- installBundle(bundleLocation, tmpFile, startLevel, start);
+ installBundle(bundleLocation, tmpFile, startLevel, start, refreshPackages);
}
return true;
}
- private FileItem getFileItem(Map params, String name,
- boolean isFormField) {
+ private FileItem getFileItem(Map params, String name, boolean isFormField) {
FileItem[] items = (FileItem[]) params.get(name);
if (items != null) {
for (int i = 0; i < items.length; i++) {
@@ -137,11 +144,11 @@
}
private void installBundle(String location, File bundleFile,
- int startLevel, boolean start) {
+ int startLevel, boolean start, boolean refreshPackages) {
if (bundleFile != null) {
// try to get the bundle name, fail if none
- String symbolicName = this.getSymbolicName(bundleFile);
+ String symbolicName = getSymbolicName(bundleFile);
if (symbolicName == null) {
bundleFile.delete();
return;
@@ -149,7 +156,7 @@
// check for existing bundle first
Bundle updateBundle = null;
- Bundle[] bundles = this.getBundleContext().getBundles();
+ Bundle[] bundles = getBundleContext().getBundles();
for (int i = 0; i < bundles.length; i++) {
if ((bundles[i].getLocation() != null && bundles[i].getLocation().equals(
location))
@@ -162,11 +169,12 @@
if (updateBundle != null) {
- updateBackground(updateBundle, bundleFile);
+ updateBackground(updateBundle, bundleFile, refreshPackages);
} else {
- installBackground(bundleFile, location, startLevel, start);
+ installBackground(bundleFile, location, startLevel, start,
+ refreshPackages);
}
}
@@ -200,10 +208,11 @@
}
private void installBackground(final File bundleFile,
- final String location, final int startlevel, final boolean doStart) {
+ final String location, final int startlevel, final boolean doStart,
+ final boolean refreshPackages) {
Thread t = new InstallHelper(this, "Background Install " + bundleFile,
- bundleFile) {
+ bundleFile, refreshPackages) {
protected void doRun(InputStream bundleStream)
throws BundleException {
@@ -224,10 +233,11 @@
t.start();
}
- private void updateBackground(final Bundle bundle, final File bundleFile) {
+ private void updateBackground(final Bundle bundle, final File bundleFile,
+ final boolean refreshPackages) {
Thread t = new InstallHelper(this, "Background Update"
+ bundle.getSymbolicName() + " (" + bundle.getBundleId() + ")",
- bundleFile) {
+ bundleFile, refreshPackages) {
protected void doRun(InputStream bundleStream)
throws BundleException {
@@ -244,12 +254,16 @@
private final File bundleFile;
- InstallHelper(InstallAction installAction, String name, File bundleFile) {
+ private final boolean refreshPackages;
+
+ InstallHelper(InstallAction installAction, String name,
+ File bundleFile, boolean refreshPackages) {
super(name);
setDaemon(true);
this.installAction = installAction;
this.bundleFile = bundleFile;
+ this.refreshPackages = refreshPackages;
}
protected abstract void doRun(InputStream bundleStream)
@@ -268,6 +282,13 @@
try {
bundleStream = new FileInputStream(bundleFile);
doRun(bundleStream);
+
+ if (refreshPackages) {
+ PackageAdmin pa = installAction.getPackageAdmin();
+ if (pa != null) {
+ pa.refreshPackages(null);
+ }
+ }
} catch (IOException ioe) {
installAction.getLog().log(LogService.LOG_ERROR,
"Cannot install or update bundle from " + bundleFile, ioe);