From 9a9c831eddc5ab496768bb644bc069d0ea7d3226 Mon Sep 17 00:00:00 2001 From: Hannes Wellmann Date: Wed, 14 Feb 2024 20:12:20 +0100 Subject: [PATCH] Suppress Windows Defender Autofix startup check in test-runtimes Only run the startup check if the running application is 'org.eclipse.ui.ide.workbench', which runs in a usual Eclipse IDE. Requiring this specific app-id prevents the start-up check and consequently a pop-up in test applications launched by PDE or Tycho for OSGi Junit tests or general console applications (that still have the 'o.e.ui.workbench' plugin installed) on Windows. Fixes https://github.com/eclipse-platform/eclipse.platform.ui/issues/1683 --- .../ui/internal/WindowsDefenderConfigurator.java | 13 ++++++++++--- .../ui/internal/dialogs/StartupPreferencePage.java | 2 +- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WindowsDefenderConfigurator.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WindowsDefenderConfigurator.java index 0a13bdd99f8..66e6510d094 100644 --- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WindowsDefenderConfigurator.java +++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WindowsDefenderConfigurator.java @@ -30,6 +30,7 @@ import java.util.concurrent.Future; import java.util.stream.Collectors; import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProduct; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.OperationCanceledException; import org.eclipse.core.runtime.Platform; @@ -83,7 +84,7 @@ public class WindowsDefenderConfigurator implements EventHandler { @Override public void handleEvent(Event event) { - if (isRelevant()) { + if (runStartupCheck()) { Job job = Job.create(WorkbenchMessages.WindowsDefenderConfigurator_statusCheck, m -> { SubMonitor monitor = SubMonitor.convert(m, 10); if (preferences.getBoolean(PI_WORKBENCH, PREFERENCE_SKIP, PREFERENCE_SKIP_DEFAULT, null)) { @@ -105,8 +106,14 @@ public void handleEvent(Event event) { } } - public static boolean isRelevant() { - return Platform.OS_WIN32.equals(Platform.getOS()) && !Platform.inDevelopmentMode(); + private static boolean runStartupCheck() { + if (Platform.isRunning() && Platform.OS.isWindows() && !Platform.inDevelopmentMode()) { + IProduct product = Platform.getProduct(); + if (product != null) { + return "org.eclipse.ui.ide.workbench".equals(product.getApplication()); //$NON-NLS-1$ + } + } + return false; } /** diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/dialogs/StartupPreferencePage.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/dialogs/StartupPreferencePage.java index 7cfadab3249..a8eaf4329e3 100644 --- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/dialogs/StartupPreferencePage.java +++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/dialogs/StartupPreferencePage.java @@ -92,7 +92,7 @@ protected Control createContents(Composite parent) { } protected void createExtraContent(Composite composite) { - if (WindowsDefenderConfigurator.isRelevant()) { + if (Platform.OS.isWindows()) { new Label(composite, SWT.NONE); // add spacer GridDataFactory grapHorizontalSpace = GridDataFactory.swtDefaults().align(SWT.FILL, SWT.BEGINNING)