Search in sources :

Example 1 with BundleInfo

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;
}
Also used : BundleInfo(org.osgi.service.deploymentadmin.BundleInfo) Version(org.osgi.framework.Version) Bundle(org.osgi.framework.Bundle)

Example 2 with BundleInfo

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.");
            }
        }
    }
}
Also used : Bundle(org.osgi.framework.Bundle) AbstractDeploymentPackage(org.apache.felix.deploymentadmin.AbstractDeploymentPackage) IOException(java.io.IOException) DeploymentException(org.osgi.service.deploymentadmin.DeploymentException) BundleInfo(org.osgi.service.deploymentadmin.BundleInfo) DeploymentException(org.osgi.service.deploymentadmin.DeploymentException) Map(java.util.Map) File(java.io.File) BundleContext(org.osgi.framework.BundleContext)

Example 3 with BundleInfo

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() + "'");
            }
        }
    }
}
Also used : BundleInfo(org.osgi.service.deploymentadmin.BundleInfo) Bundle(org.osgi.framework.Bundle) DeploymentPackage(org.osgi.service.deploymentadmin.DeploymentPackage) DeploymentException(org.osgi.service.deploymentadmin.DeploymentException) File(java.io.File)

Example 4 with BundleInfo

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");
        }
    }
}
Also used : BundleInfo(org.osgi.service.deploymentadmin.BundleInfo) Bundle(org.osgi.framework.Bundle) DeploymentException(org.osgi.service.deploymentadmin.DeploymentException) AbstractDeploymentPackage(org.apache.felix.deploymentadmin.AbstractDeploymentPackage) LogService(org.osgi.service.log.LogService) DeploymentException(org.osgi.service.deploymentadmin.DeploymentException)

Example 5 with BundleInfo

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");
}
Also used : BundleInfo(org.osgi.service.deploymentadmin.BundleInfo) DeploymentPackageBuilder(org.apache.felix.deploymentadmin.itest.util.DeploymentPackageBuilder) DeploymentPackage(org.osgi.service.deploymentadmin.DeploymentPackage) Test(org.junit.Test)

Aggregations

BundleInfo (org.osgi.service.deploymentadmin.BundleInfo)5 Bundle (org.osgi.framework.Bundle)4 DeploymentException (org.osgi.service.deploymentadmin.DeploymentException)3 File (java.io.File)2 AbstractDeploymentPackage (org.apache.felix.deploymentadmin.AbstractDeploymentPackage)2 DeploymentPackage (org.osgi.service.deploymentadmin.DeploymentPackage)2 IOException (java.io.IOException)1 Map (java.util.Map)1 DeploymentPackageBuilder (org.apache.felix.deploymentadmin.itest.util.DeploymentPackageBuilder)1 Test (org.junit.Test)1 BundleContext (org.osgi.framework.BundleContext)1 Version (org.osgi.framework.Version)1 LogService (org.osgi.service.log.LogService)1