Search in sources :

Example 1 with ProjectConfiguration

use of org.eclipse.buildship.core.internal.configuration.ProjectConfiguration in project eclipse.jdt.ls by eclipse.

the class GradleProjectImporterTest method testSubprojects.

@Test
public void testSubprojects() throws Exception {
    List<String> arguments = JavaLanguageServerPlugin.getPreferencesManager().getPreferences().getGradleArguments();
    try {
        // force overrideWorkspace
        JavaLanguageServerPlugin.getPreferencesManager().getPreferences().setGradleArguments(ImmutableList.of("--stacktrace"));
        List<IProject> projects = importProjects("gradle/subprojects");
        // default + 3 gradle projects
        assertEquals(4, projects.size());
        IProject root = WorkspaceHelper.getProject("subprojects");
        assertIsGradleProject(root);
        IProject project1 = WorkspaceHelper.getProject("project1");
        assertIsGradleProject(project1);
        IProject project2 = WorkspaceHelper.getProject("project2");
        assertIsGradleProject(project2);
        projectsManager.updateProject(root, true);
        projectsManager.updateProject(project1, true);
        projectsManager.updateProject(project2, true);
        waitForBackgroundJobs();
        ProjectConfiguration configuration = getProjectConfiguration(root);
        // check the children .settings/org.eclipse.buildship.core.prefs
        assertTrue(configuration.getBuildConfiguration().isOverrideWorkspaceSettings());
        configuration = getProjectConfiguration(project1);
        assertFalse(configuration.getBuildConfiguration().isOverrideWorkspaceSettings());
        configuration = getProjectConfiguration(project2);
        assertFalse(configuration.getBuildConfiguration().isOverrideWorkspaceSettings());
        JavaLanguageServerPlugin.getPreferencesManager().getPreferences().setGradleArguments(ImmutableList.of("--stacktrace"));
        configuration = CorePlugin.configurationManager().loadProjectConfiguration(project1);
        assertTrue(configuration.getBuildConfiguration().isOverrideWorkspaceSettings());
        configuration = CorePlugin.configurationManager().loadProjectConfiguration(project2);
        assertTrue(configuration.getBuildConfiguration().isOverrideWorkspaceSettings());
        JavaLanguageServerPlugin.getPreferencesManager().getPreferences().setGradleArguments(arguments);
        projectsManager.updateProject(root, true);
        JobHelpers.waitForJobsToComplete();
        Job.getJobManager().join(CorePlugin.GRADLE_JOB_FAMILY, new NullProgressMonitor());
        configuration = CorePlugin.configurationManager().loadProjectConfiguration(root);
        assertFalse(configuration.getBuildConfiguration().isOverrideWorkspaceSettings());
        // check that the children are updated
        configuration = CorePlugin.configurationManager().loadProjectConfiguration(project1);
        assertFalse(configuration.getBuildConfiguration().isOverrideWorkspaceSettings());
        configuration = CorePlugin.configurationManager().loadProjectConfiguration(project2);
        assertFalse(configuration.getBuildConfiguration().isOverrideWorkspaceSettings());
    } finally {
        JavaLanguageServerPlugin.getPreferencesManager().getPreferences().setGradleArguments(arguments);
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IProject(org.eclipse.core.resources.IProject) ProjectConfiguration(org.eclipse.buildship.core.internal.configuration.ProjectConfiguration) Test(org.junit.Test)

Example 2 with ProjectConfiguration

use of org.eclipse.buildship.core.internal.configuration.ProjectConfiguration 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);
            }
        }
    }
}
Also used : Path(java.nio.file.Path) WrapperGradleDistribution(org.eclipse.buildship.core.WrapperGradleDistribution) GradleDistribution(org.eclipse.buildship.core.GradleDistribution) CoreException(org.eclipse.core.runtime.CoreException) WrapperGradleDistribution(org.eclipse.buildship.core.WrapperGradleDistribution) WrapperValidator(org.eclipse.jdt.ls.internal.gradle.checksums.WrapperValidator) ValidationResult(org.eclipse.jdt.ls.internal.gradle.checksums.ValidationResult) ProjectConfiguration(org.eclipse.buildship.core.internal.configuration.ProjectConfiguration)

Example 3 with ProjectConfiguration

use of org.eclipse.buildship.core.internal.configuration.ProjectConfiguration in project eclipse.jdt.ls by eclipse.

the class GradleProjectImporterTest method testGradleUserHome.

@Test
public void testGradleUserHome() throws Exception {
    String gradleUserHomePreference = JavaLanguageServerPlugin.getPreferencesManager().getPreferences().getGradleUserHome();
    File gradleUserHome = null;
    try {
        gradleUserHome = Files.createTempDir();
        gradleUserHome.deleteOnExit();
        JavaLanguageServerPlugin.getPreferencesManager().getPreferences().setGradleUserHome(gradleUserHome.getAbsolutePath());
        List<IProject> projects = importProjects("gradle/simple-gradle");
        // default + 1 eclipse projects
        assertEquals(2, projects.size());
        IProject project = WorkspaceHelper.getProject("simple-gradle");
        assertNotNull(project);
        assertTrue(project.getName() + " does not have the Gradle nature", ProjectUtils.isGradleProject(project));
        assertTrue(gradleUserHome.exists());
        ProjectConfiguration projectConfiguration = CorePlugin.configurationManager().loadProjectConfiguration(project);
        assertEquals(gradleUserHome, projectConfiguration.getBuildConfiguration().getGradleUserHome());
    } finally {
        JavaLanguageServerPlugin.getPreferencesManager().getPreferences().setGradleUserHome(gradleUserHomePreference);
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) File(java.io.File) IProject(org.eclipse.core.resources.IProject) ProjectConfiguration(org.eclipse.buildship.core.internal.configuration.ProjectConfiguration) Test(org.junit.Test)

Aggregations

ProjectConfiguration (org.eclipse.buildship.core.internal.configuration.ProjectConfiguration)3 IProject (org.eclipse.core.resources.IProject)2 Test (org.junit.Test)2 File (java.io.File)1 Path (java.nio.file.Path)1 GradleDistribution (org.eclipse.buildship.core.GradleDistribution)1 WrapperGradleDistribution (org.eclipse.buildship.core.WrapperGradleDistribution)1 IFile (org.eclipse.core.resources.IFile)1 CoreException (org.eclipse.core.runtime.CoreException)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1 ValidationResult (org.eclipse.jdt.ls.internal.gradle.checksums.ValidationResult)1 WrapperValidator (org.eclipse.jdt.ls.internal.gradle.checksums.WrapperValidator)1