Search in sources :

Example 1 with GradleEnvironment

use of org.gradle.tooling.model.build.GradleEnvironment in project eclipse.jdt.ls by eclipse.

the class GradleProjectImporter method startSynchronization.

protected IStatus startSynchronization(Path projectFolder, IProgressMonitor monitor) {
    File location = projectFolder.toFile();
    boolean shouldSynchronize = shouldSynchronize(location);
    if (shouldSynchronize) {
        BuildConfiguration build = getBuildConfiguration(projectFolder);
        GradleBuild gradleBuild = GradleCore.getWorkspace().createBuild(build);
        SynchronizationResult result = gradleBuild.synchronize(monitor);
        IStatus resultStatus = result.getStatus();
        if (isFailedStatus(resultStatus)) {
            try {
                BuildEnvironment environment = gradleBuild.withConnection(connection -> connection.getModel(BuildEnvironment.class), monitor);
                GradleEnvironment gradleEnvironment = environment.getGradle();
                String gradleVersion = gradleEnvironment.getGradleVersion();
                File javaHome = getJavaHome(getPreferences());
                String javaVersion;
                if (javaHome == null) {
                    javaVersion = System.getProperty("java.version");
                } else {
                    StandardVMType type = new StandardVMType();
                    javaVersion = type.readReleaseVersion(javaHome);
                }
                if (GradleCompatibilityChecker.isIncompatible(GradleVersion.version(gradleVersion), javaVersion)) {
                    Path projectName = projectFolder.getName(projectFolder.getNameCount() - 1);
                    String message = String.format("Can't use Java %s and Gradle %s to import Gradle project %s.", javaVersion, gradleVersion, projectName.toString());
                    String highestJavaVersion = GradleCompatibilityChecker.getHighestSupportedJava(GradleVersion.version(gradleVersion));
                    return new GradleCompatibilityStatus(resultStatus, message, projectFolder.toUri().toString(), highestJavaVersion);
                }
            } catch (Exception e) {
            // Do nothing
            }
        }
        return resultStatus;
    }
    return Status.OK_STATUS;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(java.nio.file.Path) IStatus(org.eclipse.core.runtime.IStatus) CoreException(org.eclipse.core.runtime.CoreException) IOException(java.io.IOException) BuildConfiguration(org.eclipse.buildship.core.BuildConfiguration) GradleEnvironment(org.gradle.tooling.model.build.GradleEnvironment) BuildEnvironment(org.gradle.tooling.model.build.BuildEnvironment) SynchronizationResult(org.eclipse.buildship.core.SynchronizationResult) StandardVMType(org.eclipse.jdt.internal.launching.StandardVMType) File(java.io.File) GradleBuild(org.eclipse.buildship.core.GradleBuild)

Aggregations

File (java.io.File)1 IOException (java.io.IOException)1 Path (java.nio.file.Path)1 BuildConfiguration (org.eclipse.buildship.core.BuildConfiguration)1 GradleBuild (org.eclipse.buildship.core.GradleBuild)1 SynchronizationResult (org.eclipse.buildship.core.SynchronizationResult)1 CoreException (org.eclipse.core.runtime.CoreException)1 IPath (org.eclipse.core.runtime.IPath)1 IStatus (org.eclipse.core.runtime.IStatus)1 StandardVMType (org.eclipse.jdt.internal.launching.StandardVMType)1 BuildEnvironment (org.gradle.tooling.model.build.BuildEnvironment)1 GradleEnvironment (org.gradle.tooling.model.build.GradleEnvironment)1