From 5c6c1173a6affea3716c52cbe6f2d8e916f064ac Mon Sep 17 00:00:00 2001 From: Nikolay Krasko Date: Mon, 8 Feb 2016 21:06:16 +0300 Subject: [PATCH] Aggregate configuration messages into one notification (KT-10489) #KT-10489 Fixed --- .../ConfigureKotlinInProjectUtils.kt | 9 +- .../KotlinMavenConfigurator.java | 13 ++- .../KotlinWithGradleConfigurator.java | 18 ++-- .../KotlinWithLibraryConfigurator.java | 100 ++++++++++-------- .../NotificationMessageCollector.kt | 48 +++++++++ ...omLibraryDescriptorWithDeferredConfig.java | 8 +- .../idea/inspections/AddKotlinLibQuickFix.kt | 11 +- .../idea/versions/KotlinRuntimeLibraryUtil.kt | 18 ++-- ...actConfigureProjectByChangingFileTest.java | 6 +- .../configuration/ConfigureKotlinTest.java | 7 +- 10 files changed, 155 insertions(+), 83 deletions(-) create mode 100644 idea/src/org/jetbrains/kotlin/idea/configuration/NotificationMessageCollector.kt diff --git a/idea/src/org/jetbrains/kotlin/idea/configuration/ConfigureKotlinInProjectUtils.kt b/idea/src/org/jetbrains/kotlin/idea/configuration/ConfigureKotlinInProjectUtils.kt index 9babdd2b1f0..7176e02487e 100644 --- a/idea/src/org/jetbrains/kotlin/idea/configuration/ConfigureKotlinInProjectUtils.kt +++ b/idea/src/org/jetbrains/kotlin/idea/configuration/ConfigureKotlinInProjectUtils.kt @@ -16,9 +16,6 @@ package org.jetbrains.kotlin.idea.configuration -import com.intellij.notification.Notification -import com.intellij.notification.NotificationType -import com.intellij.notification.Notifications import com.intellij.openapi.extensions.Extensions import com.intellij.openapi.module.Module import com.intellij.openapi.project.Project @@ -96,8 +93,4 @@ fun getNonConfiguredModules(project: Project, excludeModules: Collection return modulesWithKotlinFiles.filter { module -> ableToRunConfigurators.any { !it.isConfigured(module) } } -} - -fun showInfoNotification(project: Project, message: String) { - Notifications.Bus.notify(Notification("Configure Kotlin: info notification", "Configure Kotlin", message, NotificationType.INFORMATION), project) -} +} \ No newline at end of file diff --git a/idea/src/org/jetbrains/kotlin/idea/configuration/KotlinMavenConfigurator.java b/idea/src/org/jetbrains/kotlin/idea/configuration/KotlinMavenConfigurator.java index 92fd2c911a8..d03b02f523e 100644 --- a/idea/src/org/jetbrains/kotlin/idea/configuration/KotlinMavenConfigurator.java +++ b/idea/src/org/jetbrains/kotlin/idea/configuration/KotlinMavenConfigurator.java @@ -117,16 +117,18 @@ public abstract class KotlinMavenConfigurator implements KotlinProjectConfigurat dialog.show(); if (!dialog.isOK()) return; + NotificationMessageCollector collector = NotificationMessageCollectorKt.createConfigureKotlinNotificationCollector(project); for (Module module : dialog.getModulesToConfigure()) { PsiFile file = findModulePomFile(module); if (file != null && canConfigureFile(file)) { - changePomFile(module, file, dialog.getKotlinVersion()); + changePomFile(module, file, dialog.getKotlinVersion(), collector); OpenFileAction.openFile(file.getVirtualFile(), project); } else { showErrorMessage(project, "Cannot find pom.xml for module " + module.getName()); } } + collector.showNotification(); } protected abstract boolean isKotlinModule(@NotNull Module module); @@ -143,7 +145,12 @@ public abstract class KotlinMavenConfigurator implements KotlinProjectConfigurat return isTest ? TEST_COMPILE_EXECUTION_ID : COMPILE_EXECUTION_ID; } - protected void changePomFile(@NotNull final Module module, final @NotNull PsiFile file, @NotNull final String version) { + protected void changePomFile( + @NotNull final Module module, + final @NotNull PsiFile file, + @NotNull final String version, + @NotNull NotificationMessageCollector collector + ) { final VirtualFile virtualFile = file.getVirtualFile(); assert virtualFile != null : "Virtual file should exists for psi file " + file.getName(); final MavenDomProjectModel domModel = MavenDomUtil.getMavenDomProjectModel(module.getProject(), virtualFile); @@ -168,7 +175,7 @@ public abstract class KotlinMavenConfigurator implements KotlinProjectConfigurat } }.execute(); - ConfigureKotlinInProjectUtilsKt.showInfoNotification(module.getProject(), virtualFile.getPath() + " was modified"); + collector.addMessage(virtualFile.getPath() + " was modified"); } protected void createExecution( diff --git a/idea/src/org/jetbrains/kotlin/idea/configuration/KotlinWithGradleConfigurator.java b/idea/src/org/jetbrains/kotlin/idea/configuration/KotlinWithGradleConfigurator.java index 50e54cb0aa5..302c268bc4c 100644 --- a/idea/src/org/jetbrains/kotlin/idea/configuration/KotlinWithGradleConfigurator.java +++ b/idea/src/org/jetbrains/kotlin/idea/configuration/KotlinWithGradleConfigurator.java @@ -51,8 +51,6 @@ import org.jetbrains.plugins.groovy.lang.psi.api.util.GrStatementOwner; import java.io.File; import java.util.Collection; -import static org.jetbrains.kotlin.idea.configuration.ConfigureKotlinInProjectUtilsKt.showInfoNotification; - public abstract class KotlinWithGradleConfigurator implements KotlinProjectConfigurator { private static final String[] KOTLIN_VERSIONS = {"0.6.+"}; @@ -92,17 +90,19 @@ public abstract class KotlinWithGradleConfigurator implements KotlinProjectConfi dialog.show(); if (!dialog.isOK()) return; + NotificationMessageCollector collector = NotificationMessageCollectorKt.createConfigureKotlinNotificationCollector(project); for (Module module : dialog.getModulesToConfigure()) { String gradleFilePath = getDefaultPathToBuildGradleFile(module); GroovyFile file = getBuildGradleFile(project, gradleFilePath); if (file != null && canConfigureFile(file)) { - changeGradleFile(file, dialog.getKotlinVersion()); + changeGradleFile(file, dialog.getKotlinVersion(), collector); OpenFileAction.openFile(gradleFilePath, project); } else { showErrorMessage(project, "Cannot find build.gradle file for module " + module.getName()); } } + collector.showNotification(); } public static void addKotlinLibraryToModule(final Module module, final DependencyScope scope, final ExternalLibraryDescriptor libraryDescriptor) { @@ -150,7 +150,9 @@ public abstract class KotlinWithGradleConfigurator implements KotlinProjectConfi VirtualFile virtualFile = gradleFile.getVirtualFile(); if (virtualFile != null) { - showInfoNotification(gradleFile.getProject(), virtualFile.getPath() + " was modified"); + NotificationMessageCollectorKt.createConfigureKotlinNotificationCollector(gradleFile.getProject()) + .addMessage(virtualFile.getPath() + " was modified") + .showNotification(); } } } @@ -255,7 +257,11 @@ public abstract class KotlinWithGradleConfigurator implements KotlinProjectConfi return version.contains("SNAPSHOT"); } - protected void changeGradleFile(@NotNull final GroovyFile groovyFile, @NotNull final String version) { + protected void changeGradleFile( + @NotNull final GroovyFile groovyFile, + @NotNull final String version, + @NotNull NotificationMessageCollector collector + ) { new WriteCommandAction(groovyFile.getProject()) { @Override protected void run(@NotNull Result result) { @@ -267,7 +273,7 @@ public abstract class KotlinWithGradleConfigurator implements KotlinProjectConfi VirtualFile virtualFile = groovyFile.getVirtualFile(); if (virtualFile != null) { - showInfoNotification(groovyFile.getProject(), virtualFile.getPath() + " was modified"); + collector.addMessage(virtualFile.getPath() + " was modified"); } } diff --git a/idea/src/org/jetbrains/kotlin/idea/configuration/KotlinWithLibraryConfigurator.java b/idea/src/org/jetbrains/kotlin/idea/configuration/KotlinWithLibraryConfigurator.java index 5e3c2b590f7..d23bb971aac 100644 --- a/idea/src/org/jetbrains/kotlin/idea/configuration/KotlinWithLibraryConfigurator.java +++ b/idea/src/org/jetbrains/kotlin/idea/configuration/KotlinWithLibraryConfigurator.java @@ -45,8 +45,6 @@ import java.util.Arrays; import java.util.Collection; import java.util.List; -import static org.jetbrains.kotlin.idea.configuration.ConfigureKotlinInProjectUtilsKt.showInfoNotification; - public abstract class KotlinWithLibraryConfigurator implements KotlinProjectConfigurator { public static final String DEFAULT_LIBRARY_DIR = "lib"; @@ -108,15 +106,19 @@ public abstract class KotlinWithLibraryConfigurator implements KotlinProjectConf List finalModulesToConfigure = modulesToConfigure; String finalCopyLibraryIntoPath = copyLibraryIntoPath; + NotificationMessageCollector collector = NotificationMessageCollectorKt.createConfigureKotlinNotificationCollector(project); for (Module module : finalModulesToConfigure) { - configureModuleWithLibrary(module, defaultPathToJar, finalCopyLibraryIntoPath); + configureModuleWithLibrary(module, defaultPathToJar, finalCopyLibraryIntoPath, collector); } + + collector.showNotification(); } protected void configureModuleWithLibrary( @NotNull Module module, @NotNull String defaultPath, - @Nullable String pathFromDialog + @Nullable String pathFromDialog, + @NotNull NotificationMessageCollector collector ) { Project project = module.getProject(); @@ -126,7 +128,7 @@ public abstract class KotlinWithLibraryConfigurator implements KotlinProjectConf FileState runtimeState = getJarState(project, files.getRuntimeDestination(dirToCopyJar), OrderRootType.CLASSES, pathFromDialog == null); - configureModuleWithLibraryClasses(module, libraryState, runtimeState, dirToCopyJar); + configureModuleWithLibraryClasses(module, libraryState, runtimeState, dirToCopyJar, collector); Library library = getKotlinLibrary(project); assert library != null : "Kotlin library should exists when adding sources root"; @@ -134,14 +136,15 @@ public abstract class KotlinWithLibraryConfigurator implements KotlinProjectConf FileState sourcesState = getJarState(project, files.getRuntimeSourcesDestination(dirToCopySourcesJar), OrderRootType.SOURCES, pathFromDialog == null); - configureModuleWithLibrarySources(project, library, sourcesState, dirToCopySourcesJar); + configureModuleWithLibrarySources(library, sourcesState, dirToCopySourcesJar, collector); } protected void configureModuleWithLibraryClasses( @NotNull Module module, @NotNull LibraryState libraryState, @NotNull FileState jarState, - @NotNull String dirToCopyJarTo + @NotNull String dirToCopyJarTo, + @NotNull NotificationMessageCollector collector ) { Project project = module.getProject(); RuntimeLibraryFiles files = getExistingJarFiles(); @@ -155,9 +158,9 @@ public abstract class KotlinWithLibraryConfigurator implements KotlinProjectConf break; } case COPY: { - copyFileToDir(project, runtimeJar, dirToCopyJarTo); + copyFileToDir(runtimeJar, dirToCopyJarTo, collector); if (reflectJar != null) { - copyFileToDir(project, reflectJar, dirToCopyJarTo); + copyFileToDir(reflectJar, dirToCopyJarTo, collector); } break; } @@ -171,18 +174,18 @@ public abstract class KotlinWithLibraryConfigurator implements KotlinProjectConf switch (jarState) { case EXISTS: { addJarsToExistingLibrary( - project, files.getRuntimeDestination(dirToCopyJarTo), files.getReflectDestination(dirToCopyJarTo) + project, files.getRuntimeDestination(dirToCopyJarTo), files.getReflectDestination(dirToCopyJarTo), collector ); break; } case COPY: { - addJarsToExistingLibrary( - project, copyFileToDir(project, runtimeJar, dirToCopyJarTo), copyFileToDir(project, reflectJar, dirToCopyJarTo) - ); + File copiedRuntimeJar = copyFileToDir(runtimeJar, dirToCopyJarTo, collector); + File copiedReflectJar = copyFileToDir(reflectJar, dirToCopyJarTo, collector); + addJarsToExistingLibrary(project, copiedRuntimeJar, copiedReflectJar, collector); break; } case DO_NOT_COPY: { - addJarsToExistingLibrary(project, runtimeJar, reflectJar); + addJarsToExistingLibrary(project, runtimeJar, reflectJar, collector); break; } } @@ -191,48 +194,50 @@ public abstract class KotlinWithLibraryConfigurator implements KotlinProjectConf switch (jarState) { case EXISTS: { addJarsToNewLibrary( - project, files.getRuntimeDestination(dirToCopyJarTo), files.getReflectDestination(dirToCopyJarTo) + project, files.getRuntimeDestination(dirToCopyJarTo), files.getReflectDestination(dirToCopyJarTo), collector ); break; } case COPY: { - addJarsToNewLibrary(project, copyFileToDir(project, runtimeJar, dirToCopyJarTo), copyFileToDir(project, reflectJar, dirToCopyJarTo)); + File copiedRuntimeJar = copyFileToDir(runtimeJar, dirToCopyJarTo, collector); + File copiedReflectJar = copyFileToDir(reflectJar, dirToCopyJarTo, collector); + addJarsToNewLibrary(project, copiedRuntimeJar, copiedReflectJar, collector); break; } case DO_NOT_COPY: { - addJarsToNewLibrary(project, runtimeJar, reflectJar); + addJarsToNewLibrary(project, runtimeJar, reflectJar, collector); break; } } break; } - addLibraryToModuleIfNeeded(module); + addLibraryToModuleIfNeeded(module, collector); } protected void configureModuleWithLibrarySources( - @NotNull Project project, @NotNull Library library, @NotNull FileState jarState, - @Nullable String dirToCopyJarTo + @Nullable String dirToCopyJarTo, + @NotNull NotificationMessageCollector collector ) { RuntimeLibraryFiles files = getExistingJarFiles(); File runtimeSourcesJar = files.getRuntimeSourcesJar(); switch (jarState) { case EXISTS: { if (dirToCopyJarTo != null) { - addSourcesToLibraryIfNeeded(project, library, files.getRuntimeSourcesDestination(dirToCopyJarTo)); + addSourcesToLibraryIfNeeded(library, files.getRuntimeSourcesDestination(dirToCopyJarTo), collector); } break; } case COPY: { assert dirToCopyJarTo != null : "Path to copy should be non-null"; - File file = copyFileToDir(project, runtimeSourcesJar, dirToCopyJarTo); - addSourcesToLibraryIfNeeded(project, library, file); + File file = copyFileToDir(runtimeSourcesJar, dirToCopyJarTo, collector); + addSourcesToLibraryIfNeeded(library, file, collector); break; } case DO_NOT_COPY: { - addSourcesToLibraryIfNeeded(project, library, runtimeSourcesJar); + addSourcesToLibraryIfNeeded(library, runtimeSourcesJar, collector); break; } } @@ -254,14 +259,14 @@ public abstract class KotlinWithLibraryConfigurator implements KotlinProjectConf return null; } - @Contract("_, !null, _ -> !null") + @Contract("!null, _, _ -> !null") @Nullable - public File copyFileToDir(@NotNull Project project, @Nullable File file, @NotNull String toDir) { + public File copyFileToDir(@Nullable File file, @NotNull String toDir, @NotNull NotificationMessageCollector collector) { if (file == null) return null; File copy = FileUIUtils.copyWithOverwriteDialog(getMessageForOverrideDialog(), toDir, file); if (copy != null) { - showInfoNotification(project, file.getName() + " was copied to " + toDir); + collector.addMessage(file.getName() + " was copied to " + toDir); } return copy; } @@ -289,7 +294,11 @@ public abstract class KotlinWithLibraryConfigurator implements KotlinProjectConf return parentDir; } - protected static boolean addSourcesToLibraryIfNeeded(@NotNull Project project, @NotNull Library library, @NotNull File file) { + protected static boolean addSourcesToLibraryIfNeeded( + @NotNull Library library, + @NotNull File file, + @NotNull NotificationMessageCollector collector + ) { String[] librarySourceRoots = library.getUrls(OrderRootType.SOURCES); String librarySourceRoot = VfsUtil.getUrlForLibraryRoot(file); for (String sourceRoot : librarySourceRoots) { @@ -306,11 +315,11 @@ public abstract class KotlinWithLibraryConfigurator implements KotlinProjectConf } }); - showInfoNotification(project, "Source root '" + librarySourceRoot + "' was added to " + library.getName() + " library"); + collector.addMessage("Source root '" + librarySourceRoot + "' was added to " + library.getName() + " library"); return true; } - private void addLibraryToModuleIfNeeded(Module module) { + private void addLibraryToModuleIfNeeded(Module module, NotificationMessageCollector collector) { DependencyScope expectedDependencyScope = getDependencyScope(module); Library kotlinLibrary = getKotlinLibrary(module); if (kotlinLibrary == null) { @@ -318,7 +327,7 @@ public abstract class KotlinWithLibraryConfigurator implements KotlinProjectConf assert library != null : "Kotlin project library should exists"; ModuleRootModificationUtil.addDependency(module, library, expectedDependencyScope, false); - showInfoNotification(module.getProject(), library.getName() + " library was added to module " + module.getName()); + collector.addMessage(library.getName() + " library was added to module " + module.getName()); } else { LibraryOrderEntry libraryEntry = findLibraryOrderEntry(ModuleRootManager.getInstance(module).getOrderEntries(), kotlinLibrary); @@ -327,9 +336,9 @@ public abstract class KotlinWithLibraryConfigurator implements KotlinProjectConf if (!expectedDependencyScope.equals(libraryDependencyScope)) { libraryEntry.setScope(expectedDependencyScope); - showInfoNotification(module.getProject(), - kotlinLibrary.getName() + " library scope has changed from " + libraryDependencyScope + - " to " + expectedDependencyScope + " for module " + module.getName()); + collector.addMessage( + kotlinLibrary.getName() + " library scope has changed from " + libraryDependencyScope + + " to " + expectedDependencyScope + " for module " + module.getName()); } } } @@ -354,7 +363,7 @@ public abstract class KotlinWithLibraryConfigurator implements KotlinProjectConf return DependencyScope.COMPILE; } - private void addJarsToExistingLibrary(@NotNull Project project, @NotNull File runtimeJar, @Nullable File reflectJar) { + private void addJarsToExistingLibrary(@NotNull Project project, @NotNull File runtimeJar, @Nullable File reflectJar, @NotNull NotificationMessageCollector collector) { Library library = getKotlinLibrary(project); assert library != null : "Kotlin library should present, instead createNewLibrary should be invoked"; @@ -371,13 +380,14 @@ public abstract class KotlinWithLibraryConfigurator implements KotlinProjectConf } }); - showInfoNotification(project, library.getName() + " library was configured"); + collector.addMessage(library.getName() + " library was configured"); } private void addJarsToNewLibrary( @NotNull Project project, @NotNull final File runtimeJar, - @Nullable final File reflectJar + @Nullable final File reflectJar, + @NotNull NotificationMessageCollector collector ) { final LibraryTable table = LibraryTablesRegistrar.getInstance().getLibraryTable(project); final Ref library = new Ref(); @@ -394,7 +404,7 @@ public abstract class KotlinWithLibraryConfigurator implements KotlinProjectConf } }); - showInfoNotification(project, library.get().getName() + " library was created"); + collector.addMessage(library.get().getName() + " library was created"); } private boolean isProjectLibraryWithoutPathsPresent(@NotNull Project project) { @@ -520,25 +530,25 @@ public abstract class KotlinWithLibraryConfigurator implements KotlinProjectConf return file; } - public void copySourcesToPathFromLibrary(@NotNull Project project, @NotNull Library library) { + public void copySourcesToPathFromLibrary(@NotNull Library library, @NotNull NotificationMessageCollector collector) { String dirToJarFromLibrary = getPathFromLibrary(library, OrderRootType.SOURCES); assert dirToJarFromLibrary != null : "Directory to file from library should be non null"; - copyFileToDir(project, getExistingJarFiles().getRuntimeSourcesJar(), dirToJarFromLibrary); + copyFileToDir(getExistingJarFiles().getRuntimeSourcesJar(), dirToJarFromLibrary, collector); } - public boolean changeOldSourcesPathIfNeeded(@NotNull Project project, @NotNull Library library) { - if (!removeOldSourcesRootIfNeeded(project, library)) { + public boolean changeOldSourcesPathIfNeeded(@NotNull Library library, @NotNull NotificationMessageCollector collector) { + if (!removeOldSourcesRootIfNeeded(library, collector)) { return false; } String parentDir = getPathFromLibrary(library, OrderRootType.CLASSES); assert parentDir != null : "Parent dir for classes jar should exists for Kotlin library"; - return addSourcesToLibraryIfNeeded(project, library, getExistingJarFiles().getRuntimeSourcesDestination(parentDir)); + return addSourcesToLibraryIfNeeded(library, getExistingJarFiles().getRuntimeSourcesDestination(parentDir), collector); } - protected boolean removeOldSourcesRootIfNeeded(@NotNull Project project, @NotNull Library library) { + protected boolean removeOldSourcesRootIfNeeded(@NotNull Library library, @NotNull NotificationMessageCollector collector) { String oldLibrarySourceRoot = getOldSourceRootUrl(library); String[] librarySourceRoots = library.getUrls(OrderRootType.SOURCES); @@ -553,7 +563,7 @@ public abstract class KotlinWithLibraryConfigurator implements KotlinProjectConf } }); - showInfoNotification(project, "Source root '" + oldLibrarySourceRoot + "' was removed for " + library.getName() + " library"); + collector.addMessage("Source root '" + oldLibrarySourceRoot + "' was removed for " + library.getName() + " library"); return true; } } diff --git a/idea/src/org/jetbrains/kotlin/idea/configuration/NotificationMessageCollector.kt b/idea/src/org/jetbrains/kotlin/idea/configuration/NotificationMessageCollector.kt new file mode 100644 index 00000000000..2e65ab2f475 --- /dev/null +++ b/idea/src/org/jetbrains/kotlin/idea/configuration/NotificationMessageCollector.kt @@ -0,0 +1,48 @@ +/* + * Copyright 2010-2016 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.kotlin.idea.configuration + +import com.intellij.notification.Notification +import com.intellij.notification.NotificationType +import com.intellij.notification.Notifications +import com.intellij.openapi.project.Project +import java.util.* + +open class NotificationMessageCollector(private val project: Project, + private val groupDisplayId: String, + private val title: String) { + private val messages = ArrayList() + + fun addMessage(message: String): NotificationMessageCollector { + messages.add(message) + return this + } + + fun showNotification() { + Notifications.Bus.notify(Notification(groupDisplayId, title, resultMessage, NotificationType.INFORMATION), project) + } + + private val resultMessage: String get() { + val singleMessage = messages.singleOrNull() + if (singleMessage != null) return singleMessage + + return messages.joinToString(separator = "

") + } +} + +fun createConfigureKotlinNotificationCollector(project: Project) = + NotificationMessageCollector(project, "Configure Kotlin: info notification", "Configure Kotlin") \ No newline at end of file diff --git a/idea/src/org/jetbrains/kotlin/idea/framework/CustomLibraryDescriptorWithDeferredConfig.java b/idea/src/org/jetbrains/kotlin/idea/framework/CustomLibraryDescriptorWithDeferredConfig.java index ee81a3931a1..4904b0cd4e6 100644 --- a/idea/src/org/jetbrains/kotlin/idea/framework/CustomLibraryDescriptorWithDeferredConfig.java +++ b/idea/src/org/jetbrains/kotlin/idea/framework/CustomLibraryDescriptorWithDeferredConfig.java @@ -34,9 +34,7 @@ import com.intellij.openapi.vfs.VirtualFile; import kotlin.jvm.functions.Function1; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import org.jetbrains.kotlin.idea.configuration.ConfigureKotlinInProjectUtilsKt; -import org.jetbrains.kotlin.idea.configuration.KotlinWithLibraryConfigurator; -import org.jetbrains.kotlin.idea.configuration.RuntimeLibraryFiles; +import org.jetbrains.kotlin.idea.configuration.*; import org.jetbrains.kotlin.idea.framework.ui.CreateLibraryDialog; import org.jetbrains.kotlin.idea.framework.ui.FileUIUtils; import org.jetbrains.kotlin.idea.util.projectStructure.ProjectStructureUtilKt; @@ -129,17 +127,19 @@ public abstract class CustomLibraryDescriptorWithDeferredConfig extends CustomLi } public void performRequests(@NotNull Project project, @NotNull String relativePath, Library.ModifiableModel model) { + NotificationMessageCollector collector = NotificationMessageCollectorKt.createConfigureKotlinNotificationCollector(project); for (CopyFileRequest request : copyFilesRequests) { String destinationPath = FileUtil.isAbsolute(request.toDir) ? request.toDir : new File(relativePath, request.toDir).getPath(); - File resultFile = configurator.copyFileToDir(project, request.file, destinationPath); + File resultFile = configurator.copyFileToDir(request.file, destinationPath, collector); if (request.replaceInLib) { ProjectStructureUtilKt.replaceFileRoot(model, request.file, resultFile); } } + collector.showNotification(); } public void addCopyWithReplaceRequest(@NotNull File file, @NotNull String copyIntoPath) { diff --git a/idea/src/org/jetbrains/kotlin/idea/inspections/AddKotlinLibQuickFix.kt b/idea/src/org/jetbrains/kotlin/idea/inspections/AddKotlinLibQuickFix.kt index 41510d05d49..46828bd0dc9 100644 --- a/idea/src/org/jetbrains/kotlin/idea/inspections/AddKotlinLibQuickFix.kt +++ b/idea/src/org/jetbrains/kotlin/idea/inspections/AddKotlinLibQuickFix.kt @@ -38,7 +38,7 @@ import org.jetbrains.kotlin.idea.KotlinPluginUtil import org.jetbrains.kotlin.idea.configuration.KotlinJavaModuleConfigurator import org.jetbrains.kotlin.idea.configuration.KotlinProjectConfigurator import org.jetbrains.kotlin.idea.configuration.KotlinWithGradleConfigurator -import org.jetbrains.kotlin.idea.configuration.showInfoNotification +import org.jetbrains.kotlin.idea.configuration.createConfigureKotlinNotificationCollector import org.jetbrains.kotlin.idea.framework.JavaRuntimePresentationProvider import org.jetbrains.kotlin.idea.quickfix.KotlinQuickFixAction import org.jetbrains.kotlin.idea.quickfix.KotlinSingleIntentionActionFactory @@ -156,6 +156,8 @@ abstract class AddKotlinLibQuickFix(element: KtElement) : KotlinQuickFixAction() ?: return + val collector = createConfigureKotlinNotificationCollector(project) + for (library in findAllUsedLibraries(project).keySet()) { val runtimeJar = JavaRuntimePresentationProvider.getRuntimeJar(library) ?: continue if (hasLibJarInLibrary(library)) continue @@ -169,15 +171,14 @@ abstract class AddKotlinLibQuickFix(element: KtElement) : KotlinQuickFixAction { diff --git a/idea/tests/org/jetbrains/kotlin/idea/configuration/AbstractConfigureProjectByChangingFileTest.java b/idea/tests/org/jetbrains/kotlin/idea/configuration/AbstractConfigureProjectByChangingFileTest.java index 5feb45d4845..6fc6f65976a 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/configuration/AbstractConfigureProjectByChangingFileTest.java +++ b/idea/tests/org/jetbrains/kotlin/idea/configuration/AbstractConfigureProjectByChangingFileTest.java @@ -52,12 +52,14 @@ public abstract class AbstractConfigureProjectByChangingFileTest extends LightCo String versionFromFile = InTextDirectivesUtils.findStringWithPrefixes(getFile().getText(), "// VERSION:"); String version = versionFromFile != null ? versionFromFile : DEFAULT_VERSION; + NotificationMessageCollector collector = NotificationMessageCollectorKt.createConfigureKotlinNotificationCollector(getProject()); if (configurator instanceof KotlinWithGradleConfigurator) { - ((KotlinWithGradleConfigurator) configurator).changeGradleFile((GroovyFile) getFile(), version); + ((KotlinWithGradleConfigurator) configurator).changeGradleFile((GroovyFile) getFile(), version, collector); } else if (configurator instanceof KotlinMavenConfigurator) { - ((KotlinMavenConfigurator) configurator).changePomFile(getModule(), getFile(), version); + ((KotlinMavenConfigurator) configurator).changePomFile(getModule(), getFile(), version, collector); } + collector.showNotification(); KotlinTestUtils.assertEqualsToFile(new File(afterFile), getFile().getText().replace(version, "$VERSION$")); } diff --git a/idea/tests/org/jetbrains/kotlin/idea/configuration/ConfigureKotlinTest.java b/idea/tests/org/jetbrains/kotlin/idea/configuration/ConfigureKotlinTest.java index 873319fb51f..4875413dbf2 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/configuration/ConfigureKotlinTest.java +++ b/idea/tests/org/jetbrains/kotlin/idea/configuration/ConfigureKotlinTest.java @@ -215,10 +215,13 @@ public class ConfigureKotlinTest extends PlatformTestCase { @NotNull String jarFromDist, @NotNull String jarFromTemp ) { + Project project = modules.iterator().next().getProject(); + NotificationMessageCollector collector = NotificationMessageCollectorKt.createConfigureKotlinNotificationCollector(project); for (Module module : modules) { String pathToJar = getPathToJar(runtimeState, jarFromDist, jarFromTemp); - configurator.configureModuleWithLibraryClasses(module, libraryState, runtimeState, pathToJar); + configurator.configureModuleWithLibraryClasses(module, libraryState, runtimeState, pathToJar, collector); } + collector.showNotification(); } @NotNull @@ -288,7 +291,7 @@ public class ConfigureKotlinTest extends PlatformTestCase { } @Override - protected Project doCreateProject(File projectFile) throws Exception { + protected Project doCreateProject(@NotNull File projectFile) throws Exception { return myProjectManager.loadProject(projectFile.getPath()); }