mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
DoNotSaveDefaultsTest (initial)
This commit is contained in:
@@ -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()))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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(" ")
|
||||
}
|
||||
}
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user