use of org.osgi.framework.BundleException in project bnd by bndtools.
the class Launcher method install.
Bundle install(File f) throws Exception {
BundleContext context = systemBundle.getBundleContext();
try {
String reference;
if (isWindows() || parms.noreferences) {
trace("no reference: url %s", parms.noreferences);
reference = f.toURI().toURL().toExternalForm();
} else
reference = "reference:" + f.toURI().toURL().toExternalForm();
Bundle b = context.installBundle(reference);
if (b.getLastModified() < f.lastModified()) {
b.update();
}
return b;
} catch (BundleException e) {
trace("failed reference, will try to install %s with input stream", f.getAbsolutePath());
String reference = f.toURI().toURL().toExternalForm();
try (InputStream in = IO.stream(f)) {
return context.installBundle(reference, in);
}
}
}
use of org.osgi.framework.BundleException in project bnd by bndtools.
the class Launcher method update.
/**
* Ensure that all the bundles in the parameters are actually started. We
* can start in embedded mode (bundles are inside our main jar) or in file
* system mode.
*
* @param begin
*/
void update(long before) throws Exception {
trace("Updating framework with %s", parms.runbundles);
List<Bundle> tobestarted = new ArrayList<Bundle>();
if (parms.embedded)
installEmbedded(tobestarted);
else
synchronizeFiles(tobestarted, before);
if (padmin != null) {
inrefresh = true;
padmin.refreshPackages(null);
trace("Waiting for refresh to finish");
// when we created the framework.
while (inrefresh) Thread.sleep(100);
} else
trace("cannot refresh the bundles because there is no Package Admin");
trace("bundles administered %s", installedBundles.keySet());
// they will not automatically get AllPermission anymore
if (security)
policy.setDefaultPermissions(null);
// Get the resolved status
if (padmin != null && padmin.resolveBundles(null) == false) {
List<String> failed = new ArrayList<String>();
for (Bundle b : installedBundles.values()) {
try {
if (b.getState() == Bundle.INSTALLED) {
b.start();
}
} catch (Exception e) {
failed.add(b.getSymbolicName() + "-" + b.getVersion() + " " + e + "\n");
}
}
error("could not resolve the bundles: " + failed);
// return LauncherConstants.RESOLVE_ERROR;
}
// Now start all the installed bundles in the same order
// (unless they're a fragment)
trace("Will start bundles: %s", tobestarted);
List<Bundle> all = new ArrayList<Bundle>(tobestarted);
// Add all bundles that we've tried to start but failed
all.addAll(wantsToBeStarted);
for (Bundle b : tobestarted) {
try {
trace("starting %s", b.getSymbolicName());
if (!isFragment(b))
b.start(Bundle.START_ACTIVATION_POLICY);
trace("started %s", b.getSymbolicName());
} catch (BundleException e) {
wantsToBeStarted.add(b);
error("Failed to start bundle %s-%s, exception %s", b.getSymbolicName(), b.getVersion(), e);
}
}
}
use of org.osgi.framework.BundleException in project bnd by bndtools.
the class MiniFramework method installBundle.
@Override
public Bundle installBundle(String location) throws BundleException {
try {
if (location.startsWith("reference:"))
location = new File(new URL(location.substring("reference:".length())).toURI()).getPath();
else if (location.startsWith("file:"))
location = new File(location.substring("file:".length())).getPath();
while (location.startsWith("//")) location = location.substring(1);
Context c = new Context(this, last, ++ID, location);
bundles.put(Long.valueOf(c.id), c);
last = c;
return c;
} catch (Exception e) {
throw new BundleException("Failed to install", e);
}
}
use of org.osgi.framework.BundleException in project bnd by bndtools.
the class UnresolvedTester method testAllResolved.
@SuppressWarnings("deprecation")
public void testAllResolved() {
assertNotNull("Expected a Bundle Context", context);
StringBuilder sb = new StringBuilder();
for (Bundle b : context.getBundles()) {
if (b.getState() == Bundle.INSTALLED && b.getHeaders().get(aQute.bnd.osgi.Constants.FRAGMENT_HOST) == null) {
try {
b.start();
} catch (BundleException e) {
sb.append(b.getSymbolicName()).append(" [").append(b.getBundleId()).append("];").append(b.getVersion()).append("\n");
sb.append(" ").append(e.getMessage()).append("\n\n");
System.err.println(e.getMessage());
}
}
}
Matcher matcher = IP_P.matcher(sb);
String out = matcher.replaceAll("\n\n " + aQute.bnd.osgi.Constants.IMPORT_PACKAGE + ": $1;version=[$2,$3)\n");
assertTrue("Unresolved bundles\n" + out, sb.length() == 0);
}
Aggregations