@@ -38,12 +38,15 @@
${tycho-version}
+
+
+ ${lsp4e.targetPlatform}
+
false
true
true
1200
-Dfile.encoding=${project.build.sourceEncoding} -Xms1g -Xmx1g -Djava.util.logging.config.file=${project.basedir}/src/jul.properties ${ui.test.vmargs} ${os-jvm-flags}
- junit6
diff --git a/org.eclipse.lsp4e.test/src/org/eclipse/lsp4e/test/codeactions/CodeActionTests.java b/org.eclipse.lsp4e.test/src/org/eclipse/lsp4e/test/codeactions/CodeActionTests.java
index ba901586f..9dfa84da6 100644
--- a/org.eclipse.lsp4e.test/src/org/eclipse/lsp4e/test/codeactions/CodeActionTests.java
+++ b/org.eclipse.lsp4e.test/src/org/eclipse/lsp4e/test/codeactions/CodeActionTests.java
@@ -188,12 +188,9 @@ public void testCodeActionLiteralWorkspaceEdit() throws CoreException {
@Test
public void testNoCodeActionOnReadOnlySource() throws CoreException {
IFile f = TestUtils.createUniqueTestFile(project, "error");
- f.setResourceAttributes(new ResourceAttributes() {
- @Override
- public boolean isReadOnly() {
- return true;
- }
- });
+ ResourceAttributes attrs = f.getResourceAttributes();
+ attrs.setReadOnly(true);
+ f.setResourceAttributes(attrs);
final var tEdit = new TextEdit(new Range(new Position(0, 0), new Position(0, 5)), "fixed");
final var wEdit = new WorkspaceEdit(Collections.singletonMap(f.getLocationURI().toString(), List.of(tEdit)));
diff --git a/org.eclipse.lsp4e.test/src/org/eclipse/lsp4e/test/documentLink/DocumentLinkReconcilingTest.java b/org.eclipse.lsp4e.test/src/org/eclipse/lsp4e/test/documentLink/DocumentLinkReconcilingTest.java
index afbd0f257..90ff3bcfa 100644
--- a/org.eclipse.lsp4e.test/src/org/eclipse/lsp4e/test/documentLink/DocumentLinkReconcilingTest.java
+++ b/org.eclipse.lsp4e.test/src/org/eclipse/lsp4e/test/documentLink/DocumentLinkReconcilingTest.java
@@ -37,6 +37,7 @@
import org.eclipse.swt.custom.StyleRange;
import org.eclipse.swt.graphics.Color;
import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.condition.DisabledIfSystemProperty;
public class DocumentLinkReconcilingTest extends AbstractTestWithProject {
@@ -188,6 +189,9 @@ public void testMidLineClippedDocumentLinkReconciling() throws Exception {
}
@Test
+ @DisabledIfSystemProperty(named = "lsp4e.targetPlatform", matches = "oldest", disabledReason = """
+ Fails on oldest target platform.
+ Note: this will only work when called from Maven or when setting the propery explicitly.""")
public void testClippedDocumentLinkReconciling() throws Exception {
MockLanguageServer.INSTANCE.setDocumentLinks(CONTENT_LINKS);
diff --git a/org.eclipse.lsp4e.test/src/org/eclipse/lsp4e/test/utils/AbstractTestWithProject.java b/org.eclipse.lsp4e.test/src/org/eclipse/lsp4e/test/utils/AbstractTestWithProject.java
index 316e8271d..381dd03a4 100644
--- a/org.eclipse.lsp4e.test/src/org/eclipse/lsp4e/test/utils/AbstractTestWithProject.java
+++ b/org.eclipse.lsp4e.test/src/org/eclipse/lsp4e/test/utils/AbstractTestWithProject.java
@@ -15,6 +15,7 @@
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.ResourceAttributes;
import org.eclipse.core.runtime.CoreException;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
@@ -53,6 +54,17 @@ private static void deleteProjectWithRetries(IProject project, int maxAttempts,
if (!project.exists()) {
break;
}
+ project.open(null);
+ project.accept(r -> {
+ ResourceAttributes attrs = r.getResourceAttributes();
+ // At least one test creates a read-only resource.
+ // This leads to errors when trying to delete the project, so we make all files writable again.
+ if (attrs != null && attrs.isReadOnly()) {
+ attrs.setReadOnly(false);
+ r.setResourceAttributes(attrs);
+ }
+ return true;
+ });
project.close(null);
project.delete(IResource.FORCE | IResource.ALWAYS_DELETE_PROJECT_CONTENT, null);
break;
diff --git a/org.eclipse.lsp4e/src/org/eclipse/lsp4e/outline/CNFOutlinePage.java b/org.eclipse.lsp4e/src/org/eclipse/lsp4e/outline/CNFOutlinePage.java
index fd267ad48..9b32c07c9 100644
--- a/org.eclipse.lsp4e/src/org/eclipse/lsp4e/outline/CNFOutlinePage.java
+++ b/org.eclipse.lsp4e/src/org/eclipse/lsp4e/outline/CNFOutlinePage.java
@@ -16,6 +16,7 @@
import static org.eclipse.lsp4e.internal.NullSafetyHelper.castNullable;
import static org.eclipse.lsp4e.internal.NullSafetyHelper.lateNonNull;
+import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import org.eclipse.core.runtime.Adapters;
@@ -54,7 +55,6 @@
import org.eclipse.swt.widgets.Control;
import org.eclipse.ui.IActionBars;
import org.eclipse.ui.navigator.CommonViewer;
-import org.eclipse.ui.navigator.CommonViewerComparator;
import org.eclipse.ui.navigator.CommonViewerSorter;
import org.eclipse.ui.texteditor.ITextEditor;
import org.eclipse.ui.views.contentoutline.IContentOutlinePage;
@@ -77,8 +77,8 @@ public class CNFOutlinePage implements IContentOutlinePage, ILabelProviderListen
private final LanguageServerWrapper wrapper;
- @Nullable
- private static Boolean canUseCommonViewerComparator;
+ private static @Nullable Class> comparatorClass = null;
+ private static boolean checkedForComparatorClass = false;
public CNFOutlinePage(LanguageServerWrapper wrapper, @Nullable ITextEditor textEditor) {
preferences = InstanceScope.INSTANCE.getNode(LanguageServerPlugin.PLUGIN_ID);
@@ -95,7 +95,7 @@ public void createControl(final Composite parent) {
if (document != null) {
outlineViewer.setInput(new OutlineViewerInput(document, wrapper, textEditor));
}
- outlineViewer.setComparator(createComparator());
+ configureSorterOrComparator(outlineViewer);
outlineViewer.getLabelProvider().addListener(this);
final var textEditor = this.textEditor;
if (textEditor != null) {
@@ -130,60 +130,34 @@ public void createControl(final Composite parent) {
}
/**
- * Try to be compatible with older Eclipse versions (before 4.39) where
- * CommonViewerComparator is not available.
- *
- * @return comparator for the outline
- */
- private static ViewerComparator createComparator() {
- if (checkIfCommonViewerComparatorAvailable()) {
- return Eclipse439PlusComparator.create();
- }
- return EclipseBefore439Comparator.create();
- }
-
- private static boolean checkIfCommonViewerComparatorAvailable() {
- if(canUseCommonViewerComparator != null) {
- return canUseCommonViewerComparator.booleanValue();
- }
- try {
- Class.forName("org.eclipse.ui.navigator.CommonViewerComparator"); //$NON-NLS-1$
- canUseCommonViewerComparator = Boolean.TRUE;
- return true;
- } catch (ClassNotFoundException e) {
- canUseCommonViewerComparator = Boolean.FALSE;
- return false;
- }
- }
-
- /**
- * Compatible with modern Eclipse versions (4.39 and later) where
- * CommonViewerComparator is available.
- *
- * This is extracted to an extra class to avoid classloading issues on older Eclipse versions where
- * the CommonViewerComparator class is not available. If we try to load a class referencing
- * CommonViewerComparator on an older Eclipse version, it will result in a ClassNotFoundException.
- *
- * @return comparator for the outline
+ * Workaround for a Bug in Eclipse 4.39:
+ * Before 4.39, the CommonViewerSorter can be used.
+ * Starting with 4.39, using the CommonViewerSorter breaks sorting,
+ * so the newer CommonViewerComparator must be used.
+ * Once our oldest Target Platform contains CommonViewerComparator, we can drop this workaround.
+ * @param viewer The viewer to configure
*/
- private static final class Eclipse439PlusComparator {
- static ViewerComparator create() {
- return new CommonViewerComparator();
+ private void configureSorterOrComparator(CommonViewer viewer) {
+ if (!checkedForComparatorClass) {
+ checkedForComparatorClass = true;
+ try {
+ comparatorClass = Class.forName("org.eclipse.ui.navigator.CommonViewerComparator"); //$NON-NLS-1$
+ } catch (ClassNotFoundException e) {
+ // Will trigger on < 4.39.
+ }
}
- }
- /**
- * Compatible with older Eclipse versions (before 4.39) where
- * CommonViewerComparator is not available.
- *
- * This is extracted to an extra class to avoid classloading issues
- *
- * @return comparator for the outline
- */
- private static final class EclipseBefore439Comparator {
- static ViewerComparator create() {
- return new CommonViewerSorter();
+ if (comparatorClass != null) {
+ try {
+ ViewerComparator comparator = (ViewerComparator) comparatorClass.getDeclaredConstructor().newInstance();
+ viewer.setComparator(comparator);
+ return;
+ } catch (InstantiationException | IllegalAccessException | IllegalArgumentException
+ | InvocationTargetException | NoSuchMethodException | SecurityException e) {
+ // Fall-through
+ }
}
+ viewer.setSorter(new CommonViewerSorter());
}
/**
diff --git a/pom.xml b/pom.xml
index 28dd40043..d2907a2ed 100644
--- a/pom.xml
+++ b/pom.xml
@@ -15,6 +15,7 @@
scm:git:https://github.com/eclipse-lsp4e/lsp4e.git
error
+ oldest