scope all notifications to a specific project
#KT-9680 Fixed
This commit is contained in:
@@ -157,7 +157,7 @@ public class ConfigureKotlinInProjectUtils {
|
||||
private ConfigureKotlinInProjectUtils() {
|
||||
}
|
||||
|
||||
public static void showInfoNotification(@NotNull String message) {
|
||||
Notifications.Bus.notify(new Notification("Configure Kotlin: info notification", "Configure Kotlin", message, NotificationType.INFORMATION));
|
||||
public static void showInfoNotification(@NotNull Project project, @NotNull String message) {
|
||||
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();
|
||||
|
||||
ConfigureKotlinInProjectUtils.showInfoNotification(virtualFile.getPath() + " was modified");
|
||||
ConfigureKotlinInProjectUtils.showInfoNotification(module.getProject(), virtualFile.getPath() + " was modified");
|
||||
}
|
||||
|
||||
protected void createExecution(
|
||||
|
||||
@@ -189,7 +189,7 @@ public abstract class KotlinWithGradleConfigurator implements KotlinProjectConfi
|
||||
|
||||
VirtualFile virtualFile = groovyFile.getVirtualFile();
|
||||
if (virtualFile != null) {
|
||||
showInfoNotification(virtualFile.getPath() + " was modified");
|
||||
showInfoNotification(groovyFile.getProject(), virtualFile.getPath() + " was modified");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+27
-25
@@ -131,7 +131,7 @@ public abstract class KotlinWithLibraryConfigurator implements KotlinProjectConf
|
||||
FileState sourcesState = getJarState(project, files.getRuntimeSourcesDestination(dirToCopySourcesJar), OrderRootType.SOURCES,
|
||||
pathFromDialog == null);
|
||||
|
||||
configureModuleWithLibrarySources(library, sourcesState, dirToCopySourcesJar);
|
||||
configureModuleWithLibrarySources(project, library, sourcesState, dirToCopySourcesJar);
|
||||
}
|
||||
|
||||
protected void configureModuleWithLibraryClasses(
|
||||
@@ -152,9 +152,9 @@ public abstract class KotlinWithLibraryConfigurator implements KotlinProjectConf
|
||||
break;
|
||||
}
|
||||
case COPY: {
|
||||
copyFileToDir(runtimeJar, dirToCopyJarTo);
|
||||
copyFileToDir(project, runtimeJar, dirToCopyJarTo);
|
||||
if (reflectJar != null) {
|
||||
copyFileToDir(reflectJar, dirToCopyJarTo);
|
||||
copyFileToDir(project, reflectJar, dirToCopyJarTo);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -174,7 +174,7 @@ public abstract class KotlinWithLibraryConfigurator implements KotlinProjectConf
|
||||
}
|
||||
case COPY: {
|
||||
addJarsToExistingLibrary(
|
||||
project, copyFileToDir(runtimeJar, dirToCopyJarTo), copyFileToDir(reflectJar, dirToCopyJarTo)
|
||||
project, copyFileToDir(project, runtimeJar, dirToCopyJarTo), copyFileToDir(project, reflectJar, dirToCopyJarTo)
|
||||
);
|
||||
break;
|
||||
}
|
||||
@@ -193,7 +193,7 @@ public abstract class KotlinWithLibraryConfigurator implements KotlinProjectConf
|
||||
break;
|
||||
}
|
||||
case COPY: {
|
||||
addJarsToNewLibrary(project, copyFileToDir(runtimeJar, dirToCopyJarTo), copyFileToDir(reflectJar, dirToCopyJarTo));
|
||||
addJarsToNewLibrary(project, copyFileToDir(project, runtimeJar, dirToCopyJarTo), copyFileToDir(project, reflectJar, dirToCopyJarTo));
|
||||
break;
|
||||
}
|
||||
case DO_NOT_COPY: {
|
||||
@@ -208,6 +208,7 @@ public abstract class KotlinWithLibraryConfigurator implements KotlinProjectConf
|
||||
}
|
||||
|
||||
protected void configureModuleWithLibrarySources(
|
||||
@NotNull Project project,
|
||||
@NotNull Library library,
|
||||
@NotNull FileState jarState,
|
||||
@Nullable String dirToCopyJarTo
|
||||
@@ -217,18 +218,18 @@ public abstract class KotlinWithLibraryConfigurator implements KotlinProjectConf
|
||||
switch (jarState) {
|
||||
case EXISTS: {
|
||||
if (dirToCopyJarTo != null) {
|
||||
addSourcesToLibraryIfNeeded(library, files.getRuntimeSourcesDestination(dirToCopyJarTo));
|
||||
addSourcesToLibraryIfNeeded(project, library, files.getRuntimeSourcesDestination(dirToCopyJarTo));
|
||||
}
|
||||
break;
|
||||
}
|
||||
case COPY: {
|
||||
assert dirToCopyJarTo != null : "Path to copy should be non-null";
|
||||
File file = copyFileToDir(runtimeSourcesJar, dirToCopyJarTo);
|
||||
addSourcesToLibraryIfNeeded(library, file);
|
||||
File file = copyFileToDir(project, runtimeSourcesJar, dirToCopyJarTo);
|
||||
addSourcesToLibraryIfNeeded(project, library, file);
|
||||
break;
|
||||
}
|
||||
case DO_NOT_COPY: {
|
||||
addSourcesToLibraryIfNeeded(library, runtimeSourcesJar);
|
||||
addSourcesToLibraryIfNeeded(project, library, runtimeSourcesJar);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -250,14 +251,14 @@ public abstract class KotlinWithLibraryConfigurator implements KotlinProjectConf
|
||||
return null;
|
||||
}
|
||||
|
||||
@Contract("!null, _ -> !null")
|
||||
@Contract("_, !null, _ -> !null")
|
||||
@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;
|
||||
|
||||
File copy = FileUIUtils.copyWithOverwriteDialog(getMessageForOverrideDialog(), toDir, file);
|
||||
if (copy != null) {
|
||||
showInfoNotification(file.getName() + " was copied to " + toDir);
|
||||
showInfoNotification(project, file.getName() + " was copied to " + toDir);
|
||||
}
|
||||
return copy;
|
||||
}
|
||||
@@ -285,7 +286,7 @@ public abstract class KotlinWithLibraryConfigurator implements KotlinProjectConf
|
||||
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 librarySourceRoot = VfsUtil.getUrlForLibraryRoot(file);
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -314,7 +315,7 @@ public abstract class KotlinWithLibraryConfigurator implements KotlinProjectConf
|
||||
assert library != null : "Kotlin project library should exists";
|
||||
|
||||
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 {
|
||||
LibraryOrderEntry libraryEntry = findLibraryOrderEntry(ModuleRootManager.getInstance(module).getOrderEntries(), kotlinLibrary);
|
||||
@@ -323,7 +324,8 @@ public abstract class KotlinWithLibraryConfigurator implements KotlinProjectConf
|
||||
if (!expectedDependencyScope.equals(libraryDependencyScope)) {
|
||||
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());
|
||||
}
|
||||
}
|
||||
@@ -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(
|
||||
@@ -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) {
|
||||
@@ -515,25 +517,25 @@ public abstract class KotlinWithLibraryConfigurator implements KotlinProjectConf
|
||||
return file;
|
||||
}
|
||||
|
||||
public void copySourcesToPathFromLibrary(@NotNull Library library) {
|
||||
public void copySourcesToPathFromLibrary(@NotNull Project project, @NotNull Library library) {
|
||||
String dirToJarFromLibrary = getPathFromLibrary(library, OrderRootType.SOURCES);
|
||||
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) {
|
||||
if (!removeOldSourcesRootIfNeeded(library)) {
|
||||
public boolean changeOldSourcesPathIfNeeded(@NotNull Project project, @NotNull Library library) {
|
||||
if (!removeOldSourcesRootIfNeeded(project, library)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
String parentDir = getPathFromLibrary(library, OrderRootType.CLASSES);
|
||||
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[] 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;
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -113,7 +113,7 @@ public abstract class CustomLibraryDescriptorWithDeferredConfig extends CustomLi
|
||||
|
||||
Library.ModifiableModel model = library.getModifiableModel();
|
||||
try {
|
||||
deferredCopyFileRequests.performRequests(ProjectStructureUtilKt.getModuleDir(module), model);
|
||||
deferredCopyFileRequests.performRequests(module.getProject(), ProjectStructureUtilKt.getModuleDir(module), model);
|
||||
}
|
||||
finally {
|
||||
model.commit();
|
||||
@@ -128,13 +128,13 @@ public abstract class CustomLibraryDescriptorWithDeferredConfig extends CustomLi
|
||||
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) {
|
||||
String destinationPath = FileUtil.isAbsolute(request.toDir) ?
|
||||
request.toDir :
|
||||
new File(relativePath, request.toDir).getPath();
|
||||
|
||||
File resultFile = configurator.copyFileToDir(request.file, destinationPath);
|
||||
File resultFile = configurator.copyFileToDir(project, request.file, destinationPath);
|
||||
|
||||
if (request.replaceInLib) {
|
||||
ProjectStructureUtilKt.replaceFileRoot(model, request.file, resultFile);
|
||||
|
||||
@@ -61,13 +61,13 @@ public class AddReflectionQuickFix(element: KtElement) : KotlinQuickFixAction<Kt
|
||||
model.addRoot(VfsUtil.getUrlForLibraryRoot(reflectIoFile), OrderRootType.CLASSES)
|
||||
}
|
||||
else {
|
||||
val copied = configurator.copyFileToDir(pluginReflectJar, libFilesDir)!!
|
||||
val copied = configurator.copyFileToDir(project, pluginReflectJar, libFilesDir)!!
|
||||
model.addRoot(VfsUtil.getUrlForLibraryRoot(copied), OrderRootType.CLASSES)
|
||||
}
|
||||
|
||||
model.commit()
|
||||
|
||||
ConfigureKotlinInProjectUtils.showInfoNotification(
|
||||
ConfigureKotlinInProjectUtils.showInfoNotification(project,
|
||||
"${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.getReflectJar(library), LibraryJarDescriptor.REFLECT_JAR);
|
||||
|
||||
if (kJvmConfigurator.changeOldSourcesPathIfNeeded(library)) {
|
||||
kJvmConfigurator.copySourcesToPathFromLibrary(library);
|
||||
if (kJvmConfigurator.changeOldSourcesPathIfNeeded(project, library)) {
|
||||
kJvmConfigurator.copySourcesToPathFromLibrary(project, library);
|
||||
}
|
||||
else {
|
||||
updateJar(project, JavaRuntimePresentationProvider.getRuntimeSrcJar(library), LibraryJarDescriptor.RUNTIME_SRC_JAR);
|
||||
@@ -132,8 +132,8 @@ public class KotlinRuntimeLibraryUtil {
|
||||
else if (LibraryPresentationProviderUtil.isDetected(JSLibraryStdPresentationProvider.getInstance(), library)) {
|
||||
updateJar(project, JSLibraryStdPresentationProvider.getJsStdLibJar(library), LibraryJarDescriptor.JS_STDLIB_JAR);
|
||||
|
||||
if (kJsConfigurator.changeOldSourcesPathIfNeeded(library)) {
|
||||
kJsConfigurator.copySourcesToPathFromLibrary(library);
|
||||
if (kJsConfigurator.changeOldSourcesPathIfNeeded(project, library)) {
|
||||
kJsConfigurator.copySourcesToPathFromLibrary(project, library);
|
||||
}
|
||||
else {
|
||||
updateJar(project, JSLibraryStdPresentationProvider.getJsStdLibSrcJar(library), LibraryJarDescriptor.JS_STDLIB_SRC_JAR);
|
||||
|
||||
Reference in New Issue
Block a user