Bug 498044 - [1.9] Adapt JEP 261 changes to support new options

Change-Id: I0c50f7ef1c07234b5ca83b0b02482a911c88136e
diff --git a/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/debug/ui/launchConfigurations/JavaDependenciesTab.java b/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/debug/ui/launchConfigurations/JavaDependenciesTab.java
index a71148c..c462d30 100644
--- a/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/debug/ui/launchConfigurations/JavaDependenciesTab.java
+++ b/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/debug/ui/launchConfigurations/JavaDependenciesTab.java
@@ -66,6 +66,7 @@
 import org.eclipse.swt.layout.GridData;
 import org.eclipse.swt.layout.GridLayout;
 import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Combo;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Label;
 import org.eclipse.ui.PlatformUI;
@@ -85,6 +86,11 @@
  */
 public class JavaDependenciesTab extends JavaClasspathTab {
 
+	private static final String NO_ADDED_MODULES = "---"; //$NON-NLS-1$
+
+	private static final String[] SPECIAL_ADD_MODULE_OPTIONS = new String[] { NO_ADDED_MODULES, //
+			"ALL-DEFAULT", "ALL-SYSTEM", "ALL-MODULE-PATH" }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+
 	private DependencyModel fModel;
 
 	protected static final String DIALOG_SETTINGS_PREFIX = "JavaDependenciesTab"; //$NON-NLS-1$
@@ -96,6 +102,8 @@
 
 	private Button fExcludeTestCodeButton;
 
+	private Combo fAddModulesBox;
+
 	/**
 	 * Constructor
 	 */
@@ -154,6 +162,17 @@
 				updateLaunchConfigurationDialog();
 			}
 		});
+
+		Composite addModComp = SWTFactory.createComposite(comp, 2, 1, SWT.HORIZONTAL);
+		SWTFactory.createLabel(addModComp, LauncherMessages.JavaDependenciesTab_add_modules_label, 1);
+		fAddModulesBox = SWTFactory.createCombo(addModComp, SWT.READ_ONLY, 1, SPECIAL_ADD_MODULE_OPTIONS);
+		fAddModulesBox.addSelectionListener(new SelectionAdapter() {
+			@Override
+			public void widgetSelected(SelectionEvent e) {
+				setDirty(true);
+				getLaunchConfigurationDialog().updateButtons();
+			}
+		});
 	}
 
 	/**
@@ -231,6 +250,7 @@
 		fClasspathViewer.getTreeViewer().expandToLevel(2);
 		try {
 			fExcludeTestCodeButton.setSelection(configuration.getAttribute(IJavaLaunchConfigurationConstants.ATTR_EXCLUDE_TEST_CODE, false));
+			fAddModulesBox.setText(configuration.getAttribute(IJavaLaunchConfigurationConstants.ATTR_SPECIAL_ADD_MODULES, NO_ADDED_MODULES));
 		} catch (CoreException e) {
 		}
 	}
@@ -330,6 +350,12 @@
 					configuration.setAttribute(IJavaLaunchConfigurationConstants.ATTR_EXCLUDE_TEST_CODE, fExcludeTestCodeButton.getSelection());
 					fClasspathViewer.setEntries(JavaRuntime.computeUnresolvedRuntimeClasspath(configuration));
 				}
+				String add = fAddModulesBox.getText();
+				if (add.equals(NO_ADDED_MODULES)) {
+					configuration.removeAttribute(IJavaLaunchConfigurationConstants.ATTR_SPECIAL_ADD_MODULES);
+				} else {
+					configuration.setAttribute(IJavaLaunchConfigurationConstants.ATTR_SPECIAL_ADD_MODULES, add);
+				}
 			}
 			catch (CoreException e) {
 				JDIDebugUIPlugin.statusDialog(LauncherMessages.JavaClasspathTab_Unable_to_save_classpath_1, e.getStatus());
diff --git a/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/launcher/LauncherMessages.java b/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/launcher/LauncherMessages.java
index 85f2885..339bade 100644
--- a/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/launcher/LauncherMessages.java
+++ b/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/launcher/LauncherMessages.java
@@ -119,6 +119,7 @@
 
 	public static String JavaDependenciesTab_0;
 	public static String JavaDependenciesTab_Dependencies_3;
+	public static String JavaDependenciesTab_add_modules_label;
 
 	public static String JavaSourceLookupTab_Source_1;
 
diff --git a/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/launcher/LauncherMessages.properties b/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/launcher/LauncherMessages.properties
index 08691e3..2116d33 100644
--- a/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/launcher/LauncherMessages.properties
+++ b/org.eclipse.jdt.debug.ui/ui/org/eclipse/jdt/internal/debug/ui/launcher/LauncherMessages.properties
@@ -112,6 +112,7 @@
 
 JavaDependenciesTab_0=De&pendencies
 JavaDependenciesTab_Dependencies_3=Dependencies
+JavaDependenciesTab_add_modules_label=Add mod&ules:
 
 JavaSourceLookupTab_Source_1=Source
 
diff --git a/org.eclipse.jdt.launching/META-INF/MANIFEST.MF b/org.eclipse.jdt.launching/META-INF/MANIFEST.MF
index 0d9c312..a61e556 100644
--- a/org.eclipse.jdt.launching/META-INF/MANIFEST.MF
+++ b/org.eclipse.jdt.launching/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@
 Bundle-ManifestVersion: 2
 Bundle-Name: %pluginName
 Bundle-SymbolicName: org.eclipse.jdt.launching; singleton:=true
-Bundle-Version: 3.15.100.qualifier
+Bundle-Version: 3.16.0.qualifier
 Bundle-Activator: org.eclipse.jdt.internal.launching.LaunchingPlugin
 Bundle-Vendor: %providerName
 Bundle-Localization: plugin
diff --git a/org.eclipse.jdt.launching/launching/org/eclipse/jdt/launching/AbstractJavaLaunchConfigurationDelegate.java b/org.eclipse.jdt.launching/launching/org/eclipse/jdt/launching/AbstractJavaLaunchConfigurationDelegate.java
index eb3e28d..bdb2880 100644
--- a/org.eclipse.jdt.launching/launching/org/eclipse/jdt/launching/AbstractJavaLaunchConfigurationDelegate.java
+++ b/org.eclipse.jdt.launching/launching/org/eclipse/jdt/launching/AbstractJavaLaunchConfigurationDelegate.java
@@ -1190,7 +1190,8 @@
 				}
 			}
 		}
-		if (moduleToLocations.isEmpty()) {
+		String addModules = configuration.getAttribute(IJavaLaunchConfigurationConstants.ATTR_SPECIAL_ADD_MODULES, ""); //$NON-NLS-1$
+		if (moduleToLocations.isEmpty() && addModules.isEmpty()) {
 			return moduleCLIOptions;
 		}
 
@@ -1214,6 +1215,10 @@
 				}
 			}
 		}
+		if (!addModules.isEmpty()) {
+			list.add("--add-modules"); //$NON-NLS-1$
+			list.add(addModules);
+		}
 		return DebugPlugin.renderArguments(list.toArray(new String[list.size()]), null);
 	}
 
diff --git a/org.eclipse.jdt.launching/launching/org/eclipse/jdt/launching/IJavaLaunchConfigurationConstants.java b/org.eclipse.jdt.launching/launching/org/eclipse/jdt/launching/IJavaLaunchConfigurationConstants.java
index edba00b..48d6b48 100644
--- a/org.eclipse.jdt.launching/launching/org/eclipse/jdt/launching/IJavaLaunchConfigurationConstants.java
+++ b/org.eclipse.jdt.launching/launching/org/eclipse/jdt/launching/IJavaLaunchConfigurationConstants.java
@@ -372,6 +372,15 @@
 	public static final String ATTR_EXCLUDE_TEST_CODE = LaunchingPlugin.getUniqueIdentifier() + ".ATTR_EXCLUDE_TEST_CODE"; //$NON-NLS-1$
 
 	/**
+	 * Launch configuration attribute key. When set, the JPMS option {@code --add-modules} will be added to the command line with the provided string
+	 * value as the option's argument. This attribute is specifically designed to support the special arguments "ALL-DEFAULT", "ALL-SYSTEM", and
+	 * "ALL-MODULE-PATH".
+	 *
+	 * @since 3.16
+	 */
+	public static final String ATTR_SPECIAL_ADD_MODULES = LaunchingPlugin.getUniqueIdentifier() + ".ATTR_SPECIAL_ADD_MODULES"; //$NON-NLS-1$
+
+	/**
 	 * @since 3.11
 	 */
 	public static final String ATTR_USE_CLASSPATH_ONLY_JAR = LaunchingPlugin.getUniqueIdentifier() + ".ATTR_USE_CLASSPATH_ONLY_JAR"; //$NON-NLS-1$
diff --git a/org.eclipse.jdt.launching/pom.xml b/org.eclipse.jdt.launching/pom.xml
index e09d4a0..cd4db65 100644
--- a/org.eclipse.jdt.launching/pom.xml
+++ b/org.eclipse.jdt.launching/pom.xml
@@ -18,7 +18,7 @@
   </parent>
   <groupId>org.eclipse.jdt</groupId>
   <artifactId>org.eclipse.jdt.launching</artifactId>
-  <version>3.15.100-SNAPSHOT</version>
+  <version>3.16.0-SNAPSHOT</version>
   <packaging>eclipse-plugin</packaging>
   
   <build>