Search in sources :

Example 16 with GradleProjectSettings

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

the class GradleUtil method attemptToUseEmbeddedGradle.

public static void attemptToUseEmbeddedGradle(@NotNull Project project) {
    if (IdeInfo.getInstance().isAndroidStudio()) {
        GradleWrapper gradleWrapper = GradleWrapper.find(project);
        if (gradleWrapper != null) {
            String gradleVersion = null;
            try {
                Properties properties = gradleWrapper.getProperties();
                String url = properties.getProperty(DISTRIBUTION_URL_PROPERTY);
                gradleVersion = getGradleWrapperVersionOnlyIfComingForGradleDotOrg(url);
            } catch (IOException e) {
                LOG.warn("Failed to read file " + gradleWrapper.getPropertiesFilePath().getPath());
            }
            if (gradleVersion != null && isCompatibleWithEmbeddedGradleVersion(gradleVersion) && !GradleLocalCache.getInstance().containsGradleWrapperVersion(gradleVersion, project)) {
                File embeddedGradlePath = EmbeddedDistributionPaths.getInstance().findEmbeddedGradleDistributionPath();
                if (embeddedGradlePath != null) {
                    GradleProjectSettings gradleSettings = getGradleProjectSettings(project);
                    if (gradleSettings != null) {
                        gradleSettings.setDistributionType(LOCAL);
                        gradleSettings.setGradleHome(embeddedGradlePath.getPath());
                    }
                }
            }
        }
    }
}
Also used : GradleProjectSettings(org.jetbrains.plugins.gradle.settings.GradleProjectSettings) IOException(java.io.IOException) VirtualFile(com.intellij.openapi.vfs.VirtualFile) VfsUtil.findFileByIoFile(com.intellij.openapi.vfs.VfsUtil.findFileByIoFile) VfsUtilCore.virtualToIoFile(com.intellij.openapi.vfs.VfsUtilCore.virtualToIoFile) File(java.io.File)

Example 17 with GradleProjectSettings

use of org.jetbrains.plugins.gradle.settings.GradleProjectSettings 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 18 with GradleProjectSettings

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

the class GradleUtil method getGradleExecutionSettings.

@Nullable
public static GradleExecutionSettings getGradleExecutionSettings(@NotNull Project project) {
    GradleProjectSettings projectSettings = getGradleProjectSettings(project);
    if (projectSettings == null) {
        File baseDirPath = getBaseDirPath(project);
        String msg = String.format("Unable to obtain Gradle project settings for project '%1$s', located at '%2$s'", project.getName(), baseDirPath.getPath());
        LOG.info(msg);
        return null;
    }
    try {
        return getExecutionSettings(project, projectSettings.getExternalProjectPath(), GRADLE_SYSTEM_ID);
    } catch (IllegalArgumentException e) {
        LOG.info("Failed to obtain Gradle execution settings", e);
        return null;
    }
}
Also used : GradleProjectSettings(org.jetbrains.plugins.gradle.settings.GradleProjectSettings) VirtualFile(com.intellij.openapi.vfs.VirtualFile) VfsUtil.findFileByIoFile(com.intellij.openapi.vfs.VfsUtil.findFileByIoFile) VfsUtilCore.virtualToIoFile(com.intellij.openapi.vfs.VfsUtilCore.virtualToIoFile) File(java.io.File) Nullable(org.jetbrains.annotations.Nullable)

Example 19 with GradleProjectSettings

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

the class FixGradleVersionInWrapperHyperlink method setDistributionTypeAndSync.

private static void setDistributionTypeAndSync(@NotNull Project project) {
    GradleProjectSettings settings = GradleProjectSettingsFinder.getInstance().findGradleProjectSettings(project);
    if (settings != null) {
        settings.setDistributionType(DistributionType.DEFAULT_WRAPPED);
    }
    requestSync(project);
}
Also used : GradleProjectSettings(org.jetbrains.plugins.gradle.settings.GradleProjectSettings)

Example 20 with GradleProjectSettings

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

GradleProjectSettings (org.jetbrains.plugins.gradle.settings.GradleProjectSettings)34 File (java.io.File)9 Project (com.intellij.openapi.project.Project)8 VirtualFile (com.intellij.openapi.vfs.VirtualFile)7 Nullable (org.jetbrains.annotations.Nullable)6 NotNull (org.jetbrains.annotations.NotNull)5 IOException (java.io.IOException)4 DistributionType (org.jetbrains.plugins.gradle.settings.DistributionType)4 GradleSettings (org.jetbrains.plugins.gradle.settings.GradleSettings)4 GradleWrapper (com.android.tools.idea.gradle.util.GradleWrapper)3 Sdk (com.intellij.openapi.projectRoots.Sdk)3 GradleVersion (com.android.ide.common.repository.GradleVersion)2 Result (com.intellij.openapi.application.Result)2 WriteAction (com.intellij.openapi.application.WriteAction)2 ExternalSystemSettingsListenerAdapter (com.intellij.openapi.externalSystem.settings.ExternalSystemSettingsListenerAdapter)2 Module (com.intellij.openapi.module.Module)2 JavaSdk (com.intellij.openapi.projectRoots.JavaSdk)2 VfsUtil.findFileByIoFile (com.intellij.openapi.vfs.VfsUtil.findFileByIoFile)2 VfsUtilCore.virtualToIoFile (com.intellij.openapi.vfs.VfsUtilCore.virtualToIoFile)2 BuildParticipant (org.jetbrains.plugins.gradle.model.data.BuildParticipant)2