Bug 502318 - osgi.framework.activeThreadType is no longer used

Change-Id: I54fa1cce33e778d02a792b7c24a651c30555d08e
Signed-off-by: Thomas Watson <tjwatson@us.ibm.com>
diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/SystemBundleTests.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/SystemBundleTests.java
index 983fabf..1909278 100755
--- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/SystemBundleTests.java
+++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/SystemBundleTests.java
@@ -2887,4 +2887,58 @@
 		assertEquals("Wrong state for SystemBundle", Bundle.RESOLVED, equinox.getState()); //$NON-NLS-1$
 	}
 
+	public void testDaemonActiveThread() throws BundleException, InterruptedException {
+		File config = OSGiTestsActivator.getContext().getDataFile(getName());
+		config.mkdirs();
+		Map<String, Object> configuration = new HashMap<String, Object>();
+		configuration.put(Constants.FRAMEWORK_STORAGE, config.getAbsolutePath());
+
+		// test setting to anything other than 'normal'
+		// should result in a daemon thread
+		configuration.put(EquinoxConfiguration.PROP_ACTIVE_THREAD_TYPE, "daemon");
+		Equinox equinox = new Equinox(configuration);
+		equinox.start();
+		checkActiveThreadType(equinox, true);
+		equinox.stop();
+		equinox.waitForStop(10000);
+
+		// test setting to 'normal'
+		// should result in a non-daemon thread
+		configuration.put(EquinoxConfiguration.PROP_ACTIVE_THREAD_TYPE, EquinoxConfiguration.ACTIVE_THREAD_TYPE_NORMAL);
+		equinox = new Equinox(configuration);
+		equinox.start();
+		checkActiveThreadType(equinox, false);
+		equinox.stop();
+		equinox.waitForStop(10000);
+
+		// test setting to null (default)
+		// should result in a non-daemon thread
+		configuration.remove(EquinoxConfiguration.PROP_ACTIVE_THREAD_TYPE);
+		equinox = new Equinox(configuration);
+		equinox.start();
+		checkActiveThreadType(equinox, false);
+		equinox.stop();
+	}
+
+	void checkActiveThreadType(Equinox equinox, boolean expectIsDeamon) {
+		String uuid = equinox.getBundleContext().getProperty(Constants.FRAMEWORK_UUID);
+		ThreadGroup topGroup = Thread.currentThread().getThreadGroup();
+		if (topGroup != null) {
+			while (topGroup.getParent() != null) {
+				topGroup = topGroup.getParent();
+			}
+		}
+		Thread[] threads = new Thread[topGroup.activeCount()];
+		topGroup.enumerate(threads);
+		Thread found = null;
+		for (Thread t : threads) {
+			String name = t.getName();
+			if (("Active Thread: Equinox Container: " + uuid).equals(name)) {
+				found = t;
+				break;
+			}
+		}
+		assertNotNull("No framework active thread for \"" + uuid + "\" found in : " + Arrays.toString(threads), found);
+		assertEquals("Wrong daemon type.", expectIsDeamon, found.isDaemon());
+	}
 }
diff --git a/bundles/org.eclipse.osgi/META-INF/MANIFEST.MF b/bundles/org.eclipse.osgi/META-INF/MANIFEST.MF
index d42e78f..2c1d77b 100644
--- a/bundles/org.eclipse.osgi/META-INF/MANIFEST.MF
+++ b/bundles/org.eclipse.osgi/META-INF/MANIFEST.MF
@@ -95,7 +95,7 @@
 Bundle-Description: %systemBundle
 Bundle-Copyright: %copyright
 Bundle-Vendor: %eclipse.org
-Bundle-Version: 3.11.1.qualifier
+Bundle-Version: 3.11.2.qualifier
 Bundle-Localization: systembundle
 Bundle-DocUrl: http://www.eclipse.org
 Eclipse-ExtensibleAPI: true
diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/EquinoxConfiguration.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/EquinoxConfiguration.java
index e2899c4..4fc0480 100644
--- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/EquinoxConfiguration.java
+++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/EquinoxConfiguration.java
@@ -209,6 +209,9 @@
 	public static final Collection<String> PROP_WITH_ECLIPSE_STARTER_DEFAULTS = Collections.singletonList(PROP_COMPATIBILITY_BOOTDELEGATION);
 	public static final String PROP_INIT_UUID = "equinox.init.uuid"; //$NON-NLS-1$
 
+	public static final String PROP_ACTIVE_THREAD_TYPE = "osgi.framework.activeThreadType"; //$NON-NLS-1$
+	public static final String ACTIVE_THREAD_TYPE_NORMAL = "normal"; //$NON-NLS-1$
+
 	public static final class ConfigValues {
 		/**
 		 * Value of {@link #localConfig} properties that should be considered
diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/EquinoxContainer.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/EquinoxContainer.java
index def3ffd..87011f3 100644
--- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/EquinoxContainer.java
+++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/EquinoxContainer.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2012, 2015 IBM Corporation and others.
+ * Copyright (c) 2012, 2016 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -272,8 +272,13 @@
 
 	@Override
 	public Thread newThread(Runnable r) {
+		String type = equinoxConfig.getConfiguration(EquinoxConfiguration.PROP_ACTIVE_THREAD_TYPE, EquinoxConfiguration.ACTIVE_THREAD_TYPE_NORMAL);
 		Thread t = new Thread(r, "Active Thread: " + toString()); //$NON-NLS-1$
-		t.setDaemon(false);
+		if (EquinoxConfiguration.ACTIVE_THREAD_TYPE_NORMAL.equals(type)) {
+			t.setDaemon(false);
+		} else {
+			t.setDaemon(true);
+		}
 		t.setPriority(Thread.NORM_PRIORITY);
 		return t;
 	}
diff --git a/bundles/org.eclipse.osgi/pom.xml b/bundles/org.eclipse.osgi/pom.xml
index c0ca22c..b2c24bc 100644
--- a/bundles/org.eclipse.osgi/pom.xml
+++ b/bundles/org.eclipse.osgi/pom.xml
@@ -19,7 +19,7 @@
   </parent>
   <groupId>org.eclipse.osgi</groupId>
   <artifactId>org.eclipse.osgi</artifactId>
-  <version>3.11.1-SNAPSHOT</version>
+  <version>3.11.2-SNAPSHOT</version>
   <packaging>eclipse-plugin</packaging>
 
   <build>