Aggregate configuration messages into one notification (KT-10489)

#KT-10489 Fixed
This commit is contained in:
Nikolay Krasko
2016-02-08 21:06:16 +03:00
parent e2f1a5c092
commit 5c6c1173a6
10 changed files with 155 additions and 83 deletions
@@ -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<Module>
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)
}
}
@@ -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(
@@ -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");
}
}
@@ -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<Module> 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> library = new Ref<Library>();
@@ -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;
}
}
@@ -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<String>()
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 = "<br/><br/>")
}
}
fun createConfigureKotlinNotificationCollector(project: Project) =
NotificationMessageCollector(project, "Configure Kotlin: info notification", "Configure Kotlin")
@@ -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) {
@@ -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<K
val configurator = Extensions.getExtensions(KotlinProjectConfigurator.EP_NAME)
.firstIsInstanceOrNull<KotlinJavaModuleConfigurator>() ?: 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<K
model.addRoot(VfsUtil.getUrlForLibraryRoot(libIoFile), OrderRootType.CLASSES)
}
else {
val copied = configurator.copyFileToDir(project, libFile, libFilesDir)!!
val copied = configurator.copyFileToDir(libFile, libFilesDir, collector)!!
model.addRoot(VfsUtil.getUrlForLibraryRoot(copied), OrderRootType.CLASSES)
}
model.commit()
showInfoNotification(
project, "${libraryPath()} was added to the library ${library.name}")
}
collector.showNotification()
}
companion object {
@@ -40,6 +40,7 @@ import com.intellij.util.indexing.ScalarIndexExtension
import org.jetbrains.kotlin.idea.KotlinPluginUtil
import org.jetbrains.kotlin.idea.configuration.KotlinJavaModuleConfigurator
import org.jetbrains.kotlin.idea.configuration.KotlinJsModuleConfigurator
import org.jetbrains.kotlin.idea.configuration.createConfigureKotlinNotificationCollector
import org.jetbrains.kotlin.idea.configuration.getConfiguratorByName
import org.jetbrains.kotlin.idea.framework.JSLibraryStdPresentationProvider
import org.jetbrains.kotlin.idea.framework.JavaRuntimePresentationProvider
@@ -73,14 +74,16 @@ fun updateLibraries(
val kJsConfigurator = getConfiguratorByName(KotlinJsModuleConfigurator.NAME) as KotlinJsModuleConfigurator? ?:
error("Configurator with given name doesn't exists: " + KotlinJsModuleConfigurator.NAME)
val collector = createConfigureKotlinNotificationCollector(project)
for (library in libraries) {
if (LibraryPresentationProviderUtil.isDetected(JavaRuntimePresentationProvider.getInstance(), library)) {
updateJar(project, JavaRuntimePresentationProvider.getRuntimeJar(library), LibraryJarDescriptor.RUNTIME_JAR)
updateJar(project, JavaRuntimePresentationProvider.getReflectJar(library), LibraryJarDescriptor.REFLECT_JAR)
updateJar(project, JavaRuntimePresentationProvider.getTestJar(library), LibraryJarDescriptor.TEST_JAR)
if (kJvmConfigurator.changeOldSourcesPathIfNeeded(project, library)) {
kJvmConfigurator.copySourcesToPathFromLibrary(project, library)
if (kJvmConfigurator.changeOldSourcesPathIfNeeded(library, collector)) {
kJvmConfigurator.copySourcesToPathFromLibrary(library, collector)
}
else {
updateJar(project, JavaRuntimePresentationProvider.getRuntimeSrcJar(library), LibraryJarDescriptor.RUNTIME_SRC_JAR)
@@ -89,14 +92,16 @@ fun updateLibraries(
else if (LibraryPresentationProviderUtil.isDetected(JSLibraryStdPresentationProvider.getInstance(), library)) {
updateJar(project, JSLibraryStdPresentationProvider.getJsStdLibJar(library), LibraryJarDescriptor.JS_STDLIB_JAR)
if (kJsConfigurator.changeOldSourcesPathIfNeeded(project, library)) {
kJsConfigurator.copySourcesToPathFromLibrary(project, library)
if (kJsConfigurator.changeOldSourcesPathIfNeeded(library, collector)) {
kJsConfigurator.copySourcesToPathFromLibrary(library, collector)
}
else {
updateJar(project, JSLibraryStdPresentationProvider.getJsStdLibSrcJar(library), LibraryJarDescriptor.JS_STDLIB_SRC_JAR)
}
}
}
collector.showNotification()
}
}
@@ -123,10 +128,7 @@ private fun updateJar(
return
}
val localJar = getLocalJar(fileToReplace)
assert(localJar != null)
replaceFile(jarPath, localJar!!)
replaceFile(jarPath, getLocalJar(fileToReplace)!!)
}
fun findAllUsedLibraries(project: Project): MultiMap<Library, Module> {
@@ -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$"));
}
@@ -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());
}