예제 #1
0
  public long getLastModified() {

    if (artifact != null) {
      return artifact.lastModified();
    } else {
      return bundle.getLastModified();
    }
  }
예제 #2
0
  public long getLastModifiedTime(String file) {
    if (fBundleVersion == -1) {
      Version v = SVCorePlugin.getDefault().getBundle().getVersion();
      // Ensure the version is always really big to work around the temporary
      // current problem of having existing versions out in the wild
      fBundleVersion = v.getMicro();
      fBundleVersion |= v.getMinor() << 16;
      fBundleVersion |= v.getMajor() << 24;
      fBundleVersion |= (8L << 48L);
    }
    if (fBundleVersion < fBundle.getLastModified()) {
      System.out.println(
          "computed bundle version older than BundleVersion: "
              + fBundleVersion
              + " "
              + fBundle.getLastModified());
    }

    return fBundleVersion;
  }
 public static BundleDTO newBundleDTO(Bundle bundle) {
   if (bundle == null) {
     return null;
   }
   BundleDTO dto = new BundleDTO();
   dto.id = bundle.getBundleId();
   dto.lastModified = bundle.getLastModified();
   dto.state = bundle.getState();
   dto.symbolicName = bundle.getSymbolicName();
   dto.version = bundle.getVersion().toString();
   return dto;
 }
  private Properties createBundleProperties(Bundle bundle) {
    Properties props = new Properties();

    props.setProperty("id", Long.toString(bundle.getBundleId()));
    props.setProperty("state", printBundleState(bundle));
    props.setProperty("location", bundle.getLocation());
    props.setProperty("lastModified", Long.toString(bundle.getLastModified()));

    Dictionary headers = bundle.getHeaders();
    for (Enumeration keys = headers.keys(); keys.hasMoreElements(); ) {
      String key = (String) keys.nextElement();
      Object value = headers.get(key);
      if (value != null) props.setProperty(key, value.toString());
    }

    return props;
  }
예제 #5
0
  private Map<String, Object> marshal(Bundle b) {
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ssZ");

    Map<String, Object> m = new HashMap<String, Object>();
    m.put("id", b.getBundleId());
    m.put("name", b.getSymbolicName());
    m.put("version", b.getHeaders().get("Bundle-Version"));
    m.put("vendor", b.getHeaders().get("Bundle-Vendor"));
    m.put("last_modified", dateFormat.format(new Date(b.getLastModified())));
    m.put("location", b.getLocation());
    m.put("export_package", b.getHeaders().get("Export-Package"));
    m.put("import_package", b.getHeaders().get("Import-Package"));
    m.put("built_by", b.getHeaders().get("Built-By"));
    m.put("license", b.getHeaders().get("Bundle-License"));
    m.put("url", b.getHeaders().get("Bundle-DocURL"));
    m.put("status", getBundleState(b.getState()));
    return m;
  }
  /** Registers the NamespacePlugins instance as an Osgi Resolver service */
  private void registerResolverServices() {
    if (log.isDebugEnabled()) {
      log.debug("Registering Spring NamespaceHandlerResolver and EntityResolver...");
    }

    Bundle bnd = BundleUtils.getDMCoreBundle(context);
    Properties props = null;
    if (bnd != null) {
      props = new Properties();
      props.setProperty(BundleUtils.DM_CORE_ID, "" + bnd.getBundleId());
      props.setProperty(BundleUtils.DM_CORE_TS, "" + bnd.getLastModified());
    }
    nsResolverRegistration =
        context.registerService(
            new String[] {NamespaceHandlerResolver.class.getName()}, this.namespacePlugins, props);

    enResolverRegistration =
        context.registerService(
            new String[] {EntityResolver.class.getName()}, this.namespacePlugins, props);
  }
예제 #7
0
 Bundle install(File f) throws Exception {
   BundleContext context = systemBundle.getBundleContext();
   try {
     trace("will install %s with reference", f.getAbsolutePath());
     String 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();
     InputStream in = new FileInputStream(f);
     try {
       return context.installBundle(reference, in);
     } finally {
       in.close();
     }
   }
 }
예제 #8
0
  /**
   * @param systemContext
   * @throws MalformedURLException
   * @throws FileNotFoundException
   * @throws IOException
   */
  private void update() throws Exception {
    trace("Updating framework with %s", parms.runbundles);

    // Turn the bundle location paths into files
    List<File> desired = new ArrayList<File>();
    for (Object o : parms.runbundles) {
      File file = new File((String) o).getAbsoluteFile();
      if (!file.exists()) error("Bundle files does not exist: " + file);
      else desired.add(file);
    }

    // deleted = old - new
    List<File> tobedeleted = new ArrayList<File>(installedBundles.keySet());
    tobedeleted.removeAll(desired);

    // updated = old /\ new
    List<File> tobeupdated = new ArrayList<File>(installedBundles.keySet());
    tobeupdated.retainAll(desired);

    // install = new - old
    List<File> tobeinstalled = new ArrayList<File>(desired);
    tobeinstalled.removeAll(installedBundles.keySet());

    List<Bundle> tobestarted = new ArrayList<Bundle>();

    for (File f : tobedeleted)
      try {
        trace("uninstalling %s", f);
        installedBundles.get(f).uninstall();
        installedBundles.remove(f);
      } catch (Exception e) {
        error("Failed to uninstall bundle %s, exception %s", f, e);
      }

    for (File f : tobeinstalled)
      try {
        trace("installing %s", f);
        Bundle b = install(f);
        installedBundles.put(f, b);
        tobestarted.add(b);
      } catch (Exception e) {
        error("Failed to uninstall bundle %s, exception %s", f, e);
      }

    for (File f : tobeupdated)
      try {
        Bundle b = installedBundles.get(f);
        if (b.getLastModified() < f.lastModified()) {
          trace("updating %s", f);
          if (b.getState() == Bundle.ACTIVE) {
            tobestarted.add(b);
            b.stop();
          }
          b.update();
        } else trace("bundle is still current according to timestamp %s", f);
      } catch (Exception e) {
        error("Failed to update bundle %s, exception %s", f, e);
      }

    if (padmin != null) padmin.refreshPackages(null);

    trace("bundles administered %s", installedBundles.keySet());

    // From now on, the bundles are on their own. They have
    // by default AllPermission, but if they install bundles
    // they will not automatically get AllPermission anymore

    // Get the resolved status
    if (padmin != null && padmin.resolveBundles(null) == false) {
      error("could not resolve the bundles");
      // 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);
    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) {
        error("Failed to start bundle %s-%s, exception %s", b.getSymbolicName(), b.getVersion(), e);
      }
    }
  }