do not save default colors.scheme.xml

This commit is contained in:
Vladimir Krivosheev
2016-12-28 15:31:22 +01:00
parent 8af5aa96c2
commit 4378f00473
6 changed files with 35 additions and 12 deletions
@@ -2,15 +2,22 @@ package com.intellij.configurationStore
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.application.PathManager
import com.intellij.openapi.application.ex.PathManagerEx
import com.intellij.openapi.application.impl.ApplicationImpl
import com.intellij.openapi.components.stateStore
import com.intellij.openapi.util.io.FileUtil
import com.intellij.testFramework.ProjectRule
import com.intellij.testFramework.assertions.Assertions.assertThat
import com.intellij.testFramework.runInEdtAndWait
import com.intellij.util.io.delete
import org.junit.ClassRule
import org.junit.Test
import java.nio.file.Path
import java.nio.file.Paths
private val testData: Path
get() = Paths.get(PathManagerEx.getHomePath(DoNotSaveDefaultsTest::class.java), FileUtil.toSystemDependentName("platform/configuration-store-impl/testSrc"))
class DoNotSaveDefaultsTest {
companion object {
@JvmField
@@ -41,7 +48,9 @@ class DoNotSaveDefaultsTest {
}
println(directory)
println(printDirectoryTree(dirPath))
val directoryTree = printDirectoryTree(dirPath, setOf("path.macros.xml"))
println(directoryTree)
assertThat(directoryTree).toMatchSnapshot(testData.resolve("DoNotSaveDefaults.snap.txt"))
}
}
@@ -5,21 +5,27 @@ import com.intellij.util.io.isDirectory
import java.nio.file.Path
import java.util.*
fun printDirectoryTree(dir: Path): String {
fun printDirectoryTree(dir: Path, excluded: Set<String> = emptySet()): String {
val sb = StringBuilder()
printDirectoryTree(dir, 0, sb)
printDirectoryTree(dir, 0, sb, excluded)
return sb.toString()
}
private fun printDirectoryTree(dir: Path, indent: Int, sb: StringBuilder) {
private fun printDirectoryTree(dir: Path, indent: Int, sb: StringBuilder, excluded: Set<String>) {
val fileList = sortedFileList(dir) ?: return
getIndentString(indent, sb)
sb.append("\u251c\u2500\u2500")
sb.append(dir.fileName.toString())
sb.append("/")
sb.append("\n")
for (file in sortedFileList(dir)) {
for (file in fileList) {
if (excluded.contains(file.fileName.toString())) {
continue
}
if (file.isDirectory()) {
printDirectoryTree(file, indent + 1, sb)
printDirectoryTree(file, indent + 1, sb, excluded)
}
else {
printFile(file, indent + 1, sb)
@@ -27,13 +33,13 @@ private fun printDirectoryTree(dir: Path, indent: Int, sb: StringBuilder) {
}
}
private fun sortedFileList(dir: Path): List<Path> {
private fun sortedFileList(dir: Path): List<Path>? {
return dir.directoryStreamIfExists {
val list = ArrayList<Path>()
it.mapTo(list) { it }
list.sort()
list
} ?: emptyList()
}
}
private fun printFile(file: Path, indent: Int, sb: StringBuilder) {
@@ -353,9 +353,10 @@ public class EditorColorsManagerImpl extends EditorColorsManager implements Pers
@Nullable
@Override
public State getState() {
if (mySchemeManager.getCurrentScheme() != null) {
String name = mySchemeManager.getCurrentScheme().getName();
myState.colorScheme = "Default".equals(name) ? null : name;
String currentSchemeName = mySchemeManager.getCurrentSchemeName();
if (currentSchemeName != null) {
myState.colorScheme = ("Default".equals(currentSchemeName) || (SchemeManager.EDITABLE_COPY_PREFIX + "Default").equals(
currentSchemeName)) ? null : currentSchemeName;
}
return myState;
}
@@ -68,4 +68,10 @@ class StringAssertEx(actual: String?) : AbstractCharSequenceAssert<StringAssertE
compareFileContent(actual, expected)
}
fun toMatchSnapshot(snapshotFile: Path) {
isNotNull
compareFileContent(actual, snapshotFile)
}
}
@@ -183,7 +183,7 @@ public class PathManagerEx {
/**
* @return path to 'community' project home if {@code testClass} is located in the community project and path to 'ultimate' project otherwise
*/
public static String getHomePath(Class<? extends TestCase> testClass) {
public static String getHomePath(Class<?> testClass) {
TestDataLookupStrategy strategy = isLocatedInCommunity() ? TestDataLookupStrategy.COMMUNITY : determineLookupStrategy(testClass);
return strategy == TestDataLookupStrategy.COMMUNITY_FROM_ULTIMATE ? getCommunityHomePath() : PathManager.getHomePath();
}