Skip to content

Commit

Permalink
Open edit launch dialog using correct mode
Browse files Browse the repository at this point in the history
When a launch fails validation, the user is given a link to Edit Launch
Configuration. Previously, this link always opened the Edit Run
Configurations dialog in Run mode, even if the user initially attempted
to Debug. This change ensures that the edit dialog is opening using the
original mode.

Co-authored-by: Hannes Wellmann <[email protected]>
  • Loading branch information
kysmith-csg and HannesWell committed Jul 8, 2024
1 parent fb24f19 commit 7d8b8f2
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@ public class EclipsePluginValidationOperation extends LaunchValidationOperation
private final Map<Object, Object[]> fExtensionErrors = new HashMap<>(2);

public EclipsePluginValidationOperation(ILaunchConfiguration configuration, Set<IPluginModelBase> models) {
super(configuration, models);
this(configuration, models, null);
}

public EclipsePluginValidationOperation(ILaunchConfiguration configuration, Set<IPluginModelBase> models, String launchMode) {
super(configuration, models, launchMode);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,17 @@ public class LaunchValidationOperation implements IWorkspaceRunnable {

private BundleValidationOperation fOperation;
public final ILaunchConfiguration fLaunchConfiguration;
public final String fLaunchMode;
protected final Set<IPluginModelBase> fModels;

public LaunchValidationOperation(ILaunchConfiguration configuration, Set<IPluginModelBase> models) {
this(configuration, models, null);
}

public LaunchValidationOperation(ILaunchConfiguration configuration, Set<IPluginModelBase> models, String launchMode) {
fLaunchConfiguration = configuration;
fModels = models;
fLaunchMode = launchMode;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.SubMonitor;
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.ILaunch;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
import org.eclipse.debug.core.IStatusHandler;
Expand Down Expand Up @@ -80,11 +79,6 @@ private LauncherUtils() {
private static final String TIMESTAMP = "timestamp"; //$NON-NLS-1$
private static final String FILE_NAME = "dep-timestamp.properties"; //$NON-NLS-1$
private static Properties fLastRun;
/**
* Stores the last known launch mode so status handlers can open the correct launch configuration dialog
* @see LauncherUtils#setLastLaunchMode(String)
*/
private static String fLastLaunchMode;

/**
* Checks if the workspace being launched is already in use or needs to be cleared
Expand All @@ -98,7 +92,7 @@ private LauncherUtils() {
* @throws CoreException
* if unable to retrieve launch attribute values or the clear operation was cancelled
*/
public static void clearWorkspace(ILaunchConfiguration configuration, String workspace, IProgressMonitor monitor) throws CoreException {
public static void clearWorkspace(ILaunchConfiguration configuration, String workspace, String launchMode, IProgressMonitor monitor) throws CoreException {

SubMonitor subMon = SubMonitor.convert(monitor, 100);

Expand Down Expand Up @@ -136,7 +130,7 @@ public static void clearWorkspace(ILaunchConfiguration configuration, String wor
Status status = new Status(IStatus.ERROR, IPDEConstants.PLUGIN_ID, WORKSPACE_LOCKED, null, null);
IStatusHandler statusHandler = DebugPlugin.getDefault().getStatusHandler(status);
if (statusHandler != null)
statusHandler.handleStatus(status, new Object[] {workspace, configuration, fLastLaunchMode});
statusHandler.handleStatus(status, new Object[] {workspace, configuration, launchMode});
throw new CoreException(Status.CANCEL_STATUS);
}

Expand All @@ -156,7 +150,7 @@ public static void clearWorkspace(ILaunchConfiguration configuration, String wor
result = ((Integer) statusHandler.handleStatus(status, workspaceFile.getPath())).intValue();
}

if (result == 2 /*Cancel Button*/|| result == -1 /*Dialog close button*/) {
if (result == 2 /*Cancel Button*/ || result == -1 /*Dialog close button*/) {
throw new CoreException(Status.CANCEL_STATUS);
} else if (result == 0) {
if (configuration.getAttribute(IPDEConstants.DOCLEARLOG, false)) {
Expand Down Expand Up @@ -333,7 +327,7 @@ private static Properties getLastRun() {
File file = new File(getDirectory(), FILE_NAME);
if (file.exists()) {
try (FileInputStream fis = new FileInputStream(file)) {
fLastRun.load(fis);
fLastRun.load(fis);
}
}
} catch (IOException e) {
Expand Down Expand Up @@ -381,13 +375,4 @@ public static boolean clearWorkspaceLog(String workspace) {
return true;
}

/**
* Updates the stores launch mode. This should be called on any PDE Eclipse launch. The launch mode
* is passed to the status handler so it can open the correct launch configuration dialog
*
* @param launchMode last known launch mode, see {@link ILaunch#getLaunchMode()}
*/
public static void setLastLaunchMode(String launchMode) {
fLastLaunchMode = launchMode;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
public class ProductValidationOperation extends LaunchValidationOperation {

public ProductValidationOperation(Set<IPluginModelBase> models) {
super(null, models);
super(null, models, null);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
public abstract class AbstractPDELaunchConfiguration extends LaunchConfigurationDelegate {

protected File fConfigDir = null;
String launchMode;

/**
* This field will control the addition of argument --add-modules=ALL-SYSTEM in the VM arguments
Expand Down Expand Up @@ -427,6 +428,7 @@ public String[] getProgramArguments(ILaunchConfiguration configuration) throws C
* from the launch configuration
*/
protected void preLaunchCheck(ILaunchConfiguration configuration, ILaunch launch, IProgressMonitor monitor) throws CoreException {
launchMode = launch.getLaunchMode();
String attribute = launch.getAttribute(PDE_LAUNCH_SHOW_COMMAND);
boolean isShowCommand = false;
if (attribute != null) {
Expand All @@ -439,7 +441,6 @@ protected void preLaunchCheck(ILaunchConfiguration configuration, ILaunch launch
validatePluginDependencies(configuration, subMonitor.split(10));
}
validateProjectDependencies(configuration, subMonitor.split(10));
LauncherUtils.setLastLaunchMode(launch.getLaunchMode());
clear(configuration, subMonitor.split(10));
}
launch.setAttribute(PDE_LAUNCH_SHOW_COMMAND, "false"); //$NON-NLS-1$
Expand Down Expand Up @@ -556,7 +557,7 @@ protected void clear(ILaunchConfiguration configuration, IProgressMonitor monito
*/
protected void validatePluginDependencies(ILaunchConfiguration configuration, IProgressMonitor monitor) throws CoreException {
Set<IPluginModelBase> models = BundleLauncherHelper.getMergedBundleMap(configuration, false).keySet();
EclipsePluginValidationOperation op = new EclipsePluginValidationOperation(configuration, models);
EclipsePluginValidationOperation op = new EclipsePluginValidationOperation(configuration, models, launchMode);
LaunchPluginValidator.runValidationOperation(op, monitor);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ protected void clear(ILaunchConfiguration configuration, IProgressMonitor monito
}

// Clear workspace and prompt, if necessary
LauncherUtils.clearWorkspace(configuration, fWorkspaceLocation, subMon.split(1));
LauncherUtils.clearWorkspace(configuration, fWorkspaceLocation, launchMode, subMon.split(1));

// clear config area, if necessary
if (configuration.getAttribute(IPDELauncherConstants.CONFIG_CLEAR_AREA, false)) {
Expand Down Expand Up @@ -238,7 +238,7 @@ private void validateConfigIni(ILaunchConfiguration configuration) throws CoreEx

@Override
protected void validatePluginDependencies(ILaunchConfiguration configuration, IProgressMonitor monitor) throws CoreException {
EclipsePluginValidationOperation op = new EclipsePluginValidationOperation(configuration, fModels.keySet());
EclipsePluginValidationOperation op = new EclipsePluginValidationOperation(configuration, fModels.keySet(), launchMode);
LaunchPluginValidator.runValidationOperation(op, monitor);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ protected void preLaunchCheck(ILaunchConfiguration configuration, ILaunch launch

@Override
protected void validatePluginDependencies(ILaunchConfiguration configuration, IProgressMonitor monitor) throws CoreException {
LaunchValidationOperation op = new LaunchValidationOperation(configuration, fModels.keySet());
LaunchValidationOperation op = new LaunchValidationOperation(configuration, fModels.keySet(), launchMode);
LaunchPluginValidator.runValidationOperation(op, monitor);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ public class JUnitLaunchConfigurationDelegate extends org.eclipse.jdt.junit.laun

// key is a model, value is startLevel:autoStart
private Map<IPluginModelBase, String> fModels;
private String launchMode;

private static final String PDE_JUNIT_SHOW_COMMAND = "pde.junit.showcommandline"; //$NON-NLS-1$

Expand Down Expand Up @@ -469,6 +470,7 @@ protected void preLaunchCheck(ILaunchConfiguration configuration, ILaunch launch
fConfigDir = null;
fModels = BundleLauncherHelper.getMergedBundleMap(configuration, false);
fAllBundles = fModels.keySet().stream().collect(Collectors.groupingBy(m -> m.getPluginBase().getId(), LinkedHashMap::new, Collectors.toCollection(ArrayList::new)));
launchMode = launch.getLaunchMode();

// implicitly add the plug-ins required for JUnit testing if necessary
addRequiredJunitRuntimePlugins(configuration);
Expand All @@ -481,10 +483,10 @@ protected void preLaunchCheck(ILaunchConfiguration configuration, ILaunch launch
boolean autoValidate = configuration.getAttribute(IPDELauncherConstants.AUTOMATIC_VALIDATE, false);
SubMonitor subMonitor = SubMonitor.convert(monitor, autoValidate ? 3 : 4);
if (isShowCommand == false) {
if (autoValidate)
if (autoValidate) {
validatePluginDependencies(configuration, subMonitor.split(1));
}
validateProjectDependencies(configuration, subMonitor.split(1));
LauncherUtils.setLastLaunchMode(launch.getLaunchMode());
clear(configuration, subMonitor.split(1));
}
launch.setAttribute(PDE_JUNIT_SHOW_COMMAND, "false"); //$NON-NLS-1$
Expand Down Expand Up @@ -580,7 +582,7 @@ protected void clear(ILaunchConfiguration configuration, IProgressMonitor monito
SubMonitor subMon = SubMonitor.convert(monitor, 50);

// Clear workspace and prompt, if necessary
LauncherUtils.clearWorkspace(configuration, fWorkspaceLocation, subMon.split(25));
LauncherUtils.clearWorkspace(configuration, fWorkspaceLocation, launchMode, subMon.split(25));

subMon.setWorkRemaining(25);

Expand Down Expand Up @@ -615,7 +617,7 @@ protected void validateProjectDependencies(ILaunchConfiguration configuration, I
* a progress monitor
*/
protected void validatePluginDependencies(ILaunchConfiguration configuration, IProgressMonitor monitor) throws CoreException {
EclipsePluginValidationOperation op = new EclipsePluginValidationOperation(configuration, fModels.keySet());
EclipsePluginValidationOperation op = new EclipsePluginValidationOperation(configuration, fModels.keySet(), launchMode);
LaunchPluginValidator.runValidationOperation(op, monitor);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import org.eclipse.core.runtime.MultiStatus;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.ui.DebugUITools;
import org.eclipse.debug.ui.IDebugUIConstants;
import org.eclipse.debug.ui.ILaunchGroup;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.IDialogSettings;
Expand All @@ -45,9 +47,9 @@
import org.eclipse.ui.PlatformUI;

/**
* Dialog that opens when plug-in validation fails during launching. Displays
* a list of problems discovered. Allows the user to continue the launch or
* cancel if @link {@link #showCancelButton(boolean)} is set to true.
* Dialog that opens when plug-in validation fails during launching. Displays a
* list of problems discovered. Allows the user to continue the launch or cancel
* if @link {@link #showCancelButton(boolean)} is set to true.
*/
public class PluginStatusDialog extends TrayDialog {

Expand Down Expand Up @@ -92,6 +94,7 @@ public Object[] getElements(Object inputElement) {
private Map<?, ?> fInput;
private TreeViewer treeViewer;
private ILaunchConfiguration fLaunchConfiguration;
private String launchMode;

public PluginStatusDialog(Shell parentShell, int style) {
super(parentShell);
Expand All @@ -116,6 +119,7 @@ public void showLink(boolean showLink) {
public void setInput(LaunchValidationOperation operation) {
fInput = operation.getInput();
fLaunchConfiguration = operation.fLaunchConfiguration;
launchMode = operation.fLaunchMode;
}

@Override
Expand Down Expand Up @@ -154,8 +158,12 @@ private void createLink(Composite parent) {
// Closing the validation dialog to avoid cyclic dependency
setReturnCode(CANCEL);
close();
ILaunchGroup launchGroup = DebugUITools.getLaunchGroup(fLaunchConfiguration, launchMode);
String groupIdentifier = launchGroup != null //
? launchGroup.getIdentifier()
: IDebugUIConstants.ID_RUN_LAUNCH_GROUP;
DebugUITools.openLaunchConfigurationDialog(Display.getCurrent().getActiveShell(), fLaunchConfiguration,
"org.eclipse.debug.ui.launchGroup.run", null); //$NON-NLS-1$
groupIdentifier, null);
}));
}
}
Expand Down Expand Up @@ -195,12 +203,10 @@ public boolean close() {
return super.close();
}


protected String getDialogSectionName() {
return PDEPlugin.getPluginId() + ".PLUGIN_STATUS_DIALOG"; //$NON-NLS-1$
}


public void refresh(Map<?, ?> input) {
fInput = input;
treeViewer.setInput(input);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,7 @@ private int evaluatePort() throws CoreException {
*/
protected void preLaunchCheck(ILaunchConfiguration configuration, ILaunch launch, IProgressMonitor monitor)
throws CoreException {
launchMode = launch.getLaunchMode();
fWorkspaceLocation = null;
fConfigDir = null;
fModels = BundleLauncherHelper.getMergedBundleMap(configuration, false);
Expand All @@ -377,7 +378,6 @@ protected void preLaunchCheck(ILaunchConfiguration configuration, ILaunch launch
if (autoValidate)
validatePluginDependencies(configuration, subMonitor.split(1));
validateProjectDependencies(configuration, subMonitor.split(1));
LauncherUtils.setLastLaunchMode(launch.getLaunchMode());
clear(configuration, subMonitor.split(1));
}
launch.setAttribute(PDE_JUNIT_SHOW_COMMAND, "false"); //$NON-NLS-1$
Expand Down Expand Up @@ -1013,6 +1013,7 @@ protected void abort(String message, Throwable exception, int code) throws CoreE

// key is a model, value is startLevel:autoStart
private Map<IPluginModelBase, String> fModels;
private String launchMode;

private static final String PDE_JUNIT_SHOW_COMMAND = "pde.junit.showcommandline"; //$NON-NLS-1$

Expand Down Expand Up @@ -1234,7 +1235,7 @@ protected void clear(ILaunchConfiguration configuration, IProgressMonitor monito
SubMonitor subMon = SubMonitor.convert(monitor, 50);

// Clear workspace and prompt, if necessary
LauncherUtils.clearWorkspace(configuration, fWorkspaceLocation, subMon.split(25));
LauncherUtils.clearWorkspace(configuration, fWorkspaceLocation, launchMode, subMon.split(25));

subMon.setWorkRemaining(25);

Expand Down Expand Up @@ -1267,7 +1268,8 @@ protected void validateProjectDependencies(ILaunchConfiguration configuration, I
*/
protected void validatePluginDependencies(ILaunchConfiguration configuration, IProgressMonitor monitor)
throws CoreException {
EclipsePluginValidationOperation op = new EclipsePluginValidationOperation(configuration, fModels.keySet());
EclipsePluginValidationOperation op = new EclipsePluginValidationOperation(configuration, fModels.keySet(),
launchMode);
LaunchPluginValidator.runValidationOperation(op, monitor);
}
}

0 comments on commit 7d8b8f2

Please sign in to comment.