Search in sources :

Example 1 with BundleInfoImpl

use of org.apache.felix.deploymentadmin.BundleInfoImpl in project felix by apache.

the class DropAllBundlesCommand method doExecute.

protected void doExecute(DeploymentSessionImpl session) throws Exception {
    AbstractDeploymentPackage target = session.getTargetAbstractDeploymentPackage();
    LogService log = session.getLog();
    BundleInfoImpl[] orderedTargetBundles = target.getOrderedBundleInfos();
    for (int i = orderedTargetBundles.length - 1; i >= 0; i--) {
        BundleInfoImpl bundleInfo = orderedTargetBundles[i];
        // stale bundle, save a copy for rolling back and uninstall it
        String symbolicName = bundleInfo.getSymbolicName();
        try {
            Bundle bundle = target.getBundle(symbolicName);
            if (bundle != null) {
                bundle.uninstall();
                addRollback(new InstallBundleRunnable(bundle, target, log));
            }
        } catch (Exception be) {
            log.log(LogService.LOG_WARNING, "Bundle '" + symbolicName + "' could not be uninstalled", be);
        }
    }
}
Also used : BundleInfoImpl(org.apache.felix.deploymentadmin.BundleInfoImpl) Bundle(org.osgi.framework.Bundle) AbstractDeploymentPackage(org.apache.felix.deploymentadmin.AbstractDeploymentPackage) LogService(org.osgi.service.log.LogService)

Example 2 with BundleInfoImpl

use of org.apache.felix.deploymentadmin.BundleInfoImpl in project felix by apache.

the class DropBundleCommand method doExecute.

protected void doExecute(DeploymentSessionImpl session) throws Exception {
    AbstractDeploymentPackage target = session.getTargetAbstractDeploymentPackage();
    AbstractDeploymentPackage source = session.getSourceAbstractDeploymentPackage();
    LogService log = session.getLog();
    BundleInfoImpl[] orderedTargetBundles = target.getOrderedBundleInfos();
    for (int i = orderedTargetBundles.length - 1; i >= 0; i--) {
        BundleInfoImpl bundleInfo = orderedTargetBundles[i];
        String symbolicName = bundleInfo.getSymbolicName();
        if (!bundleInfo.isCustomizer() && source.getBundleInfoByName(symbolicName) == null) {
            // stale bundle, save a copy for rolling back and uninstall it
            try {
                Bundle bundle = target.getBundle(symbolicName);
                bundle.uninstall();
                addRollback(new InstallBundleRunnable(bundle, target, log));
            } catch (Exception be) {
                log.log(LogService.LOG_WARNING, "Bundle '" + symbolicName + "' could not be uninstalled", be);
            }
        }
    }
}
Also used : BundleInfoImpl(org.apache.felix.deploymentadmin.BundleInfoImpl) Bundle(org.osgi.framework.Bundle) AbstractDeploymentPackage(org.apache.felix.deploymentadmin.AbstractDeploymentPackage) LogService(org.osgi.service.log.LogService)

Example 3 with BundleInfoImpl

use of org.apache.felix.deploymentadmin.BundleInfoImpl in project felix by apache.

the class StartBundleCommand method doExecute.

protected void doExecute(DeploymentSessionImpl session) throws Exception {
    AbstractDeploymentPackage source = session.getSourceAbstractDeploymentPackage();
    PackageAdmin packageAdmin = session.getPackageAdmin();
    RefreshPackagesListener listener = new RefreshPackagesListener();
    LogService log = session.getLog();
    session.getBundleContext().addFrameworkListener(listener);
    packageAdmin.refreshPackages(null);
    m_refreshMonitor.waitForRefresh();
    session.getBundleContext().removeFrameworkListener(listener);
    // start source bundles
    BundleInfoImpl[] bundleInfos = source.getOrderedBundleInfos();
    for (int i = 0; i < bundleInfos.length; i++) {
        BundleInfoImpl bundleInfoImpl = bundleInfos[i];
        if (!bundleInfoImpl.isCustomizer()) {
            String symbolicName = bundleInfoImpl.getSymbolicName();
            Bundle bundle = source.getBundle(symbolicName);
            if (bundle != null) {
                if (isFragmentBundle(bundle)) {
                    log.log(LogService.LOG_INFO, "Skipping fragment bundle '" + symbolicName + "'");
                } else {
                    try {
                        bundle.start();
                    } catch (Exception be) {
                        log.log(LogService.LOG_WARNING, "Could not start bundle '" + symbolicName + "'", be);
                    }
                }
            } else {
                log.log(LogService.LOG_WARNING, "Could not start bundle '" + symbolicName + "' because it is not present in the framework");
            }
        }
    }
}
Also used : PackageAdmin(org.osgi.service.packageadmin.PackageAdmin) BundleInfoImpl(org.apache.felix.deploymentadmin.BundleInfoImpl) Bundle(org.osgi.framework.Bundle) AbstractDeploymentPackage(org.apache.felix.deploymentadmin.AbstractDeploymentPackage) LogService(org.osgi.service.log.LogService)

Example 4 with BundleInfoImpl

use of org.apache.felix.deploymentadmin.BundleInfoImpl in project felix by apache.

the class StartCustomizerCommand method doExecute.

protected void doExecute(DeploymentSessionImpl session) throws Exception {
    AbstractDeploymentPackage target = session.getTargetAbstractDeploymentPackage();
    AbstractDeploymentPackage source = session.getSourceAbstractDeploymentPackage();
    Set bundles = new HashSet();
    Set sourceBundlePaths = new HashSet();
    BundleInfoImpl[] targetInfos = target.getBundleInfoImpls();
    BundleInfoImpl[] sourceInfos = source.getBundleInfoImpls();
    for (int i = 0; i < sourceInfos.length; i++) {
        if (sourceInfos[i].isCustomizer()) {
            sourceBundlePaths.add(sourceInfos[i].getPath());
            Bundle bundle = source.getBundle(sourceInfos[i].getSymbolicName());
            if (bundle != null) {
                bundles.add(bundle);
            }
        }
    }
    for (int i = 0; i < targetInfos.length; i++) {
        if (targetInfos[i].isCustomizer() && !sourceBundlePaths.contains(targetInfos[i].getPath())) {
            Bundle bundle = target.getBundle(targetInfos[i].getSymbolicName());
            if (bundle != null) {
                bundles.add(bundle);
            }
        }
    }
    for (Iterator i = bundles.iterator(); i.hasNext(); ) {
        Bundle bundle = (Bundle) i.next();
        try {
            bundle.start();
        } catch (Exception be) {
            throw new DeploymentException(CODE_OTHER_ERROR, "Could not start customizer bundle '" + bundle.getSymbolicName() + "'", be);
        }
        addRollback(new StopCustomizerRunnable(session, bundle));
    }
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) BundleInfoImpl(org.apache.felix.deploymentadmin.BundleInfoImpl) Bundle(org.osgi.framework.Bundle) Iterator(java.util.Iterator) DeploymentException(org.osgi.service.deploymentadmin.DeploymentException) AbstractDeploymentPackage(org.apache.felix.deploymentadmin.AbstractDeploymentPackage) DeploymentException(org.osgi.service.deploymentadmin.DeploymentException) HashSet(java.util.HashSet)

Example 5 with BundleInfoImpl

use of org.apache.felix.deploymentadmin.BundleInfoImpl in project felix by apache.

the class StopBundleCommand method omitBundleStop.

/**
 * Determines whether stopping a bundle is strictly needed.
 *
 * @param session The current deployment session.
 * @param symbolicName The symbolic name of the bundle to inspect.
 *
 * @return Returns <code>true</code> if
 *         <code>Constants.DEPLOYMENTPACKAGE_MISSING</code> is true for the
 *         specified bundle in the source deployment package or if the
 *         version of the bundle is the same in both source and target
 *         deployment package. Returns <code>false</code> otherwise.
 */
private boolean omitBundleStop(DeploymentSessionImpl session, String symbolicName) {
    boolean stopUnaffectedBundles = session.getConfiguration().isStopUnaffectedBundles();
    if (stopUnaffectedBundles) {
        // Default behavior: stop all bundles (see spec)...
        return false;
    }
    BundleInfoImpl sourceBundleInfo = session.getSourceAbstractDeploymentPackage().getBundleInfoByName(symbolicName);
    BundleInfoImpl targetBundleInfo = session.getTargetAbstractDeploymentPackage().getBundleInfoByName(symbolicName);
    boolean fixPackageMissing = sourceBundleInfo != null && sourceBundleInfo.isMissing();
    boolean sameVersion = (targetBundleInfo != null && sourceBundleInfo != null && targetBundleInfo.getVersion().equals(sourceBundleInfo.getVersion()));
    return (fixPackageMissing || sameVersion);
}
Also used : BundleInfoImpl(org.apache.felix.deploymentadmin.BundleInfoImpl)

Aggregations

BundleInfoImpl (org.apache.felix.deploymentadmin.BundleInfoImpl)6 AbstractDeploymentPackage (org.apache.felix.deploymentadmin.AbstractDeploymentPackage)5 Bundle (org.osgi.framework.Bundle)5 LogService (org.osgi.service.log.LogService)4 DeploymentException (org.osgi.service.deploymentadmin.DeploymentException)2 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 Map (java.util.Map)1 Set (java.util.Set)1 AbstractInfo (org.apache.felix.deploymentadmin.AbstractInfo)1 BundleContext (org.osgi.framework.BundleContext)1 Version (org.osgi.framework.Version)1 PackageAdmin (org.osgi.service.packageadmin.PackageAdmin)1