use of org.osgi.framework.BundleException in project atlas by alibaba.
the class Framework method installNewBundle.
/**
* install a bundle from input file, the file will move to bundle storage directory.
*
* @param location the bundle location.
* @param file the input file.
* @return a Bundle object.
* @throws BundleException if the installation failed.
* @throws
*/
static BundleImpl installNewBundle(final String location, final File file) throws BundleException {
File bundleDir = null;
try {
bundleDir = new File(STORAGE_LOCATION, location);
if (!bundleDir.exists()) {
bundleDir.mkdirs();
}
BundleLock.WriteLock(location);
AtlasFileLock.getInstance().LockExclusive(bundleDir);
/*
* <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>
*/
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(), null, file, 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 PatchInstaller method install.
public void install() throws BundleException {
if (mergeOutputs.isEmpty()) {
throw new BundleException("merge bundles is empty");
}
//
// buildBundleInventory(updateInfo);
//
// File fileDir = new File(RuntimeVariables.androidApplication.getFilesDir(), "bundlelisting");
// String fileName = String.format("%s%s.json", new Object[]{"bundleInfo-", updateInfo.dexPatchVersion>0 ? updateInfo.dexPatchVersion+"" : updateInfo.updateVersion});
//
// if (!fileDir.exists() || !new File(fileDir, fileName).exists()) {
// throw new BundleException("bundle file list is empty");
// }
Iterator entries = mergeOutputs.entrySet().iterator();
String[] packageName = new String[mergeOutputs.size()];
File[] bundleFilePath = new File[mergeOutputs.size()];
String[] versions = new String[mergeOutputs.size()];
int index = 0;
while (entries.hasNext()) {
Map.Entry entry = (Map.Entry) entries.next();
packageName[index] = (String) entry.getKey();
Pair<String, String> bundlePair = (Pair<String, String>) entry.getValue();
bundleFilePath[index] = new File(bundlePair.first);
if (!bundleFilePath[index].exists()) {
throw new BundleException("bundle input is wrong");
}
versions[index] = bundlePair.second;
index++;
}
List<String> realInstalledBundle = Arrays.asList(packageName);
for (UpdateInfo.Item bundle : updateInfo.updateBundles) {
if (!realInstalledBundle.contains(bundle.name) && AtlasBundleInfoManager.instance().isInternalBundle(bundle.name)) {
throw new BundleException("bundle " + bundle.name + " is error");
}
}
Atlas.getInstance().installOrUpdate(packageName, bundleFilePath, versions, updateInfo.dexPatchVersion);
List<String> rollbackBundles = new ArrayList<String>();
for (UpdateInfo.Item item : updateInfo.updateBundles) {
if (item != null) {
String bundleCodeVersion = item.version.split("@")[1];
if (bundleCodeVersion.trim().equals("-1")) {
rollbackBundles.add(item.name);
}
}
}
if (rollbackBundles.size() > 0) {
Atlas.getInstance().restoreBundle(rollbackBundles.toArray(new String[rollbackBundles.size()]));
}
saveBaselineInfo(updateInfo, realInstalledBundle);
}
use of org.osgi.framework.BundleException in project jersey by jersey.
the class ExtendedWadlWebappOsgiTest method testExtendedWadl.
/**
* Test checks that the WADL generated using the WadlGenerator api doesn't
* contain the expected text.
*
* @throws java.lang.Exception in case of a test error.
*/
@Test
public void testExtendedWadl() throws Exception {
// TODO - temporary workaround
// This is a workaround related to issue JERSEY-2093; grizzly (1.9.5) needs to have the correct context
// class loader set
ClassLoader myClassLoader = this.getClass().getClassLoader();
for (Bundle bundle : bundleContext.getBundles()) {
if ("webapp".equals(bundle.getSymbolicName())) {
myClassLoader = bundle.loadClass("org.glassfish.jersey.examples.extendedwadl.resources.MyApplication").getClassLoader();
break;
}
}
Thread.currentThread().setContextClassLoader(myClassLoader);
// END of workaround - the entire block can be deleted after grizzly is updated to recent version
// List all the OSGi bundles
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(" |");
try {
b.start();
sb.append(" STARTED | ");
} catch (BundleException e) {
sb.append(" *FAILED* | ").append(e.getMessage());
}
sb.append(b.getLocation()).append("\n");
}
sb.append("-- \n\n");
LOGGER.fine(sb.toString());
final ResourceConfig resourceConfig = createResourceConfig();
final HttpServer server = GrizzlyHttpServerFactory.createHttpServer(baseUri, resourceConfig);
final Client client = ClientBuilder.newClient();
final Response response = client.target(baseUri).path("application.wadl").request(MediaTypes.WADL_TYPE).buildGet().invoke();
String wadl = response.readEntity(String.class);
LOGGER.info("RESULT = " + wadl);
assertTrue("Generated wadl is of null length", !wadl.isEmpty());
assertTrue("Generated wadl doesn't contain the expected text", wadl.contains("This is a paragraph"));
assertFalse(wadl.contains("application.wadl/xsd0.xsd"));
server.shutdownNow();
}
use of org.osgi.framework.BundleException in project gocd by gocd.
the class FelixGoPluginOSGiFrameworkTest method shouldMarkThePluginAsInvalidIfAnyExceptionOccursAfterLoad.
@Test
public void shouldMarkThePluginAsInvalidIfAnyExceptionOccursAfterLoad() throws BundleException {
final Bundle bundle = mock(Bundle.class);
spy.addPluginChangeListener(new PluginChangeListener() {
@Override
public void pluginLoaded(GoPluginDescriptor pluginDescriptor) {
throw new RuntimeException("some error");
}
@Override
public void pluginUnLoaded(GoPluginDescriptor pluginDescriptor) {
}
});
when(bundleContext.installBundle(any(String.class))).thenReturn(bundle);
final GoPluginDescriptor goPluginDescriptor = new GoPluginDescriptor(TEST_SYMBOLIC_NAME, "1.0", null, "location", new File(""), false);
spy.start();
try {
spy.loadPlugin(goPluginDescriptor);
fail("should throw exception");
} catch (Exception e) {
assertTrue(goPluginDescriptor.getStatus().isInvalid());
}
}
use of org.osgi.framework.BundleException in project lwjgl by LWJGL.
the class Activator method start.
/*
* (non-Javadoc)
* @see org.eclipse.core.runtime.Plugins#start(org.osgi.framework.BundleContext)
*/
@Override
public void start(BundleContext context) throws Exception {
super.start(context);
try {
String path = LibraryPathUtil.getLWJGLLibraryPath(context);
Status status = new Status(Status.INFO, PLUGIN_ID, Status.INFO, "Set org.lwjgl.librarypath to " + path, null);
getLog().log(status);
} catch (Throwable ex) {
Status status = new Status(Status.ERROR, PLUGIN_ID, Status.ERROR, "Error setting native LWJGL libraries path: " + ex.toString(), ex);
getLog().log(status);
throw new BundleException(status.getMessage(), ex);
}
}
Aggregations