Search in sources :

Example 11 with GradleProjectSettings

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

the class GradleImportingTestCase method importProject.

@Override
protected void importProject() {
    ExternalSystemApiUtil.subscribe(myProject, GradleConstants.SYSTEM_ID, new ExternalSystemSettingsListenerAdapter() {

        @Override
        public void onProjectsLinked(@NotNull Collection settings) {
            Object item = ContainerUtil.getFirstItem(settings);
            if (item instanceof GradleProjectSettings) {
                ((GradleProjectSettings) item).setGradleJvm(GRADLE_JDK_NAME);
            }
        }
    });
    super.importProject();
}
Also used : ExternalSystemSettingsListenerAdapter(com.intellij.openapi.externalSystem.settings.ExternalSystemSettingsListenerAdapter) GradleProjectSettings(org.jetbrains.plugins.gradle.settings.GradleProjectSettings) Collection(java.util.Collection)

Example 12 with GradleProjectSettings

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

the class CreateGradleWrapperHyperlink method execute.

@Override
protected void execute(@NotNull Project project) {
    File projectDirPath = getBaseDirPath(project);
    try {
        GradleWrapper.create(projectDirPath);
        GradleProjectSettings settings = GradleProjectSettingsFinder.getInstance().findGradleProjectSettings(project);
        if (settings != null) {
            settings.setDistributionType(DEFAULT_WRAPPED);
        }
        requestSync(project);
    } catch (IOException e) {
        // Unlikely to happen.
        Messages.showErrorDialog(project, "Failed to create Gradle wrapper: " + e.getMessage(), "Quick Fix");
    }
}
Also used : GradleProjectSettings(org.jetbrains.plugins.gradle.settings.GradleProjectSettings) IOException(java.io.IOException) File(java.io.File)

Example 13 with GradleProjectSettings

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

the class UnsupportedGradleVersionErrorHandler method getQuickFixHyperlinks.

@NotNull
public static List<NotificationHyperlink> getQuickFixHyperlinks(@NotNull Project project, @Nullable String gradleVersion) {
    List<NotificationHyperlink> hyperlinks = new ArrayList<>();
    GradleWrapper gradleWrapper = GradleWrapper.find(project);
    if (gradleWrapper != null) {
        // It is very likely that we need to fix the model version as well. Do everything in one shot.
        NotificationHyperlink hyperlink = createIfProjectUsesGradleWrapper(project, gradleVersion);
        if (hyperlink != null) {
            hyperlinks.add(hyperlink);
        }
    } else {
        GradleProjectSettings gradleProjectSettings = GradleProjectSettingsFinder.getInstance().findGradleProjectSettings(project);
        if (gradleProjectSettings != null && gradleProjectSettings.getDistributionType() == DistributionType.LOCAL) {
            hyperlinks.add(new CreateGradleWrapperHyperlink());
        }
    }
    hyperlinks.add(new OpenGradleSettingsHyperlink());
    return hyperlinks;
}
Also used : OpenGradleSettingsHyperlink(com.android.tools.idea.gradle.project.sync.hyperlink.OpenGradleSettingsHyperlink) GradleProjectSettings(org.jetbrains.plugins.gradle.settings.GradleProjectSettings) ArrayList(java.util.ArrayList) GradleWrapper(com.android.tools.idea.gradle.util.GradleWrapper) FixGradleVersionInWrapperHyperlink.createIfProjectUsesGradleWrapper(com.android.tools.idea.gradle.project.sync.hyperlink.FixGradleVersionInWrapperHyperlink.createIfProjectUsesGradleWrapper) NotificationHyperlink(com.android.tools.idea.gradle.project.sync.hyperlink.NotificationHyperlink) CreateGradleWrapperHyperlink(com.android.tools.idea.gradle.project.sync.hyperlink.CreateGradleWrapperHyperlink) NotNull(org.jetbrains.annotations.NotNull)

Example 14 with GradleProjectSettings

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

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

the class GradleSettingsCleanUpTask method cleanUp.

@Override
void cleanUp(@NotNull Project project) {
    GradleProjectSettings projectSettings = GradleProjectSettingsFinder.getInstance().findGradleProjectSettings(project);
    if (projectSettings == null) {
        projectSettings = new GradleProjectSettings();
    }
    setUpGradleProjectSettings(project, projectSettings);
    GradleSettings gradleSettings = GradleSettings.getInstance(project);
    gradleSettings.setLinkedProjectsSettings(ImmutableList.of(projectSettings));
}
Also used : GradleSettings(org.jetbrains.plugins.gradle.settings.GradleSettings) GradleProjectSettings(org.jetbrains.plugins.gradle.settings.GradleProjectSettings)

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