use of org.eclipse.buildship.core.GradleBuild in project eclipse.jdt.ls by eclipse.
the class GradleBuildSupport method update.
@Override
public void update(IProject project, boolean force, IProgressMonitor monitor) throws CoreException {
if (!applies(project)) {
return;
}
JavaLanguageServerPlugin.logInfo("Starting Gradle update for " + project.getName());
Optional<GradleBuild> build = GradleCore.getWorkspace().getBuild(project);
if (build.isPresent()) {
GradleBuild gradleBuild = build.get();
boolean isRoot = isRoot(project, gradleBuild, monitor);
if (force && isRoot) {
String projectPath = project.getLocation().toFile().getAbsolutePath();
BuildConfiguration buildConfiguration = GradleProjectImporter.getBuildConfiguration(Paths.get(projectPath));
gradleBuild = GradleCore.getWorkspace().createBuild(buildConfiguration);
}
File buildFile = project.getFile(GradleProjectImporter.BUILD_GRADLE_DESCRIPTOR).getLocation().toFile();
File settingsFile = project.getFile(GradleProjectImporter.SETTINGS_GRADLE_DESCRIPTOR).getLocation().toFile();
File buildKtsFile = project.getFile(GradleProjectImporter.BUILD_GRADLE_KTS_DESCRIPTOR).getLocation().toFile();
File settingsKtsFile = project.getFile(GradleProjectImporter.SETTINGS_GRADLE_KTS_DESCRIPTOR).getLocation().toFile();
boolean shouldUpdate = (buildFile.exists() && JavaLanguageServerPlugin.getDigestStore().updateDigest(buildFile.toPath())) || (settingsFile.exists() && JavaLanguageServerPlugin.getDigestStore().updateDigest(settingsFile.toPath())) || (buildKtsFile.exists() && JavaLanguageServerPlugin.getDigestStore().updateDigest(buildKtsFile.toPath())) || (settingsKtsFile.exists() && JavaLanguageServerPlugin.getDigestStore().updateDigest(settingsKtsFile.toPath()));
if (isRoot || shouldUpdate) {
gradleBuild.synchronize(monitor);
}
}
}
use of org.eclipse.buildship.core.GradleBuild in project xtext-eclipse by eclipse.
the class IgnoreBuildDirContribution method configure.
/**
* Store the build dir for the given project.
*/
@Override
public void configure(ProjectContext context, IProgressMonitor monitor) {
/*
* Implementation note: This is called for each project in the workspace that
* participates in a Gradle build. We keep track of the gradle build dir and the
* Eclipse project to allow efficient rejection of the build dir when the Xtext
* builder runs.
*/
IProject project = context.getProject();
if (project.isAccessible()) {
Optional<GradleBuild> gradleBuild = GradleCore.getWorkspace().getBuild(project);
if (gradleBuild.isPresent()) {
try {
GradleProject gradleProject = gradleBuild.get().withConnection(connection -> connection.getModel(GradleProject.class), new NullProgressMonitor());
File buildDirectory = gradleProject.getBuildDirectory();
File projectDirectory = gradleProject.getProjectDirectory();
IPath relativePath = Path.fromOSString(projectDirectory.toPath().relativize(buildDirectory.toPath()).toString());
project.setPersistentProperty(BUILDSHIP_BUILD_DIR_KEY, relativePath.toString());
} catch (Exception e) {
LOGGER.error(e);
}
}
}
}
use of org.eclipse.buildship.core.GradleBuild in project eclipse.jdt.ls by eclipse.
the class GradleProjectImporter method upgradeGradleVersion.
public static boolean upgradeGradleVersion(String projectUri, IProgressMonitor monitor) {
String newDistributionUrl = String.format("https://services.gradle.org/distributions/gradle-%s-bin.zip", GradleCompatibilityChecker.CURRENT_GRADLE);
Path projectFolder = Paths.get(URI.create(projectUri));
File propertiesFile = projectFolder.resolve("gradle").resolve("wrapper").resolve("gradle-wrapper.properties").toFile();
Properties properties = new Properties();
if (propertiesFile.exists()) {
try (FileInputStream stream = new FileInputStream(propertiesFile)) {
properties.load(stream);
properties.setProperty("distributionUrl", newDistributionUrl);
} catch (IOException e) {
return false;
}
} else {
properties.setProperty("distributionBase", "GRADLE_USER_HOME");
properties.setProperty("distributionPath", "wrapper/dists");
properties.setProperty("distributionUrl", newDistributionUrl);
properties.setProperty("zipStoreBase", "GRADLE_USER_HOME");
properties.setProperty("zipStorePath", "wrapper/dists");
}
try {
properties.store(new FileOutputStream(propertiesFile), null);
} catch (Exception e) {
return false;
}
BuildConfiguration build = getBuildConfiguration(projectFolder);
GradleBuild gradleBuild = GradleCore.getWorkspace().createBuild(build);
try {
gradleBuild.withConnection(connection -> {
connection.newBuild().forTasks("wrapper").run();
return null;
}, monitor);
} catch (Exception e) {
return false;
}
return true;
}
use of org.eclipse.buildship.core.GradleBuild 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;
}
Aggregations