From 05e51bca8c32e9d999eac61ed64df3d4ab528f23 Mon Sep 17 00:00:00 2001 From: Hannes Wellmann Date: Sat, 24 Aug 2024 17:52:18 +0200 Subject: [PATCH] Fix failing tests for the M2E-PDE connector console printout handler and clean-up ConsoleTest. The 'ConsoleTest.testConsole_debuggerAttachmentAndLinkAlignmentAndBehavior_tychoProject' failed because the test-case used the out-dated Tycho version 3.0.0, which seems to have a dependency that pulls in Apache's 'commons-parent' version 35 that is considered as invalid by recent Maven versions: org\apache\commons\commons-parent\35\commons-parent-35.pom: UTF-8 BOM plus xml decl of ISO-8859-1 is incompatible (position: START_DOCUMENT seen org.eclipse.tycho tycho-build - 3.0.0 + 4.0.8 \ No newline at end of file diff --git a/org.eclipse.m2e.core.ui.tests/resources/projects/simple-tycho/pom.xml b/org.eclipse.m2e.core.ui.tests/resources/projects/simple-tycho/pom.xml index 671342cc8f..09fc582bec 100644 --- a/org.eclipse.m2e.core.ui.tests/resources/projects/simple-tycho/pom.xml +++ b/org.eclipse.m2e.core.ui.tests/resources/projects/simple-tycho/pom.xml @@ -9,7 +9,7 @@ pom - 3.0.0 + 4.0.8 UTF-8 @@ -37,18 +37,18 @@ ${tycho.version} - - org.eclipse.m2e.tests - simple.target - 1.0.0-SNAPSHOT - + + + + + + - simple.target simple.tests \ No newline at end of file diff --git a/org.eclipse.m2e.core.ui.tests/resources/projects/simple-tycho/simple.target/simple.target.target b/org.eclipse.m2e.core.ui.tests/resources/projects/simple-tycho/simple.target/simple.target.target deleted file mode 100644 index 38d13792a5..0000000000 --- a/org.eclipse.m2e.core.ui.tests/resources/projects/simple-tycho/simple.target/simple.target.target +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/org.eclipse.m2e.core.ui.tests/src/org/eclipse/m2e/core/ui/tests/ConsoleTest.java b/org.eclipse.m2e.core.ui.tests/src/org/eclipse/m2e/core/ui/tests/ConsoleTest.java index eb6561733d..60a63a0bac 100644 --- a/org.eclipse.m2e.core.ui.tests/src/org/eclipse/m2e/core/ui/tests/ConsoleTest.java +++ b/org.eclipse.m2e.core.ui.tests/src/org/eclipse/m2e/core/ui/tests/ConsoleTest.java @@ -29,7 +29,6 @@ import java.io.File; import java.io.IOException; -import java.io.InputStream; import java.net.URISyntaxException; import java.net.URL; import java.nio.file.Files; @@ -52,6 +51,7 @@ 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.core.runtime.NullProgressMonitor; import org.eclipse.debug.core.DebugPlugin; import org.eclipse.debug.core.ILaunch; @@ -178,7 +178,7 @@ public void testConsole_debuggerAttachmentAndLinkAlignmentAndBehavior_tychoProje assertLinkTextAndOpenedEditor(0, "org.eclipse.m2e.tests:" + TYCHO_TEST_PROJECT, // ManifestEditor.class, TYCHO_TEST_PROJECT, document); - assertLinkTextAndOpenedEditor(3, TYCHO_TEST_PROJECT, // + assertLinkTextAndOpenedEditor(-2, TYCHO_TEST_PROJECT, // ManifestEditor.class, TYCHO_TEST_PROJECT, document); assertDebugeePrintOutAndDebuggerLaunch(document, TYCHO_TEST_PROJECT, "8000"); @@ -188,7 +188,8 @@ private void assertLinkTextAndOpenedEditor(int index, String expectedLinkText, C String expectedEditorTitle, IDocument document) throws Exception { Position[] positions = document.getPositions(ConsoleHyperlinkPosition.HYPER_LINK_CATEGORY); - ConsoleHyperlinkPosition link = (ConsoleHyperlinkPosition) positions[index]; + int i = index < 0 ? positions.length + index : index; + ConsoleHyperlinkPosition link = (ConsoleHyperlinkPosition) positions[i]; assertEquals(expectedLinkText, document.get(link.getOffset(), link.getLength())); @@ -218,10 +219,11 @@ private static void assertDebugeePrintOutAndDebuggerLaunch(IDocument document, S .getAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME, "")); assertEquals(ILaunchManager.DEBUG_MODE, debugLaunch.getLaunchMode()); long startTime = System.currentTimeMillis(); - while (!debugLaunch.isTerminated() && System.currentTimeMillis() - startTime < 10000 ) { + while (!debugLaunch.isTerminated() && System.currentTimeMillis() - startTime < 10000) { Thread.onSpinWait(); } - assertTrue("Debug launch " + debugLaunch.getLaunchConfiguration().getName() + " is not terminated yet after waiting for 10 seconds", debugLaunch.isTerminated()); + assertTrue("Debug launch " + debugLaunch.getLaunchConfiguration().getName() + + " is not terminated yet after waiting for 10 seconds", debugLaunch.isTerminated()); } // --- common utility methods --- @@ -251,11 +253,9 @@ private static Path importProjectIntoWorkspace(String containerPath, String test Path tempProjectFolder = copyTestProjectIntoWorkspace(containerPath); Path projectPath = tempProjectFolder.resolve(testProjectName); - try (InputStream input = Files.newInputStream(projectPath.resolve(".project"))) { - IProjectDescription description = workspace.loadProjectDescription(input); - description.setLocationURI(projectPath.toUri()); - project.create(description, null); - } + IPath projectFile = IPath.fromPath(projectPath.resolve(".project")); + IProjectDescription description = workspace.loadProjectDescription(projectFile); + project.create(description, null); project.open(monitor); // build project to make it available in the PluginRegistryManager project.refreshLocal(IResource.DEPTH_INFINITE, null); @@ -265,7 +265,6 @@ private static Path importProjectIntoWorkspace(String containerPath, String test return Path.of(project.getLocationURI()).getParent(); } - private static Path copyTestProjectIntoWorkspace(String projectName) throws IOException, URISyntaxException { String projectPath = "/resources/projects/" + projectName; // import project into workspace, the super class cleans up after each test @@ -335,12 +334,10 @@ public void documentAboutToBeChanged(DocumentEvent event) { // ignore } private static boolean isBuildFinished(String text) { - return lines(text) - .anyMatch(l -> l.startsWith("[INFO] Finished at: ") - || l.startsWith("[\u001B[1;34mINFO\u001B[m] Finished at: ")); + return lines(text).anyMatch( + l -> l.startsWith("[INFO] Finished at: ") || l.startsWith("[\u001B[1;34mINFO\u001B[m] Finished at: ")); } - private static final Pattern LINE_SEPARATOR = Pattern.compile("\\R"); private static Stream lines(String consoleText) {