231358 [Contributions] Provide a core expression to check for bundle activation
diff --git a/bundles/org.eclipse.core.expressions/plugin.xml b/bundles/org.eclipse.core.expressions/plugin.xml
index 3134c65..b49141d 100644
--- a/bundles/org.eclipse.core.expressions/plugin.xml
+++ b/bundles/org.eclipse.core.expressions/plugin.xml
@@ -11,7 +11,7 @@
               id="org.eclipse.core.expressions.bundlePropertyTester"
               type="org.eclipse.core.runtime.Platform"
               namespace="org.eclipse.core.runtime"
-              properties="product,isBundleInstalled"
+              properties="product,isBundleInstalled,bundleState"
               class="org.eclipse.core.internal.expressions.propertytester.PlatformPropertyTester">
         </propertyTester>
      </extension>
diff --git a/bundles/org.eclipse.core.expressions/src/org/eclipse/core/internal/expressions/propertytester/PlatformPropertyTester.java b/bundles/org.eclipse.core.expressions/src/org/eclipse/core/internal/expressions/propertytester/PlatformPropertyTester.java
index e2dc9f7..40b1b54 100644
--- a/bundles/org.eclipse.core.expressions/src/org/eclipse/core/internal/expressions/propertytester/PlatformPropertyTester.java
+++ b/bundles/org.eclipse.core.expressions/src/org/eclipse/core/internal/expressions/propertytester/PlatformPropertyTester.java
@@ -10,6 +10,8 @@
  *******************************************************************************/
 package org.eclipse.core.internal.expressions.propertytester;
 
+import org.osgi.framework.Bundle;
+
 import org.eclipse.core.runtime.IProduct;
 import org.eclipse.core.runtime.Platform;
 
@@ -19,15 +21,18 @@
  * A property tester for testing platform properties. Can test whether or
  * not a given bundle is installed in the running environment, as well as
  * the id of the currently active product.
- * 
- * For example:
- * <test property="org.eclipse.core.runtime.product" args="org.eclipse.sdk.ide"/>
- * <test property="org.eclipse.core.runtime.isBundleInstalled" args="org.eclipse.core.expressions"/>
+ * <p>
+ * For example:<br />
+ * &lt;test property="org.eclipse.core.runtime.product" value="org.eclipse.sdk.ide"/&gt; <br />
+ * &lt;test property="org.eclipse.core.runtime.isBundleInstalled" args="org.eclipse.core.expressions"/&gt; <br />
+ * &lt;test property="org.eclipse.core.runtime.bundleState" args="org.eclipse.core.expressions" value="ACTIVE"/&gt;
+ * <p>
  */
 public class PlatformPropertyTester extends PropertyTester {
 	
 	private static final String PROPERTY_PRODUCT = "product"; //$NON-NLS-1$
 	private static final String PROPERTY_IS_BUNDLE_INSTALLED = "isBundleInstalled"; //$NON-NLS-1$
+	private static final String PROPERTY_BUNDLE_STATE = "bundleState"; //$NON-NLS-1$
 
 	/* (non-Javadoc)
 	 * @see org.eclipse.core.expressions.IPropertyTester#test(java.lang.Object, java.lang.String, java.lang.Object[], java.lang.Object)
@@ -42,8 +47,37 @@
 				return false;
 			} else if (PROPERTY_IS_BUNDLE_INSTALLED.equals(property) && args.length >= 1 && args[0] instanceof String) {
 				return Platform.getBundle((String)args[0]) != null;
+			} else if (PROPERTY_BUNDLE_STATE.equals(property)
+					&& args.length >= 1 && args[0] instanceof String) {
+				Bundle b = Platform.getBundle((String) args[0]);
+				if (b != null) {
+					return bundleState(b.getState(), expectedValue);
+				}
+				return false;
 			}
 		}
 		return false;
 	}
+	
+	private boolean bundleState(int bundleState, Object expectedValue) {
+		if ("UNINSTALLED".equals(expectedValue)) { //$NON-NLS-1$
+			return bundleState == Bundle.UNINSTALLED;
+		}
+		if ("INSTALLED".equals(expectedValue)) { //$NON-NLS-1$
+			return bundleState == Bundle.INSTALLED;
+		}
+		if ("RESOLVED".equals(expectedValue)) { //$NON-NLS-1$
+			return bundleState == Bundle.RESOLVED;
+		}
+		if ("STARTING".equals(expectedValue)) { //$NON-NLS-1$
+			return bundleState == Bundle.STARTING;
+		}
+		if ("STOPPING".equals(expectedValue)) { //$NON-NLS-1$
+			return bundleState == Bundle.STOPPING;
+		}
+		if ("ACTIVE".equals(expectedValue)) { //$NON-NLS-1$
+			return bundleState == Bundle.ACTIVE;
+		}
+		return false;
+	}
 }
diff --git a/tests/org.eclipse.core.expressions.tests/src/org/eclipse/core/internal/expressions/tests/PropertyTesterTests.java b/tests/org.eclipse.core.expressions.tests/src/org/eclipse/core/internal/expressions/tests/PropertyTesterTests.java
index 35d7b8f..1f2e6f8 100644
--- a/tests/org.eclipse.core.expressions.tests/src/org/eclipse/core/internal/expressions/tests/PropertyTesterTests.java
+++ b/tests/org.eclipse.core.expressions.tests/src/org/eclipse/core/internal/expressions/tests/PropertyTesterTests.java
@@ -166,6 +166,15 @@
 		assertTrue(p.isInstantiated());
 	}
 	
+	public void testPlatformTester() throws Exception {
+		TestExpression exp = new TestExpression("org.eclipse.core.runtime",
+				"bundleState",
+				new Object[] { "org.eclipse.core.expressions" }, "ACTIVE", false);
+		EvaluationContext context= new EvaluationContext(null, Platform.class);
+		EvaluationResult result= exp.evaluate(context);
+		assertEquals(EvaluationResult.TRUE, result);
+	}
+	
 	public void testDifferentNameSpace() throws Exception {
 		assertTrue(test("org.eclipse.core.internal.expressions.tests2", a, "differentNamespace", null, "A3"));		 //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
 	}