Search in sources :

Example 1 with GradleSettingsListenerAdapter

use of org.jetbrains.plugins.gradle.config.GradleSettingsListenerAdapter in project intellij-community by JetBrains.

the class GradleManager method runActivity.

@Override
public void runActivity(@NotNull final Project project) {
    // We want to automatically refresh linked projects on gradle service directory change.
    MessageBusConnection connection = project.getMessageBus().connect(project);
    connection.subscribe(GradleSettings.getInstance(project).getChangesTopic(), new GradleSettingsListenerAdapter() {

        @Override
        public void onServiceDirectoryPathChange(@Nullable String oldPath, @Nullable String newPath) {
            ensureProjectsRefresh();
        }

        @Override
        public void onGradleHomeChange(@Nullable String oldPath, @Nullable String newPath, @NotNull String linkedProjectPath) {
            ensureProjectsRefresh();
        }

        @Override
        public void onGradleDistributionTypeChange(DistributionType currentValue, @NotNull String linkedProjectPath) {
            ensureProjectsRefresh();
        }

        private void ensureProjectsRefresh() {
            ExternalSystemUtil.refreshProjects(project, GradleConstants.SYSTEM_ID, true);
        }
    });
    // We used to assume that gradle scripts are always named 'build.gradle' and kept path to that build.gradle file at ide settings.
    // However, it was found out that that is incorrect assumption (IDEA-109064). Now we keep paths to gradle script's directories
    // instead. However, we don't want to force old users to re-import gradle projects because of that. That's why we check gradle
    // config and re-point it from build.gradle to the parent dir if necessary.
    Map<String, String> adjustedPaths = patchLinkedProjects(project);
    if (adjustedPaths == null) {
        return;
    }
    GradleLocalSettings localSettings = GradleLocalSettings.getInstance(project);
    patchRecentTasks(adjustedPaths, localSettings);
    patchAvailableProjects(adjustedPaths, localSettings);
    patchAvailableTasks(adjustedPaths, localSettings);
}
Also used : MessageBusConnection(com.intellij.util.messages.MessageBusConnection) GradleSettingsListenerAdapter(org.jetbrains.plugins.gradle.config.GradleSettingsListenerAdapter)

Aggregations

MessageBusConnection (com.intellij.util.messages.MessageBusConnection)1 GradleSettingsListenerAdapter (org.jetbrains.plugins.gradle.config.GradleSettingsListenerAdapter)1