From 2afdb236108ecb591566ddac66379b9cf9841696 Mon Sep 17 00:00:00 2001 From: Matthias Becker Date: Fri, 20 Sep 2024 14:02:25 +0200 Subject: [PATCH] Don't run the automatic registration during test execution If the IDE is running because we are executing automated tests it doesn't make sense to run this registration job. Fixes : https://github.com/eclipse-platform/eclipse.platform.ui/issues/2245 --- .../ide/application/IDEWorkbenchAdvisor.java | 2 +- .../ide/application/JUnitTestUtil.java | 59 +++++++++++++++++++ 2 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 bundles/org.eclipse.ui.ide.application/src/org/eclipse/ui/internal/ide/application/JUnitTestUtil.java diff --git a/bundles/org.eclipse.ui.ide.application/src/org/eclipse/ui/internal/ide/application/IDEWorkbenchAdvisor.java b/bundles/org.eclipse.ui.ide.application/src/org/eclipse/ui/internal/ide/application/IDEWorkbenchAdvisor.java index 9052cfa1563..ceda5e16222 100644 --- a/bundles/org.eclipse.ui.ide.application/src/org/eclipse/ui/internal/ide/application/IDEWorkbenchAdvisor.java +++ b/bundles/org.eclipse.ui.ide.application/src/org/eclipse/ui/internal/ide/application/IDEWorkbenchAdvisor.java @@ -226,7 +226,7 @@ public void initialize(IWorkbenchConfigurer configurer) { jfaceComparatorIsSet = true; } - if (!Platform.inDevelopmentMode()) { + if (!Platform.inDevelopmentMode() && !JUnitTestUtil.isJunitTestRunning()) { new AutoRegisterSchemeHandlersJob().schedule(); } } diff --git a/bundles/org.eclipse.ui.ide.application/src/org/eclipse/ui/internal/ide/application/JUnitTestUtil.java b/bundles/org.eclipse.ui.ide.application/src/org/eclipse/ui/internal/ide/application/JUnitTestUtil.java new file mode 100644 index 00000000000..df055af922b --- /dev/null +++ b/bundles/org.eclipse.ui.ide.application/src/org/eclipse/ui/internal/ide/application/JUnitTestUtil.java @@ -0,0 +1,59 @@ +/******************************************************************************* + * Copyright (c) 2024 SAP SE. + * + * 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: + * Matthias Becker / Sebastian Ratz - initial API and implementation + *******************************************************************************/ +package org.eclipse.ui.internal.ide.application; + +import java.util.Set; +import java.util.concurrent.atomic.AtomicBoolean; + +import org.eclipse.core.runtime.Platform; +import org.eclipse.core.runtime.ServiceCaller; +import org.eclipse.osgi.service.environment.EnvironmentInfo; + +public class JUnitTestUtil { + private static Boolean cachedIsJunitTestRunning = null; + + public static boolean isJunitTestRunning() { + if (cachedIsJunitTestRunning == null) { + try { + if (Platform.isRunning()) { + AtomicBoolean result = new AtomicBoolean(); + cachedIsJunitTestRunning = ServiceCaller.callOnce(JUnitTestUtil.class, EnvironmentInfo.class, envInfo -> { + String application = envInfo.getProperty("eclipse.application"); //$NON-NLS-1$ + result.set(application != null && Set.of( // + // see org.eclipse.pde.internal.launching.IPDEConstants + "org.eclipse.pde.junit.runtime.nonuithreadtestapplication", // //$NON-NLS-1$ + "org.eclipse.pde.junit.runtime.uitestapplication", // //$NON-NLS-1$ + "org.eclipse.pde.junit.runtime.coretestapplication", // //$NON-NLS-1$ + // bundle "org.eclipse.test" (Platform tests) + "org.eclipse.test.uitestapplication", //$NON-NLS-1$ + "org.eclipse.test.coretestapplication", // //$NON-NLS-1$ + // see org.eclipse.tycho.surefire.AbstractTestMojo + "org.eclipse.tycho.surefire.osgibooter.uitest", //$NON-NLS-1$ + "org.eclipse.tycho.surefire.osgibooter.headlesstest") // //$NON-NLS-1$ + .contains(application)); + }); + cachedIsJunitTestRunning = result.get(); + } else { + cachedIsJunitTestRunning = true; // probably + } + } catch (Throwable t) { + // log + cachedIsJunitTestRunning = false; + } + } + + return cachedIsJunitTestRunning; + } + +} \ No newline at end of file