Skip to content

Commit

Permalink
Improve handling of settings files exported from Eclipse
Browse files Browse the repository at this point in the history
Fixes redhat-developer/vscode-java#1939

Signed-off-by: Snjezana Peco <[email protected]>
  • Loading branch information
snjeza authored and rgrunber committed May 15, 2021
1 parent 09af6aa commit 9b71f1c
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.eclipse.core.internal.preferences.EclipsePreferences;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
Expand Down Expand Up @@ -289,9 +290,13 @@ public static void configureSettings(Preferences preferences) {
if (properties != null && !properties.isEmpty()) {
properties.forEach((k, v) -> {
if (k instanceof String && v instanceof String) {
k = ((String) k).replace("/instance/", "");
if (javaOptions.get(k) != null) {
javaOptions.put((String) k, (String) v);
String path = (String) k;
if (!"file_export_version".equals(path) && path.charAt(0) != '@' && path.charAt(0) != '!') {
String[] decoded = EclipsePreferences.decodePath(path);
String key = decoded[1];
if (key != null) {
javaOptions.put(key, (String) v);
}
}
}
});
Expand Down
6 changes: 6 additions & 0 deletions org.eclipse.jdt.ls.tests/formatter/settings2.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#Mon May 10 12:54:52 CEST 2021
\!/=
/instance/org.eclipse.jdt.core/org.eclipse.jdt.core.compiler.problem.staticAccessReceiver=ignore
/instance/org.eclipse.jdt.core/org.eclipse.jdt.core.compiler.problem.missingSerialVersion=warning
@org.eclipse.jdt.core=3.25.0.v20210223-0522
file_export_version=3.0
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@
@RunWith(MockitoJUnitRunner.class)
public class JavaSettingsTest extends AbstractCompilationUnitBasedTest {

private static final String MISSING_SERIAL_VERSION = "org.eclipse.jdt.core.compiler.problem.missingSerialVersion";
private static final String MISSING_SERIAL_VERSION = JavaCore.COMPILER_PB_MISSING_SERIAL_VERSION;
private static final String STATIC_ACCESS_RECEIVER = JavaCore.COMPILER_PB_STATIC_ACCESS_RECEIVER;
private IJavaProject javaProject;
private Hashtable<String, String> options;

Expand Down Expand Up @@ -170,4 +171,32 @@ public void testFormatter() throws Exception {
assertEquals(DefaultCodeFormatterConstants.END_OF_LINE, JavaCore.getOption(DefaultCodeFormatterConstants.FORMATTER_BRACE_POSITION_FOR_BLOCK));
}

// https://github.com/redhat-developer/vscode-java/issues/1939
@Test
public void testSettingsV3() throws Exception {
assertEquals("ignore", JavaCore.getOption(MISSING_SERIAL_VERSION));
assertEquals("warning", JavaCore.getOption(STATIC_ACCESS_RECEIVER));
assertEquals("ignore", javaProject.getOption(MISSING_SERIAL_VERSION, true));
assertEquals("warning", javaProject.getOption(STATIC_ACCESS_RECEIVER, true));
try {
String settingsUrl = "../../formatter/settings2.prefs";
preferences.setSettingsUrl(settingsUrl);
projectsManager.fileChanged(preferences.getSettingsAsURI().toURL().toString(), CHANGE_TYPE.CHANGED);
waitForBackgroundJobs();
assertEquals("warning", JavaCore.getOption(MISSING_SERIAL_VERSION));
assertEquals("ignore", JavaCore.getOption(STATIC_ACCESS_RECEIVER));
assertEquals("warning", javaProject.getOption(MISSING_SERIAL_VERSION, true));
assertEquals("ignore", javaProject.getOption(STATIC_ACCESS_RECEIVER, true));
} finally {
JavaCore.setOptions(options);
preferences.setSettingsUrl(null);
StandardProjectsManager.configureSettings(preferences);
waitForBackgroundJobs();
}
assertEquals("ignore", JavaCore.getOption(MISSING_SERIAL_VERSION));
assertEquals("warning", JavaCore.getOption(STATIC_ACCESS_RECEIVER));
assertEquals("ignore", javaProject.getOption(MISSING_SERIAL_VERSION, true));
assertEquals("warning", javaProject.getOption(STATIC_ACCESS_RECEIVER, true));
}

}

0 comments on commit 9b71f1c

Please sign in to comment.