mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[jps build] don't show "Clean up old output directories" notification
Since IDEA-185574 is fixed (IDEA 2018.1) when you rename or remove a module, the obsolete output directory is deleted automatically when Build Project is invoked. This notification was needed to clean up old output directories which were left by IDEA 2017.3 or older versions. But now it isn't necessary and may be annoying: if you update the project from VCS and get a change where some modules were removed or renamed, and then reopen the project, you'll see the notification before Build Project cleans up the old directories automatically (IDEA-237388). Also marker file for the notification may be created in unexpected places (IDEA-202729). Removing the notification is the simplest way to fix these issues. We may assume that users of IntelliJ IDEA 2017.3 or older already took the opportunity to clean the old directories after updating to IDEA version between 2018.1 and 2020.1. GitOrigin-RevId: 93d371f43f3b61e1e7d9040e44df0683f582e0c7
This commit is contained in:
committed by
intellij-monorepo-bot
parent
0cbe6aa81a
commit
81b309e99c
@@ -1,119 +0,0 @@
|
||||
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.compiler.impl
|
||||
|
||||
import com.intellij.CommonBundle
|
||||
import com.intellij.compiler.server.BuildManager
|
||||
import com.intellij.notification.Notification
|
||||
import com.intellij.notification.NotificationAction
|
||||
import com.intellij.notification.NotificationType
|
||||
import com.intellij.notification.Notifications
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent
|
||||
import com.intellij.openapi.application.runReadAction
|
||||
import com.intellij.openapi.compiler.JavaCompilerBundle
|
||||
import com.intellij.openapi.module.ModuleManager
|
||||
import com.intellij.openapi.progress.ProgressIndicator
|
||||
import com.intellij.openapi.progress.Task
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.roots.CompilerModuleExtension
|
||||
import com.intellij.openapi.roots.CompilerProjectExtension
|
||||
import com.intellij.openapi.startup.StartupActivity
|
||||
import com.intellij.openapi.ui.Messages
|
||||
import com.intellij.openapi.util.io.FileUtil
|
||||
import com.intellij.openapi.vfs.LocalFileSystem
|
||||
import com.intellij.openapi.vfs.VfsUtil
|
||||
import com.intellij.openapi.vfs.VirtualFile
|
||||
import java.io.File
|
||||
|
||||
/**
|
||||
* Shows notification which suggests to delete stale output directories corresponding to renamed or deleted modules. Such directories may
|
||||
* be kept on disk because of a bug (https://youtrack.jetbrains.com/issue/IDEA-185574) in previous IntelliJ IDEA versions.
|
||||
*/
|
||||
class CleanStaleModuleOutputsActivity : StartupActivity.DumbAware {
|
||||
override fun runActivity(project: Project) {
|
||||
val markerFile = File(BuildManager.getInstance().getProjectSystemDirectory(project), "stale_outputs_checked")
|
||||
if (markerFile.exists()) return
|
||||
|
||||
fun createMarker() {
|
||||
FileUtil.createIfDoesntExist(markerFile)
|
||||
}
|
||||
|
||||
val staleOutputs = runReadAction { collectStaleOutputs(project) }
|
||||
if (staleOutputs.isEmpty()) {
|
||||
createMarker()
|
||||
return
|
||||
}
|
||||
|
||||
runReadAction {
|
||||
val outputPath = CompilerProjectExtension.getInstance(project)!!.compilerOutput!!.presentableUrl
|
||||
val notification = Notification(
|
||||
"Build", JavaCompilerBundle.message("notification.title.delete.old.output.directories"),
|
||||
JavaCompilerBundle.message("notification.content.delete.old.output.directories", staleOutputs.size, outputPath),
|
||||
NotificationType.INFORMATION
|
||||
).addAction(object : NotificationAction(JavaCompilerBundle.message("notification.action.text.cleanup")) {
|
||||
override fun actionPerformed(e: AnActionEvent, notification: Notification) {
|
||||
notification.expire()
|
||||
runCleanup(staleOutputs, project, ::createMarker)
|
||||
}
|
||||
}).addAction(object : NotificationAction(JavaCompilerBundle.message("notification.action.text.do.not.ask")) {
|
||||
override fun actionPerformed(e: AnActionEvent, notification: Notification) {
|
||||
notification.expire()
|
||||
createMarker()
|
||||
}
|
||||
})
|
||||
Notifications.Bus.notify(notification, project)
|
||||
}
|
||||
}
|
||||
|
||||
private fun runCleanup(outputs: List<VirtualFile>, project: Project, onSuccess: () -> Unit) {
|
||||
val outputsString: String
|
||||
val threshold = 50
|
||||
if (outputs.size <= threshold + 2) {
|
||||
outputsString = outputs.joinToString("<br>") { it.presentableUrl }
|
||||
}
|
||||
else {
|
||||
val parents = outputs.subList(threshold, outputs.size).mapTo(LinkedHashSet()) {it.parent}.toList()
|
||||
outputsString = (outputs.subList(0, threshold).map {it.presentableUrl}
|
||||
+ listOf("${outputs.size - threshold} more directories under ${parents.first().presentableUrl}")
|
||||
+ parents.drop(1).map { "and ${it.presentableUrl}" }
|
||||
).joinToString("<br>")
|
||||
}
|
||||
|
||||
//until IDEA-186296 is fixed we need to use IDEA's message dialog for potentially long messages
|
||||
val answer = Messages.showIdeaMessageDialog(project, JavaCompilerBundle.message("dialog.text.delete.old.outputs", outputs.size, outputsString),
|
||||
JavaCompilerBundle.message("dialog.title.delete.old.outputs"),
|
||||
arrayOf(
|
||||
JavaCompilerBundle.message("button.text.delete.old.outputs"), CommonBundle.getCancelButtonText()), 0, null, null)
|
||||
if (answer == Messages.CANCEL) return
|
||||
|
||||
val filesToDelete = outputs.map { VfsUtil.virtualToIoFile(it) }
|
||||
object : Task.Backgroundable(project, JavaCompilerBundle.message("dialog.title.delete.old.outputs")) {
|
||||
override fun run(indicator: ProgressIndicator) {
|
||||
indicator.isIndeterminate = false
|
||||
filesToDelete.forEachIndexed { i, file ->
|
||||
indicator.checkCanceled()
|
||||
indicator.fraction = i.toDouble() / filesToDelete.size
|
||||
indicator.text = JavaCompilerBundle.message("progress.text.deleting.directory", file.absolutePath)
|
||||
FileUtil.delete(file)
|
||||
}
|
||||
onSuccess()
|
||||
indicator.text = JavaCompilerBundle.message("progress.text.synchronizing.output.directories")
|
||||
LocalFileSystem.getInstance().refreshIoFiles(filesToDelete, true, false, null)
|
||||
}
|
||||
}.queue()
|
||||
}
|
||||
|
||||
private fun collectStaleOutputs(project: Project): List<VirtualFile> {
|
||||
val projectOutput = CompilerProjectExtension.getInstance(project)?.compilerOutput
|
||||
if (projectOutput == null) return emptyList()
|
||||
|
||||
val outputsOnDisk = listOf(CompilerModuleExtension.PRODUCTION, CompilerModuleExtension.TEST)
|
||||
.flatMap { projectOutput.findChild(it)?.children?.asIterable() ?: emptyList() }
|
||||
|
||||
val currentOutputs = ModuleManager.getInstance(project).modules.flatMap {
|
||||
val extension = CompilerModuleExtension.getInstance(it)
|
||||
listOfNotNull(extension?.compilerOutputPath, extension?.compilerOutputPathForTests)
|
||||
}
|
||||
|
||||
return outputsOnDisk - currentOutputs
|
||||
}
|
||||
}
|
||||
@@ -120,16 +120,6 @@ button.text.checkin.handler.commit=&Commit
|
||||
button.text.checkin.handler.show.errors=&Show Errors
|
||||
checkbox.text.compile.affected.unloaded.modules=Compile affected &unloaded modules
|
||||
|
||||
notification.title.delete.old.output.directories=Clean up old output directories
|
||||
notification.content.delete.old.output.directories={0, choice, 1#An output directory which doesn''t|2#{0} output directories which don''''t} correspond to existing modules {0, choice, 1#is|2#are} found under {1}. You may delete {0, choice, 1#this directory|2#these directories} to save disk space.
|
||||
notification.action.text.cleanup=Clean Up...
|
||||
notification.action.text.do.not.ask=Do not ask again
|
||||
dialog.title.delete.old.outputs=Delete Old Output Directories
|
||||
progress.text.deleting.directory=Deleting directory {0}...
|
||||
progress.text.synchronizing.output.directories=Synchronizing output directories...
|
||||
dialog.text.delete.old.outputs=<html>The following {0, choice, 1#directory|2#directories} will be deleted. You will not be able to undo this operation!<br/>{1}</html>
|
||||
button.text.delete.old.outputs=Delete
|
||||
|
||||
#artifacts
|
||||
dialog.title.output.directory.for.artifact=Output Directory for Artifact
|
||||
chooser.description.select.output.directory.for.0.artifact=Select output directory for ''{0}'' artifact
|
||||
|
||||
@@ -525,8 +525,6 @@
|
||||
<moduleConfigurationEditorProvider implementation="com.intellij.openapi.roots.ui.configuration.DefaultModuleEditorsProvider"
|
||||
order="first"/>
|
||||
|
||||
<postStartupActivity implementation="com.intellij.compiler.impl.CleanStaleModuleOutputsActivity"/>
|
||||
|
||||
<postStartupActivity implementation="com.intellij.codeInsight.daemon.problems.pass.ProjectProblemFileSelectionListener$MyStartupActivity"/>
|
||||
|
||||
<bundledKeymap file="Visual Studio.xml"/>
|
||||
|
||||
Reference in New Issue
Block a user