IOException {
List<BundleInfo> bundleInfoList = new ArrayList<BundleInfo>();
for (InputStream bundleInputStream : bundleInputStreams) {
// 得到插件的信息
try {
BundleInfo bundleInfo = new BundleInfo(bundleInputStream);
bundleInfoList.add(bundleInfo);
} catch (Exception ex) {
log.warn("警告:加载Bundle清单文件信息时失败。原因:" + ex.getMessage());
}
}
// 排出安装顺序
orderBundleInstallList(bundleInfoList);
// 排出停止顺序(倒序)
List<BundleInfo> shouldStopBundleInfoList = getShouldRefreshBundleInfoList(
bundleInfoList, BundleUtils.getAllBundleInfoList(bundleContext));
// 按照逆序停止Bundle
for (int i = 0; i < shouldStopBundleInfoList.size(); i++) {
BundleInfo bundleInfo = shouldStopBundleInfoList
.get(shouldStopBundleInfoList.size() - i - 1);
String bundleName = bundleInfo.getBundleName();
Bundle bundle = getBundleByName(bundleContext, bundleName);
if (bundle != null && bundle.getState() == Bundle.ACTIVE) {
log.debug(String.format("插件智能安装函数:根据依赖关系准备停止[%s]插件!",
bundleName));
bundle.stop();
}
}
// 休息0.001秒钟
try {
Thread.sleep(1);
} catch (InterruptedException e) {
}
Bundle[] installedBundles = new Bundle[bundleInfoList.size()];
// 按照顺序安装,注意:此处只是安装并不启动插件
for (int i = 0; i < bundleInfoList.size(); i++) {
BundleInfo bundleInfo = bundleInfoList.get(i);
installedBundles[i] = installOrUpdateBundle(bundleContext,
bundleInfo);
}
try {
// 刷新Bundle
Bundle systemBundle = bundleContext.getBundle(0);
FrameworkWiring frameworkWiring = systemBundle
.adapt(FrameworkWiring.class);
for (Bundle bundle : frameworkWiring.getRemovalPendingBundles()) {
log.debug("RemovalPendingBundle:" + bundle.getSymbolicName());
}
frameworkWiring.refreshBundles(null);
} catch (Error error) {
log.warn("RemovalPendingBundle error." + error.getMessage());
}
// 休息0.001秒钟
try {
Thread.sleep(1);
} catch (InterruptedException e) {
}
// 重新排出启动或刷新顺序
List<BundleInfo> shouldStartBundleInfoList = getShouldRefreshBundleInfoList(
bundleInfoList, BundleUtils.getAllBundleInfoList(bundleContext));
orderBundleInstallList(shouldStartBundleInfoList);
// 按照顺序启动Bundle
for (int i = 0; i < shouldStartBundleInfoList.size(); i++) {
BundleInfo bundleInfo = shouldStartBundleInfoList.get(i);
String bundleName = bundleInfo.getBundleName();
Bundle bundle = getBundleByName(bundleContext, bundleName);
if (bundle == null) {
log.warn(String.format("插件智能安装函数警告:在OSGi容器中未发现名称为[%s]的插件!",
bundleName));
continue;