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