Search in sources :

Example 1 with GradleVersion

use of org.eclipse.buildship.core.internal.util.gradle.GradleVersion 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)

Aggregations

File (java.io.File)1 WrapperGradleDistribution (org.eclipse.buildship.core.WrapperGradleDistribution)1 GradleVersion (org.eclipse.buildship.core.internal.util.gradle.GradleVersion)1 CoreException (org.eclipse.core.runtime.CoreException)1 PreferenceManager (org.eclipse.jdt.ls.core.internal.preferences.PreferenceManager)1 Preferences (org.eclipse.jdt.ls.core.internal.preferences.Preferences)1 ValidationResult (org.eclipse.jdt.ls.internal.gradle.checksums.ValidationResult)1 WrapperValidator (org.eclipse.jdt.ls.internal.gradle.checksums.WrapperValidator)1 ExecuteCommandParams (org.eclipse.lsp4j.ExecuteCommandParams)1 MessageParams (org.eclipse.lsp4j.MessageParams)1