Cleanup 192 patchset files (KTI-315)
This commit is contained in:
@@ -1,30 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
package org.jetbrains.kotlin.idea
|
||||
|
||||
import com.intellij.openapi.application.ApplicationManager
|
||||
import com.intellij.openapi.components.BaseComponent
|
||||
import org.jetbrains.kotlin.idea.ThreadTrackerPatcherForTeamCityTesting.patchThreadTracker
|
||||
import org.jetbrains.kotlin.idea.debugger.filter.addKotlinStdlibDebugFilterIfNeeded
|
||||
import org.jetbrains.kotlin.idea.util.application.isUnitTestMode
|
||||
|
||||
// FIX ME WHEN BUNCH 192 REMOVED
|
||||
class JvmPluginStartupComponent : BaseComponent {
|
||||
override fun getComponentName(): String = JvmPluginStartupComponent::class.java.name
|
||||
|
||||
override fun initComponent() {
|
||||
if (isUnitTestMode()) {
|
||||
patchThreadTracker()
|
||||
}
|
||||
addKotlinStdlibDebugFilterIfNeeded()
|
||||
}
|
||||
|
||||
override fun disposeComponent() {}
|
||||
|
||||
companion object {
|
||||
fun getInstance(): JvmPluginStartupComponent =
|
||||
ApplicationManager.getApplication().getComponent(JvmPluginStartupComponent::class.java)
|
||||
}
|
||||
}
|
||||
@@ -1,99 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2015 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.compiler
|
||||
|
||||
import com.intellij.diagnostic.PluginException
|
||||
import com.intellij.ide.plugins.PluginManagerCore
|
||||
import com.intellij.openapi.application.ApplicationManager
|
||||
import com.intellij.openapi.compiler.CompilationStatusListener
|
||||
import com.intellij.openapi.compiler.CompileContext
|
||||
import com.intellij.openapi.compiler.CompilerManager
|
||||
import com.intellij.openapi.compiler.CompilerMessageCategory
|
||||
import com.intellij.openapi.components.ProjectComponent
|
||||
import com.intellij.openapi.diagnostic.Logger
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.util.io.FileUtilRt
|
||||
import com.intellij.openapi.vfs.LocalFileSystem
|
||||
import com.intellij.util.containers.ContainerUtil
|
||||
import org.jetbrains.kotlin.config.CompilerRunnerConstants
|
||||
import org.jetbrains.kotlin.idea.KotlinFileType
|
||||
import org.jetbrains.kotlin.js.JavaScript
|
||||
import java.io.PrintStream
|
||||
import java.io.PrintWriter
|
||||
|
||||
// FIX ME WHEN BUNCH 192 REMOVED
|
||||
class KotlinCompilerManager(project: Project, manager: CompilerManager) : ProjectComponent {
|
||||
// Extending PluginException ensures that Exception Analyzer recognizes this as a Kotlin exception
|
||||
private class KotlinCompilerException(private val text: String) :
|
||||
PluginException("", PluginManagerCore.getPluginByClassName(KotlinCompilerManager::class.java.name)) {
|
||||
override fun printStackTrace(s: PrintWriter) {
|
||||
s.print(text)
|
||||
}
|
||||
|
||||
override fun printStackTrace(s: PrintStream) {
|
||||
s.print(text)
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
override fun fillInStackTrace(): Throwable {
|
||||
return this
|
||||
}
|
||||
|
||||
override fun getStackTrace(): Array<StackTraceElement> {
|
||||
LOG.error("Somebody called getStackTrace() on KotlinCompilerException")
|
||||
// Return some stack trace that originates in Kotlin
|
||||
return UnsupportedOperationException().stackTrace
|
||||
}
|
||||
|
||||
override val message: String
|
||||
get() = "<Exception from standalone Kotlin compiler>"
|
||||
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val LOG = Logger.getInstance(KotlinCompilerManager::class.java)
|
||||
|
||||
// Comes from external make
|
||||
private const val PREFIX_WITH_COMPILER_NAME =
|
||||
CompilerRunnerConstants.KOTLIN_COMPILER_NAME + ": " + CompilerRunnerConstants.INTERNAL_ERROR_PREFIX
|
||||
private val FILE_EXTS_WHICH_NEEDS_REFRESH = ContainerUtil.immutableSet(JavaScript.DOT_EXTENSION, ".map")
|
||||
}
|
||||
|
||||
init {
|
||||
manager.addCompilableFileType(KotlinFileType.INSTANCE)
|
||||
manager.addCompilationStatusListener(object : CompilationStatusListener {
|
||||
override fun compilationFinished(aborted: Boolean, errors: Int, warnings: Int, compileContext: CompileContext) {
|
||||
for (error in compileContext.getMessages(CompilerMessageCategory.ERROR)) {
|
||||
val message = error.message
|
||||
if (message.startsWith(CompilerRunnerConstants.INTERNAL_ERROR_PREFIX) || message.startsWith(PREFIX_WITH_COMPILER_NAME)) {
|
||||
LOG.error(KotlinCompilerException(message))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun fileGenerated(outputRoot: String, relativePath: String) {
|
||||
if (ApplicationManager.getApplication().isUnitTestMode) return
|
||||
val ext = FileUtilRt.getExtension(relativePath).toLowerCase()
|
||||
if (FILE_EXTS_WHICH_NEEDS_REFRESH.contains(ext)) {
|
||||
val outFile = "$outputRoot/$relativePath"
|
||||
val virtualFile = LocalFileSystem.getInstance().findFileByPath(outFile)
|
||||
?: error("Virtual file not found for generated file path: $outFile")
|
||||
virtualFile.refresh( /*async =*/false, /*recursive =*/false)
|
||||
}
|
||||
}
|
||||
}, project)
|
||||
}
|
||||
}
|
||||
-39
@@ -1,39 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.idea.compiler.configuration
|
||||
|
||||
import com.intellij.compiler.server.BuildProcessParametersProvider
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.util.registry.Registry
|
||||
import org.jetbrains.kotlin.config.IncrementalCompilation
|
||||
import org.jetbrains.kotlin.idea.PluginStartupComponent
|
||||
|
||||
class KotlinBuildProcessParametersProvider(private val project: Project) : BuildProcessParametersProvider() {
|
||||
override fun getVMArguments(): MutableList<String> {
|
||||
val compilerWorkspaceSettings = KotlinCompilerWorkspaceSettings.getInstance(project)
|
||||
|
||||
val res = arrayListOf<String>()
|
||||
if (compilerWorkspaceSettings.preciseIncrementalEnabled) {
|
||||
res.add("-D" + IncrementalCompilation.INCREMENTAL_COMPILATION_JVM_PROPERTY + "=true")
|
||||
}
|
||||
if (compilerWorkspaceSettings.incrementalCompilationForJsEnabled) {
|
||||
res.add("-D" + IncrementalCompilation.INCREMENTAL_COMPILATION_JS_PROPERTY + "=true")
|
||||
}
|
||||
if (compilerWorkspaceSettings.enableDaemon) {
|
||||
res.add("-Dkotlin.daemon.enabled")
|
||||
}
|
||||
if (Registry.`is`("kotlin.jps.instrument.bytecode", false)) {
|
||||
res.add("-Dkotlin.jps.instrument.bytecode=true")
|
||||
}
|
||||
PluginStartupComponent.getInstance().aliveFlagPath.let {
|
||||
if (!it.isBlank()) {
|
||||
// TODO: consider taking the property name from compiler/daemon/common (check whether dependency will be not too heavy)
|
||||
res.add("-Dkotlin.daemon.client.alive.path=\"$it\"")
|
||||
}
|
||||
}
|
||||
return res
|
||||
}
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.idea.configuration
|
||||
|
||||
import com.intellij.openapi.application.ModalityState
|
||||
import com.intellij.openapi.application.ReadAction.nonBlocking
|
||||
import com.intellij.openapi.module.Module
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.util.concurrency.AppExecutorUtil
|
||||
import org.jetbrains.kotlin.idea.configuration.ui.notifications.ConfigureKotlinNotification
|
||||
import java.util.concurrent.Callable
|
||||
|
||||
fun notify(manager: ConfigureKotlinNotificationManager, project: Project, excludeModules: List<Module>) {
|
||||
nonBlocking(Callable {
|
||||
ConfigureKotlinNotification.getNotificationState(project, excludeModules)
|
||||
})
|
||||
.expireWith(project)
|
||||
.finishOnUiThread(ModalityState.any()) { notificationState ->
|
||||
notificationState?.let {
|
||||
manager.notify(project, ConfigureKotlinNotification(project, excludeModules, it))
|
||||
}
|
||||
}
|
||||
.submit(AppExecutorUtil.getAppExecutorService())
|
||||
}
|
||||
-94
@@ -1,94 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2015 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.ui
|
||||
|
||||
import com.intellij.notification.NotificationDisplayType
|
||||
import com.intellij.notification.NotificationsConfiguration
|
||||
import com.intellij.openapi.application.ApplicationManager
|
||||
import com.intellij.openapi.application.runReadAction
|
||||
import com.intellij.openapi.components.ProjectComponent
|
||||
import com.intellij.openapi.externalSystem.service.project.manage.ProjectDataImportListener
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.startup.StartupManager
|
||||
import org.jetbrains.kotlin.idea.configuration.getModulesWithKotlinFiles
|
||||
import org.jetbrains.kotlin.idea.configuration.notifyOutdatedBundledCompilerIfNecessary
|
||||
import org.jetbrains.kotlin.idea.configuration.ui.notifications.notifyKotlinStyleUpdateIfNeeded
|
||||
import org.jetbrains.kotlin.idea.project.getAndCacheLanguageLevelByDependencies
|
||||
import org.jetbrains.kotlin.idea.util.runReadActionInSmartMode
|
||||
import java.util.concurrent.atomic.AtomicInteger
|
||||
|
||||
class KotlinConfigurationCheckerComponent(val project: Project) : ProjectComponent {
|
||||
private val syncDepth = AtomicInteger()
|
||||
|
||||
init {
|
||||
NotificationsConfiguration.getNotificationsConfiguration()
|
||||
.register(CONFIGURE_NOTIFICATION_GROUP_ID, NotificationDisplayType.STICKY_BALLOON, true)
|
||||
|
||||
val connection = project.messageBus.connect(project)
|
||||
connection.subscribe(ProjectDataImportListener.TOPIC, ProjectDataImportListener {
|
||||
notifyOutdatedBundledCompilerIfNecessary(project)
|
||||
})
|
||||
|
||||
notifyKotlinStyleUpdateIfNeeded(project)
|
||||
}
|
||||
|
||||
override fun projectOpened() {
|
||||
super.projectOpened()
|
||||
|
||||
StartupManager.getInstance(project).registerPostStartupActivity {
|
||||
performProjectPostOpenActions()
|
||||
}
|
||||
}
|
||||
|
||||
fun performProjectPostOpenActions() {
|
||||
ApplicationManager.getApplication().executeOnPooledThread {
|
||||
val modulesWithKotlinFiles = project.runReadActionInSmartMode {
|
||||
getModulesWithKotlinFiles(project)
|
||||
}
|
||||
for (module in modulesWithKotlinFiles) {
|
||||
runReadAction {
|
||||
if (project.isDisposed) return@runReadAction
|
||||
module.getAndCacheLanguageLevelByDependencies()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val isSyncing: Boolean get() = syncDepth.get() > 0
|
||||
|
||||
fun syncStarted() {
|
||||
syncDepth.incrementAndGet()
|
||||
}
|
||||
|
||||
fun syncDone() {
|
||||
syncDepth.decrementAndGet()
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val CONFIGURE_NOTIFICATION_GROUP_ID = "Configure Kotlin in Project"
|
||||
|
||||
fun getInstance(project: Project): KotlinConfigurationCheckerComponent =
|
||||
project.getComponent(KotlinConfigurationCheckerComponent::class.java)
|
||||
?: error("Can't find ${KotlinConfigurationCheckerComponent::class} component")
|
||||
|
||||
fun getInstanceIfNotDisposed(project: Project): KotlinConfigurationCheckerComponent? {
|
||||
return runReadAction {
|
||||
if (!project.isDisposed) getInstance(project) else null
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
-19
@@ -1,19 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2015 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.ui
|
||||
|
||||
typealias KotlinConfigurationCheckerService = KotlinConfigurationCheckerComponent
|
||||
-190
@@ -1,190 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.idea.internal.makeBackup
|
||||
|
||||
import com.intellij.compiler.server.BuildManager
|
||||
import com.intellij.history.core.RevisionsCollector
|
||||
import com.intellij.history.integration.LocalHistoryImpl
|
||||
import com.intellij.history.integration.patches.PatchCreator
|
||||
import com.intellij.ide.actions.ShowFilePathAction
|
||||
import com.intellij.openapi.actionSystem.AnAction
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent
|
||||
import com.intellij.openapi.application.PathManager
|
||||
import com.intellij.openapi.progress.ProgressIndicator
|
||||
import com.intellij.openapi.progress.ProgressManager
|
||||
import com.intellij.openapi.progress.Task
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.util.io.FileUtil
|
||||
import com.intellij.openapi.vcs.changes.Change
|
||||
import com.intellij.util.WaitForProgressToShow
|
||||
import com.intellij.util.io.ZipUtil
|
||||
import org.jetbrains.kotlin.idea.KotlinJvmBundle
|
||||
import org.jetbrains.kotlin.idea.util.application.runReadAction
|
||||
import java.io.File
|
||||
import java.io.FileOutputStream
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.*
|
||||
import java.util.zip.ZipOutputStream
|
||||
|
||||
class CreateIncrementalCompilationBackup : AnAction(KotlinJvmBundle.message("create.backup.for.debugging.kotlin.incremental.compilation")) {
|
||||
companion object {
|
||||
const val BACKUP_DIR_NAME = ".backup"
|
||||
const val PATCHES_TO_CREATE = 5
|
||||
|
||||
const val PATCHES_FRACTION = .25
|
||||
const val LOGS_FRACTION = .05
|
||||
const val PROJECT_SYSTEM_FRACTION = .05
|
||||
const val ZIP_FRACTION = 1.0 - PATCHES_FRACTION - LOGS_FRACTION - PROJECT_SYSTEM_FRACTION
|
||||
}
|
||||
|
||||
override fun actionPerformed(e: AnActionEvent) {
|
||||
val project = e.project!!
|
||||
val projectBaseDir = File(project.baseDir!!.path)
|
||||
val backupDir = File(FileUtil.createTempDirectory("makeBackup", null), BACKUP_DIR_NAME)
|
||||
|
||||
ProgressManager.getInstance().run(
|
||||
object : Task.Backgroundable(
|
||||
project,
|
||||
KotlinJvmBundle.message("creating.backup.for.debugging.kotlin.incremental.compilation"),
|
||||
true
|
||||
) {
|
||||
override fun run(indicator: ProgressIndicator) {
|
||||
createPatches(backupDir, project, indicator)
|
||||
copyLogs(backupDir, indicator)
|
||||
copyProjectSystemDir(backupDir, project, indicator)
|
||||
|
||||
zipProjectDir(backupDir, project, projectBaseDir, indicator)
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
private fun createPatches(backupDir: File, project: Project, indicator: ProgressIndicator) {
|
||||
runReadAction {
|
||||
val localHistoryImpl = LocalHistoryImpl.getInstanceImpl()!!
|
||||
val gateway = localHistoryImpl.gateway!!
|
||||
val localHistoryFacade = localHistoryImpl.facade
|
||||
|
||||
val revisionsCollector = RevisionsCollector(
|
||||
localHistoryFacade,
|
||||
gateway.createTransientRootEntry(),
|
||||
project.baseDir!!.path,
|
||||
project.locationHash,
|
||||
null
|
||||
)
|
||||
|
||||
var patchesCreated = 0
|
||||
|
||||
val patchesDir = File(backupDir, "patches")
|
||||
patchesDir.mkdirs()
|
||||
|
||||
val revisions = revisionsCollector.result!!
|
||||
for (rev in revisions) {
|
||||
val label = rev.label
|
||||
if (label != null && label.startsWith(HISTORY_LABEL_PREFIX)) {
|
||||
val patchFile = File(patchesDir, label.removePrefix(HISTORY_LABEL_PREFIX) + ".patch")
|
||||
|
||||
indicator.text = KotlinJvmBundle.message("creating.patch.0", patchFile)
|
||||
indicator.fraction = PATCHES_FRACTION * patchesCreated / PATCHES_TO_CREATE
|
||||
|
||||
val differences = revisions[0].getDifferencesWith(rev)!!
|
||||
val changes = differences.map { d ->
|
||||
Change(d.getLeftContentRevision(gateway), d.getRightContentRevision(gateway))
|
||||
}
|
||||
|
||||
PatchCreator.create(project, changes, patchFile.path, false, null)
|
||||
|
||||
if (++patchesCreated >= PATCHES_TO_CREATE) {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun copyLogs(backupDir: File, indicator: ProgressIndicator) {
|
||||
indicator.text = KotlinJvmBundle.message("copying.logs")
|
||||
indicator.fraction = PATCHES_FRACTION
|
||||
|
||||
val logsDir = File(backupDir, "logs")
|
||||
FileUtil.copyDir(File(PathManager.getLogPath()), logsDir)
|
||||
|
||||
indicator.fraction = PATCHES_FRACTION + LOGS_FRACTION
|
||||
}
|
||||
|
||||
private fun copyProjectSystemDir(backupDir: File, project: Project, indicator: ProgressIndicator) {
|
||||
indicator.text = KotlinJvmBundle.message("copying.project.s.system.dir")
|
||||
indicator.fraction = PATCHES_FRACTION
|
||||
|
||||
val projectSystemDir = File(backupDir, "project-system")
|
||||
FileUtil.copyDir(BuildManager.getInstance().getProjectSystemDirectory(project)!!, projectSystemDir)
|
||||
|
||||
indicator.fraction = PATCHES_FRACTION + LOGS_FRACTION + PROJECT_SYSTEM_FRACTION
|
||||
}
|
||||
|
||||
private fun zipProjectDir(backupDir: File, project: Project, projectDir: File, indicator: ProgressIndicator) {
|
||||
// files and relative paths
|
||||
|
||||
val files = ArrayList<Pair<File, String>>() // files and relative paths
|
||||
var totalBytes = 0L
|
||||
|
||||
for (dir in listOf(projectDir, backupDir.parentFile!!)) {
|
||||
FileUtil.processFilesRecursively(
|
||||
dir,
|
||||
/*processor*/ {
|
||||
if (it!!.isFile
|
||||
&& !it.name.endsWith(".hprof")
|
||||
&& !(it.name.startsWith("make_backup_") && it.name.endsWith(".zip"))
|
||||
) {
|
||||
|
||||
indicator.text = KotlinJvmBundle.message("scanning.project.dir.0", it)
|
||||
|
||||
files.add(Pair(it, FileUtil.getRelativePath(dir, it)!!))
|
||||
totalBytes += it.length()
|
||||
}
|
||||
true
|
||||
},
|
||||
/*directoryFilter*/ {
|
||||
val name = it!!.name
|
||||
name != ".git" && name != "out"
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
val backupFile = File(projectDir, "make_backup_" + SimpleDateFormat("yyyy-MM-dd_HH-mm-ss").format(Date()) + ".zip")
|
||||
|
||||
|
||||
val zos = ZipOutputStream(FileOutputStream(backupFile))
|
||||
|
||||
var processedBytes = 0L
|
||||
|
||||
zos.use {
|
||||
for ((file, relativePath) in files) {
|
||||
indicator.text = KotlinJvmBundle.message("adding.file.to.backup.0", relativePath)
|
||||
indicator.fraction = PATCHES_FRACTION + LOGS_FRACTION + processedBytes.toDouble() / totalBytes * ZIP_FRACTION
|
||||
|
||||
ZipUtil.addFileToZip(zos, file, relativePath, null, null)
|
||||
|
||||
processedBytes += file.length()
|
||||
}
|
||||
}
|
||||
|
||||
FileUtil.delete(backupDir)
|
||||
|
||||
WaitForProgressToShow.runOrInvokeLaterAboveProgress(
|
||||
{
|
||||
ShowFilePathAction.showDialog(
|
||||
project,
|
||||
KotlinJvmBundle.message("successfully.created.backup.0", backupFile.absolutePath),
|
||||
KotlinJvmBundle.message("created.backup"),
|
||||
backupFile,
|
||||
null
|
||||
)
|
||||
}, null, project
|
||||
)
|
||||
}
|
||||
}
|
||||
-64
@@ -1,64 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2017 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.scratch
|
||||
|
||||
import com.intellij.codeInsight.daemon.DaemonCodeAnalyzer
|
||||
import com.intellij.openapi.components.ProjectComponent
|
||||
import com.intellij.openapi.diagnostic.Logger
|
||||
import com.intellij.openapi.module.ModuleManager
|
||||
import com.intellij.openapi.project.Project
|
||||
import org.jetbrains.kotlin.idea.core.script.ScriptDependenciesModificationTracker
|
||||
import org.jetbrains.kotlin.idea.core.script.scriptRelatedModuleName
|
||||
import org.jetbrains.kotlin.idea.util.projectStructure.getModule
|
||||
import org.jetbrains.kotlin.parsing.KotlinParserDefinition.Companion.STD_SCRIPT_SUFFIX
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
|
||||
// FIX ME WHEN BUNCH 192 REMOVED
|
||||
class ScratchFileModuleInfoProvider(val project: Project) : ProjectComponent {
|
||||
private val LOG = Logger.getInstance(this.javaClass)
|
||||
|
||||
override fun projectOpened() {
|
||||
project.messageBus.connect().subscribe(ScratchFileListener.TOPIC, object : ScratchFileListener {
|
||||
override fun fileCreated(scratchFile: ScratchFile) {
|
||||
val ktFile = scratchFile.getPsiFile() as? KtFile ?: return
|
||||
val file = ktFile.virtualFile ?: return
|
||||
|
||||
if (file.extension != STD_SCRIPT_SUFFIX) {
|
||||
LOG.error("Kotlin Scratch file should have .kts extension. Cannot add scratch panel for ${file.path}")
|
||||
return
|
||||
}
|
||||
|
||||
scratchFile.addModuleListener { psiFile, module ->
|
||||
psiFile.virtualFile.scriptRelatedModuleName = module?.name
|
||||
|
||||
// Drop caches for old module
|
||||
ScriptDependenciesModificationTracker.getInstance(project).incModificationCount()
|
||||
// Force re-highlighting
|
||||
DaemonCodeAnalyzer.getInstance(project).restart(psiFile)
|
||||
}
|
||||
|
||||
if (file.isKotlinWorksheet) {
|
||||
val module = file.getModule(project) ?: return
|
||||
scratchFile.setModule(module)
|
||||
} else {
|
||||
val module = file.scriptRelatedModuleName?.let { ModuleManager.getInstance(project).findModuleByName(it) } ?: return
|
||||
scratchFile.setModule(module)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -1,110 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2017 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.scratch.actions
|
||||
|
||||
import com.intellij.icons.AllIcons
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent
|
||||
import com.intellij.openapi.keymap.KeymapManager
|
||||
import com.intellij.openapi.keymap.KeymapUtil
|
||||
import com.intellij.openapi.project.DumbService
|
||||
import com.intellij.task.ProjectTaskManager
|
||||
import org.jetbrains.kotlin.idea.KotlinJvmBundle
|
||||
import org.jetbrains.kotlin.idea.scratch.*
|
||||
import org.jetbrains.kotlin.idea.scratch.printDebugMessage
|
||||
import org.jetbrains.kotlin.idea.scratch.LOG as log
|
||||
|
||||
class RunScratchAction : ScratchAction(
|
||||
KotlinJvmBundle.message("scratch.run.button"),
|
||||
AllIcons.Actions.Execute
|
||||
) {
|
||||
|
||||
init {
|
||||
KeymapManager.getInstance().activeKeymap.getShortcuts("Kotlin.RunScratch").firstOrNull()?.let {
|
||||
templatePresentation.text += " (${KeymapUtil.getShortcutText(it)})"
|
||||
}
|
||||
}
|
||||
|
||||
override fun actionPerformed(e: AnActionEvent) {
|
||||
val project = e.project ?: return
|
||||
val scratchFile = getScratchFileFromSelectedEditor(project) ?: return
|
||||
|
||||
doAction(scratchFile, false)
|
||||
}
|
||||
|
||||
companion object {
|
||||
fun doAction(scratchFile: ScratchFile, isAutoRun: Boolean) {
|
||||
val isRepl = scratchFile.options.isRepl
|
||||
val executor = (if (isRepl) scratchFile.replScratchExecutor else scratchFile.compilingScratchExecutor) ?: return
|
||||
|
||||
log.printDebugMessage("Run Action: isRepl = $isRepl")
|
||||
|
||||
fun executeScratch() {
|
||||
try {
|
||||
if (isAutoRun && executor is SequentialScratchExecutor) {
|
||||
executor.executeNew()
|
||||
} else {
|
||||
executor.execute()
|
||||
}
|
||||
} catch (ex: Throwable) {
|
||||
executor.errorOccurs(KotlinJvmBundle.message("exception.occurs.during.run.scratch.action"), ex, true)
|
||||
}
|
||||
}
|
||||
|
||||
val isMakeBeforeRun = scratchFile.options.isMakeBeforeRun
|
||||
log.printDebugMessage("Run Action: isMakeBeforeRun = $isMakeBeforeRun")
|
||||
|
||||
val module = scratchFile.module
|
||||
log.printDebugMessage("Run Action: module = ${module?.name}")
|
||||
|
||||
if (!isAutoRun && module != null && isMakeBeforeRun) {
|
||||
val project = scratchFile.project
|
||||
ProjectTaskManager.getInstance(project).build(arrayOf(module)) { result ->
|
||||
if (result.isAborted || result.errors > 0) {
|
||||
executor.errorOccurs(KotlinJvmBundle.message("there.were.compilation.errors.in.module.0", module.name))
|
||||
}
|
||||
|
||||
if (DumbService.isDumb(project)) {
|
||||
DumbService.getInstance(project).smartInvokeLater {
|
||||
executeScratch()
|
||||
}
|
||||
} else {
|
||||
executeScratch()
|
||||
}
|
||||
}
|
||||
} else {
|
||||
executeScratch()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun update(e: AnActionEvent) {
|
||||
super.update(e)
|
||||
|
||||
e.presentation.isEnabled = !ScratchCompilationSupport.isAnyInProgress()
|
||||
|
||||
if (e.presentation.isEnabled) {
|
||||
e.presentation.text = templatePresentation.text
|
||||
} else {
|
||||
e.presentation.text = KotlinJvmBundle.message("other.scratch.file.execution.is.in.progress")
|
||||
}
|
||||
|
||||
val project = e.project ?: return
|
||||
val scratchFile = getScratchFileFromSelectedEditor(project) ?: return
|
||||
|
||||
e.presentation.isVisible = !ScratchCompilationSupport.isInProgress(scratchFile)
|
||||
}
|
||||
}
|
||||
@@ -1,139 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.idea.vcs
|
||||
|
||||
import com.intellij.BundleBase.replaceMnemonicAmpersand
|
||||
import com.intellij.CommonBundle
|
||||
import com.intellij.ide.plugins.PluginManager
|
||||
import com.intellij.openapi.extensions.PluginId
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.ui.Messages
|
||||
import com.intellij.openapi.ui.Messages.NO
|
||||
import com.intellij.openapi.ui.Messages.YES
|
||||
import com.intellij.openapi.util.Key
|
||||
import com.intellij.openapi.vcs.CheckinProjectPanel
|
||||
import com.intellij.openapi.vcs.changes.CommitContext
|
||||
import com.intellij.openapi.vcs.changes.CommitExecutor
|
||||
import com.intellij.openapi.vcs.checkin.CheckinHandler
|
||||
import com.intellij.openapi.vcs.checkin.CheckinHandlerFactory
|
||||
import com.intellij.openapi.vcs.ui.RefreshableOnComponent
|
||||
import com.intellij.openapi.vfs.VirtualFile
|
||||
import com.intellij.ui.NonFocusableCheckBox
|
||||
import com.intellij.util.PairConsumer
|
||||
import org.jetbrains.kotlin.idea.KotlinJvmBundle
|
||||
import org.jetbrains.kotlin.psi.NotNullableUserDataProperty
|
||||
import java.awt.GridLayout
|
||||
import java.io.File
|
||||
import javax.swing.JComponent
|
||||
import javax.swing.JPanel
|
||||
|
||||
private val BUNCH_PLUGIN_ID = PluginId.getId("org.jetbrains.bunch.tool.idea.plugin")
|
||||
|
||||
private var Project.bunchFileCheckEnabled: Boolean
|
||||
by NotNullableUserDataProperty(Key.create("IS_BUNCH_FILE_CHECK_ENABLED_KOTLIN"), !PluginManager.isPluginInstalled(BUNCH_PLUGIN_ID))
|
||||
|
||||
class BunchFileCheckInHandlerFactory : CheckinHandlerFactory() {
|
||||
override fun createHandler(panel: CheckinProjectPanel, commitContext: CommitContext): CheckinHandler {
|
||||
return BunchCheckInHandler(panel)
|
||||
}
|
||||
|
||||
class BunchCheckInHandler(private val checkInProjectPanel: CheckinProjectPanel) : CheckinHandler() {
|
||||
private val project get() = checkInProjectPanel.project
|
||||
|
||||
override fun getBeforeCheckinConfigurationPanel(): RefreshableOnComponent? {
|
||||
if (PluginManager.isPluginInstalled(BUNCH_PLUGIN_ID)) return null
|
||||
BunchFileUtils.bunchFile(project) ?: return null
|
||||
|
||||
val bunchFilesCheckBox = NonFocusableCheckBox(replaceMnemonicAmpersand(KotlinJvmBundle.message("check.bunch.files")))
|
||||
return object : RefreshableOnComponent {
|
||||
override fun getComponent(): JComponent {
|
||||
val panel = JPanel(GridLayout(1, 0))
|
||||
panel.add(bunchFilesCheckBox)
|
||||
return panel
|
||||
}
|
||||
|
||||
override fun refresh() {}
|
||||
override fun saveState() {
|
||||
project.bunchFileCheckEnabled = bunchFilesCheckBox.isSelected
|
||||
}
|
||||
|
||||
override fun restoreState() {
|
||||
bunchFilesCheckBox.isSelected = project.bunchFileCheckEnabled
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun beforeCheckin(
|
||||
executor: CommitExecutor?,
|
||||
additionalDataConsumer: PairConsumer<Any, Any>?
|
||||
): ReturnResult {
|
||||
if (!project.bunchFileCheckEnabled) return ReturnResult.COMMIT
|
||||
|
||||
val extensions = BunchFileUtils.bunchExtension(project)?.toSet() ?: return ReturnResult.COMMIT
|
||||
|
||||
val forgottenFiles = HashSet<File>()
|
||||
val commitFiles = checkInProjectPanel.files.filter { it.isFile }.toSet()
|
||||
for (file in commitFiles) {
|
||||
if (file.extension in extensions) continue
|
||||
|
||||
val parent = file.parent ?: continue
|
||||
val name = file.name
|
||||
for (extension in extensions) {
|
||||
val bunchFile = File(parent, "$name.$extension")
|
||||
if (bunchFile !in commitFiles && bunchFile.exists()) {
|
||||
forgottenFiles.add(bunchFile)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (forgottenFiles.isEmpty()) return ReturnResult.COMMIT
|
||||
|
||||
val projectBaseFile = File(project.basePath)
|
||||
var filePaths = forgottenFiles.map { it.relativeTo(projectBaseFile).path }.sorted()
|
||||
if (filePaths.size > 15) {
|
||||
filePaths = filePaths.take(15) + "..."
|
||||
}
|
||||
|
||||
when (Messages.showYesNoCancelDialog(
|
||||
project,
|
||||
KotlinJvmBundle.message(
|
||||
"several.bunch.files.haven.t.been.updated.0.do.you.want.to.review.them.before.commit",
|
||||
filePaths.joinToString("\n")
|
||||
),
|
||||
KotlinJvmBundle.message("button.text.forgotten.bunch.files"),
|
||||
KotlinJvmBundle.message("button.text.review"),
|
||||
KotlinJvmBundle.message("button.text.commit"),
|
||||
CommonBundle.getCancelButtonText(),
|
||||
Messages.getWarningIcon()
|
||||
)) {
|
||||
YES -> {
|
||||
return ReturnResult.CLOSE_WINDOW
|
||||
}
|
||||
NO -> return ReturnResult.COMMIT
|
||||
}
|
||||
|
||||
return ReturnResult.CANCEL
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
object BunchFileUtils {
|
||||
fun bunchFile(project: Project): VirtualFile? {
|
||||
val baseDir = project.baseDir ?: return null
|
||||
return baseDir.findChild(".bunch")
|
||||
}
|
||||
|
||||
fun bunchExtension(project: Project): List<String>? {
|
||||
val bunchFile: VirtualFile = bunchFile(project) ?: return null
|
||||
val file = File(bunchFile.path)
|
||||
if (!file.exists()) return null
|
||||
|
||||
val lines = file.readLines().map { it.trim() }.filter { it.isNotEmpty() }
|
||||
if (lines.size <= 1) return null
|
||||
|
||||
return lines.drop(1).map { it.split('_').first() }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user