Skip to content

Commit

Permalink
[FIXUP] Pass launch mode through instead of setting a global static
Browse files Browse the repository at this point in the history
field
  • Loading branch information
HannesWell committed Jun 30, 2024
1 parent 1076d77 commit 0c36d32
Show file tree
Hide file tree
Showing 10 changed files with 38 additions and 48 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 Down Expand Up @@ -381,21 +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;
}

/**
* @return the last known launch mode
* @see #setLastLaunchMode(String)
*/
public static String getLastLaunchMode() {
return fLastLaunchMode;
}
}
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,7 +428,7 @@ public String[] getProgramArguments(ILaunchConfiguration configuration) throws C
* from the launch configuration
*/
protected void preLaunchCheck(ILaunchConfiguration configuration, ILaunch launch, IProgressMonitor monitor) throws CoreException {
LauncherUtils.setLastLaunchMode(launch.getLaunchMode());
launchMode = launch.getLaunchMode();
String attribute = launch.getAttribute(PDE_LAUNCH_SHOW_COMMAND);
boolean isShowCommand = false;
if (attribute != null) {
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 @@ -465,11 +466,11 @@ protected void manageLaunch(ILaunch launch) {

@Override
protected void preLaunchCheck(ILaunchConfiguration configuration, ILaunch launch, IProgressMonitor monitor) throws CoreException {
LauncherUtils.setLastLaunchMode(launch.getLaunchMode());
fWorkspaceLocation = null;
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 @@ -482,8 +483,9 @@ 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));
clear(configuration, subMonitor.split(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,7 @@
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;
Expand All @@ -30,7 +31,6 @@
import org.eclipse.jface.viewers.ViewerComparator;
import org.eclipse.osgi.service.resolver.BundleDescription;
import org.eclipse.pde.internal.launching.launcher.LaunchValidationOperation;
import org.eclipse.pde.internal.launching.launcher.LauncherUtils;
import org.eclipse.pde.internal.ui.IHelpContextIds;
import org.eclipse.pde.internal.ui.PDEPlugin;
import org.eclipse.pde.internal.ui.PDEUIMessages;
Expand Down Expand Up @@ -94,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 @@ -118,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 @@ -156,14 +158,10 @@ private void createLink(Composite parent) {
// Closing the validation dialog to avoid cyclic dependency
setReturnCode(CANCEL);
close();
ILaunchGroup launchGroup = DebugUITools.getLaunchGroup(fLaunchConfiguration,
LauncherUtils.getLastLaunchMode());
String groupIdentifier = null;
if (launchGroup != null) {
groupIdentifier = launchGroup.getIdentifier();
} else {
groupIdentifier = "org.eclipse.debug.ui.launchGroup.run"; //$NON-NLS-1$
}
ILaunchGroup launchGroup = DebugUITools.getLaunchGroup(fLaunchConfiguration, launchMode);
String groupIdentifier = launchGroup != null //
? launchGroup.getIdentifier()
: IDebugUIConstants.ID_RUN_LAUNCH_GROUP;
DebugUITools.openLaunchConfigurationDialog(Display.getCurrent().getActiveShell(), fLaunchConfiguration,
groupIdentifier, null);
}));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ private int evaluatePort() throws CoreException {
*/
protected void preLaunchCheck(ILaunchConfiguration configuration, ILaunch launch, IProgressMonitor monitor)
throws CoreException {
LauncherUtils.setLastLaunchMode(launch.getLaunchMode());
launchMode = launch.getLaunchMode();
fWorkspaceLocation = null;
fConfigDir = null;
fModels = BundleLauncherHelper.getMergedBundleMap(configuration, false);
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;
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 0c36d32

Please sign in to comment.