Skip to content

Commit 7b0f776

Browse files
committed
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 : eclipse-platform#2245
1 parent ebbc32d commit 7b0f776

File tree

2 files changed

+60
-1
lines changed

2 files changed

+60
-1
lines changed

bundles/org.eclipse.ui.ide.application/src/org/eclipse/ui/internal/ide/application/IDEWorkbenchAdvisor.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ public void initialize(IWorkbenchConfigurer configurer) {
226226
jfaceComparatorIsSet = true;
227227
}
228228

229-
if (!Platform.inDevelopmentMode()) {
229+
if (!Platform.inDevelopmentMode() && !JUnitTestUtil.isJunitTestRunning()) {
230230
new AutoRegisterSchemeHandlersJob().schedule();
231231
}
232232
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2024 SAP SE.
3+
*
4+
* This program and the accompanying materials
5+
* are made available under the terms of the Eclipse Public License 2.0
6+
* which accompanies this distribution, and is available at
7+
* https://www.eclipse.org/legal/epl-2.0/
8+
*
9+
* SPDX-License-Identifier: EPL-2.0
10+
*
11+
* Contributors:
12+
* Matthias Becker / Sebastian Ratz - initial API and implementation
13+
*******************************************************************************/
14+
package org.eclipse.ui.internal.ide.application;
15+
16+
import java.util.Set;
17+
import java.util.concurrent.atomic.AtomicBoolean;
18+
19+
import org.eclipse.core.runtime.Platform;
20+
import org.eclipse.core.runtime.ServiceCaller;
21+
import org.eclipse.osgi.service.environment.EnvironmentInfo;
22+
23+
public class JUnitTestUtil {
24+
private static Boolean cachedIsJunitTestRunning = null;
25+
26+
public static boolean isJunitTestRunning() {
27+
if (cachedIsJunitTestRunning == null) {
28+
try {
29+
if (Platform.isRunning()) {
30+
AtomicBoolean result = new AtomicBoolean();
31+
cachedIsJunitTestRunning = ServiceCaller.callOnce(JUnitTestUtil.class, EnvironmentInfo.class, envInfo -> {
32+
String application = envInfo.getProperty("eclipse.application"); //$NON-NLS-1$
33+
result.set(application != null && Set.of( //
34+
// see org.eclipse.pde.internal.launching.IPDEConstants
35+
"org.eclipse.pde.junit.runtime.nonuithreadtestapplication", // //$NON-NLS-1$
36+
"org.eclipse.pde.junit.runtime.uitestapplication", // //$NON-NLS-1$
37+
"org.eclipse.pde.junit.runtime.coretestapplication", // //$NON-NLS-1$
38+
// bundle "org.eclipse.test" (Platform tests)
39+
"org.eclipse.test.uitestapplication", //$NON-NLS-1$
40+
"org.eclipse.test.coretestapplication", // //$NON-NLS-1$
41+
// see org.eclipse.tycho.surefire.AbstractTestMojo
42+
"org.eclipse.tycho.surefire.osgibooter.uitest", //$NON-NLS-1$
43+
"org.eclipse.tycho.surefire.osgibooter.headlesstest") // //$NON-NLS-1$
44+
.contains(application));
45+
});
46+
cachedIsJunitTestRunning = result.get();
47+
} else {
48+
cachedIsJunitTestRunning = true; // probably
49+
}
50+
} catch (Throwable t) {
51+
// log
52+
cachedIsJunitTestRunning = false;
53+
}
54+
}
55+
56+
return cachedIsJunitTestRunning;
57+
}
58+
59+
}

0 commit comments

Comments
 (0)