From 6904f06d51bf76c99694d9c27b6a9168837db6b1 Mon Sep 17 00:00:00 2001 From: Heiko Klare Date: Tue, 30 Dec 2025 21:58:28 +0100 Subject: [PATCH] Remove inheritance hierarchy from Ant UI performance tests Ant UI tests use an inheritance hierarchy for sharing configuration and utility methods. This leads to duplications of performance test functionality and unnecessary classes for sharing utilities. This change removes the AbstractAntUIBuildPerformanceTest and AbstractAntPerformanceTest classes by reusing the PerformanceTestCaseJunit5 and integrating the remaining functionality into the single concrete performance test classes. In order to allow reuse of several inherited utility methods, they are moved to a dedicated AntUITestUtil class. In addition, the functionality for closing the welcome screen, which is embedded into the setup functionality of the common Ant UI test superclass, is extracted into a JUnit 5 extension to be used throughout all tests upon JUnit 5 migration. --- .../tests/ui/debug/AbstractAntDebugTest.java | 5 +- .../ant/tests/ui/debug/BreakpointTests.java | 1 + .../ant/tests/ui/debug/PropertyTests.java | 1 + .../ant/tests/ui/debug/SteppingTests.java | 1 + .../editor/performance/OpenAntEditorTest.java | 6 +- .../ui/AbstractAntUIBuildPerformanceTest.java | 87 -------- .../ant/tests/ui/AbstractAntUIBuildTest.java | 12 - .../eclipse/ant/tests/ui/AntUtilTests.java | 3 +- .../org/eclipse/ant/tests/ui/BuildTests.java | 3 + .../AbstractAntPerformanceTest.java | 34 --- .../OpenLaunchConfigurationDialogTests.java | 7 +- .../tests/ui/performance/SeparateVMTests.java | 40 +++- .../tests/ui/separateVM/SeparateVMTests.java | 7 +- .../AbstractExternalToolTest.java | 9 +- .../externaltools/BuilderCoreUtilsTests.java | 5 +- .../META-INF/MANIFEST.MF | 3 +- .../ui/testplugin/AbstractAntUITest.java | 208 +----------------- .../tests/ui/testplugin/AntUITestUtil.java | 196 +++++++++++++++++ .../CloseWelcomeScreenExtension.java | 64 ++++++ .../tests/ui/testplugin/ProjectHelper.java | 19 +- 20 files changed, 351 insertions(+), 360 deletions(-) delete mode 100644 ant/org.eclipse.ant.tests.ui/Ant Tests/org/eclipse/ant/tests/ui/AbstractAntUIBuildPerformanceTest.java delete mode 100644 ant/org.eclipse.ant.tests.ui/Ant Tests/org/eclipse/ant/tests/ui/performance/AbstractAntPerformanceTest.java create mode 100644 ant/org.eclipse.ant.tests.ui/test plugin/org/eclipse/ant/tests/ui/testplugin/AntUITestUtil.java create mode 100644 ant/org.eclipse.ant.tests.ui/test plugin/org/eclipse/ant/tests/ui/testplugin/CloseWelcomeScreenExtension.java diff --git a/ant/org.eclipse.ant.tests.ui/Ant Debug Tests/org/eclipse/ant/tests/ui/debug/AbstractAntDebugTest.java b/ant/org.eclipse.ant.tests.ui/Ant Debug Tests/org/eclipse/ant/tests/ui/debug/AbstractAntDebugTest.java index 45082f7da26..d8624381da6 100644 --- a/ant/org.eclipse.ant.tests.ui/Ant Debug Tests/org/eclipse/ant/tests/ui/debug/AbstractAntDebugTest.java +++ b/ant/org.eclipse.ant.tests.ui/Ant Debug Tests/org/eclipse/ant/tests/ui/debug/AbstractAntDebugTest.java @@ -13,6 +13,8 @@ *******************************************************************************/ package org.eclipse.ant.tests.ui.debug; +import static org.eclipse.ant.tests.ui.testplugin.AntUITestUtil.getLaunchConfiguration; +import static org.eclipse.ant.tests.ui.testplugin.AntUITestUtil.getLaunchManager; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; @@ -96,8 +98,7 @@ protected IBreakpointManager getBreakpointManager() { * the event waiter to use * @return Object the source of the event */ - @Override - protected Object launchAndWait(ILaunchConfiguration configuration, DebugEventWaiter waiter) throws CoreException { + private Object launchAndWait(ILaunchConfiguration configuration, DebugEventWaiter waiter) throws CoreException { return launchAndWait(configuration, waiter, true); } diff --git a/ant/org.eclipse.ant.tests.ui/Ant Debug Tests/org/eclipse/ant/tests/ui/debug/BreakpointTests.java b/ant/org.eclipse.ant.tests.ui/Ant Debug Tests/org/eclipse/ant/tests/ui/debug/BreakpointTests.java index 4bb88bc6c92..a648b17af79 100644 --- a/ant/org.eclipse.ant.tests.ui/Ant Debug Tests/org/eclipse/ant/tests/ui/debug/BreakpointTests.java +++ b/ant/org.eclipse.ant.tests.ui/Ant Debug Tests/org/eclipse/ant/tests/ui/debug/BreakpointTests.java @@ -13,6 +13,7 @@ *******************************************************************************/ package org.eclipse.ant.tests.ui.debug; +import static org.eclipse.ant.tests.ui.testplugin.AntUITestUtil.getLaunchConfiguration; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; diff --git a/ant/org.eclipse.ant.tests.ui/Ant Debug Tests/org/eclipse/ant/tests/ui/debug/PropertyTests.java b/ant/org.eclipse.ant.tests.ui/Ant Debug Tests/org/eclipse/ant/tests/ui/debug/PropertyTests.java index 313f99dc261..a4c0d924c9d 100644 --- a/ant/org.eclipse.ant.tests.ui/Ant Debug Tests/org/eclipse/ant/tests/ui/debug/PropertyTests.java +++ b/ant/org.eclipse.ant.tests.ui/Ant Debug Tests/org/eclipse/ant/tests/ui/debug/PropertyTests.java @@ -14,6 +14,7 @@ package org.eclipse.ant.tests.ui.debug; import static org.assertj.core.api.Assertions.assertThat; +import static org.eclipse.ant.tests.ui.testplugin.AntUITestUtil.getLaunchConfiguration; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; diff --git a/ant/org.eclipse.ant.tests.ui/Ant Debug Tests/org/eclipse/ant/tests/ui/debug/SteppingTests.java b/ant/org.eclipse.ant.tests.ui/Ant Debug Tests/org/eclipse/ant/tests/ui/debug/SteppingTests.java index 5eb1d9fa1f6..a48182661be 100644 --- a/ant/org.eclipse.ant.tests.ui/Ant Debug Tests/org/eclipse/ant/tests/ui/debug/SteppingTests.java +++ b/ant/org.eclipse.ant.tests.ui/Ant Debug Tests/org/eclipse/ant/tests/ui/debug/SteppingTests.java @@ -13,6 +13,7 @@ *******************************************************************************/ package org.eclipse.ant.tests.ui.debug; +import static org.eclipse.ant.tests.ui.testplugin.AntUITestUtil.getLaunchConfiguration; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; diff --git a/ant/org.eclipse.ant.tests.ui/Ant Editor Tests/org/eclipse/ant/tests/ui/editor/performance/OpenAntEditorTest.java b/ant/org.eclipse.ant.tests.ui/Ant Editor Tests/org/eclipse/ant/tests/ui/editor/performance/OpenAntEditorTest.java index abc4236d011..4c8199ca10d 100644 --- a/ant/org.eclipse.ant.tests.ui/Ant Editor Tests/org/eclipse/ant/tests/ui/editor/performance/OpenAntEditorTest.java +++ b/ant/org.eclipse.ant.tests.ui/Ant Editor Tests/org/eclipse/ant/tests/ui/editor/performance/OpenAntEditorTest.java @@ -14,31 +14,33 @@ package org.eclipse.ant.tests.ui.editor.performance; +import static org.eclipse.ant.tests.ui.testplugin.AntUITestUtil.assertProject; import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.File; import org.eclipse.ant.internal.ui.AntUIPlugin; import org.eclipse.ant.internal.ui.preferences.AntEditorPreferenceConstants; -import org.eclipse.ant.tests.ui.performance.AbstractAntPerformanceTest; import org.eclipse.ant.tests.ui.testplugin.ProjectHelper; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.test.performance.Dimension; +import org.eclipse.test.performance.PerformanceTestCaseJunit5; import org.eclipse.ui.PartInitException; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestInfo; @SuppressWarnings("restriction") -public class OpenAntEditorTest extends AbstractAntPerformanceTest { +public class OpenAntEditorTest extends PerformanceTestCaseJunit5 { @BeforeEach @Override public void setUp(TestInfo testInfo) throws Exception { super.setUp(testInfo); + assertProject(); EditorTestHelper.runEventQueue(); } diff --git a/ant/org.eclipse.ant.tests.ui/Ant Tests/org/eclipse/ant/tests/ui/AbstractAntUIBuildPerformanceTest.java b/ant/org.eclipse.ant.tests.ui/Ant Tests/org/eclipse/ant/tests/ui/AbstractAntUIBuildPerformanceTest.java deleted file mode 100644 index 203dbc5d7b2..00000000000 --- a/ant/org.eclipse.ant.tests.ui/Ant Tests/org/eclipse/ant/tests/ui/AbstractAntUIBuildPerformanceTest.java +++ /dev/null @@ -1,87 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2008 IBM Corporation and others. - * - * 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.ant.tests.ui; - -import org.eclipse.core.runtime.CoreException; -import org.eclipse.debug.core.ILaunchConfiguration; -import org.eclipse.test.performance.Performance; -import org.eclipse.test.performance.PerformanceMeter; -import org.junit.After; -import org.junit.Before; - -public class AbstractAntUIBuildPerformanceTest extends AbstractAntUIBuildTest { - - protected PerformanceMeter fPerformanceMeter; - - /** - * Overridden to create a default performance meter for this test case. - */ - @Before - @Override - public void setUp() throws Exception { - super.setUp(); - Performance performance = Performance.getDefault(); - fPerformanceMeter = performance.createPerformanceMeter(performance.getDefaultScenarioId(this.getClass())); - } - - /** - * Overridden to dispose of the performance meter. - */ - @After - public void tearDown() throws Exception { - fPerformanceMeter.dispose(); - } - - /** - * Called from within a test case immediately before the code to measure is run. It starts capturing of performance data. Must be followed by a - * call to {@link #stopMeasuring()} before subsequent calls to this method or {@link #commitMeasurements()}. - */ - protected void startMeasuring() { - fPerformanceMeter.start(); - } - - protected void stopMeasuring() { - fPerformanceMeter.stop(); - } - - protected void commitMeasurements() { - fPerformanceMeter.commit(); - } - - /** - * Asserts default properties of the measurements captured for this test case. - * - * @throws RuntimeException - * if the properties do not hold - */ - protected void assertPerformance() { - Performance.getDefault().assertPerformance(fPerformanceMeter); - } - - /** - * Launches the Ant build for this config. Waits for all of the lines to be appended to the console. - * - * @param config - * the launch configuration to execute - * @param i - * the number of times to perform the launch - */ - protected void launch(ILaunchConfiguration config, int i) throws CoreException { - startMeasuring(); - for (int j = 0; j < i; j++) { - super.launch(config); - } - stopMeasuring(); - } -} diff --git a/ant/org.eclipse.ant.tests.ui/Ant Tests/org/eclipse/ant/tests/ui/AbstractAntUIBuildTest.java b/ant/org.eclipse.ant.tests.ui/Ant Tests/org/eclipse/ant/tests/ui/AbstractAntUIBuildTest.java index 91ef534893e..979c5a3cf40 100644 --- a/ant/org.eclipse.ant.tests.ui/Ant Tests/org/eclipse/ant/tests/ui/AbstractAntUIBuildTest.java +++ b/ant/org.eclipse.ant.tests.ui/Ant Tests/org/eclipse/ant/tests/ui/AbstractAntUIBuildTest.java @@ -15,8 +15,6 @@ package org.eclipse.ant.tests.ui; import org.eclipse.ant.tests.ui.testplugin.AbstractAntUITest; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.debug.core.ILaunchConfiguration; import org.eclipse.swt.widgets.Display; import org.eclipse.ui.console.IHyperlink; import org.junit.Rule; @@ -26,16 +24,6 @@ public abstract class AbstractAntUIBuildTest extends AbstractAntUITest { @Rule public RunInSeparateThreadRule runInSeparateThread = new RunInSeparateThreadRule(); - /** - * Launches the launch configuration Waits for all of the lines to be appended - * to the console. - * - * @param config the config to execute - */ - protected void launch(ILaunchConfiguration config) throws CoreException { - launchAndTerminate(config, 20000); - } - protected void activateLink(final IHyperlink link) { Display.getDefault().asyncExec(() -> link.linkActivated()); } diff --git a/ant/org.eclipse.ant.tests.ui/Ant Tests/org/eclipse/ant/tests/ui/AntUtilTests.java b/ant/org.eclipse.ant.tests.ui/Ant Tests/org/eclipse/ant/tests/ui/AntUtilTests.java index c2ab5ef6ce2..0871c5be535 100644 --- a/ant/org.eclipse.ant.tests.ui/Ant Tests/org/eclipse/ant/tests/ui/AntUtilTests.java +++ b/ant/org.eclipse.ant.tests.ui/Ant Tests/org/eclipse/ant/tests/ui/AntUtilTests.java @@ -33,6 +33,7 @@ import org.eclipse.ant.internal.ui.model.IAntModel; import org.eclipse.ant.launching.IAntLaunchConstants; import org.eclipse.ant.tests.ui.testplugin.AbstractAntUITest; +import org.eclipse.ant.tests.ui.testplugin.AntUITestUtil; import org.eclipse.core.externaltools.internal.IExternalToolConstants; import org.eclipse.core.runtime.CoreException; import org.eclipse.debug.core.ILaunchConfiguration; @@ -275,7 +276,7 @@ private void assertTargets(AntTargetNode[] targets, String[] expectedTargetNames } protected ILaunchConfiguration getLaunchConfiguration(String buildFileName, String arguments, Map properties, String propertyFiles) throws CoreException { - ILaunchConfiguration config = getLaunchConfiguration(buildFileName); + ILaunchConfiguration config = AntUITestUtil.getLaunchConfiguration(buildFileName); assertNotNull("Could not locate launch configuration for " + buildFileName, config); //$NON-NLS-1$ ILaunchConfigurationWorkingCopy copy = config.getWorkingCopy(); if (arguments != null) { diff --git a/ant/org.eclipse.ant.tests.ui/Ant Tests/org/eclipse/ant/tests/ui/BuildTests.java b/ant/org.eclipse.ant.tests.ui/Ant Tests/org/eclipse/ant/tests/ui/BuildTests.java index 800181c8496..561dafa9deb 100644 --- a/ant/org.eclipse.ant.tests.ui/Ant Tests/org/eclipse/ant/tests/ui/BuildTests.java +++ b/ant/org.eclipse.ant.tests.ui/Ant Tests/org/eclipse/ant/tests/ui/BuildTests.java @@ -14,6 +14,9 @@ package org.eclipse.ant.tests.ui; +import static org.eclipse.ant.tests.ui.testplugin.AntUITestUtil.getLaunchConfiguration; +import static org.eclipse.ant.tests.ui.testplugin.AntUITestUtil.getProject; +import static org.eclipse.ant.tests.ui.testplugin.AntUITestUtil.launchAndTerminate; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; diff --git a/ant/org.eclipse.ant.tests.ui/Ant Tests/org/eclipse/ant/tests/ui/performance/AbstractAntPerformanceTest.java b/ant/org.eclipse.ant.tests.ui/Ant Tests/org/eclipse/ant/tests/ui/performance/AbstractAntPerformanceTest.java deleted file mode 100644 index 2124b17fa0b..00000000000 --- a/ant/org.eclipse.ant.tests.ui/Ant Tests/org/eclipse/ant/tests/ui/performance/AbstractAntPerformanceTest.java +++ /dev/null @@ -1,34 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2008 IBM Corporation and others. - * - * 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.ant.tests.ui.performance; - -import org.eclipse.ant.tests.ui.testplugin.AbstractAntUITest; -import org.eclipse.test.performance.PerformanceTestCaseJunit5; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.TestInfo; - -/** - * Abstract class for ant performance tests, ensures the test project is created and ready in the test workspace. - * - * @since 3.5 - */ -public abstract class AbstractAntPerformanceTest extends PerformanceTestCaseJunit5 { - - @BeforeEach - @Override - public void setUp(TestInfo testInfo) throws Exception { - super.setUp(testInfo); - AbstractAntUITest.assertProject(); - } -} diff --git a/ant/org.eclipse.ant.tests.ui/Ant Tests/org/eclipse/ant/tests/ui/performance/OpenLaunchConfigurationDialogTests.java b/ant/org.eclipse.ant.tests.ui/Ant Tests/org/eclipse/ant/tests/ui/performance/OpenLaunchConfigurationDialogTests.java index ad93fc77eb3..807f4fe4f47 100644 --- a/ant/org.eclipse.ant.tests.ui/Ant Tests/org/eclipse/ant/tests/ui/performance/OpenLaunchConfigurationDialogTests.java +++ b/ant/org.eclipse.ant.tests.ui/Ant Tests/org/eclipse/ant/tests/ui/performance/OpenLaunchConfigurationDialogTests.java @@ -14,11 +14,12 @@ package org.eclipse.ant.tests.ui.performance; +import static org.eclipse.ant.tests.ui.testplugin.AntUITestUtil.getJavaProject; +import static org.eclipse.ant.tests.ui.testplugin.AntUITestUtil.getLaunchManager; import static org.junit.jupiter.api.Assertions.assertTrue; import org.eclipse.ant.internal.ui.IAntUIConstants; import org.eclipse.ant.tests.ui.editor.performance.EditorTestHelper; -import org.eclipse.ant.tests.ui.testplugin.AbstractAntUITest; import org.eclipse.core.resources.IFile; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; @@ -70,8 +71,8 @@ public void testOpenAntLaunchConfigurationDialog2() { } private ILaunchConfiguration getLaunchConfiguration(String buildFileName) { - IFile file = AbstractAntUITest.getJavaProject().getProject().getFolder("launchConfigurations").getFile(buildFileName + ".launch"); //$NON-NLS-1$ //$NON-NLS-2$ - ILaunchConfiguration config = AbstractAntUITest.getLaunchManager().getLaunchConfiguration(file); + IFile file = getJavaProject().getProject().getFolder("launchConfigurations").getFile(buildFileName + ".launch"); //$NON-NLS-1$ //$NON-NLS-2$ + ILaunchConfiguration config = getLaunchManager().getLaunchConfiguration(file); assertTrue(config.exists(), "Could not find launch configuration for " + buildFileName); //$NON-NLS-1$ return config; } diff --git a/ant/org.eclipse.ant.tests.ui/Ant Tests/org/eclipse/ant/tests/ui/performance/SeparateVMTests.java b/ant/org.eclipse.ant.tests.ui/Ant Tests/org/eclipse/ant/tests/ui/performance/SeparateVMTests.java index ccd13eb65ea..b1f6d2e53fb 100644 --- a/ant/org.eclipse.ant.tests.ui/Ant Tests/org/eclipse/ant/tests/ui/performance/SeparateVMTests.java +++ b/ant/org.eclipse.ant.tests.ui/Ant Tests/org/eclipse/ant/tests/ui/performance/SeparateVMTests.java @@ -14,19 +14,32 @@ package org.eclipse.ant.tests.ui.performance; -import static org.junit.Assert.assertNotNull; +import static org.eclipse.ant.tests.ui.testplugin.AntUITestUtil.assertProject; +import static org.eclipse.ant.tests.ui.testplugin.AntUITestUtil.getLaunchConfiguration; +import static org.eclipse.ant.tests.ui.testplugin.AntUITestUtil.launchAndTerminate; +import static org.junit.jupiter.api.Assertions.assertNotNull; -import org.eclipse.ant.tests.ui.AbstractAntUIBuildPerformanceTest; +import org.eclipse.ant.tests.ui.testplugin.AntUITestUtil; +import org.eclipse.ant.tests.ui.testplugin.CloseWelcomeScreenExtension; import org.eclipse.core.externaltools.internal.IExternalToolConstants; import org.eclipse.core.runtime.CoreException; import org.eclipse.debug.core.DebugPlugin; import org.eclipse.debug.core.ILaunchConfiguration; import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; import org.eclipse.debug.ui.IDebugUIConstants; -import org.junit.Test; +import org.eclipse.test.performance.PerformanceTestCaseJunit5; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; @SuppressWarnings("restriction") -public class SeparateVMTests extends AbstractAntUIBuildPerformanceTest { +@ExtendWith(CloseWelcomeScreenExtension.class) +public class SeparateVMTests extends PerformanceTestCaseJunit5 { + + @BeforeEach + void setup() throws Exception { + assertProject(); + } /** * Performance test for launching Ant in a separate vm. @@ -52,7 +65,7 @@ public void testBuild() throws CoreException { public void testBuildNoConsole() throws CoreException { // tagAsSummary("Separate JRE Build; capture output off", Dimension.ELAPSED_PROCESS); ILaunchConfiguration config = getLaunchConfiguration("echoingSepVM"); //$NON-NLS-1$ - assertNotNull("Could not locate launch configuration for " + "echoingSepVM", config); //$NON-NLS-1$ //$NON-NLS-2$ + assertNotNull(config, "Could not locate launch configuration for " + "echoingSepVM"); //$NON-NLS-1$ //$NON-NLS-2$ ILaunchConfigurationWorkingCopy copy = config.getWorkingCopy(); copy.setAttribute(IDebugUIConstants.ATTR_CAPTURE_IN_CONSOLE, false); copy.setAttribute(DebugPlugin.ATTR_CAPTURE_OUTPUT, false); @@ -73,7 +86,7 @@ public void testBuildNoConsole() throws CoreException { public void testBuildMinusDebug() throws CoreException { // tagAsSummary("Separate JRE Build; -debug", Dimension.ELAPSED_PROCESS); ILaunchConfiguration config = getLaunchConfiguration("echoingSepVM"); //$NON-NLS-1$ - assertNotNull("Could not locate launch configuration for " + "echoingSepVM", config); //$NON-NLS-1$ //$NON-NLS-2$ + assertNotNull(config, "Could not locate launch configuration for " + "echoingSepVM"); //$NON-NLS-1$ //$NON-NLS-2$ ILaunchConfigurationWorkingCopy copy = config.getWorkingCopy(); copy.setAttribute(IExternalToolConstants.ATTR_TOOL_ARGUMENTS, "-debug"); //$NON-NLS-1$ // possible first time hit of the SWT pieces getting written from the JAR to the @@ -102,4 +115,19 @@ public void testBuildWithLotsOfLinks() throws CoreException { commitMeasurements(); assertPerformance(); } + + /** + * Launches the Ant build for this config. Waits for all of the lines to be + * appended to the console. + * + * @param config the launch configuration to execute + * @param i the number of times to perform the launch + */ + private void launch(ILaunchConfiguration config, int i) throws CoreException { + startMeasuring(); + for (int j = 0; j < i; j++) { + AntUITestUtil.launch(config); + } + stopMeasuring(); + } } diff --git a/ant/org.eclipse.ant.tests.ui/Ant Tests/org/eclipse/ant/tests/ui/separateVM/SeparateVMTests.java b/ant/org.eclipse.ant.tests.ui/Ant Tests/org/eclipse/ant/tests/ui/separateVM/SeparateVMTests.java index 4da2a714006..527b039e0af 100644 --- a/ant/org.eclipse.ant.tests.ui/Ant Tests/org/eclipse/ant/tests/ui/separateVM/SeparateVMTests.java +++ b/ant/org.eclipse.ant.tests.ui/Ant Tests/org/eclipse/ant/tests/ui/separateVM/SeparateVMTests.java @@ -14,6 +14,10 @@ package org.eclipse.ant.tests.ui.separateVM; +import static org.eclipse.ant.tests.ui.testplugin.AntUITestUtil.getJavaProject; +import static org.eclipse.ant.tests.ui.testplugin.AntUITestUtil.getLaunchConfiguration; +import static org.eclipse.ant.tests.ui.testplugin.AntUITestUtil.getProject; +import static org.eclipse.ant.tests.ui.testplugin.AntUITestUtil.launchAndTerminate; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; @@ -32,6 +36,7 @@ import org.eclipse.ant.launching.IAntLaunchConstants; import org.eclipse.ant.tests.ui.AbstractAntUIBuildTest; import org.eclipse.ant.tests.ui.debug.TestAgainException; +import org.eclipse.ant.tests.ui.testplugin.AntUITestUtil; import org.eclipse.ant.tests.ui.testplugin.ConsoleLineTracker; import org.eclipse.ant.tests.ui.testplugin.ProjectHelper; import org.eclipse.core.resources.IFile; @@ -306,7 +311,7 @@ public void testFailInputHandler() throws CoreException { assertNotNull("Could not locate launch configuration for " + "echoingSepVM", config); //$NON-NLS-1$ //$NON-NLS-2$ ILaunchConfigurationWorkingCopy copy = config.getWorkingCopy(); copy.setAttribute(IAntUIConstants.SET_INPUTHANDLER, false); - launch(copy); + AntUITestUtil.launch(copy); String message = ConsoleLineTracker.getMessage(1); assertNotNull("There must be a message", message); //$NON-NLS-1$ assertTrue("Incorrect message. Should start with Message:. Message: " + message, message.startsWith("echo1")); //$NON-NLS-1$ //$NON-NLS-2$ diff --git a/ant/org.eclipse.ant.tests.ui/External Tools/org/eclipse/ant/tests/ui/externaltools/AbstractExternalToolTest.java b/ant/org.eclipse.ant.tests.ui/External Tools/org/eclipse/ant/tests/ui/externaltools/AbstractExternalToolTest.java index 3ebf54e5a2f..fdf85bf4166 100644 --- a/ant/org.eclipse.ant.tests.ui/External Tools/org/eclipse/ant/tests/ui/externaltools/AbstractExternalToolTest.java +++ b/ant/org.eclipse.ant.tests.ui/External Tools/org/eclipse/ant/tests/ui/externaltools/AbstractExternalToolTest.java @@ -13,6 +13,9 @@ *******************************************************************************/ package org.eclipse.ant.tests.ui.externaltools; +import static org.eclipse.ant.tests.ui.testplugin.AntUITestUtil.getLaunchManager; +import static org.eclipse.ant.tests.ui.testplugin.AntUITestUtil.getProject; + import java.util.HashMap; import java.util.Map; @@ -57,7 +60,8 @@ protected ILaunchConfiguration createExternalToolBuilder(IProject project, Strin if (!dir.exists()) { dir.create(true, true, null); } - ILaunchConfigurationType type = AbstractAntUITest.getLaunchManager().getLaunchConfigurationType(IAntLaunchConstants.ID_ANT_BUILDER_LAUNCH_CONFIGURATION_TYPE); + ILaunchConfigurationType type = getLaunchManager() + .getLaunchConfigurationType(IAntLaunchConstants.ID_ANT_BUILDER_LAUNCH_CONFIGURATION_TYPE); if (type != null) { ILaunchConfigurationWorkingCopy config = type.newInstance(dir, name); config.setAttributes(args); @@ -74,7 +78,8 @@ protected ILaunchConfigurationWorkingCopy createExternalToolBuilderWorkingCopy(I if (!dir.exists()) { dir.create(true, true, null); } - ILaunchConfigurationType type = AbstractAntUITest.getLaunchManager().getLaunchConfigurationType(IAntLaunchConstants.ID_ANT_BUILDER_LAUNCH_CONFIGURATION_TYPE); + ILaunchConfigurationType type = getLaunchManager() + .getLaunchConfigurationType(IAntLaunchConstants.ID_ANT_BUILDER_LAUNCH_CONFIGURATION_TYPE); if (type != null) { ILaunchConfigurationWorkingCopy config = type.newInstance(dir, name); config.setAttributes(args); diff --git a/ant/org.eclipse.ant.tests.ui/External Tools/org/eclipse/ant/tests/ui/externaltools/BuilderCoreUtilsTests.java b/ant/org.eclipse.ant.tests.ui/External Tools/org/eclipse/ant/tests/ui/externaltools/BuilderCoreUtilsTests.java index 712beb62989..83b4af606ea 100644 --- a/ant/org.eclipse.ant.tests.ui/External Tools/org/eclipse/ant/tests/ui/externaltools/BuilderCoreUtilsTests.java +++ b/ant/org.eclipse.ant.tests.ui/External Tools/org/eclipse/ant/tests/ui/externaltools/BuilderCoreUtilsTests.java @@ -13,6 +13,8 @@ *******************************************************************************/ package org.eclipse.ant.tests.ui.externaltools; +import static org.eclipse.ant.tests.ui.testplugin.AntUITestUtil.getLaunchManager; +import static org.eclipse.ant.tests.ui.testplugin.AntUITestUtil.getProject; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; @@ -24,7 +26,6 @@ import org.eclipse.ant.internal.launching.AntLaunchingUtil; import org.eclipse.ant.launching.IAntLaunchConstants; -import org.eclipse.ant.tests.ui.testplugin.AbstractAntUITest; import org.eclipse.core.externaltools.internal.IExternalToolConstants; import org.eclipse.core.externaltools.internal.model.BuilderCoreUtils; import org.eclipse.core.resources.ICommand; @@ -383,7 +384,7 @@ public void testConfigureTriggers10() throws Exception { */ @Test public void testIsUnmigratedConfig1() throws Exception { - ILaunchConfigurationType type = AbstractAntUITest.getLaunchManager().getLaunchConfigurationType(IAntLaunchConstants.ID_ANT_BUILDER_LAUNCH_CONFIGURATION_TYPE); + ILaunchConfigurationType type = getLaunchManager().getLaunchConfigurationType(IAntLaunchConstants.ID_ANT_BUILDER_LAUNCH_CONFIGURATION_TYPE); if (type != null) { ILaunchConfigurationWorkingCopy config = type.newInstance(BuilderCoreUtils.getBuilderFolder(getProject(), true), "testIsUnmigratedConfig1"); //$NON-NLS-1$ assertTrue("should be considered 'unmigrated'", BuilderCoreUtils.isUnmigratedConfig(config)); //$NON-NLS-1$ diff --git a/ant/org.eclipse.ant.tests.ui/META-INF/MANIFEST.MF b/ant/org.eclipse.ant.tests.ui/META-INF/MANIFEST.MF index 96f4d2511ea..ba5e1eb93a5 100644 --- a/ant/org.eclipse.ant.tests.ui/META-INF/MANIFEST.MF +++ b/ant/org.eclipse.ant.tests.ui/META-INF/MANIFEST.MF @@ -40,7 +40,8 @@ Require-Bundle: org.eclipse.ui.ide;resolution:=optional, Import-Package: org.assertj.core.api, org.assertj.core.api.iterable, org.junit.jupiter.api;version="[5.14.0,6.0.0)", - org.junit.platform.suite.api;version="[1.14.0,2.0.0)" + org.junit.platform.suite.api;version="[1.14.0,2.0.0)", + org.junit.jupiter.api.extension;version="[5.14.0,6.0.0)" Bundle-ActivationPolicy: lazy Bundle-RequiredExecutionEnvironment: JavaSE-21 Eclipse-BundleShape: dir diff --git a/ant/org.eclipse.ant.tests.ui/test plugin/org/eclipse/ant/tests/ui/testplugin/AbstractAntUITest.java b/ant/org.eclipse.ant.tests.ui/test plugin/org/eclipse/ant/tests/ui/testplugin/AbstractAntUITest.java index 9a1439152ed..1d7c6723a40 100644 --- a/ant/org.eclipse.ant.tests.ui/test plugin/org/eclipse/ant/tests/ui/testplugin/AbstractAntUITest.java +++ b/ant/org.eclipse.ant.tests.ui/test plugin/org/eclipse/ant/tests/ui/testplugin/AbstractAntUITest.java @@ -13,6 +13,9 @@ *******************************************************************************/ package org.eclipse.ant.tests.ui.testplugin; +import static org.eclipse.ant.tests.ui.testplugin.AntUITestUtil.assertProject; +import static org.eclipse.ant.tests.ui.testplugin.AntUITestUtil.getLaunchConfiguration; +import static org.eclipse.ant.tests.ui.testplugin.AntUITestUtil.launchAndTerminate; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; @@ -22,37 +25,18 @@ import java.io.IOException; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; -import java.net.URL; import java.nio.file.Files; import org.eclipse.ant.internal.ui.AntUIPlugin; -import org.eclipse.ant.internal.ui.IAntUIPreferenceConstants; import org.eclipse.ant.internal.ui.model.AntModel; -import org.eclipse.ant.tests.ui.debug.TestAgainException; import org.eclipse.ant.tests.ui.editor.support.TestLocationProvider; import org.eclipse.ant.tests.ui.editor.support.TestProblemRequestor; import org.eclipse.core.externaltools.internal.IExternalToolConstants; import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IFolder; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.Assert; import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.FileLocator; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.core.runtime.jobs.Job; -import org.eclipse.debug.core.DebugEvent; -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.ILaunchManager; -import org.eclipse.debug.core.model.IProcess; -import org.eclipse.jdt.core.IJavaProject; -import org.eclipse.jdt.core.JavaCore; import org.eclipse.jface.text.BadLocationException; import org.eclipse.jface.text.BadPositionCategoryException; import org.eclipse.jface.text.Document; @@ -61,19 +45,11 @@ import org.eclipse.jface.text.ITypedRegion; import org.eclipse.jface.text.Position; import org.eclipse.swt.graphics.Color; -import org.eclipse.ui.IWorkbench; -import org.eclipse.ui.IWorkbenchWindow; -import org.eclipse.ui.PlatformUI; import org.eclipse.ui.console.IHyperlink; import org.eclipse.ui.internal.console.ConsoleHyperlinkPosition; import org.eclipse.ui.internal.console.IOConsolePartition; -import org.eclipse.ui.intro.IIntroManager; -import org.eclipse.ui.intro.IIntroPart; -import org.eclipse.ui.progress.UIJob; import org.junit.Before; import org.junit.Rule; -import org.osgi.framework.Bundle; -import org.osgi.framework.FrameworkUtil; /** * Abstract Ant UI test class @@ -81,8 +57,8 @@ @SuppressWarnings("restriction") public abstract class AbstractAntUITest { - public static String ANT_EDITOR_ID = "org.eclipse.ant.ui.internal.editor.AntEditor"; //$NON-NLS-1$ - private boolean welcomeClosed = false; + public static final String ANT_EDITOR_ID = "org.eclipse.ant.ui.internal.editor.AntEditor"; //$NON-NLS-1$ + private final CloseWelcomeScreenExtension closeWelcomeScreenExtension = new CloseWelcomeScreenExtension(); private IDocument currentDocument; @Rule @@ -94,7 +70,7 @@ public abstract class AbstractAntUITest { * @return the associated {@link IFile} for the given build file name */ protected IFile getIFile(String buildFileName) { - return getProject().getFolder("buildfiles").getFile(buildFileName); //$NON-NLS-1$ + return AntUITestUtil.getProject().getFolder("buildfiles").getFile(buildFileName); //$NON-NLS-1$ } /** @@ -111,101 +87,7 @@ protected File getBuildFile(String buildFileName) { @Before public void setUp() throws Exception { assertProject(); - assertWelcomeScreenClosed(); - } - - /** - * Ensure the welcome screen is closed because in 4.x the debug perspective opens a giant fast-view causing issues - * - * @since 3.8 - */ - void assertWelcomeScreenClosed() throws Exception { - if (!welcomeClosed && PlatformUI.isWorkbenchRunning()) { - final IWorkbench wb = PlatformUI.getWorkbench(); - if (wb != null) { - UIJob job = new UIJob("close welcome screen for Ant test suite") { //$NON-NLS-1$ - @Override - public IStatus runInUIThread(IProgressMonitor monitor) { - IWorkbenchWindow window = wb.getActiveWorkbenchWindow(); - if (window != null) { - IIntroManager im = wb.getIntroManager(); - IIntroPart intro = im.getIntro(); - if (intro != null) { - welcomeClosed = im.closeIntro(intro); - } - } - return Status.OK_STATUS; - } - }; - job.setPriority(Job.INTERACTIVE); - job.setSystem(true); - job.schedule(); - } - } - } - - /** - * Asserts that the testing project has been setup in the test workspace - * - * @throws Exception - * - * @since 3.5 - */ - public static void assertProject() throws Exception { - IProject pro = ResourcesPlugin.getWorkspace().getRoot().getProject(ProjectHelper.PROJECT_NAME); - if (!pro.exists()) { - // create project and import build files and support files - IProject project = ProjectHelper.createProject(ProjectHelper.PROJECT_NAME); - IFolder folder = ProjectHelper.addFolder(project, "buildfiles"); //$NON-NLS-1$ - ProjectHelper.addFolder(project, "launchConfigurations"); //$NON-NLS-1$ - File root = getFileInPlugin(ProjectHelper.TEST_BUILDFILES_DIR); - ProjectHelper.importFilesFromDirectory(root, folder.getFullPath(), null); - - ProjectHelper.createLaunchConfigurationForBoth("echoing"); //$NON-NLS-1$ - ProjectHelper.createLaunchConfigurationForBoth("102282"); //$NON-NLS-1$ - ProjectHelper.createLaunchConfigurationForBoth("74840"); //$NON-NLS-1$ - ProjectHelper.createLaunchConfigurationForBoth("failingTarget"); //$NON-NLS-1$ - ProjectHelper.createLaunchConfiguration("build"); //$NON-NLS-1$ - ProjectHelper.createLaunchConfiguration("bad"); //$NON-NLS-1$ - ProjectHelper.createLaunchConfiguration("importRequiringUserProp"); //$NON-NLS-1$ - ProjectHelper.createLaunchConfigurationForSeparateVM("echoPropertiesSepVM", "echoProperties"); //$NON-NLS-1$ //$NON-NLS-2$ - ProjectHelper.createLaunchConfigurationForSeparateVM("extensionPointSepVM", null); //$NON-NLS-1$ - ProjectHelper.createLaunchConfigurationForSeparateVM("extensionPointTaskSepVM", null); //$NON-NLS-1$ - ProjectHelper.createLaunchConfigurationForSeparateVM("extensionPointTypeSepVM", null); //$NON-NLS-1$ - ProjectHelper.createLaunchConfigurationForSeparateVM("input", null); //$NON-NLS-1$ - ProjectHelper.createLaunchConfigurationForSeparateVM("environmentVar", null); //$NON-NLS-1$ - - ProjectHelper.createLaunchConfigurationForBoth("breakpoints"); //$NON-NLS-1$ - ProjectHelper.createLaunchConfigurationForBoth("debugAntCall"); //$NON-NLS-1$ - ProjectHelper.createLaunchConfigurationForBoth("96022"); //$NON-NLS-1$ - ProjectHelper.createLaunchConfigurationForBoth("macrodef"); //$NON-NLS-1$ - ProjectHelper.createLaunchConfigurationForBoth("85769"); //$NON-NLS-1$ - - ProjectHelper.createLaunchConfiguration("big", ProjectHelper.PROJECT_NAME + "/buildfiles/performance/build.xml"); //$NON-NLS-1$ //$NON-NLS-2$ - - // do not show the Ant build failed error dialog - AntUIPlugin.getDefault().getPreferenceStore().setValue(IAntUIPreferenceConstants.ANT_ERROR_DIALOG, false); - } - } - - public static File getFileInPlugin(IPath path) { - try { - Bundle bundle = FrameworkUtil.getBundle(AbstractAntUITest.class); - URL installURL = bundle.getEntry("/" + path.toString()); //$NON-NLS-1$ - URL localURL = FileLocator.toFileURL(installURL); - return new File(localURL.getFile()); - } catch (IOException e) { - return null; - } - } - - /** - * Returns the 'AntUITests' project. - * - * @return the test project - */ - protected static IProject getProject() { - return ResourcesPlugin.getWorkspace().getRoot().getProject(ProjectHelper.PROJECT_NAME); + closeWelcomeScreenExtension.assertWelcomeScreenClosed(); } /** @@ -303,82 +185,6 @@ protected void launch(String buildFileName, String arguments) throws CoreExcepti launchAndTerminate(copy, 20000); } - /** - * Returns the launch configuration for the given build file - * - * @param buildFileName - * build file to launch - */ - protected ILaunchConfiguration getLaunchConfiguration(String buildFileName) { - IFile file = getJavaProject().getProject().getFolder("launchConfigurations").getFile(buildFileName + ".launch"); //$NON-NLS-1$ //$NON-NLS-2$ - ILaunchConfiguration config = getLaunchManager().getLaunchConfiguration(file); - assertTrue("Could not find launch configuration for " + buildFileName, config.exists()); //$NON-NLS-1$ - return config; - } - - /** - * Returns the launch manager - * - * @return launch manager - */ - public static ILaunchManager getLaunchManager() { - return DebugPlugin.getDefault().getLaunchManager(); - } - - /** - * Returns the 'AntUITests' project. - * - * @return the test project - */ - public static IJavaProject getJavaProject() { - return JavaCore.create(getProject()); - } - - /** - * Launches the given configuration and waits for the terminated event or the length of the given timeout, whichever comes first - */ - protected void launchAndTerminate(ILaunchConfiguration config, int timeout) throws CoreException { - DebugEventWaiter waiter = new DebugElementKindEventWaiter(DebugEvent.TERMINATE, IProcess.class); - waiter.setTimeout(timeout); - - Object terminatee = launchAndWait(config, waiter); - assertTrue("terminatee is not an IProcess", terminatee instanceof IProcess); //$NON-NLS-1$ - IProcess process = (IProcess) terminatee; - boolean terminated = process.isTerminated(); - assertTrue("process is not terminated", terminated); //$NON-NLS-1$ - } - - /** - * Launches the given configuration and waits for an event. Returns the source of the event. If the event is not received, the launch is - * terminated and an exception is thrown. - * - * @param configuration - * the configuration to launch - * @param waiter - * the event waiter to use - * @return Object the source of the event - */ - protected Object launchAndWait(ILaunchConfiguration configuration, DebugEventWaiter waiter) throws CoreException { - ILaunch launch = configuration.launch(ILaunchManager.RUN_MODE, null); - Object suspendee = waiter.waitForEvent(); - if (suspendee == null) { - try { - launch.terminate(); - } - catch (CoreException e) { - e.printStackTrace(); - } - throw new TestAgainException("Retest - Program did not suspend launching: " + configuration.getName()); //$NON-NLS-1$ - } - boolean terminated = launch.isTerminated(); - assertTrue("launch did not terminate", terminated); //$NON-NLS-1$ - if (terminated && !ConsoleLineTracker.isClosed()) { - ConsoleLineTracker.waitForConsole(); - } - assertTrue("Console is not closed", ConsoleLineTracker.isClosed()); //$NON-NLS-1$ - return suspendee; - } - /** * Returns the {@link IHyperlink} at the given offset on the given document, or null if there is no {@link IHyperlink} at that offset * on the document. diff --git a/ant/org.eclipse.ant.tests.ui/test plugin/org/eclipse/ant/tests/ui/testplugin/AntUITestUtil.java b/ant/org.eclipse.ant.tests.ui/test plugin/org/eclipse/ant/tests/ui/testplugin/AntUITestUtil.java new file mode 100644 index 00000000000..7daa8207324 --- /dev/null +++ b/ant/org.eclipse.ant.tests.ui/test plugin/org/eclipse/ant/tests/ui/testplugin/AntUITestUtil.java @@ -0,0 +1,196 @@ +/******************************************************************************* + * Copyright (c) 2025 Vector Informatik GmbH and others. + * + * 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 + *******************************************************************************/ +package org.eclipse.ant.tests.ui.testplugin; + +import static org.junit.Assert.assertTrue; + +import java.io.File; +import java.io.IOException; +import java.net.URL; + +import org.eclipse.ant.internal.ui.AntUIPlugin; +import org.eclipse.ant.internal.ui.IAntUIPreferenceConstants; +import org.eclipse.ant.tests.ui.debug.TestAgainException; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IFolder; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.FileLocator; +import org.eclipse.core.runtime.IPath; +import org.eclipse.debug.core.DebugEvent; +import org.eclipse.debug.core.DebugPlugin; +import org.eclipse.debug.core.ILaunch; +import org.eclipse.debug.core.ILaunchConfiguration; +import org.eclipse.debug.core.ILaunchManager; +import org.eclipse.debug.core.model.IProcess; +import org.eclipse.jdt.core.IJavaProject; +import org.eclipse.jdt.core.JavaCore; +import org.osgi.framework.Bundle; +import org.osgi.framework.FrameworkUtil; + +@SuppressWarnings("restriction") +public final class AntUITestUtil { + + private AntUITestUtil() { + } + + /** + * Returns the launch configuration for the given build file + * + * @param buildFileName + * build file to launch + */ + public static ILaunchConfiguration getLaunchConfiguration(String buildFileName) { + IFile file = getJavaProject().getProject().getFolder("launchConfigurations").getFile(buildFileName + ".launch"); //$NON-NLS-1$ //$NON-NLS-2$ + ILaunchConfiguration config = getLaunchManager().getLaunchConfiguration(file); + assertTrue("Could not find launch configuration for " + buildFileName, config.exists()); //$NON-NLS-1$ + return config; + } + + /** + * Launches the given configuration and waits for an event. Returns the source of the event. If the event is not received, the launch is + * terminated and an exception is thrown. + * + * @param configuration + * the configuration to launch + * @param waiter + * the event waiter to use + * @return Object the source of the event + */ + public static Object launchAndWait(ILaunchConfiguration configuration, DebugEventWaiter waiter) + throws CoreException { + ILaunch launch = configuration.launch(ILaunchManager.RUN_MODE, null); + Object suspendee = waiter.waitForEvent(); + if (suspendee == null) { + try { + launch.terminate(); + } + catch (CoreException e) { + e.printStackTrace(); + } + throw new TestAgainException("Retest - Program did not suspend launching: " + configuration.getName()); //$NON-NLS-1$ + } + boolean terminated = launch.isTerminated(); + assertTrue("launch did not terminate", terminated); //$NON-NLS-1$ + if (terminated && !ConsoleLineTracker.isClosed()) { + ConsoleLineTracker.waitForConsole(); + } + assertTrue("Console is not closed", ConsoleLineTracker.isClosed()); //$NON-NLS-1$ + return suspendee; + } + + /** + * Launches the given configuration and waits for the terminated event or the length of the given timeout, whichever comes first + */ + public static void launchAndTerminate(ILaunchConfiguration config, int timeout) throws CoreException { + DebugEventWaiter waiter = new DebugElementKindEventWaiter(DebugEvent.TERMINATE, IProcess.class); + waiter.setTimeout(timeout); + + Object terminatee = launchAndWait(config, waiter); + assertTrue("terminatee is not an IProcess", terminatee instanceof IProcess); //$NON-NLS-1$ + IProcess process = (IProcess) terminatee; + boolean terminated = process.isTerminated(); + assertTrue("process is not terminated", terminated); //$NON-NLS-1$ + } + + /** + * Launches the launch configuration Waits for all of the lines to be appended + * to the console. + * + * @param config the config to execute + */ + public static void launch(ILaunchConfiguration config) throws CoreException { + launchAndTerminate(config, 20000); + } + + /** + * Asserts that the testing project has been setup in the test workspace + * + * @throws Exception + * + * @since 3.5 + */ + public static void assertProject() throws Exception { + IProject pro = ResourcesPlugin.getWorkspace().getRoot().getProject(ProjectHelper.PROJECT_NAME); + if (!pro.exists()) { + // create project and import build files and support files + IProject project = ProjectHelper.createProject(ProjectHelper.PROJECT_NAME); + IFolder folder = ProjectHelper.addFolder(project, "buildfiles"); //$NON-NLS-1$ + ProjectHelper.addFolder(project, "launchConfigurations"); //$NON-NLS-1$ + File root = getFileInPlugin(ProjectHelper.TEST_BUILDFILES_DIR); + ProjectHelper.importFilesFromDirectory(root, folder.getFullPath(), null); + + ProjectHelper.createLaunchConfigurationForBoth("echoing"); //$NON-NLS-1$ + ProjectHelper.createLaunchConfigurationForBoth("102282"); //$NON-NLS-1$ + ProjectHelper.createLaunchConfigurationForBoth("74840"); //$NON-NLS-1$ + ProjectHelper.createLaunchConfigurationForBoth("failingTarget"); //$NON-NLS-1$ + ProjectHelper.createLaunchConfiguration("build"); //$NON-NLS-1$ + ProjectHelper.createLaunchConfiguration("bad"); //$NON-NLS-1$ + ProjectHelper.createLaunchConfiguration("importRequiringUserProp"); //$NON-NLS-1$ + ProjectHelper.createLaunchConfigurationForSeparateVM("echoPropertiesSepVM", "echoProperties"); //$NON-NLS-1$ //$NON-NLS-2$ + ProjectHelper.createLaunchConfigurationForSeparateVM("extensionPointSepVM", null); //$NON-NLS-1$ + ProjectHelper.createLaunchConfigurationForSeparateVM("extensionPointTaskSepVM", null); //$NON-NLS-1$ + ProjectHelper.createLaunchConfigurationForSeparateVM("extensionPointTypeSepVM", null); //$NON-NLS-1$ + ProjectHelper.createLaunchConfigurationForSeparateVM("input", null); //$NON-NLS-1$ + ProjectHelper.createLaunchConfigurationForSeparateVM("environmentVar", null); //$NON-NLS-1$ + + ProjectHelper.createLaunchConfigurationForBoth("breakpoints"); //$NON-NLS-1$ + ProjectHelper.createLaunchConfigurationForBoth("debugAntCall"); //$NON-NLS-1$ + ProjectHelper.createLaunchConfigurationForBoth("96022"); //$NON-NLS-1$ + ProjectHelper.createLaunchConfigurationForBoth("macrodef"); //$NON-NLS-1$ + ProjectHelper.createLaunchConfigurationForBoth("85769"); //$NON-NLS-1$ + + ProjectHelper.createLaunchConfiguration("big", ProjectHelper.PROJECT_NAME + "/buildfiles/performance/build.xml"); //$NON-NLS-1$ //$NON-NLS-2$ + + // do not show the Ant build failed error dialog + AntUIPlugin.getDefault().getPreferenceStore().setValue(IAntUIPreferenceConstants.ANT_ERROR_DIALOG, false); + } + } + + private static File getFileInPlugin(IPath path) { + try { + Bundle bundle = FrameworkUtil.getBundle(AntUITestUtil.class); + URL installURL = bundle.getEntry("/" + path.toString()); //$NON-NLS-1$ + URL localURL = FileLocator.toFileURL(installURL); + return new File(localURL.getFile()); + } catch (IOException e) { + return null; + } + } + + /** + * Returns the 'AntUITests' project. + * + * @return the test project + */ + public static IJavaProject getJavaProject() { + return JavaCore.create(getProject()); + } + + /** + * Returns the launch manager + * + * @return launch manager + */ + public static ILaunchManager getLaunchManager() { + return DebugPlugin.getDefault().getLaunchManager(); + } + + /** + * Returns the 'AntUITests' project. + * + * @return the test project + */ + public static IProject getProject() { + return ResourcesPlugin.getWorkspace().getRoot().getProject(ProjectHelper.PROJECT_NAME); + } +} diff --git a/ant/org.eclipse.ant.tests.ui/test plugin/org/eclipse/ant/tests/ui/testplugin/CloseWelcomeScreenExtension.java b/ant/org.eclipse.ant.tests.ui/test plugin/org/eclipse/ant/tests/ui/testplugin/CloseWelcomeScreenExtension.java new file mode 100644 index 00000000000..30e6ac78aba --- /dev/null +++ b/ant/org.eclipse.ant.tests.ui/test plugin/org/eclipse/ant/tests/ui/testplugin/CloseWelcomeScreenExtension.java @@ -0,0 +1,64 @@ +/******************************************************************************* + * Copyright (c) 2025 Vector Informatik GmbH and others. + * + * 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 + *******************************************************************************/ +package org.eclipse.ant.tests.ui.testplugin; + +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.jobs.Job; +import org.eclipse.ui.IWorkbench; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.intro.IIntroManager; +import org.eclipse.ui.intro.IIntroPart; +import org.eclipse.ui.progress.UIJob; +import org.junit.jupiter.api.extension.BeforeEachCallback; +import org.junit.jupiter.api.extension.ExtensionContext; + +public class CloseWelcomeScreenExtension implements BeforeEachCallback { + + private boolean welcomeClosed = false; + + @Override + public void beforeEach(ExtensionContext context) throws Exception { + assertWelcomeScreenClosed(); + } + + /** + * Ensure the welcome screen is closed because in 4.x the debug perspective + * opens a giant fast-view causing issues + */ + public void assertWelcomeScreenClosed() throws Exception { + if (!welcomeClosed && PlatformUI.isWorkbenchRunning()) { + final IWorkbench wb = PlatformUI.getWorkbench(); + if (wb != null) { + UIJob job = new UIJob("close welcome screen for Ant test suite") { //$NON-NLS-1$ + @Override + public IStatus runInUIThread(IProgressMonitor monitor) { + IWorkbenchWindow window = wb.getActiveWorkbenchWindow(); + if (window != null) { + IIntroManager im = wb.getIntroManager(); + IIntroPart intro = im.getIntro(); + if (intro != null) { + welcomeClosed = im.closeIntro(intro); + } + } + return Status.OK_STATUS; + } + }; + job.setPriority(Job.INTERACTIVE); + job.setSystem(true); + job.schedule(); + } + } + } + +} diff --git a/ant/org.eclipse.ant.tests.ui/test plugin/org/eclipse/ant/tests/ui/testplugin/ProjectHelper.java b/ant/org.eclipse.ant.tests.ui/test plugin/org/eclipse/ant/tests/ui/testplugin/ProjectHelper.java index b859d18764a..e639fd3de2c 100644 --- a/ant/org.eclipse.ant.tests.ui/test plugin/org/eclipse/ant/tests/ui/testplugin/ProjectHelper.java +++ b/ant/org.eclipse.ant.tests.ui/test plugin/org/eclipse/ant/tests/ui/testplugin/ProjectHelper.java @@ -13,6 +13,9 @@ *******************************************************************************/ package org.eclipse.ant.tests.ui.testplugin; +import static org.eclipse.ant.tests.ui.testplugin.AntUITestUtil.getJavaProject; +import static org.eclipse.ant.tests.ui.testplugin.AntUITestUtil.getLaunchManager; + import java.io.File; import java.io.IOException; import java.lang.reflect.InvocationTargetException; @@ -158,12 +161,14 @@ public static void createLaunchConfigurationForBoth(String launchConfigName) thr */ public static void createLaunchConfigurationForSeparateVM(String launchConfigName, String buildFileName) throws Exception { String bf = buildFileName; - ILaunchConfigurationType type = AbstractAntUITest.getLaunchManager().getLaunchConfigurationType(IAntLaunchConstants.ID_ANT_LAUNCH_CONFIGURATION_TYPE); - ILaunchConfigurationWorkingCopy config = type.newInstance(AbstractAntUITest.getJavaProject().getProject().getFolder("launchConfigurations"), launchConfigName); //$NON-NLS-1$ + ILaunchConfigurationType type = getLaunchManager() + .getLaunchConfigurationType(IAntLaunchConstants.ID_ANT_LAUNCH_CONFIGURATION_TYPE); + ILaunchConfigurationWorkingCopy config = type + .newInstance(getJavaProject().getProject().getFolder("launchConfigurations"), launchConfigName); //$NON-NLS-1$ config.setAttribute(IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME, "org.eclipse.ant.internal.launching.remote.InternalAntRunner"); //$NON-NLS-1$ config.setAttribute(IJavaLaunchConfigurationConstants.ATTR_CLASSPATH_PROVIDER, "org.eclipse.ant.ui.AntClasspathProvider"); //$NON-NLS-1$ - config.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME, AbstractAntUITest.getJavaProject().getElementName()); + config.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME, getJavaProject().getElementName()); if (bf == null) { bf = launchConfigName; } @@ -206,10 +211,12 @@ public static void createLaunchConfiguration(String launchConfigName) throws Exc * @return the handle to the new launch configuration */ public static ILaunchConfiguration createLaunchConfiguration(String launchConfigName, String path) throws CoreException { - ILaunchConfigurationType type = AbstractAntUITest.getLaunchManager().getLaunchConfigurationType(IAntLaunchConstants.ID_ANT_LAUNCH_CONFIGURATION_TYPE); - ILaunchConfigurationWorkingCopy config = type.newInstance(AbstractAntUITest.getJavaProject().getProject().getFolder("launchConfigurations"), launchConfigName); //$NON-NLS-1$ + ILaunchConfigurationType type = getLaunchManager() + .getLaunchConfigurationType(IAntLaunchConstants.ID_ANT_LAUNCH_CONFIGURATION_TYPE); + ILaunchConfigurationWorkingCopy config = type + .newInstance(getJavaProject().getProject().getFolder("launchConfigurations"), launchConfigName); //$NON-NLS-1$ - config.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME, AbstractAntUITest.getJavaProject().getElementName()); + config.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME, getJavaProject().getElementName()); config.setAttribute(IExternalToolConstants.ATTR_LOCATION, "${workspace_loc:/" + path + "}"); //$NON-NLS-1$ //$NON-NLS-2$ config.setAttribute(IDebugUIConstants.ATTR_LAUNCH_IN_BACKGROUND, true);