use of org.osgi.service.deploymentadmin.BundleInfo in project felix by apache.
the class AbstractDeploymentPackage method getBundle.
public Bundle getBundle(String symbolicName) {
if (isStale()) {
throw new IllegalStateException("Can not get bundle from stale deployment package.");
}
BundleInfo bundleInfo = (BundleInfo) m_nameToBundleInfo.get(symbolicName);
if (bundleInfo != null) {
Version version = bundleInfo.getVersion();
Bundle[] bundles = m_bundleContext.getBundles();
for (int i = 0; i < bundles.length; i++) {
if (symbolicName.equals(bundles[i].getSymbolicName()) && version.equals(bundles[i].getVersion())) {
return bundles[i];
}
}
}
return null;
}
use of org.osgi.service.deploymentadmin.BundleInfo in project felix by apache.
the class SnapshotCommand method doExecute.
protected void doExecute(DeploymentSessionImpl session) throws Exception {
AbstractDeploymentPackage target = session.getTargetAbstractDeploymentPackage();
BundleContext context = session.getBundleContext();
BundleInfo[] infos = target.getBundleInfos();
Map storageAreas = m_getStorageAreaCommand.getStorageAreas();
for (int i = 0; i < infos.length; i++) {
if (isCancelled()) {
throw new DeploymentException(CODE_CANCELLED);
}
String symbolicName = infos[i].getSymbolicName();
Bundle bundle = target.getBundle(symbolicName);
if (bundle != null) {
File root = (File) storageAreas.get(symbolicName);
if (root != null) {
File snapshot = context.getDataFile("snapshots");
snapshot.mkdirs();
snapshot = new File(snapshot, infos[i].getSymbolicName());
try {
snapshot.createNewFile();
store(root, snapshot);
addRollback(new RestoreSnapshotRunnable(session, snapshot, root));
addCommit(new DeleteSnapshotRunnable(session, snapshot));
} catch (Exception e) {
session.getLog().log(LogService.LOG_WARNING, "Could not access storage area of bundle '" + symbolicName + "'!", e);
snapshot.delete();
}
} else {
session.getLog().log(LogService.LOG_WARNING, "Could not retrieve storage area of bundle '" + symbolicName + "', skipping it.");
}
}
}
}
use of org.osgi.service.deploymentadmin.BundleInfo in project felix by apache.
the class GetStorageAreaCommand method doExecute.
protected void doExecute(DeploymentSessionImpl session) throws Exception {
DeploymentPackage target = session.getTargetDeploymentPackage();
BundleInfo[] infos = target.getBundleInfos();
for (int i = 0; i < infos.length; i++) {
if (isCancelled()) {
throw new DeploymentException(CODE_CANCELLED);
}
Bundle bundle = target.getBundle(infos[i].getSymbolicName());
if (bundle != null) {
try {
File root = session.getDataFile(bundle);
m_storageAreas.put(bundle.getSymbolicName(), root);
} catch (IllegalStateException ise) {
session.getLog().log(LogService.LOG_WARNING, "Could not get reference to storage area of bundle '" + bundle.getSymbolicName() + "'");
}
}
}
}
use of org.osgi.service.deploymentadmin.BundleInfo in project felix by apache.
the class StopBundleCommand method doExecute.
protected void doExecute(DeploymentSessionImpl session) throws Exception {
LogService log = session.getLog();
AbstractDeploymentPackage target = session.getTargetAbstractDeploymentPackage();
BundleInfo[] bundleInfos = target.getOrderedBundleInfos();
for (int i = 0; i < bundleInfos.length; i++) {
if (isCancelled()) {
throw new DeploymentException(CODE_CANCELLED);
}
String symbolicName = bundleInfos[i].getSymbolicName();
Bundle bundle = target.getBundle(symbolicName);
if (bundle != null) {
if (omitBundleStop(session, symbolicName)) {
continue;
}
if (isFragmentBundle(bundle)) {
log.log(LogService.LOG_INFO, "Skipping fragment bundle '" + symbolicName + "'");
} else {
addRollback(new StartBundleRunnable(session, bundle));
try {
bundle.stop();
} catch (Exception e) {
log.log(LogService.LOG_WARNING, "Could not stop bundle '" + symbolicName + "'", e);
}
}
} else {
log.log(LogService.LOG_WARNING, "Could not stop bundle '" + symbolicName + "' because it was not present in the framework");
}
}
}
use of org.osgi.service.deploymentadmin.BundleInfo in project felix by apache.
the class InstallDeploymentPackageTest method testInstallBundlesWithPathsOk.
/**
* FELIX-1835 - test whether we can install bundles with a non-root path inside the DP.
*/
@Test
public void testInstallBundlesWithPathsOk() throws Exception {
DeploymentPackageBuilder dpBuilder = createNewDeploymentPackageBuilder("1.0.0");
// incluse two different versions of the same bundle (with the same BSN), this is *not* allowed per the DA
// spec...
dpBuilder.add(dpBuilder.createBundleResource().setUrl(getTestBundleURL("bundleapi1", "bundleapi1", "1.0.0")).setFilename("bundles/bundleapi1.jar")).add(dpBuilder.createBundleResource().setUrl(getTestBundleURL("bundleimpl1", "bundleimpl1", "1.0.0")).setFilename("bundles/bundleimpl1.jar"));
DeploymentPackage dp = installDeploymentPackage(dpBuilder);
assertNotNull(dp);
BundleInfo[] bundleInfos = dp.getBundleInfos();
assertEquals(2, bundleInfos.length);
// Verify that none of the bundles are installed...
assertBundleExists("testbundles.bundleapi", "1.0.0");
assertBundleExists("testbundles.bundleimpl", "1.0.0");
}
Aggregations