Bug 439333 - Java 8 Support with Eclipse target older than Luna

https://bugs.eclipse.org/bugs/show_bug.cgi?id=439333
diff --git a/org.eclipse.scout.sdk.compatibility/src/org/eclipse/scout/sdk/compatibility/PlatformVersionUtility.java b/org.eclipse.scout.sdk.compatibility/src/org/eclipse/scout/sdk/compatibility/PlatformVersionUtility.java
index d7a0657..64bf352 100644
--- a/org.eclipse.scout.sdk.compatibility/src/org/eclipse/scout/sdk/compatibility/PlatformVersionUtility.java
+++ b/org.eclipse.scout.sdk.compatibility/src/org/eclipse/scout/sdk/compatibility/PlatformVersionUtility.java
@@ -43,6 +43,10 @@
     return (v.getMajor() == 3 && v.getMinor() == 8) || (v.getMajor() == 4 && v.getMinor() >= 2);
   }
 
+  public static boolean isLunaOrLater(Version v) {
+    return (v.getMajor() == 4 && v.getMinor() >= 4) || v.getMajor() > 4;
+  }
+
   public static boolean isJuno() {
     return isJuno(getPlatformVersion());
   }
diff --git a/org.eclipse.scout.sdk.util/src/org/eclipse/scout/sdk/util/jdt/JdtUtility.java b/org.eclipse.scout.sdk.util/src/org/eclipse/scout/sdk/util/jdt/JdtUtility.java
index 0041c09..540f80c 100644
--- a/org.eclipse.scout.sdk.util/src/org/eclipse/scout/sdk/util/jdt/JdtUtility.java
+++ b/org.eclipse.scout.sdk.util/src/org/eclipse/scout/sdk/util/jdt/JdtUtility.java
@@ -92,7 +92,18 @@
     return null;
   }
 
-  public static String getDefaultJvmExecutionEnvironment() {
+  /**
+   * Gets the default execution environment (e.g. "JavaSE-1.8") supported in the current default JVMs and the given
+   * target platform.<br>
+   * Use {@link #getExecEnvVersion(String)} to parse the execution environment to a double.
+   *
+   * @param targetPlatformVersion
+   *          The target platform to which the execution environment must be compatible.
+   * @return A string like "JavaSE-1.8" with the latest version supported in the current default JVMs and the given
+   *         target platform.
+   * @see #getExecEnvVersion(String)
+   */
+  public static String getDefaultJvmExecutionEnvironment(Version targetPlatformVersion) {
     // defaults
     String execEnv = EXEC_ENV_PREFIX + MIN_JVM_VERSION;
     double execEnvVersion = getExecEnvVersion(execEnv);
@@ -104,7 +115,19 @@
         if (env.isStrictlyCompatible(defaultVm)) {
           double envVersion = getExecEnvVersion(executionEnvId);
           if (envVersion > execEnvVersion) {
-            execEnv = executionEnvId; // take the newest
+            if (envVersion < 1.8) {
+              execEnv = executionEnvId; // take the newest supported (1.6 and 1.7 are supported on all platforms)
+            }
+            else if (envVersion == 1.8) {
+              // 1.8 is only supported on Luna or later platforms
+              if (PlatformVersionUtility.isLunaOrLater(targetPlatformVersion)) {
+                execEnv = executionEnvId; // take the newest
+              }
+              else {
+                // it is a JRE 1.8 but an eclipse older than Luna: reduce to 1.7 level
+                execEnv = EXEC_ENV_PREFIX + "1.7";
+              }
+            }
           }
         }
       }
@@ -112,6 +135,14 @@
     return execEnv;
   }
 
+  /**
+   * Takes an java execution environment (e.g. "JavaSE-1.8") and parses the version as double (in this example 1.8).<br>
+   * If an invalid value is passed, always 1.6 is returned as minimal version.
+   *
+   * @param executionEnvId
+   *          The execution environment to parse.
+   * @return The version as double.
+   */
   public static double getExecEnvVersion(String executionEnvId) {
     if (executionEnvId != null && executionEnvId.startsWith(EXEC_ENV_PREFIX)) {
       String numPart = executionEnvId.substring(EXEC_ENV_PREFIX.length());
@@ -183,7 +214,7 @@
    * converts the given string into a string literal with leading and ending double-quotes including escaping of the
    * given string.<br>
    * this is the inverse function of {@link JdtUtility#fromStringLiteral(String)}
-   * 
+   *
    * @param s
    *          the string to convert.
    * @return the literal string ready to be directly inserted into java source or null if the input string is null.
@@ -254,7 +285,7 @@
   /**
    * converts the given input string literal into the representing original string.<br>
    * this is the inverse function of {@link JdtUtility#toStringLiteral(String)}
-   * 
+   *
    * @param l
    *          the literal with leading and ending double-quotes
    * @return the original (un-escaped) string. if it is no valid literal string, null is returned.
@@ -434,7 +465,7 @@
 
   /**
    * checks whether all of the given plugins are installed in the current platform
-   * 
+   *
    * @param pluginIds
    *          the plugin Ids to search
    * @return true if every plugin passed exists in the given platform, false otherwise. If an empty or null list is
@@ -456,7 +487,7 @@
   /**
    * Gets the newest (highest version) bundle with the given symbolic name that can be found in the active target
    * platform.
-   * 
+   *
    * @param symbolicName
    *          the symbolic name of the bundles to check.
    * @return The newest bundle having the given symbolic name or null if no bundle with the given name can be
diff --git a/org.eclipse.scout.sdk/src/org/eclipse/scout/sdk/operation/library/LibraryBundleCreateOperation.java b/org.eclipse.scout.sdk/src/org/eclipse/scout/sdk/operation/library/LibraryBundleCreateOperation.java
index 24fac0a..aaef993 100644
--- a/org.eclipse.scout.sdk/src/org/eclipse/scout/sdk/operation/library/LibraryBundleCreateOperation.java
+++ b/org.eclipse.scout.sdk/src/org/eclipse/scout/sdk/operation/library/LibraryBundleCreateOperation.java
@@ -151,7 +151,7 @@
     if (getFragmentHost() != null) {
       manifest.setEntryValue("Fragment-Host", getFragmentHost());
     }
-    manifest.setEntryValue("Bundle-RequiredExecutionEnvironment", JdtUtility.getDefaultJvmExecutionEnvironment());
+    manifest.setEntryValue("Bundle-RequiredExecutionEnvironment", JdtUtility.getDefaultJvmExecutionEnvironment(JdtUtility.getTargetPlatformVersion()));
   }
 
   private void collectPackages(IProject project, Collection<IPackageFragment> collector) throws JavaModelException {
diff --git a/org.eclipse.scout.sdk/src/org/eclipse/scout/sdk/operation/project/ScoutProjectNewOperation.java b/org.eclipse.scout.sdk/src/org/eclipse/scout/sdk/operation/project/ScoutProjectNewOperation.java
index 96604eb..ca084f6 100644
--- a/org.eclipse.scout.sdk/src/org/eclipse/scout/sdk/operation/project/ScoutProjectNewOperation.java
+++ b/org.eclipse.scout.sdk/src/org/eclipse/scout/sdk/operation/project/ScoutProjectNewOperation.java
@@ -154,7 +154,7 @@
   }
 
   protected String computeExecutionEnvironment() {
-    return JdtUtility.getDefaultJvmExecutionEnvironment();
+    return JdtUtility.getDefaultJvmExecutionEnvironment(getTargetPlatformVersion());
   }
 
   protected void putInitialProperties() {
diff --git a/org.eclipse.scout.sdk/templates/ui.swing/products/development/app-client-dev.product b/org.eclipse.scout.sdk/templates/ui.swing/products/development/app-client-dev.product
index 59af562..2b34b18 100644
--- a/org.eclipse.scout.sdk/templates/ui.swing/products/development/app-client-dev.product
+++ b/org.eclipse.scout.sdk/templates/ui.swing/products/development/app-client-dev.product
@@ -50,6 +50,7 @@
       <plugin id="org.eclipse.scout.rt.shared"/>
       <plugin id="org.eclipse.scout.rt.servicetunnel"/>
       <plugin id="org.eclipse.scout.rt.ui.swing"/>
+      <plugin id="org.eclipse.scout.rt.ui.swing.browser.swt.fragment" fragment="true"/>
       <plugin id="org.eclipse.scout.service"/>
       <plugin id="org.eclipse.scout.svg.client"/>
       <plugin id="org.eclipse.scout.svg.ui.swing"/>
diff --git a/org.eclipse.scout.sdk/templates/ui.swing/products/production/app-client.product b/org.eclipse.scout.sdk/templates/ui.swing/products/production/app-client.product
index 6cf9ea5..cc8911c 100644
--- a/org.eclipse.scout.sdk/templates/ui.swing/products/production/app-client.product
+++ b/org.eclipse.scout.sdk/templates/ui.swing/products/production/app-client.product
@@ -50,6 +50,7 @@
       <plugin id="org.eclipse.scout.rt.shared"/>
       <plugin id="org.eclipse.scout.rt.servicetunnel"/>
       <plugin id="org.eclipse.scout.rt.ui.swing"/>
+      <plugin id="org.eclipse.scout.rt.ui.swing.browser.swt.fragment" fragment="true"/>
       <plugin id="org.eclipse.scout.service"/>
       <plugin id="org.eclipse.scout.svg.client"/>
       <plugin id="org.eclipse.scout.svg.ui.swing"/>