Search in sources :

Example 1 with DistributionType

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

the class IdeaGradleProjectSettingsControlBuilder method isModified.

@Override
public boolean isModified() {
    DistributionType distributionType = myInitialSettings.getDistributionType();
    if (myUseBundledDistributionButton != null && myUseBundledDistributionButton.isSelected() && distributionType != DistributionType.BUNDLED) {
        return true;
    }
    if (myUseWrapperButton != null && myUseWrapperButton.isSelected() && distributionType != DistributionType.DEFAULT_WRAPPED) {
        return true;
    }
    if (myUseWrapperWithVerificationButton != null && myUseWrapperWithVerificationButton.isSelected() && distributionType != DistributionType.WRAPPED) {
        return true;
    }
    if (myUseLocalDistributionButton != null && myUseLocalDistributionButton.isSelected() && distributionType != DistributionType.LOCAL) {
        return true;
    }
    if (myResolveModulePerSourceSetCheckBox != null && (myResolveModulePerSourceSetCheckBox.isSelected() != myInitialSettings.isResolveModulePerSourceSet())) {
        return true;
    }
    if (myGradleJdkComboBox != null && !StringUtil.equals(myGradleJdkComboBox.getSelectedValue(), myInitialSettings.getGradleJvm())) {
        return true;
    }
    if (myGradleHomePathField == null)
        return false;
    String gradleHome = FileUtil.toCanonicalPath(myGradleHomePathField.getText());
    if (StringUtil.isEmpty(gradleHome)) {
        return !StringUtil.isEmpty(myInitialSettings.getGradleHome());
    } else {
        return !gradleHome.equals(myInitialSettings.getGradleHome());
    }
}
Also used : DistributionType(org.jetbrains.plugins.gradle.settings.DistributionType)

Example 2 with DistributionType

use of org.jetbrains.plugins.gradle.settings.DistributionType 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)

Example 3 with DistributionType

use of org.jetbrains.plugins.gradle.settings.DistributionType in project android by JetBrains.

the class GradleDistributionCleanUpTask method cleanUp.

@Override
void cleanUp(@NotNull Project project) {
    GradleProjectSettings gradleSettings = GradleProjectSettingsFinder.getInstance().findGradleProjectSettings(project);
    GradleWrapper gradleWrapper = GradleWrapper.find(project);
    DistributionType distributionType = gradleSettings != null ? gradleSettings.getDistributionType() : null;
    boolean usingWrapper = (distributionType == null || distributionType == DEFAULT_WRAPPED) && gradleWrapper != null;
    if (usingWrapper && gradleSettings != null) {
        // Do this just to ensure that the right distribution type is set. If this is not set, build.gradle editor will not have code
        // completion (see BuildClasspathModuleGradleDataService, line 119).
        gradleSettings.setDistributionType(DEFAULT_WRAPPED);
    } else if (gradleWrapper == null && gradleSettings != null) {
        createWrapperIfNecessary(project, gradleSettings, distributionType);
    }
}
Also used : GradleProjectSettings(org.jetbrains.plugins.gradle.settings.GradleProjectSettings) GradleWrapper(com.android.tools.idea.gradle.util.GradleWrapper) DistributionType(org.jetbrains.plugins.gradle.settings.DistributionType)

Example 4 with DistributionType

use of org.jetbrains.plugins.gradle.settings.DistributionType in project android by JetBrains.

the class GradleVersions method getGradleVersion.

@Nullable
public GradleVersion getGradleVersion(@NotNull Project project) {
    GradleVersion gradleVersion = GradleSyncState.getInstance(project).getSummary().getGradleVersion();
    if (gradleVersion != null) {
        // The version of Gradle used is retrieved one of the Gradle models. If that fails, we try to deduce it from the project's Gradle
        // settings.
        GradleVersion revision = GradleVersion.tryParse(removeTimestampFromGradleVersion(gradleVersion.toString()));
        if (revision != null) {
            return revision;
        }
    }
    GradleProjectSettings gradleSettings = mySettingsFinder.findGradleProjectSettings(project);
    if (gradleSettings != null) {
        DistributionType distributionType = gradleSettings.getDistributionType();
        if (distributionType == DEFAULT_WRAPPED) {
            GradleWrapper gradleWrapper = GradleWrapper.find(project);
            if (gradleWrapper != null) {
                try {
                    String wrapperVersion = gradleWrapper.getGradleVersion();
                    if (wrapperVersion != null) {
                        return GradleVersion.tryParse(removeTimestampFromGradleVersion(wrapperVersion));
                    }
                } catch (IOException e) {
                    Logger.getInstance(getClass()).info("Failed to read Gradle version in wrapper", e);
                }
            }
        } else if (distributionType == LOCAL) {
            String gradleHome = gradleSettings.getGradleHome();
            if (isNotEmpty(gradleHome)) {
                File gradleHomePath = new File(gradleHome);
                return getGradleVersion(gradleHomePath);
            }
        }
    }
    return null;
}
Also used : GradleProjectSettings(org.jetbrains.plugins.gradle.settings.GradleProjectSettings) IOException(java.io.IOException) GradleVersion(com.android.ide.common.repository.GradleVersion) File(java.io.File) DistributionType(org.jetbrains.plugins.gradle.settings.DistributionType) Nullable(org.jetbrains.annotations.Nullable)

Example 5 with DistributionType

use of org.jetbrains.plugins.gradle.settings.DistributionType in project android by JetBrains.

the class GradleDslMethodNotFoundErrorHandler method isUsingWrapper.

private static boolean isUsingWrapper(@NotNull Project project) {
    GradleProjectSettings gradleSettings = GradleProjectSettingsFinder.getInstance().findGradleProjectSettings(project);
    GradleWrapper gradleWrapper = GradleWrapper.find(project);
    DistributionType distributionType = gradleSettings != null ? gradleSettings.getDistributionType() : null;
    return (distributionType == null || distributionType == DistributionType.DEFAULT_WRAPPED) && gradleWrapper != null;
}
Also used : GradleProjectSettings(org.jetbrains.plugins.gradle.settings.GradleProjectSettings) GradleWrapper(com.android.tools.idea.gradle.util.GradleWrapper) DistributionType(org.jetbrains.plugins.gradle.settings.DistributionType)

Aggregations

DistributionType (org.jetbrains.plugins.gradle.settings.DistributionType)5 GradleProjectSettings (org.jetbrains.plugins.gradle.settings.GradleProjectSettings)4 GradleWrapper (com.android.tools.idea.gradle.util.GradleWrapper)2 GradleVersion (com.android.ide.common.repository.GradleVersion)1 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 File (java.io.File)1 IOException (java.io.IOException)1 Nullable (org.jetbrains.annotations.Nullable)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 GradleSettings (org.jetbrains.plugins.gradle.settings.GradleSettings)1