Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix javadoc in 'java.configuration.runtimes' settings #1683

Merged
merged 1 commit into from
Mar 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

import java.io.File;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;

import org.eclipse.core.runtime.IPath;
Expand Down Expand Up @@ -137,11 +139,13 @@ public URL getJavadocURL() {
url = new URL(javadoc);
} catch (MalformedURLException e) {
File file = new File(javadoc);
if (file.exists()) {
if (file.exists() && file.isAbsolute()) {
try {
return JDTUtils.toURI(javadoc).toURL();
} catch (MalformedURLException e1) {
JavaLanguageServerPlugin.logException(e.getMessage(), e);
URI uri = new URI("file", javadoc, null);
uri = new URI(ResourceUtils.fixURI(uri));
return uri.toURL();
} catch (MalformedURLException | IllegalArgumentException | URISyntaxException e1) {
JavaLanguageServerPlugin.logException(e1.getMessage(), e1);
}
}
JavaLanguageServerPlugin.logInfo("Invalid javadoc: " + javadoc);
Expand Down
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,42 @@ public void testJVM() throws Exception {
assertNull(vm);
}

@Test
public void testInvalidJavadoc() throws Exception {
Preferences prefs = new Preferences();
Bundle bundle = Platform.getBundle(JavaLanguageServerTestPlugin.PLUGIN_ID);
URL url = FileLocator.toFileURL(bundle.getEntry("/fakejdk2/11a"));
File file = URIUtil.toFile(URIUtil.toURI(url));
String path = file.getAbsolutePath();
String javadoc = new File(file, "doc").getAbsolutePath();
Set<RuntimeEnvironment> runtimes = new HashSet<>();
RuntimeEnvironment runtime = new RuntimeEnvironment();
runtime.setPath(path);
runtime.setName(ENVIRONMENT_NAME);
runtime.setJavadoc(javadoc);
assertTrue(runtime.isValid());
runtimes.add(runtime);
prefs.setRuntimes(runtimes);
file = runtime.getInstallationFile();
assertTrue(file != null && file.isDirectory());
IVMInstallType installType = JavaRuntime.getVMInstallType(StandardVMType.ID_STANDARD_VM_TYPE);
IStatus status = installType.validateInstallLocation(file);
assertTrue(status.toString(), status.isOK());
boolean changed = JVMConfigurator.configureJVMs(prefs);
assertTrue("A VM hasn't been changed", changed);
JobHelpers.waitForJobsToComplete();
IVMInstall vm = JVMConfigurator.findVM(runtime.getInstallationFile(), ENVIRONMENT_NAME);
assertNotNull(vm);
assertTrue(vm instanceof IVMInstall2);
String version = ((IVMInstall2) vm).getJavaVersion();
assertTrue(version.startsWith(JavaCore.VERSION_11));
LibraryLocation[] libs = vm.getLibraryLocations();
assertNotNull(libs);
for (LibraryLocation lib : libs) {
assertEquals(runtime.getJavadocURL(), lib.getJavadocLocation());
}
}

@Test
public void testPreviewFeatureSettings() throws Exception {
IVMInstallChangedListener jvmConfigurator = new JVMConfigurator();
Expand Down Expand Up @@ -223,7 +259,7 @@ public void testInvalidRuntime() throws Exception {
assertEquals(1, notifications.size());
MessageParams notification = notifications.get(0);
assertEquals(MessageType.Error, notification.getType());
assertEquals("Invalid runtime for " + runtime.getName() + ": 'bin' should be removed from the path (" + runtime.getPath() + ").", notification.getMessage());
assertEquals("Invalid runtime for " + runtime.getName() + ": 'bin' should be removed from the path (" + runtime.getPath() + ").", notification.getMessage());
}

private void assertComplianceAndPreviewSupport(IJavaProject javaProject, String compliance, boolean previewEnabled) {
Expand Down