Skip to content

Commit

Permalink
Fix failing tests for the M2E-PDE connector console printout handler
Browse files Browse the repository at this point in the history
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 <?xml version="1.0" encoding="ISO-8859-1"... @1:42)
  • Loading branch information
HannesWell committed Aug 24, 2024
1 parent fc87858 commit 08f1c7c
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
<extension>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-build</artifactId>
<version>3.0.0</version>
<version>4.0.8</version>
</extension>
</extensions>
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<packaging>pom</packaging>

<properties>
<tycho.version>3.0.0</tycho.version>
<tycho.version>4.0.8</tycho.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

Expand Down Expand Up @@ -37,18 +37,18 @@
<version>${tycho.version}</version>
<configuration>
<target>
<artifact>
<groupId>org.eclipse.m2e.tests</groupId>
<artifactId>simple.target</artifactId>
<version>1.0.0-SNAPSHOT</version>
</artifact>
<location includeAllPlatforms="false" includeConfigurePhase="true" includeMode="planner" includeSource="false" type="InstallableUnit">
<repository location="https://download.eclipse.org/eclipse/updates/4.32/"/>
<unit id="org.eclipse.equinox.launcher" version="0.0.0"/>
<unit id="org.eclipse.core.runtime" version="0.0.0"/>
<unit id="org.junit" version="0.0.0"/>
</location>
</target>
</configuration>
</plugin>
</plugins>
</build>
<modules>
<module>simple.target</module>
<module>simple.tests</module>
</modules>
</project>

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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");
Expand All @@ -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()));

Expand Down Expand Up @@ -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 ---
Expand Down Expand Up @@ -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);
Expand All @@ -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
Expand Down Expand Up @@ -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<String> lines(String consoleText) {
Expand Down

0 comments on commit 08f1c7c

Please sign in to comment.