BundleStorageState createStorageState(long bundleId, String location, VirtualFile rootFile)
      throws IOException {
    if (location == null) throw new IllegalArgumentException("Null location");

    // Make the bundle's storage dir
    String bundlePath = getStorageDir(bundleId).getAbsolutePath();
    File bundleDir = new File(bundlePath);
    bundleDir.mkdirs();

    Properties props = BundleStorageState.loadProperties(bundleDir);
    String previousRev = props.getProperty(BundleStorageState.PROPERTY_BUNDLE_REV);
    int revision = (previousRev != null ? Integer.parseInt(previousRev) + 1 : 0);

    if (rootFile != null) {
      File revFile = new File(bundlePath + "/bundle-" + bundleId + "-rev-" + revision + ".jar");
      FileOutputStream output = new FileOutputStream(revFile);
      InputStream input = rootFile.openStream();
      try {
        VFSUtils.copyStream(input, output);
      } finally {
        input.close();
        output.close();
      }
      props.put(BundleStorageState.PROPERTY_BUNDLE_FILE, revFile.getName());
    }

    // Write the bundle properties
    props.put(BundleStorageState.PROPERTY_BUNDLE_LOCATION, location);
    props.put(BundleStorageState.PROPERTY_BUNDLE_ID, new Long(bundleId).toString());
    props.put(BundleStorageState.PROPERTY_BUNDLE_REV, new Integer(revision).toString());
    props.put(
        BundleStorageState.PROPERTY_LAST_MODIFIED, new Long(System.currentTimeMillis()).toString());

    return BundleStorageState.createBundleStorageState(bundleDir, rootFile, props);
  }
 protected Bundle installBundle(VirtualFile virtualFile) throws BundleException, IOException {
   return getSystemContext().installBundle(virtualFile.getName(), virtualFile.openStream());
 }