Search in sources :

Example 11 with MessageParams

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;
}
Also used : WrapperGradleDistribution(org.eclipse.buildship.core.WrapperGradleDistribution) WrapperValidator(org.eclipse.jdt.ls.internal.gradle.checksums.WrapperValidator) MessageParams(org.eclipse.lsp4j.MessageParams) ExecuteCommandParams(org.eclipse.lsp4j.ExecuteCommandParams) ValidationResult(org.eclipse.jdt.ls.internal.gradle.checksums.ValidationResult) PreferenceManager(org.eclipse.jdt.ls.core.internal.preferences.PreferenceManager) CoreException(org.eclipse.core.runtime.CoreException) Preferences(org.eclipse.jdt.ls.core.internal.preferences.Preferences) GradleVersion(org.eclipse.buildship.core.internal.util.gradle.GradleVersion) File(java.io.File)

Example 12 with MessageParams

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());
}
Also used : MessageParams(org.eclipse.lsp4j.MessageParams) ClientPreferences(org.eclipse.jdt.ls.core.internal.preferences.ClientPreferences) IEclipsePreferences(org.eclipse.core.runtime.preferences.IEclipsePreferences) Preferences(org.eclipse.jdt.ls.core.internal.preferences.Preferences) File(java.io.File) HashSet(java.util.HashSet) AbstractInvisibleProjectBasedTest(org.eclipse.jdt.ls.core.internal.managers.AbstractInvisibleProjectBasedTest) Test(org.junit.Test)

Aggregations

MessageParams (org.eclipse.lsp4j.MessageParams)12 HashMap (java.util.HashMap)3 IDefinition (org.apache.flex.compiler.definitions.IDefinition)3 WorkspaceEdit (org.eclipse.lsp4j.WorkspaceEdit)3 File (java.io.File)2 IIdentifierNode (org.apache.flex.compiler.tree.as.IIdentifierNode)2 CoreException (org.eclipse.core.runtime.CoreException)2 Preferences (org.eclipse.jdt.ls.core.internal.preferences.Preferences)2 STS4LanguageClient (org.springframework.ide.vscode.commons.languageserver.STS4LanguageClient)2 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 ConcurrentModificationException (java.util.ConcurrentModificationException)1 HashSet (java.util.HashSet)1 List (java.util.List)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 ISourceLocation (org.apache.flex.compiler.common.ISourceLocation)1