Skip to content
Draft
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
1 change: 0 additions & 1 deletion org.eclipse.jdt.ls.core/build.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ bin.includes = META-INF/,\
lifecycle-mapping-metadata.xml,\
plugin.properties,\
gradle/checksums/checksums.json,\
gradle/checksums/versions.json,\
gradle/protobuf/init.gradle,\
gradle/init/init.gradle,\
gradle/android/init.gradle,\
Expand Down
40 changes: 9 additions & 31 deletions org.eclipse.jdt.ls.core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,45 +31,23 @@
import groovy.json.JsonSlurper
import groovy.json.JsonOutput

import java.net.http.HttpClient
import java.net.http.HttpClient.Redirect
import java.net.http.HttpRequest
import java.net.http.HttpResponse.BodyHandlers
import java.util.concurrent.CompletableFuture
import java.util.concurrent.ExecutorService
import java.util.concurrent.Executors
import java.util.stream.Collectors


def checksumsFile = new File(project.basedir.absolutePath, "gradle/checksums/checksums.json")
if (System.getProperty("eclipse.jdt.ls.skipGradleChecksums") != null && checksumsFile.exists()) {
println "Skipping gradle wrapper validation checksums ..."
return
}

def versionUrl = new URL("https://services.gradle.org/versions/all")
def versionStr = versionUrl.text;
def versionsFile = new File(project.basedir.absolutePath, "gradle/checksums/versions.json")
versionsFile.parentFile.mkdirs() //just in case
versionsFile.write(versionStr)
println "Wrote to ${versionsFile}"

def versions = new JsonSlurper().parseText(versionStr)
def versions = new JsonSlurper().parse(new URL("https://services.gradle.org/versions/all"))
def onlyReleases = Boolean.getBoolean("eclipse.jdt.ls.onlyGradleReleases")

class Checksum {
String wrapperChecksumUrl;
String sha256
def checksums = versions.findAll {
it.wrapperChecksumUrl != null &&
!(onlyReleases && (it.nightly || it.snapshot || it.rcFor != "" || it.broken))
}.collect {
[version: it.version, wrapperChecksumUrl: it.wrapperChecksumUrl, sha256: it.wrapperChecksum]
}
def checksums = []
versions.each {
boolean isNonRelease = it.nightly || it.snapshot || (it.rcFor != "") || it.broken
if (it.wrapperChecksumUrl == null || (System.getProperty("eclipse.jdt.ls.onlyGradleReleases") && isNonRelease)) {
return
}
checksums.add(new Checksum(wrapperChecksumUrl: it.wrapperChecksumUrl, sha256: it.wrapperChecksum));
}
def json = JsonOutput.toJson(checksums)
checksumsFile.write(JsonOutput.prettyPrint(json))

checksumsFile.write(JsonOutput.prettyPrint(JsonOutput.toJson(checksums)))
println "Wrote to ${checksumsFile}"
</script>
</scripts>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,10 +226,6 @@ public static void waitForJobs(String jobFamily, IProgressMonitor monitor) {
}
}

public static void waitForLoadingGradleVersionJob() {
waitForJobs(LoadingGradleVersionJobMatcher.INSTANCE, MAX_TIME_MILLIS);
}

public static void waitForBuildOffJobs(int maxTimeMillis) {
waitForJobs(BuildJobOffMatcher.INSTANCE, maxTimeMillis);
}
Expand Down Expand Up @@ -351,17 +347,6 @@ public boolean matches(Job job) {

}

static class LoadingGradleVersionJobMatcher implements IJobMatcher {

public static final IJobMatcher INSTANCE = new LoadingGradleVersionJobMatcher();

@Override
public boolean matches(Job job) {
return job.getClass().getName().matches("org.eclipse.buildship.core.internal.util.gradle.PublishedGradleVersionsWrapper.LoadVersionsJob");
}

}

static class DownloadSourcesJobMatcher implements IJobMatcher {

public static final IJobMatcher INSTANCE = new DownloadSourcesJobMatcher();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,8 @@
import org.eclipse.buildship.core.BuildConfiguration;
import org.eclipse.buildship.core.GradleBuild;
import org.eclipse.buildship.core.GradleCore;
import org.eclipse.buildship.core.GradleDistribution;
import org.eclipse.buildship.core.WrapperGradleDistribution;
import org.eclipse.buildship.core.internal.CorePlugin;
import org.eclipse.buildship.core.internal.configuration.ProjectConfiguration;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.core.runtime.jobs.Job;
Expand All @@ -36,7 +32,6 @@
import org.eclipse.jdt.ls.core.internal.ProjectUtils;
import org.eclipse.jdt.ls.core.internal.preferences.IPreferencesChangeListener;
import org.eclipse.jdt.ls.core.internal.preferences.Preferences;
import org.eclipse.jdt.ls.internal.gradle.checksums.ValidationResult;
import org.eclipse.jdt.ls.internal.gradle.checksums.WrapperValidator;

/**
Expand Down Expand Up @@ -112,20 +107,8 @@ private void updateProject(ProjectsManager projectsManager, IProject project, bo
String projectDir = project.getLocation().toFile().getAbsolutePath();
Path projectPath = Paths.get(projectDir);
if (gradleJavaHomeChanged || Files.exists(projectPath.resolve("gradlew"))) {
ProjectConfiguration configuration = CorePlugin.configurationManager().loadProjectConfiguration(project);
GradleDistribution distribution = configuration.getBuildConfiguration().getGradleDistribution();
if (gradleJavaHomeChanged || !(distribution instanceof WrapperGradleDistribution)) {
projectsManager.updateProject(project, true);
} else {
try {
ValidationResult result = new WrapperValidator().checkWrapper(projectDir);
if (!result.isValid()) {
projectsManager.updateProject(project, true);
}
} catch (CoreException e) {
JavaLanguageServerPlugin.logException(e.getMessage(), e);
}
}
// Validation now happens inside getGradleDistribution(), so just trigger re-import
projectsManager.updateProject(project, true);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.SubMonitor;
import org.eclipse.core.runtime.URIUtil;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.debug.core.ILaunchManager;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.internal.launching.StandardVMType;
Expand Down Expand Up @@ -243,7 +242,6 @@ public void importToWorkspace(IProgressMonitor monitor) throws CoreException {
} else if (GradleUtils.hasGradleInvalidTypeCodeException(importStatus, directory, monitor)) {
gradleUpgradeWrapperStatus.add(new GradleUpgradeWrapperStatus(importStatus, GRADLE_INVALID_TYPE_CODE_MESSAGE, directory.toUri().toString()));
}
checkWrapperChecksum(directory);
}
// store the digest for the imported gradle projects.
ProjectUtils.getGradleProjects().forEach(project -> {
Expand Down Expand Up @@ -367,50 +365,31 @@ private IStatus importDir(Path projectFolder, IProgressMonitor monitor) {
return startSynchronization(projectFolder, monitor);
}

public static void checkWrapperChecksum(Path rootFolder) {
PreferenceManager preferencesManager = JavaLanguageServerPlugin.getPreferencesManager();
if (preferencesManager == null) {
return;
}

if (Files.exists(rootFolder.resolve(WrapperValidator.GRADLE_WRAPPER_JAR))) {
Job checksumJob = new Job("Validating Gradle wrapper checksum...") {
@Override
protected IStatus run(IProgressMonitor monitor) {
WrapperValidator validator = new WrapperValidator();
try {
ValidationResult result = validator.checkWrapper(rootFolder.toFile().getAbsolutePath());
if (!result.isValid() && !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);
}
return Status.OK_STATUS;
}
};
checksumJob.setPriority(Job.LONG);
checksumJob.schedule();
}
}

public static GradleDistribution getGradleDistribution(Path rootFolder) {
Preferences preferences = getPreferences();
if (preferences.isGradleWrapperEnabled() && Files.exists(rootFolder.resolve("gradle/wrapper/gradle-wrapper.properties"))) {
return GradleDistribution.fromBuild();
if (Files.exists(rootFolder.resolve(WrapperValidator.GRADLE_WRAPPER_JAR))) {
try {
WrapperValidator validator = new WrapperValidator();
ValidationResult result = validator.checkWrapper(rootFolder.toFile().getAbsolutePath());
if (result.getStatus() == ValidationResult.Status.INVALID && !WrapperValidator.contains(result.getChecksum())) {
JavaLanguageServerPlugin.logError("Gradle wrapper checksum validation failed for " + rootFolder + ". Skipping wrapper.");
notifyInvalidChecksum(rootFolder, result);
// Fall through to next distribution option
} else if (result.isUnverifiable()) {
JavaLanguageServerPlugin.logInfo("Gradle wrapper checksum could not be verified for " + rootFolder + ". Skipping wrapper.");
notifyInvalidChecksum(rootFolder, result);
// Fall through to next distribution option
} else {
return GradleDistribution.fromBuild();
}
} catch (CoreException e) {
JavaLanguageServerPlugin.logException(e.getMessage(), e);
// On error, fall through to next distribution option
}
} else {
return GradleDistribution.fromBuild();
}
}
if (StringUtils.isNotBlank(preferences.getGradleVersion())) {
List<GradleVersion> versions = CorePlugin.publishedGradleVersions().getVersions();
Expand All @@ -435,6 +414,25 @@ public static GradleDistribution getGradleDistribution(Path rootFolder) {
return DEFAULT_DISTRIBUTION;
}

private static void notifyInvalidChecksum(Path rootFolder, ValidationResult result) {
PreferenceManager preferencesManager = JavaLanguageServerPlugin.getPreferencesManager();
ProjectsManager pm = JavaLanguageServerPlugin.getProjectsManager();
if (preferencesManager == null || pm == null || pm.getConnection() == null) {
return;
}
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));
}
}

public static File getGradleHomeFile() {
Map<String, String> env = System.getenv();
Properties sysprops = System.getProperties();
Expand Down

This file was deleted.

Loading
Loading