scope all notifications to a specific project

#KT-9680 Fixed
This commit is contained in:
Dmitry Jemerov
2015-11-09 15:33:41 +01:00
parent e3f5045343
commit 6ced597a73
7 changed files with 40 additions and 38 deletions
@@ -157,7 +157,7 @@ public class ConfigureKotlinInProjectUtils {
private ConfigureKotlinInProjectUtils() { private ConfigureKotlinInProjectUtils() {
} }
public static void showInfoNotification(@NotNull String message) { public static void showInfoNotification(@NotNull Project project, @NotNull String message) {
Notifications.Bus.notify(new Notification("Configure Kotlin: info notification", "Configure Kotlin", message, NotificationType.INFORMATION)); Notifications.Bus.notify(new Notification("Configure Kotlin: info notification", "Configure Kotlin", message, NotificationType.INFORMATION), project);
} }
} }
@@ -169,7 +169,7 @@ public abstract class KotlinMavenConfigurator implements KotlinProjectConfigurat
} }
}.execute(); }.execute();
ConfigureKotlinInProjectUtils.showInfoNotification(virtualFile.getPath() + " was modified"); ConfigureKotlinInProjectUtils.showInfoNotification(module.getProject(), virtualFile.getPath() + " was modified");
} }
protected void createExecution( protected void createExecution(
@@ -189,7 +189,7 @@ public abstract class KotlinWithGradleConfigurator implements KotlinProjectConfi
VirtualFile virtualFile = groovyFile.getVirtualFile(); VirtualFile virtualFile = groovyFile.getVirtualFile();
if (virtualFile != null) { if (virtualFile != null) {
showInfoNotification(virtualFile.getPath() + " was modified"); showInfoNotification(groovyFile.getProject(), virtualFile.getPath() + " was modified");
} }
} }
@@ -131,7 +131,7 @@ public abstract class KotlinWithLibraryConfigurator implements KotlinProjectConf
FileState sourcesState = getJarState(project, files.getRuntimeSourcesDestination(dirToCopySourcesJar), OrderRootType.SOURCES, FileState sourcesState = getJarState(project, files.getRuntimeSourcesDestination(dirToCopySourcesJar), OrderRootType.SOURCES,
pathFromDialog == null); pathFromDialog == null);
configureModuleWithLibrarySources(library, sourcesState, dirToCopySourcesJar); configureModuleWithLibrarySources(project, library, sourcesState, dirToCopySourcesJar);
} }
protected void configureModuleWithLibraryClasses( protected void configureModuleWithLibraryClasses(
@@ -152,9 +152,9 @@ public abstract class KotlinWithLibraryConfigurator implements KotlinProjectConf
break; break;
} }
case COPY: { case COPY: {
copyFileToDir(runtimeJar, dirToCopyJarTo); copyFileToDir(project, runtimeJar, dirToCopyJarTo);
if (reflectJar != null) { if (reflectJar != null) {
copyFileToDir(reflectJar, dirToCopyJarTo); copyFileToDir(project, reflectJar, dirToCopyJarTo);
} }
break; break;
} }
@@ -174,7 +174,7 @@ public abstract class KotlinWithLibraryConfigurator implements KotlinProjectConf
} }
case COPY: { case COPY: {
addJarsToExistingLibrary( addJarsToExistingLibrary(
project, copyFileToDir(runtimeJar, dirToCopyJarTo), copyFileToDir(reflectJar, dirToCopyJarTo) project, copyFileToDir(project, runtimeJar, dirToCopyJarTo), copyFileToDir(project, reflectJar, dirToCopyJarTo)
); );
break; break;
} }
@@ -193,7 +193,7 @@ public abstract class KotlinWithLibraryConfigurator implements KotlinProjectConf
break; break;
} }
case COPY: { case COPY: {
addJarsToNewLibrary(project, copyFileToDir(runtimeJar, dirToCopyJarTo), copyFileToDir(reflectJar, dirToCopyJarTo)); addJarsToNewLibrary(project, copyFileToDir(project, runtimeJar, dirToCopyJarTo), copyFileToDir(project, reflectJar, dirToCopyJarTo));
break; break;
} }
case DO_NOT_COPY: { case DO_NOT_COPY: {
@@ -208,6 +208,7 @@ public abstract class KotlinWithLibraryConfigurator implements KotlinProjectConf
} }
protected void configureModuleWithLibrarySources( protected void configureModuleWithLibrarySources(
@NotNull Project project,
@NotNull Library library, @NotNull Library library,
@NotNull FileState jarState, @NotNull FileState jarState,
@Nullable String dirToCopyJarTo @Nullable String dirToCopyJarTo
@@ -217,18 +218,18 @@ public abstract class KotlinWithLibraryConfigurator implements KotlinProjectConf
switch (jarState) { switch (jarState) {
case EXISTS: { case EXISTS: {
if (dirToCopyJarTo != null) { if (dirToCopyJarTo != null) {
addSourcesToLibraryIfNeeded(library, files.getRuntimeSourcesDestination(dirToCopyJarTo)); addSourcesToLibraryIfNeeded(project, library, files.getRuntimeSourcesDestination(dirToCopyJarTo));
} }
break; break;
} }
case COPY: { case COPY: {
assert dirToCopyJarTo != null : "Path to copy should be non-null"; assert dirToCopyJarTo != null : "Path to copy should be non-null";
File file = copyFileToDir(runtimeSourcesJar, dirToCopyJarTo); File file = copyFileToDir(project, runtimeSourcesJar, dirToCopyJarTo);
addSourcesToLibraryIfNeeded(library, file); addSourcesToLibraryIfNeeded(project, library, file);
break; break;
} }
case DO_NOT_COPY: { case DO_NOT_COPY: {
addSourcesToLibraryIfNeeded(library, runtimeSourcesJar); addSourcesToLibraryIfNeeded(project, library, runtimeSourcesJar);
break; break;
} }
} }
@@ -250,14 +251,14 @@ public abstract class KotlinWithLibraryConfigurator implements KotlinProjectConf
return null; return null;
} }
@Contract("!null, _ -> !null") @Contract("_, !null, _ -> !null")
@Nullable @Nullable
public File copyFileToDir(@Nullable File file, @NotNull String toDir) { public File copyFileToDir(@NotNull Project project, @Nullable File file, @NotNull String toDir) {
if (file == null) return null; if (file == null) return null;
File copy = FileUIUtils.copyWithOverwriteDialog(getMessageForOverrideDialog(), toDir, file); File copy = FileUIUtils.copyWithOverwriteDialog(getMessageForOverrideDialog(), toDir, file);
if (copy != null) { if (copy != null) {
showInfoNotification(file.getName() + " was copied to " + toDir); showInfoNotification(project, file.getName() + " was copied to " + toDir);
} }
return copy; return copy;
} }
@@ -285,7 +286,7 @@ public abstract class KotlinWithLibraryConfigurator implements KotlinProjectConf
return parentDir; return parentDir;
} }
protected static boolean addSourcesToLibraryIfNeeded(@NotNull Library library, @NotNull File file) { protected static boolean addSourcesToLibraryIfNeeded(@NotNull Project project, @NotNull Library library, @NotNull File file) {
String[] librarySourceRoots = library.getUrls(OrderRootType.SOURCES); String[] librarySourceRoots = library.getUrls(OrderRootType.SOURCES);
String librarySourceRoot = VfsUtil.getUrlForLibraryRoot(file); String librarySourceRoot = VfsUtil.getUrlForLibraryRoot(file);
for (String sourceRoot : librarySourceRoots) { for (String sourceRoot : librarySourceRoots) {
@@ -302,7 +303,7 @@ public abstract class KotlinWithLibraryConfigurator implements KotlinProjectConf
} }
}); });
showInfoNotification("Source root '" + librarySourceRoot + "' was added to " + library.getName() + " library"); showInfoNotification(project, "Source root '" + librarySourceRoot + "' was added to " + library.getName() + " library");
return true; return true;
} }
@@ -314,7 +315,7 @@ public abstract class KotlinWithLibraryConfigurator implements KotlinProjectConf
assert library != null : "Kotlin project library should exists"; assert library != null : "Kotlin project library should exists";
ModuleRootModificationUtil.addDependency(module, library, expectedDependencyScope, false); ModuleRootModificationUtil.addDependency(module, library, expectedDependencyScope, false);
showInfoNotification(library.getName() + " library was added to module " + module.getName()); showInfoNotification(module.getProject(), library.getName() + " library was added to module " + module.getName());
} }
else { else {
LibraryOrderEntry libraryEntry = findLibraryOrderEntry(ModuleRootManager.getInstance(module).getOrderEntries(), kotlinLibrary); LibraryOrderEntry libraryEntry = findLibraryOrderEntry(ModuleRootManager.getInstance(module).getOrderEntries(), kotlinLibrary);
@@ -323,7 +324,8 @@ public abstract class KotlinWithLibraryConfigurator implements KotlinProjectConf
if (!expectedDependencyScope.equals(libraryDependencyScope)) { if (!expectedDependencyScope.equals(libraryDependencyScope)) {
libraryEntry.setScope(expectedDependencyScope); libraryEntry.setScope(expectedDependencyScope);
showInfoNotification(kotlinLibrary.getName() + " library scope has changed from " + libraryDependencyScope + showInfoNotification(module.getProject(),
kotlinLibrary.getName() + " library scope has changed from " + libraryDependencyScope +
" to " + expectedDependencyScope + " for module " + module.getName()); " to " + expectedDependencyScope + " for module " + module.getName());
} }
} }
@@ -366,7 +368,7 @@ public abstract class KotlinWithLibraryConfigurator implements KotlinProjectConf
} }
}); });
showInfoNotification(library.getName() + " library was configured"); showInfoNotification(project, library.getName() + " library was configured");
} }
private void addJarsToNewLibrary( private void addJarsToNewLibrary(
@@ -389,7 +391,7 @@ public abstract class KotlinWithLibraryConfigurator implements KotlinProjectConf
} }
}); });
showInfoNotification(library.get().getName() + " library was created"); showInfoNotification(project, library.get().getName() + " library was created");
} }
private boolean isProjectLibraryWithoutPathsPresent(@NotNull Project project) { private boolean isProjectLibraryWithoutPathsPresent(@NotNull Project project) {
@@ -515,25 +517,25 @@ public abstract class KotlinWithLibraryConfigurator implements KotlinProjectConf
return file; return file;
} }
public void copySourcesToPathFromLibrary(@NotNull Library library) { public void copySourcesToPathFromLibrary(@NotNull Project project, @NotNull Library library) {
String dirToJarFromLibrary = getPathFromLibrary(library, OrderRootType.SOURCES); String dirToJarFromLibrary = getPathFromLibrary(library, OrderRootType.SOURCES);
assert dirToJarFromLibrary != null : "Directory to file from library should be non null"; assert dirToJarFromLibrary != null : "Directory to file from library should be non null";
copyFileToDir(getExistingJarFiles().getRuntimeSourcesJar(), dirToJarFromLibrary); copyFileToDir(project, getExistingJarFiles().getRuntimeSourcesJar(), dirToJarFromLibrary);
} }
public boolean changeOldSourcesPathIfNeeded(@NotNull Library library) { public boolean changeOldSourcesPathIfNeeded(@NotNull Project project, @NotNull Library library) {
if (!removeOldSourcesRootIfNeeded(library)) { if (!removeOldSourcesRootIfNeeded(project, library)) {
return false; return false;
} }
String parentDir = getPathFromLibrary(library, OrderRootType.CLASSES); String parentDir = getPathFromLibrary(library, OrderRootType.CLASSES);
assert parentDir != null : "Parent dir for classes jar should exists for Kotlin library"; assert parentDir != null : "Parent dir for classes jar should exists for Kotlin library";
return addSourcesToLibraryIfNeeded(library, getExistingJarFiles().getRuntimeSourcesDestination(parentDir)); return addSourcesToLibraryIfNeeded(project, library, getExistingJarFiles().getRuntimeSourcesDestination(parentDir));
} }
protected boolean removeOldSourcesRootIfNeeded(@NotNull Library library) { protected boolean removeOldSourcesRootIfNeeded(@NotNull Project project, @NotNull Library library) {
String oldLibrarySourceRoot = getOldSourceRootUrl(library); String oldLibrarySourceRoot = getOldSourceRootUrl(library);
String[] librarySourceRoots = library.getUrls(OrderRootType.SOURCES); String[] librarySourceRoots = library.getUrls(OrderRootType.SOURCES);
@@ -548,7 +550,7 @@ public abstract class KotlinWithLibraryConfigurator implements KotlinProjectConf
} }
}); });
showInfoNotification("Source root '" + oldLibrarySourceRoot + "' was removed for " + library.getName() + " library"); showInfoNotification(project, "Source root '" + oldLibrarySourceRoot + "' was removed for " + library.getName() + " library");
return true; return true;
} }
} }
@@ -113,7 +113,7 @@ public abstract class CustomLibraryDescriptorWithDeferredConfig extends CustomLi
Library.ModifiableModel model = library.getModifiableModel(); Library.ModifiableModel model = library.getModifiableModel();
try { try {
deferredCopyFileRequests.performRequests(ProjectStructureUtilKt.getModuleDir(module), model); deferredCopyFileRequests.performRequests(module.getProject(), ProjectStructureUtilKt.getModuleDir(module), model);
} }
finally { finally {
model.commit(); model.commit();
@@ -128,13 +128,13 @@ public abstract class CustomLibraryDescriptorWithDeferredConfig extends CustomLi
this.configurator = configurator; this.configurator = configurator;
} }
public void performRequests(@NotNull String relativePath, Library.ModifiableModel model) { public void performRequests(@NotNull Project project, @NotNull String relativePath, Library.ModifiableModel model) {
for (CopyFileRequest request : copyFilesRequests) { for (CopyFileRequest request : copyFilesRequests) {
String destinationPath = FileUtil.isAbsolute(request.toDir) ? String destinationPath = FileUtil.isAbsolute(request.toDir) ?
request.toDir : request.toDir :
new File(relativePath, request.toDir).getPath(); new File(relativePath, request.toDir).getPath();
File resultFile = configurator.copyFileToDir(request.file, destinationPath); File resultFile = configurator.copyFileToDir(project, request.file, destinationPath);
if (request.replaceInLib) { if (request.replaceInLib) {
ProjectStructureUtilKt.replaceFileRoot(model, request.file, resultFile); ProjectStructureUtilKt.replaceFileRoot(model, request.file, resultFile);
@@ -61,13 +61,13 @@ public class AddReflectionQuickFix(element: KtElement) : KotlinQuickFixAction<Kt
model.addRoot(VfsUtil.getUrlForLibraryRoot(reflectIoFile), OrderRootType.CLASSES) model.addRoot(VfsUtil.getUrlForLibraryRoot(reflectIoFile), OrderRootType.CLASSES)
} }
else { else {
val copied = configurator.copyFileToDir(pluginReflectJar, libFilesDir)!! val copied = configurator.copyFileToDir(project, pluginReflectJar, libFilesDir)!!
model.addRoot(VfsUtil.getUrlForLibraryRoot(copied), OrderRootType.CLASSES) model.addRoot(VfsUtil.getUrlForLibraryRoot(copied), OrderRootType.CLASSES)
} }
model.commit() model.commit()
ConfigureKotlinInProjectUtils.showInfoNotification( ConfigureKotlinInProjectUtils.showInfoNotification(project,
"${PathUtil.KOTLIN_JAVA_REFLECT_JAR} was added to the library ${library.getName()}" "${PathUtil.KOTLIN_JAVA_REFLECT_JAR} was added to the library ${library.getName()}"
) )
} }
@@ -122,8 +122,8 @@ public class KotlinRuntimeLibraryUtil {
updateJar(project, JavaRuntimePresentationProvider.getRuntimeJar(library), LibraryJarDescriptor.RUNTIME_JAR); updateJar(project, JavaRuntimePresentationProvider.getRuntimeJar(library), LibraryJarDescriptor.RUNTIME_JAR);
updateJar(project, JavaRuntimePresentationProvider.getReflectJar(library), LibraryJarDescriptor.REFLECT_JAR); updateJar(project, JavaRuntimePresentationProvider.getReflectJar(library), LibraryJarDescriptor.REFLECT_JAR);
if (kJvmConfigurator.changeOldSourcesPathIfNeeded(library)) { if (kJvmConfigurator.changeOldSourcesPathIfNeeded(project, library)) {
kJvmConfigurator.copySourcesToPathFromLibrary(library); kJvmConfigurator.copySourcesToPathFromLibrary(project, library);
} }
else { else {
updateJar(project, JavaRuntimePresentationProvider.getRuntimeSrcJar(library), LibraryJarDescriptor.RUNTIME_SRC_JAR); updateJar(project, JavaRuntimePresentationProvider.getRuntimeSrcJar(library), LibraryJarDescriptor.RUNTIME_SRC_JAR);
@@ -132,8 +132,8 @@ public class KotlinRuntimeLibraryUtil {
else if (LibraryPresentationProviderUtil.isDetected(JSLibraryStdPresentationProvider.getInstance(), library)) { else if (LibraryPresentationProviderUtil.isDetected(JSLibraryStdPresentationProvider.getInstance(), library)) {
updateJar(project, JSLibraryStdPresentationProvider.getJsStdLibJar(library), LibraryJarDescriptor.JS_STDLIB_JAR); updateJar(project, JSLibraryStdPresentationProvider.getJsStdLibJar(library), LibraryJarDescriptor.JS_STDLIB_JAR);
if (kJsConfigurator.changeOldSourcesPathIfNeeded(library)) { if (kJsConfigurator.changeOldSourcesPathIfNeeded(project, library)) {
kJsConfigurator.copySourcesToPathFromLibrary(library); kJsConfigurator.copySourcesToPathFromLibrary(project, library);
} }
else { else {
updateJar(project, JSLibraryStdPresentationProvider.getJsStdLibSrcJar(library), LibraryJarDescriptor.JS_STDLIB_SRC_JAR); updateJar(project, JSLibraryStdPresentationProvider.getJsStdLibSrcJar(library), LibraryJarDescriptor.JS_STDLIB_SRC_JAR);