Bug 510673 - Set ds.delayed.keepInstances true by default

This is done in code and as a p2 instruction.  The p2 instruction is a
safe guard when provisioned with p2 so that we ensure the property is
set in the config.ini such that it will be enabled at boot with no
chance of being missed by felix SCR if it happens to start before
equinox.ds.

Change-Id: I66dbec7b33b14bbc85e8d8d64d71e930106c415e
Signed-off-by: Thomas Watson <tjwatson@us.ibm.com>
diff --git a/bundles/org.eclipse.equinox.ds/META-INF/p2.inf b/bundles/org.eclipse.equinox.ds/META-INF/p2.inf
index 2d407fa..9dd8bfe 100644
--- a/bundles/org.eclipse.equinox.ds/META-INF/p2.inf
+++ b/bundles/org.eclipse.equinox.ds/META-INF/p2.inf
@@ -1,7 +1,9 @@
 instructions.configure=\
-  setProgramProperty(propName:equinox.use.ds, propValue:true);
+  setProgramProperty(propName:equinox.use.ds, propValue:true);\
+  setProgramProperty(propName:ds.delayed.keepInstances, propValue:true);
 instructions.unconfigure=\
-  setProgramProperty(propName:equinox.use.ds, propValue:);
+  setProgramProperty(propName:equinox.use.ds, propValue:);\
+  setProgramProperty(propName:ds.delayed.keepInstances, propValue:);
 provides.0.namespace = osgi.extender
 provides.0.name = osgi.component
 provides.0.version = 1.2
\ No newline at end of file
diff --git a/bundles/org.eclipse.equinox.ds/src/org/eclipse/equinox/internal/ds/Activator.java b/bundles/org.eclipse.equinox.ds/src/org/eclipse/equinox/internal/ds/Activator.java
index d163ebd..6c8e325 100644
--- a/bundles/org.eclipse.equinox.ds/src/org/eclipse/equinox/internal/ds/Activator.java
+++ b/bundles/org.eclipse.equinox.ds/src/org/eclipse/equinox/internal/ds/Activator.java
@@ -20,6 +20,8 @@
 
 public class Activator implements BundleActivator {
 
+	private Bundle scr;
+
 	public void start(BundleContext context) throws Exception {
 		ServiceReference<EnvironmentInfo> envInfoRef = context.getServiceReference(EnvironmentInfo.class);
 		EnvironmentInfo envInfo = null;
@@ -27,9 +29,11 @@
 			envInfo = context.getService(envInfoRef);
 		}
 		if (envInfo != null) {
+			envInfo.setProperty("ds.delayed.keepInstances", "true"); //$NON-NLS-1$//$NON-NLS-2$
 			envInfo.setProperty("equinox.use.ds", "true"); //$NON-NLS-1$//$NON-NLS-2$
 			context.ungetService(envInfoRef);
 		} else {
+			System.setProperty("ds.delayed.keepInstances", "true"); //$NON-NLS-1$//$NON-NLS-2$
 			System.setProperty("equinox.use.ds", "true"); //$NON-NLS-1$ //$NON-NLS-2$
 		}
 
@@ -38,18 +42,18 @@
 		if (required.isEmpty()) {
 			throw new IllegalStateException("No org.apache.felix.scr bundle found!"); //$NON-NLS-1$
 		}
-		Bundle scr = required.get(0).getProvider().getBundle();
+		scr = required.get(0).getProvider().getBundle();
 		if (!"org.apache.felix.scr".equals(scr.getSymbolicName())) { //$NON-NLS-1$
 			throw new IllegalStateException("Required wrong bundle: " + scr); //$NON-NLS-1$
 		}
 		BundleStartLevel equinoxSDstartLevel = context.getBundle().adapt(BundleStartLevel.class);
 		BundleStartLevel scrStartLevel = scr.adapt(BundleStartLevel.class);
 		scrStartLevel.setStartLevel(equinoxSDstartLevel.getStartLevel());
-		scr.start();
+		scr.start(Bundle.START_TRANSIENT);
 	}
 
 	public void stop(BundleContext context) throws Exception {
-		// do nothing; just keep scr persistently started
+		scr.stop(Bundle.STOP_TRANSIENT);
 	}
 
 }