Fix for bug 50002 update the state when a bundle is deleted/changed
diff --git a/bundles/org.eclipse.osgi/defaultAdaptor/src/org/eclipse/osgi/framework/internal/defaultadaptor/DefaultBundleData.java b/bundles/org.eclipse.osgi/defaultAdaptor/src/org/eclipse/osgi/framework/internal/defaultadaptor/DefaultBundleData.java
index 634cb25..45526c9 100644
--- a/bundles/org.eclipse.osgi/defaultAdaptor/src/org/eclipse/osgi/framework/internal/defaultadaptor/DefaultBundleData.java
+++ b/bundles/org.eclipse.osgi/defaultAdaptor/src/org/eclipse/osgi/framework/internal/defaultadaptor/DefaultBundleData.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2004 IBM Corporation and others.
+ * Copyright (c) 2003, 2004 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials 
  * are made available under the terms of the Common Public License v1.0
  * which accompanies this distribution, and is available at
@@ -683,4 +683,17 @@
 	public DefaultAdaptor getAdaptor() {
 		return adaptor;
 	}
+	public long getManifestTimeStamp() {
+		return 0;
+	}
+	public byte getManifestType() {
+		return 0;
+	}
+	public void setManifestTimeStamp(long stamp) {
+		//do nothing
+	}
+	public void setManifestType(byte type) {
+		//do nothing		
+	}
 }
+
diff --git a/bundles/org.eclipse.osgi/eclipseAdaptor/src/org/eclipse/core/runtime/adaptor/EclipseAdaptor.java b/bundles/org.eclipse.osgi/eclipseAdaptor/src/org/eclipse/core/runtime/adaptor/EclipseAdaptor.java
index a8390e9..2d585ac 100644
--- a/bundles/org.eclipse.osgi/eclipseAdaptor/src/org/eclipse/core/runtime/adaptor/EclipseAdaptor.java
+++ b/bundles/org.eclipse.osgi/eclipseAdaptor/src/org/eclipse/core/runtime/adaptor/EclipseAdaptor.java
@@ -47,7 +47,7 @@
 	private static final String OPTION_STATE_READER = RUNTIME_ADAPTOR + "/state/reader";//$NON-NLS-1$
 	private static final String OPTION_RESOLVER = RUNTIME_ADAPTOR + "/resolver/timing"; //$NON-NLS-1$
 	private static final String OPTION_RESOLVER_READER = RUNTIME_ADAPTOR + "/resolver/reader/timing"; //$NON-NLS-1$
-	public static final byte BUNDLEDATA_VERSION = 3;
+	public static final byte BUNDLEDATA_VERSION = 4;
 	public static final byte NULL = 0;
 	public static final byte OBJECT = 1;
 
@@ -291,6 +291,8 @@
 		data.setStatus(in.readInt());
 		data.setReference(in.readBoolean());
 		data.setFragment(in.readBoolean());
+		data.setManifestTimeStamp(in.readLong());
+		data.setManifestType(in.readByte());
 	}
 	protected void saveMetaDataFor(BundleData data, DataOutputStream out) throws IOException {
 		if (data.getBundleID() == 0 || !(data instanceof DefaultBundleData)) {
@@ -300,7 +302,7 @@
 		EclipseBundleData bundleData = (EclipseBundleData) data;
 		out.writeByte(OBJECT);
 		writeStringOrNull(out, bundleData.getLocation());
-		writeStringOrNull(out, bundleData.getName());
+		writeStringOrNull(out, bundleData.getName());	//TODO Check how this works regarding localization
 		writeStringOrNull(out, bundleData.getUniqueId());
 		writeStringOrNull(out, bundleData.getVersion().toString());
 		writeStringOrNull(out, bundleData.getActivator());
@@ -315,6 +317,8 @@
 		out.writeInt(bundleData.getStatus());
 		out.writeBoolean(bundleData.isReference());
 		out.writeBoolean(bundleData.isFragment());
+		out.writeLong(bundleData.getManifestTimeStamp());
+		out.writeByte(bundleData.getManifestType());
 	}
 
 	private String readString(DataInputStream in, boolean intern) throws IOException {
diff --git a/bundles/org.eclipse.osgi/eclipseAdaptor/src/org/eclipse/core/runtime/adaptor/EclipseBundleData.java b/bundles/org.eclipse.osgi/eclipseAdaptor/src/org/eclipse/core/runtime/adaptor/EclipseBundleData.java
index 3e40f1a..baea029 100644
--- a/bundles/org.eclipse.osgi/eclipseAdaptor/src/org/eclipse/core/runtime/adaptor/EclipseBundleData.java
+++ b/bundles/org.eclipse.osgi/eclipseAdaptor/src/org/eclipse/core/runtime/adaptor/EclipseBundleData.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2003 IBM Corporation and others.
+ * Copyright (c) 2003, 2004 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials 
  * are made available under the terms of the Common Public License v1.0
  * which accompanies this distribution, and is available at
@@ -26,9 +26,20 @@
 	private URL base;
 	private static String[] libraryVariants = null;
 
+	/** data to detect modification made in the manifest */
+	protected final byte PLUGIN = 1;
+	protected final byte MANIFEST = 0;
+
+	private byte manifestType = MANIFEST;
+	private long manifestTimeStamp = 0;
+	
 		// URL protocol designations
 	public static final String PROTOCOL = "platform"; //$NON-NLS-1$
 	public static final String FILE = "file"; //$NON-NLS-1$
+
+	private static final String PLUGIN_MANIFEST = "plugin.xml"; //$NON-NLS-1$
+	private static final String FRAGMENT_MANIFEST = "fragment.xml"; //$NON-NLS-1$
+	private static final String NO_TIMESTAMP_CHECKING = "osgi.noManifestTimeChecking"; //$NON-NLS-1$
 	protected String isLegacy = null;
 	protected String pluginClass = null;
 
@@ -108,10 +119,34 @@
 		dirData = new File(dir, ((EclipseAdaptor)adaptor).getDataDirName());
 		dirGeneration = new File(dir, String.valueOf(generation));
 		file = reference ? new File(name) : new File(dirGeneration, name);
+		if (! checkManifestTimeStamp(file))
+			throw new IOException();
 		bundleFile = BundleFile.createBundleFile(file,this);
 		initializeBase(location);
 	}
 
+	private boolean checkManifestTimeStamp(File bundlefile) {
+		boolean on = true;
+		if ("true".equalsIgnoreCase(NO_TIMESTAMP_CHECKING))	//$NON-NLS-1$
+			return true;
+		
+		// When the bundle is jar'ed, simply check the time stamp of the jar
+		if( ! bundlefile.isDirectory() )	
+			return bundlefile.lastModified() == getManifestTimeStamp();
+		
+		// Otherwise, check the file time stamp
+		switch (getManifestType()) {
+		case MANIFEST:
+			return new File(bundlefile, Constants.OSGI_BUNDLE_MANIFEST).lastModified()==getManifestTimeStamp();
+		case PLUGIN:
+			if ( new File(bundlefile, PLUGIN_MANIFEST).lastModified()==getManifestTimeStamp() )
+				return true;
+			else 
+				return new File(bundlefile, FRAGMENT_MANIFEST).lastModified()==getManifestTimeStamp();
+		}
+		return true;	 
+	}
+	
 	void initialize() throws IOException {
 		initializeBase(location);
 		dir = new File(((EclipseAdaptor)adaptor).getBundleRootDir(), Long.toString(id));
@@ -220,20 +255,43 @@
 
 	public synchronized Dictionary loadManifest() throws BundleException {		
 		URL url = getEntry(Constants.OSGI_BUNDLE_MANIFEST);
-		if (url != null)
+		if (url != null) {
+			try {
+				manifestTimeStamp = url.openConnection().getLastModified();
+				manifestType = MANIFEST;
+			} catch (IOException e) {
+				//ignore the exception since this is for timeStamp
+			}
 			return loadManifestFrom(url);
+		}
 		Dictionary result = generateManifest();		
 		if (result == null)	//TODO: need to NLS this
 			throw new BundleException("Manifest not found: " + getLocation());
 		return result;
 	}
 
+	private File findPluginManifest(File baseLocation) {
+		File pluginManifestLocation = new File(baseLocation, PLUGIN_MANIFEST); //$NON-NLS-1$
+		if (pluginManifestLocation.isFile())
+			return pluginManifestLocation;
+		pluginManifestLocation = new File(baseLocation, FRAGMENT_MANIFEST); //$NON-NLS-1$
+		if (pluginManifestLocation.isFile())
+			return pluginManifestLocation;
+		return null;
+	}
+	
 	private Dictionary generateManifest() throws BundleException {
 		PluginConverterImpl converter = PluginConverterImpl.getDefault();
-		File location = converter.convertManifest(file);
+		File location = findPluginManifest(file);
+		if (location == null)
+			return null;
+
+		setManifestTimeStamp(location.lastModified());
+		setManifestType(PLUGIN);
+		location = converter.convertManifest(location);
 		if (location == null)
 			return null;	
-		try {
+		try {	
 			return loadManifestFrom(location.toURL());
 		} catch (MalformedURLException mfue) {
 			return null;
@@ -307,4 +365,16 @@
 	public void setDynamicImports(String value) {
 		this.dynamicImports = value;
 	}
+	public long getManifestTimeStamp() {
+		return manifestTimeStamp;
+	}
+	public byte getManifestType() {
+		return manifestType;
+	}
+	public void setManifestTimeStamp(long stamp) {
+		manifestTimeStamp = stamp;
+	}
+	public void setManifestType(byte type) {
+		manifestType = type;	
+	}
 }
diff --git a/bundles/org.eclipse.osgi/eclipseAdaptor/src/org/eclipse/core/runtime/adaptor/PluginConverterImpl.java b/bundles/org.eclipse.osgi/eclipseAdaptor/src/org/eclipse/core/runtime/adaptor/PluginConverterImpl.java
index e22eada..02534f8 100644
--- a/bundles/org.eclipse.osgi/eclipseAdaptor/src/org/eclipse/core/runtime/adaptor/PluginConverterImpl.java
+++ b/bundles/org.eclipse.osgi/eclipseAdaptor/src/org/eclipse/core/runtime/adaptor/PluginConverterImpl.java
@@ -118,6 +118,8 @@
 	}
 
 	private File findPluginManifest(File baseLocation) {
+		if (baseLocation.isFile())
+			return baseLocation;
 		File pluginManifestLocation = new File(baseLocation, PLUGIN_MANIFEST); //$NON-NLS-1$
 		if (pluginManifestLocation.isFile())
 			return pluginManifestLocation;