Search in sources :

Example 6 with Bundle

use of org.osgi.framework.Bundle in project jersey by jersey.

the class AbstractWebAppTest method bundleList.

private String bundleList() {
    StringBuilder sb = new StringBuilder();
    sb.append("-- Bundle list -- \n");
    for (Bundle b : bundleContext.getBundles()) {
        sb.append(String.format("%1$5s", "[" + b.getBundleId() + "]")).append(" ").append(String.format("%1$-70s", b.getSymbolicName())).append(" | ").append(String.format("%1$-20s", b.getVersion())).append(" |");
        sb.append(stateString(b)).append(" |");
        sb.append(b.getLocation()).append("\n");
    }
    sb.append("-- \n\n");
    return sb.toString();
}
Also used : Bundle(org.osgi.framework.Bundle) CoreOptions.mavenBundle(org.ops4j.pax.exam.CoreOptions.mavenBundle)

Example 7 with Bundle

use of org.osgi.framework.Bundle in project atlas by alibaba.

the class BundleInstaller method call.

@Override
public synchronized Void call() throws Exception {
    Bundle bundle = null;
    if (!mTransitive) {
        for (int x = 0; x < mLocation.length; x++) {
            if (FileUtils.getUsableSpace(Environment.getDataDirectory()) >= 5) {
                if (mBundleSourceInputStream != null && mBundleSourceInputStream.length > x && mBundleSourceInputStream[x] != null) {
                    if ((bundle = getInstalledBundle(mLocation[x])) == null) {
                        bundle = Framework.installNewBundle(mLocation[x], mBundleSourceInputStream[x]);
                    }
                    if (bundle != null) {
                        ((BundleImpl) bundle).optDexFile();
                    }
                } else if (mBundleSourceFile != null && mBundleSourceFile.length > x && mBundleSourceFile[x] != null) {
                    if ((bundle = getInstalledBundle(mLocation[x])) == null) {
                        bundle = Framework.installNewBundle(mLocation[x], mBundleSourceFile[x]);
                    }
                    if (bundle != null) {
                        ((BundleImpl) bundle).optDexFile();
                    }
                } else {
                    if ((bundle = getInstalledBundle(mLocation[x])) == null && AtlasBundleInfoManager.instance().isInternalBundle(mLocation[x])) {
                        bundle = installBundleFromApk(mLocation[x]);
                        if (bundle != null) {
                            ((BundleImpl) bundle).optDexFile();
                        }
                    }
                }
            } else {
                throw new LowDiskException("no enough space");
            }
        }
    } else {
        for (int x = 0; x < mLocation.length; x++) {
            List<String> bundlesForInstall = AtlasBundleInfoManager.instance().getBundleInfo(mLocation[x]).getTotalDependency();
            Log.e("BundleInstaller", mLocation[x] + "-->" + bundlesForInstall.toString());
            for (String bundleName : bundlesForInstall) {
                if ((bundle = getInstalledBundle(bundleName)) == null) {
                    if (FileUtils.getUsableSpace(Environment.getDataDirectory()) >= 5) {
                        //has enough space
                        if (AtlasBundleInfoManager.instance().isInternalBundle(bundleName)) {
                            bundle = installBundleFromApk(bundleName);
                            if (bundle != null) {
                                ((BundleImpl) bundle).optDexFile();
                            }
                        }
                    } else {
                        throw new LowDiskException("no enough space");
                    }
                } else {
                    if (bundle != null && ((BundleImpl) bundle).getArchive() != null && !((BundleImpl) bundle).getArchive().isDexOpted()) {
                        ((BundleImpl) bundle).optDexFile();
                    }
                }
            }
        }
    }
    return null;
}
Also used : Bundle(org.osgi.framework.Bundle) LowDiskException(android.taobao.atlas.runtime.LowDiskException)

Example 8 with Bundle

use of org.osgi.framework.Bundle in project atlas by alibaba.

the class BundleInstaller method installBundleFromApk.

private Bundle installBundleFromApk(String bundleName) throws Exception {
    Bundle bundle = null;
    findBundleSource(bundleName);
    if (mTmpBundleSourceFile != null) {
        bundle = Framework.installNewBundle(bundleName, mTmpBundleSourceFile);
    } else if (mTmpBundleSourceInputStream != null) {
        bundle = Framework.installNewBundle(bundleName, mTmpBundleSourceInputStream);
    } else {
        throw new IOException("can not find bundle source file");
    }
    return bundle;
}
Also used : Bundle(org.osgi.framework.Bundle) IOException(java.io.IOException)

Example 9 with Bundle

use of org.osgi.framework.Bundle in project atlas by alibaba.

the class Framework method addValue.

/**
     * add a value to a value list in a Map.
     *
     * @param map the map.
     * @param key the key.
     * @param value the value to be added to the list.
     */
@SuppressWarnings({ "rawtypes", "unchecked" })
static void addValue(final Map map, final Object key, final Object value) {
    List values;
    if ((values = (List) map.get(key)) == null) {
        values = new ArrayList<Bundle>();
    }
    values.add(value);
    map.put(key, values);
}
Also used : Bundle(org.osgi.framework.Bundle) KernalBundle(android.taobao.atlas.startup.patch.KernalBundle) ArrayList(java.util.ArrayList) List(java.util.List)

Example 10 with Bundle

use of org.osgi.framework.Bundle in project atlas by alibaba.

the class Atlas method uninstallBundle.

@Deprecated
public void uninstallBundle(final String location) throws BundleException {
    Bundle bundle = Framework.getBundle(location);
    if (bundle != null) {
        BundleImpl b = (BundleImpl) bundle;
        File delDir = null;
        try {
            File soFile = b.getArchive().getArchiveFile();
            if (soFile.canWrite()) {
                soFile.delete();
            }
            b.getArchive().purge();
            delDir = b.getArchive().getCurrentRevision().getRevisionDir();
            bundle.uninstall();
            if (delDir != null) {
                Framework.deleteDirectory(delDir);
            }
        } catch (Exception e) {
        }
    } else {
        throw new BundleException("Could not uninstall bundle " + location + ", because could not find it");
    }
}
Also used : Bundle(org.osgi.framework.Bundle) BundleException(org.osgi.framework.BundleException) File(java.io.File) AssertionArrayException(android.taobao.atlas.hack.AssertionArrayException) BundleException(org.osgi.framework.BundleException) IOException(java.io.IOException)

Aggregations

Bundle (org.osgi.framework.Bundle)2527 Test (org.junit.Test)674 URL (java.net.URL)389 BundleContext (org.osgi.framework.BundleContext)319 ArrayList (java.util.ArrayList)299 File (java.io.File)298 IOException (java.io.IOException)281 BundleException (org.osgi.framework.BundleException)273 HashMap (java.util.HashMap)155 ServiceReference (org.osgi.framework.ServiceReference)152 Hashtable (java.util.Hashtable)131 Path (org.eclipse.core.runtime.Path)126 HashSet (java.util.HashSet)98 InputStream (java.io.InputStream)94 List (java.util.List)87 IStatus (org.eclipse.core.runtime.IStatus)86 Status (org.eclipse.core.runtime.Status)82 Map (java.util.Map)74 BundleWiring (org.osgi.framework.wiring.BundleWiring)74 Version (org.osgi.framework.Version)73