use of org.eclipse.buildship.core.GradleDistribution in project eclipse.jdt.ls by eclipse.
the class GradleProjectImporter method getBuildConfiguration.
public static BuildConfiguration getBuildConfiguration(Path rootFolder) {
GradleDistribution distribution = getGradleDistribution(rootFolder);
Preferences preferences = getPreferences();
File javaHome = getJavaHome(preferences);
File gradleUserHome = getGradleUserHomeFile();
List<String> gradleArguments = preferences.getGradleArguments();
List<String> gradleJvmArguments = preferences.getGradleJvmArguments();
boolean offlineMode = preferences.isImportGradleOfflineEnabled();
boolean overrideWorkspaceConfiguration = !(distribution instanceof WrapperGradleDistribution) || offlineMode || (gradleArguments != null && !gradleArguments.isEmpty()) || (gradleJvmArguments != null && !gradleJvmArguments.isEmpty()) || gradleUserHome != null || javaHome != null;
// @formatter:off
BuildConfiguration build = BuildConfiguration.forRootProjectDirectory(rootFolder.toFile()).overrideWorkspaceConfiguration(overrideWorkspaceConfiguration).gradleDistribution(distribution).javaHome(javaHome).arguments(gradleArguments).gradleUserHome(gradleUserHome).jvmArguments(gradleJvmArguments).offlineMode(offlineMode).build();
// @formatter:on
return build;
}
use of org.eclipse.buildship.core.GradleDistribution in project eclipse.jdt.ls by eclipse.
the class GradlePreferenceChangeListener method updateProject.
private void updateProject(ProjectsManager projectsManager, IProject project, boolean gradleJavaHomeChanged) {
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);
}
}
}
}
use of org.eclipse.buildship.core.GradleDistribution in project eclipse.jdt.ls by eclipse.
the class GradleProjectImporterTest method testDisableGradleWrapper.
@Test
public void testDisableGradleWrapper() throws Exception {
boolean enabled = JavaLanguageServerPlugin.getPreferencesManager().getPreferences().isGradleWrapperEnabled();
String gradleVersion = JavaLanguageServerPlugin.getPreferencesManager().getPreferences().getGradleVersion();
File file = new File(getSourceProjectDirectory(), "gradle/simple-gradle");
assertTrue(file.isDirectory());
try {
GradleDistribution distribution = GradleProjectImporter.getGradleDistribution(file.toPath());
assertTrue(distribution instanceof WrapperGradleDistribution);
JavaLanguageServerPlugin.getPreferencesManager().getPreferences().setGradleWrapperEnabled(false);
distribution = GradleProjectImporter.getGradleDistribution(file.toPath());
if (GradleProjectImporter.getGradleHomeFile() != null) {
assertEquals(distribution.getClass(), LocalGradleDistribution.class);
} else {
assertSame(distribution, GradleProjectImporter.DEFAULT_DISTRIBUTION);
}
String requiredVersion = "5.2.1";
JavaLanguageServerPlugin.getPreferencesManager().getPreferences().setGradleVersion(requiredVersion);
distribution = GradleProjectImporter.getGradleDistribution(file.toPath());
assertEquals(distribution.getClass(), FixedVersionGradleDistribution.class);
assertEquals(((FixedVersionGradleDistribution) distribution).getVersion(), requiredVersion);
List<IProject> projects = importProjects("eclipse/eclipsegradle");
// default + 1 eclipse projects
assertEquals(2, projects.size());
IProject eclipse = WorkspaceHelper.getProject("eclipsegradle");
assertNotNull(eclipse);
assertTrue(eclipse.getName() + " does not have the Gradle nature", ProjectUtils.isGradleProject(eclipse));
} finally {
JavaLanguageServerPlugin.getPreferencesManager().getPreferences().setGradleWrapperEnabled(enabled);
JavaLanguageServerPlugin.getPreferencesManager().getPreferences().setGradleVersion(gradleVersion);
}
}
Aggregations