private Bundle installBundleFromFile(
      File savedBundleFile, boolean startBundle, boolean updateExistingBundle)
      throws IOException, BundleException {
    InputStream bundleInputStream = null;
    try {
      bundleInputStream = FileUtils.openInputStream(savedBundleFile);

      JarInformation jarInformation = new JarInformation(savedBundleFile);
      if (!isValidPluginBundle(jarInformation)) {
        LOG.warn(jarInformation.getFilename() + " is not allowed to install as add-on");
        return null;
      }
      Bundle bundle = findMatchingBundle(jarInformation);

      if (bundle == null) {
        final String bundleFileLocationAsURL = savedBundleFile.toURI().toURL().toExternalForm();
        bundle = bundleContext.installBundle(bundleFileLocationAsURL, bundleInputStream);
      } else if (updateExistingBundle) {
        LOG.info("Updating bundle " + bundle.getSymbolicName() + "|" + bundle.getVersion());
        bundle.update(bundleInputStream);
      }

      if (!isFragmentBundle(bundle) && startBundle) {
        bundle.start();
      }

      return bundle;
    } finally {
      IOUtils.closeQuietly(bundleInputStream);
    }
  }
 private boolean isValidPluginBundle(JarInformation jarInformation) {
   if (isBlank(jarInformation.getBundleSymbolicName())) {
     return false;
   }
   if (jarInformation.getBundleSymbolicName().contains("org.motechproject.motech-platform-")) {
     return false; // disallow installation of core bundles from UI.
   }
   return true;
 }
 private Bundle findMatchingBundle(JarInformation jarInformation) {
   Bundle result = null;
   for (Bundle bundle : bundleContext.getBundles()) {
     final String symbolicName = bundle.getSymbolicName();
     if (symbolicName != null
         && symbolicName.equals(jarInformation.getBundleSymbolicName())
         && bundle
             .getHeaders()
             .get(JarInformation.BUNDLE_VERSION)
             .equals(jarInformation.getBundleVersion())) {
       result = bundle;
       break;
     }
   }
   return result;
 }