Search in sources :

Example 1 with GradleProjectSettingsControl

use of org.jetbrains.plugins.gradle.service.settings.GradleProjectSettingsControl in project intellij-community by JetBrains.

the class GradleProjectOpenProcessor method setupGradleProjectSettingsInHeadlessMode.

private boolean setupGradleProjectSettingsInHeadlessMode(GradleProjectImportProvider projectImportProvider, WizardContext wizardContext) {
    final ModuleWizardStep[] wizardSteps = projectImportProvider.createSteps(wizardContext);
    if (wizardSteps.length > 0 && wizardSteps[0] instanceof SelectExternalProjectStep) {
        SelectExternalProjectStep selectExternalProjectStep = (SelectExternalProjectStep) wizardSteps[0];
        wizardContext.setProjectBuilder(getBuilder());
        try {
            selectExternalProjectStep.updateStep();
            final ImportFromGradleControl importFromGradleControl = getBuilder().getControl(wizardContext.getProject());
            GradleProjectSettingsControl gradleProjectSettingsControl = (GradleProjectSettingsControl) importFromGradleControl.getProjectSettingsControl();
            final GradleProjectSettings projectSettings = gradleProjectSettingsControl.getInitialSettings();
            if (GRADLE_DISTRIBUTION_TYPE != null) {
                for (DistributionType type : DistributionType.values()) {
                    if (type.name().equals(GRADLE_DISTRIBUTION_TYPE)) {
                        projectSettings.setDistributionType(type);
                        break;
                    }
                }
            }
            if (GRADLE_HOME != null) {
                projectSettings.setGradleHome(GRADLE_HOME);
            }
            gradleProjectSettingsControl.reset();
            final GradleSystemSettingsControl systemSettingsControl = (GradleSystemSettingsControl) importFromGradleControl.getSystemSettingsControl();
            assert systemSettingsControl != null;
            final GradleSettings gradleSettings = systemSettingsControl.getInitialSettings();
            if (GRADLE_VM_OPTIONS != null) {
                gradleSettings.setGradleVmOptions(GRADLE_VM_OPTIONS);
            }
            if (GRADLE_OFFLINE != null) {
                gradleSettings.setOfflineWork(Boolean.parseBoolean(GRADLE_OFFLINE));
            }
            String serviceDirectory = GRADLE_SERVICE_DIRECTORY;
            if (GRADLE_SERVICE_DIRECTORY != null) {
                gradleSettings.setServiceDirectoryPath(serviceDirectory);
            }
            systemSettingsControl.reset();
            if (!selectExternalProjectStep.validate()) {
                return false;
            }
        } catch (ConfigurationException e) {
            Messages.showErrorDialog(wizardContext.getProject(), e.getMessage(), e.getTitle());
            return false;
        }
        selectExternalProjectStep.updateDataModel();
    }
    return true;
}
Also used : GradleProjectSettingsControl(org.jetbrains.plugins.gradle.service.settings.GradleProjectSettingsControl) GradleSettings(org.jetbrains.plugins.gradle.settings.GradleSettings) ModuleWizardStep(com.intellij.ide.util.projectWizard.ModuleWizardStep) ConfigurationException(com.intellij.openapi.options.ConfigurationException) GradleProjectSettings(org.jetbrains.plugins.gradle.settings.GradleProjectSettings) GradleSystemSettingsControl(org.jetbrains.plugins.gradle.service.settings.GradleSystemSettingsControl) ImportFromGradleControl(org.jetbrains.plugins.gradle.service.settings.ImportFromGradleControl) SelectExternalProjectStep(com.intellij.openapi.externalSystem.service.project.wizard.SelectExternalProjectStep) DistributionType(org.jetbrains.plugins.gradle.settings.DistributionType)

Aggregations

ModuleWizardStep (com.intellij.ide.util.projectWizard.ModuleWizardStep)1 SelectExternalProjectStep (com.intellij.openapi.externalSystem.service.project.wizard.SelectExternalProjectStep)1 ConfigurationException (com.intellij.openapi.options.ConfigurationException)1 GradleProjectSettingsControl (org.jetbrains.plugins.gradle.service.settings.GradleProjectSettingsControl)1 GradleSystemSettingsControl (org.jetbrains.plugins.gradle.service.settings.GradleSystemSettingsControl)1 ImportFromGradleControl (org.jetbrains.plugins.gradle.service.settings.ImportFromGradleControl)1 DistributionType (org.jetbrains.plugins.gradle.settings.DistributionType)1 GradleProjectSettings (org.jetbrains.plugins.gradle.settings.GradleProjectSettings)1 GradleSettings (org.jetbrains.plugins.gradle.settings.GradleSettings)1