if (stateManager != null) { BundleDescription bundleDescription = stateManager.getFactory().createBundleDescription(data.getManifest(), data.getLocation(), data.getBundleID()); stateManager.getSystemState().addBundle(bundleDescription); }
updateState(data, BundleEvent.INSTALLED);
	public BundleOperation installBundle(final String location, final URLConnection source) {		final AbstractBundleData bundleData = data;		data = null;		return (new BundleOperation() {			private AbstractBundleData data;			/**			 * Begin the operation on the bundle (install, update, uninstall).			 *			 * @return BundleData object for the target bundle.			 * @throws BundleException If a failure occured modifiying peristent storage.			 */			public org.eclipse.osgi.framework.adaptor.BundleData begin() throws BundleException {				long id;				try {					/*					 * Open InputStream first to trigger prereq installs, if any,					 * before allocating bundle id.					 */					InputStream in = source.getInputStream();					URL sourceURL = source.getURL();					String protocol = sourceURL == null ? null : sourceURL.getProtocol();					try {						try {							id = getNextBundleId();						} catch (IOException e) {							throw new BundleException(AdaptorMsg.formatter.getString("ADAPTOR_STORAGE_EXCEPTION"), e); //$NON-NLS-1$						}						if (bundleData == null) {							data = (AbstractBundleData) getElementFactory().createBundleData(AbstractFrameworkAdaptor.this, id);						} else {							data = bundleData;						}						data.setLastModified(System.currentTimeMillis());						data.setLocation(location);						data.setStartLevel(getInitialBundleStartLevel());						if (in instanceof ReferenceInputStream) {							URL reference = ((ReferenceInputStream) in).getReference();							if (!"file".equals(reference.getProtocol())) { //$NON-NLS-1$								throw new BundleException(AdaptorMsg.formatter.getString("ADAPTOR_URL_CREATE_EXCEPTION", reference)); //$NON-NLS-1$							}							data.setReference(true);							data.setFileName(reference.getPath());							data.initializeNewBundle();						} else {							File genDir = data.createGenerationDir();							if (!genDir.exists()) {								throw new IOException(AdaptorMsg.formatter.getString("ADAPTOR_DIRECTORY_CREATE_EXCEPTION", genDir.getPath())); //$NON-NLS-1$							}							String fileName = mapLocationToName(location);							File outFile = new File(genDir, fileName);							if ("file".equals(protocol)) { //$NON-NLS-1$								File inFile = new File(source.getURL().getPath());								if (inFile.isDirectory()) {									copyDir(inFile, outFile);								} else {									readFile(in, outFile);								}							} else {								readFile(in, outFile);							}							data.setReference(false);							data.setFileName(fileName);							data.initializeNewBundle();						}					} finally {						try {							in.close();						} catch (IOException e) {						}					}				} catch (IOException ioe) {					throw new BundleException(AdaptorMsg.formatter.getString("BUNDLE_READ_EXCEPTION"), ioe); //$NON-NLS-1$				}				return (data);			}			public void undo() {				if (data != null) {					try {						data.close();					} catch (IOException e) {						if (Debug.DEBUG && Debug.DEBUG_GENERAL) {							Debug.println("Unable to close " + data + ": " + e.getMessage()); //$NON-NLS-1$ //$NON-NLS-2$						}					}				}				if (data != null) {					File bundleDir = data.getBundleStoreDir();					if (!rm(bundleDir)) {						/* mark this bundle to be deleted to ensure it is fully cleaned up						 * on next restart.						 */						File delete = new File(bundleDir, ".delete"); //$NON-NLS-1$						if (!delete.exists()) {							try {								/* create .delete */								FileOutputStream out = new FileOutputStream(delete);								out.close();							} catch (IOException e) {								if (Debug.DEBUG && Debug.DEBUG_GENERAL) {									Debug.println("Unable to write " + delete.getPath() + ": " + e.getMessage()); //$NON-NLS-1$ //$NON-NLS-2$								}							}						}					}				}			}			public void commit(boolean postpone) throws BundleException {				try {					data.save();				} catch (IOException e) {					throw new BundleException(AdaptorMsg.formatter.getString("ADAPTOR_STORAGE_EXCEPTION"), e); //$NON-NLS-1$				}				if (stateManager != null) {					BundleDescription bundleDescription = stateManager.getFactory().createBundleDescription(data.getManifest(), data.getLocation(), data.getBundleID());					stateManager.getSystemState().addBundle(bundleDescription);				}			}		});	}