Bug 475708 - [quick fix] The "not a perfect match" problem should get a
quick fix to change the BREE

Change-Id: I32023531ffec333c8c0e45520b1d1c51f7684bc3
Signed-off-by: Vikas Chandra <Vikas.Chandra@in.ibm.com>
diff --git a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/builders/BundleErrorReporter.java b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/builders/BundleErrorReporter.java
index f28739b..bec7641 100644
--- a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/builders/BundleErrorReporter.java
+++ b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/builders/BundleErrorReporter.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2000, 2020 IBM Corporation and others.
+ * Copyright (c) 2000, 2021 IBM Corporation and others.
  *
  * This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License 2.0
@@ -53,6 +53,7 @@
 import org.eclipse.jdt.launching.IVMInstall;
 import org.eclipse.jdt.launching.JavaRuntime;
 import org.eclipse.jdt.launching.environments.IExecutionEnvironment;
+import org.eclipse.jdt.launching.environments.IExecutionEnvironmentsManager;
 import org.eclipse.osgi.service.resolver.BundleDescription;
 import org.eclipse.osgi.service.resolver.BundleSpecification;
 import org.eclipse.osgi.service.resolver.ExportPackageDescription;
@@ -639,8 +640,19 @@
 						// Check if the user is using a perfect match JRE
 						IVMInstall vm = JavaRuntime.getVMInstall(currentPath);
 						if (vm == null || !env.isStrictlyCompatible(vm)) {
+							IExecutionEnvironmentsManager manager = JavaRuntime.getExecutionEnvironmentsManager();
+							IExecutionEnvironment[] environments = manager.getExecutionEnvironments();
+							String systemEE =null;
+							for (IExecutionEnvironment environment : environments) {
+								if (environment.isStrictlyCompatible(vm)) {
+									systemEE = environment.getId();
+									break;
+								}
+							}
 							VirtualMarker marker = report(NLS.bind(PDECoreMessages.BundleErrorReporter_reqExecEnv_conflict, bundleEnvs[0]),getLine(header, bundleEnvs[0]), sev, PDEMarkerFactory.M_MISMATCHED_EXEC_ENV,PDEMarkerFactory.CAT_EE);
 							addMarkerAttribute(marker,PDEMarkerFactory.compilerKey,CompilerFlags.P_INCOMPATIBLE_ENV);
+							if(systemEE!=null)
+								addMarkerAttribute(marker, "BREE", systemEE); //$NON-NLS-1$
 						}
 					}
 				}
diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/PDEUIMessages.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/PDEUIMessages.java
index 37bb180..b60a83d 100644
--- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/PDEUIMessages.java
+++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/PDEUIMessages.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2014, 2020 IBM Corporation and others.
+ * Copyright (c) 2014, 2021 IBM Corporation and others.
  *
  * This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License 2.0
@@ -652,6 +652,7 @@
 	public static String TableSection_itemCount;
 
 	public static String UpdateClasspathResolution_label;
+	public static String UpdateExecutionEnvironment_label;
 
 	//
 	// PDE resource strings
diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/correction/ResolutionGenerator.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/correction/ResolutionGenerator.java
index f72334c..e996b52 100644
--- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/correction/ResolutionGenerator.java
+++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/correction/ResolutionGenerator.java
@@ -78,7 +78,9 @@
 			case PDEMarkerFactory.M_DIRECTIVE_HAS_NO_EFFECT :
 				return getRemoveInternalDirectiveResolution(marker);
 			case PDEMarkerFactory.M_MISMATCHED_EXEC_ENV :
-				return new IMarkerResolution[] {new UpdateClasspathResolution(AbstractPDEMarkerResolution.RENAME_TYPE, marker)};
+				return new IMarkerResolution[] {
+						new UpdateClasspathResolution(AbstractPDEMarkerResolution.RENAME_TYPE, marker),
+						new UpdateExecutionEnvironment(AbstractPDEMarkerResolution.RENAME_TYPE, marker) };
 			case PDEMarkerFactory.M_UNKNOW_EXEC_ENV :
 				return new IMarkerResolution[] {
 						new RemoveUnknownExecEnvironments(AbstractPDEMarkerResolution.REMOVE_TYPE, marker) };
diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/correction/UpdateExecutionEnvironment.java b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/correction/UpdateExecutionEnvironment.java
new file mode 100644
index 0000000..72bd654
--- /dev/null
+++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/correction/UpdateExecutionEnvironment.java
@@ -0,0 +1,51 @@
+/*******************************************************************************
+ *  Copyright (c) 2021 IBM Corporation and others.
+ *
+ *  This program and the accompanying materials
+ *  are made available under the terms of the Eclipse Public License 2.0
+ *  which accompanies this distribution, and is available at
+ *  https://www.eclipse.org/legal/epl-2.0/
+ *
+ *  SPDX-License-Identifier: EPL-2.0
+ *
+ *  Contributors:
+ *     IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.pde.internal.ui.correction;
+
+import org.eclipse.core.resources.IMarker;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.pde.internal.core.ibundle.IBundle;
+import org.eclipse.pde.internal.core.text.bundle.Bundle;
+import org.eclipse.pde.internal.core.text.bundle.BundleModel;
+import org.eclipse.pde.internal.ui.PDEUIMessages;
+import org.osgi.framework.Constants;
+
+public class UpdateExecutionEnvironment extends AbstractManifestMarkerResolution {
+
+	public UpdateExecutionEnvironment(int type, IMarker marker) {
+		super(type, marker);
+	}
+
+	@Override
+	public String getLabel() {
+		return PDEUIMessages.UpdateExecutionEnvironment_label;
+	}
+
+	@Override
+	protected void createChange(BundleModel model) {
+		IBundle bundle = model.getBundle();
+		if (bundle instanceof Bundle) {
+			String bree = null;
+			try {
+				bree = (String) marker.getAttribute("BREE"); //$NON-NLS-1$
+			} catch (CoreException e) {
+
+			}
+			if (bree != null)
+				bundle.setHeader(Constants.BUNDLE_REQUIREDEXECUTIONENVIRONMENT, bree);
+
+		}
+	}
+
+}
diff --git a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/pderesources.properties b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/pderesources.properties
index beff0a8..7423005 100644
--- a/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/pderesources.properties
+++ b/ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/pderesources.properties
@@ -1,5 +1,5 @@
 ###############################################################################
-# Copyright (c) 2000, 2020 IBM Corporation and others.
+# Copyright (c) 2000, 2021 IBM Corporation and others.
 #
 # This program and the accompanying materials
 # are made available under the terms of the Eclipse Public License 2.0
@@ -1279,6 +1279,7 @@
 UpdateClasspathJob_error_title = Update Classpaths
 UpdateClasspathJob_error_message = Updating failed. See log for details.
 UpdateClasspathResolution_label=Update the classpath and compliance settings
+UpdateExecutionEnvironment_label=Update the execution environment based on JRE on the classpath
 UpdateClasspathJob_task = Update classpaths...
 UpdateClasspathJob_title = Updating Plug-in Classpaths