use of org.osgi.framework.BundleException in project atlas by alibaba.
the class BundleImpl method update.
/**
* update the bundle from its update location or the location from where it was originally installed.
*
* @throws BundleException if something goes wrong.
* @see org.osgi.framework.Bundle#update()
* @category Bundle
*/
// public synchronized void update() throws BundleException {
// final String updateLocation = (String) headers.get(Constants.BUNDLE_UPDATELOCATION);
// try {
// update(new URL(updateLocation == null ? location : updateLocation).openConnection().getInputStream());
// markBundleUpdated((BundleArchive)archive);
// } catch (IOException ioe) {
// throw new BundleException("Could not update " + toString() + " from " + updateLocation, ioe);
// }
// }
/**
* update the bundle from an input stream.
*
* @param stream the stream.
* @throws BundleException if something goes wrong.
* @see org.osgi.framework.Bundle#update(java.io.InputStream)
* @category Bundle
*/
// public synchronized void update(final InputStream stream) throws BundleException {
//
// if (state == UNINSTALLED) {
// throw new IllegalStateException("Cannot update uninstalled bundle " + toString());
// }
//
// try {
// archive.newRevision(location, bundleDir, stream);
// markBundleUpdated((BundleArchive)archive);
// } catch (Exception e) {
// throw new BundleException("Could not update bundle " + toString(), e);
// }
// }
/**
* update the bundle from an input stream.
*
* @param file the revision file.
* @throws BundleException if something goes wrong.
* @category Bundle
*/
@Override
public synchronized void update(final File file, String version, long dexPatchVersion) throws BundleException {
if (state == UNINSTALLED) {
throw new IllegalStateException("Cannot update uninstalled bundle " + toString());
}
try {
archive.newRevision(location, bundleDir, file, version, dexPatchVersion);
markBundleUpdated((BundleArchive) archive);
} catch (Exception e) {
throw new BundleException("Could not update bundle " + toString(), e);
}
}
use of org.osgi.framework.BundleException in project atlas by alibaba.
the class BundleImpl method stop.
@Override
public void stop() throws BundleException {
if (state == UNINSTALLED) {
throw new IllegalStateException("Cannot stop uninstalled bundle " + toString());
}
if (state != ACTIVE) {
return;
}
state = STOPPING;
try {
if (Framework.DEBUG_BUNDLES) {
Log.i("Framework", "Bundle " + toString() + " stopped.");
}
} catch (Throwable t) {
throw new BundleException("Error stopping bundle " + toString(), t);
} finally {
Framework.clearBundleTrace(this);
state = RESOLVED;
Framework.notifyBundleListeners(BundleEvent.STOPPED, this);
context.isValid = false;
}
}
use of org.osgi.framework.BundleException in project atlas by alibaba.
the class Framework method installNewBundle.
/**
* install a bundle from input stream.
*
* @param location the bundle location.
* @param in the input stream.
* @return a Bundle object.
* @throws BundleException if the installation failed.
*/
static BundleImpl installNewBundle(final String location, final InputStream in) throws BundleException {
File bundleDir = null;
try {
BundleLock.WriteLock(location);
/*
* <specs page="58">Every bundle is uniquely identified by its location string. If an installed bundle is using
* the specified location, the installBundle method must return the Bundle object for that installed bundle and
* not install a new bundle.</specs>
*/
bundleDir = new File(STORAGE_LOCATION, location);
if (!bundleDir.exists()) {
bundleDir.mkdirs();
}
AtlasFileLock.getInstance().LockExclusive(bundleDir);
final BundleImpl cached;
if ((cached = (BundleImpl) getBundle(location)) != null) {
return cached;
}
Log.e("BundleInstaller", "real install " + location);
BundleImpl bundle = null;
BundleListing.BundleInfo info = AtlasBundleInfoManager.instance().getBundleInfo(location);
String version = info != null ? info.getVersion() : "-1";
bundle = new BundleImpl(bundleDir, location, new BundleContext(), in, null, version, true, -1);
storeMetadata();
return bundle;
} catch (IOException e) {
BundleException e1 = new BundleException("Failed to install bundle." + FileUtils.getAvailableDisk(), e);
if (bundleDir != null)
Framework.deleteDirectory(bundleDir);
if (FileUtils.getUsableSpace(Environment.getDataDirectory()) < LowDiskException.thredshold) {
throw new LowDiskException(FileUtils.getAvailableDisk(), e);
}
throw new BundleException("Failed to install bundle.", e);
} catch (BundleException e) {
BundleException e1 = new BundleException("Failed to install bundle." + FileUtils.getAvailableDisk(), e);
if (bundleDir != null)
Framework.deleteDirectory(bundleDir);
throw e1;
} finally {
BundleLock.WriteUnLock(location);
if (bundleDir != null) {
AtlasFileLock.getInstance().unLock(bundleDir);
}
}
}
use of org.osgi.framework.BundleException 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");
}
}
use of org.osgi.framework.BundleException in project atlas by alibaba.
the class Framework method checkInstallDebugBundle.
/**
* for debug not release
*/
static void checkInstallDebugBundle() {
File debugDirectory = new File(ATLAS_DEBUG_DIRECTORY);
if (debugDirectory.exists()) {
File[] bundles = debugDirectory.listFiles(new FilenameFilter() {
@Override
public boolean accept(File dir, String filename) {
if (filename.endsWith(".so")) {
return true;
}
return false;
}
});
if (bundles != null) {
String[] packageNames = new String[bundles.length];
String[] versions = new String[bundles.length];
for (int x = 0; x < bundles.length; x++) {
versions[x] = "1.0.0";
if (bundles[x].getName().startsWith("kernal") || bundles[x].getName().contains("com_taobao_mainDex")) {
//主dexbundle
packageNames[x] = "com.taobao.maindex";
} else {
//业务bundle
PackageInfo info = RuntimeVariables.androidApplication.getPackageManager().getPackageArchiveInfo(bundles[x].getAbsolutePath(), 0);
if (info != null) {
packageNames[x] = info.applicationInfo.packageName;
} else {
String fileName = bundles[x].getName();
fileName = fileName.substring(3, fileName.length() - 3);
packageNames[x] = fileName.replace("_", ".");
}
}
}
try {
Atlas.getInstance().installOrUpdate(packageNames, bundles, versions, -1);
Log.d("Framework", "patch success and delete file");
try {
for (File installFile : bundles) {
if (installFile.exists()) {
installFile.delete();
}
}
} catch (Exception e) {
}
} catch (BundleException e) {
e.printStackTrace();
}
}
}
}
Aggregations