From 987f838ac2c4c6e38953bd9cb6856b733cbdb253 Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Tue, 27 Dec 2016 18:05:55 +0100 Subject: [PATCH] DoNotSaveDefaultsTest (initial) --- .../testSrc/DoNotSaveDefaults.kt | 44 ++++++++++++++++++ .../testSrc/FileTreePrinter.kt | 45 +++++++++++++++++++ .../com/intellij/testFramework/FixtureRule.kt | 4 +- 3 files changed, 91 insertions(+), 2 deletions(-) create mode 100644 platform/configuration-store-impl/testSrc/DoNotSaveDefaults.kt create mode 100644 platform/configuration-store-impl/testSrc/FileTreePrinter.kt diff --git a/platform/configuration-store-impl/testSrc/DoNotSaveDefaults.kt b/platform/configuration-store-impl/testSrc/DoNotSaveDefaults.kt new file mode 100644 index 000000000000..a12c4e3c1b5a --- /dev/null +++ b/platform/configuration-store-impl/testSrc/DoNotSaveDefaults.kt @@ -0,0 +1,44 @@ +package com.intellij.configurationStore + +import com.intellij.openapi.application.ApplicationManager +import com.intellij.openapi.application.PathManager +import com.intellij.openapi.application.impl.ApplicationImpl +import com.intellij.openapi.components.stateStore +import com.intellij.testFramework.ProjectRule +import com.intellij.testFramework.runInEdtAndWait +import com.intellij.util.io.delete +import org.junit.ClassRule +import org.junit.Test +import java.nio.file.Paths + +class DoNotSaveDefaultsTest { + companion object { + @JvmField + @ClassRule + val projectRule = ProjectRule() + + init { + Paths.get(PathManager.getConfigPath()).delete() + } + } + + @Test + fun test() { + val app = ApplicationManager.getApplication() as ApplicationImpl + val directory = app.stateStore.stateStorageManager.expandMacros(APP_CONFIG) + val dirPath = Paths.get(directory) + try { + app.doNotSave(false) + runInEdtAndWait { + app.saveAll() + } + } + finally { + app.doNotSave(true) + } + + println(directory) + println(printDirectoryTree(dirPath.toFile())) + } +} + diff --git a/platform/configuration-store-impl/testSrc/FileTreePrinter.kt b/platform/configuration-store-impl/testSrc/FileTreePrinter.kt new file mode 100644 index 000000000000..5919805a9eeb --- /dev/null +++ b/platform/configuration-store-impl/testSrc/FileTreePrinter.kt @@ -0,0 +1,45 @@ +package com.intellij.configurationStore + +import java.io.File + +fun printDirectoryTree(folder: File): String { + if (!folder.isDirectory) { + throw IllegalArgumentException("folder is not a Directory") + } + val indent = 0 + val sb = StringBuilder() + printDirectoryTree(folder, indent, sb) + return sb.toString() +} + +private fun printDirectoryTree(folder: File, indent: Int, sb: StringBuilder) { + if (!folder.isDirectory) { + throw IllegalArgumentException("folder is not a Directory") + } + getIndentString(indent, sb) + sb.append("\u251c\u2500\u2500") + sb.append(folder.name) + sb.append("/") + sb.append("\n") + for (file in folder.listFiles()!!) { + if (file.isDirectory) { + printDirectoryTree(file, indent + 1, sb) + } + else { + printFile(file, indent + 1, sb) + } + } +} + +private fun printFile(file: File, indent: Int, sb: StringBuilder) { + getIndentString(indent, sb) + sb.append("\u251c\u2500\u2500") + sb.append(file.name) + sb.append("\n") +} + +private fun getIndentString(indent: Int, sb: StringBuilder) { + for (i in 0..indent - 1) { + sb.append(" ") + } +} \ No newline at end of file diff --git a/platform/testFramework/src/com/intellij/testFramework/FixtureRule.kt b/platform/testFramework/src/com/intellij/testFramework/FixtureRule.kt index 9e2be48a4ab1..3ce521a69634 100644 --- a/platform/testFramework/src/com/intellij/testFramework/FixtureRule.kt +++ b/platform/testFramework/src/com/intellij/testFramework/FixtureRule.kt @@ -64,7 +64,7 @@ open class ApplicationRule : ExternalResource() { /** * Project created on request, so, could be used as a bare (only application). */ -class ProjectRule() : ApplicationRule() { +class ProjectRule : ApplicationRule() { companion object { private var sharedProject: ProjectEx? = null private val projectOpened = AtomicBoolean() @@ -242,7 +242,7 @@ fun Project.use(task: (Project) -> Unit) { } } -class DisposeNonLightProjectsRule() : ExternalResource() { +class DisposeNonLightProjectsRule : ExternalResource() { override fun after() { val projectManager = if (ApplicationManager.getApplication().isDisposed) null else ProjectManager.getInstance() as ProjectManagerImpl projectManager?.openProjects?.forEachGuaranteed {