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;
}
Aggregations