use of org.eclipse.lsp4j.MessageParams in project eclipse.jdt.ls by eclipse.
the class GradleProjectImporter method getGradleDistribution.
public static GradleDistribution getGradleDistribution(Path rootFolder) {
PreferenceManager preferencesManager = JavaLanguageServerPlugin.getPreferencesManager();
Preferences preferences = getPreferences();
if (preferencesManager != null && preferences.isGradleWrapperEnabled() && Files.exists(rootFolder.resolve("gradlew"))) {
WrapperValidator validator = new WrapperValidator();
try {
ValidationResult result = validator.checkWrapper(rootFolder.toFile().getAbsolutePath());
if (result.isValid()) {
WrapperGradleDistribution gradleDistribution = GradleDistribution.fromBuild();
return gradleDistribution;
} else {
if (!WrapperValidator.contains(result.getChecksum())) {
ProjectsManager pm = JavaLanguageServerPlugin.getProjectsManager();
if (pm != null && pm.getConnection() != null) {
if (preferencesManager.getClientPreferences().isGradleChecksumWrapperPromptSupport()) {
String id = "gradle/checksum/prompt";
ExecuteCommandParams params = new ExecuteCommandParams(id, asList(result.getWrapperJar(), result.getChecksum()));
pm.getConnection().sendNotification(params);
} else {
// @formatter:off
String message = GRADLE_WRAPPER_CHEKSUM_WARNING_TEMPLATE.replaceAll("@wrapper@", result.getWrapperJar()).replaceAll("@checksum@", result.getChecksum());
// @formatter:on
pm.getConnection().showMessage(new MessageParams(MessageType.Error, message));
}
}
}
}
} catch (CoreException e) {
JavaLanguageServerPlugin.logException(e.getMessage(), e);
}
}
if (StringUtils.isNotBlank(preferences.getGradleVersion())) {
List<GradleVersion> versions = CorePlugin.publishedGradleVersions().getVersions();
GradleVersion gradleVersion = null;
String versionString = preferences.getGradleVersion();
GradleVersion requiredVersion = GradleVersion.version(versionString);
for (GradleVersion version : versions) {
if (version.compareTo(requiredVersion) == 0) {
gradleVersion = version;
}
}
if (gradleVersion != null) {
return GradleDistribution.forVersion(gradleVersion.getVersion());
} else {
JavaLanguageServerPlugin.logInfo("Invalid gradle version" + versionString);
}
}
File gradleHomeFile = getGradleHomeFile();
if (gradleHomeFile != null) {
return GradleDistribution.forLocalInstallation(gradleHomeFile);
}
return DEFAULT_DISTRIBUTION;
}
use of org.eclipse.lsp4j.MessageParams in project eclipse.jdt.ls by eclipse.
the class JVMConfiguratorTest method testInvalidRuntime.
@Test
public void testInvalidRuntime() throws Exception {
when(this.preferenceManager.getClientPreferences()).thenReturn(clientPreferences);
when(clientPreferences.isActionableRuntimeNotificationSupport()).thenReturn(false);
Preferences prefs = new Preferences();
File file = new File("fakejdk2", "11a" + File.separator + "bin");
String path = file.getAbsolutePath();
Set<RuntimeEnvironment> runtimes = new HashSet<>();
RuntimeEnvironment runtime = new RuntimeEnvironment();
runtime.setPath(path);
runtime.setName(ENVIRONMENT_NAME);
runtimes.add(runtime);
prefs.setRuntimes(runtimes);
JVMConfigurator.configureJVMs(prefs, javaClient);
List<MessageParams> notifications = getClientRequests("showMessage");
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());
}
Aggregations