Search in sources :

Example 1 with FixedVersionGradleDistribution

use of org.eclipse.buildship.core.FixedVersionGradleDistribution 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);
    }
}
Also used : FixedVersionGradleDistribution(org.eclipse.buildship.core.FixedVersionGradleDistribution) GradleDistribution(org.eclipse.buildship.core.GradleDistribution) LocalGradleDistribution(org.eclipse.buildship.core.LocalGradleDistribution) WrapperGradleDistribution(org.eclipse.buildship.core.WrapperGradleDistribution) WrapperGradleDistribution(org.eclipse.buildship.core.WrapperGradleDistribution) IFile(org.eclipse.core.resources.IFile) File(java.io.File) IProject(org.eclipse.core.resources.IProject) Test(org.junit.Test)

Aggregations

File (java.io.File)1 FixedVersionGradleDistribution (org.eclipse.buildship.core.FixedVersionGradleDistribution)1 GradleDistribution (org.eclipse.buildship.core.GradleDistribution)1 LocalGradleDistribution (org.eclipse.buildship.core.LocalGradleDistribution)1 WrapperGradleDistribution (org.eclipse.buildship.core.WrapperGradleDistribution)1 IFile (org.eclipse.core.resources.IFile)1 IProject (org.eclipse.core.resources.IProject)1 Test (org.junit.Test)1