From f59bfa02db51e3a9a83139cebaa3e9b8d697c196 Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Tue, 25 Aug 2015 16:17:34 +0200 Subject: [PATCH] ICS: saveContent -> write --- .../src/SchemeManagerImpl.kt | 2 +- .../src/XmlElementStorage.kt | 2 +- .../testSrc/ApplicationStoreTest.kt | 2 +- .../testSrc/MockStreamProvider.kt | 2 +- .../components/impl/stores/StreamProvider.kt | 2 +- plugins/settings-repository/src/IcsManager.kt | 2 +- .../settings-repository/testSrc/GitTest.kt | 24 +++++++------------ .../settings-repository/testSrc/LoadTest.kt | 10 ++++---- .../settings-repository/testSrc/TestCase.kt | 9 +++++-- 9 files changed, 27 insertions(+), 28 deletions(-) diff --git a/platform/configuration-store-impl/src/SchemeManagerImpl.kt b/platform/configuration-store-impl/src/SchemeManagerImpl.kt index de2a05a77ba2..48d0ca305a14 100644 --- a/platform/configuration-store-impl/src/SchemeManagerImpl.kt +++ b/platform/configuration-store-impl/src/SchemeManagerImpl.kt @@ -583,7 +583,7 @@ public class SchemeManagerImpl(private val if (renamed) { externalInfo!!.scheduleDelete() } - provider!!.saveContent(providerPath, byteOut.getInternalBuffer(), byteOut.size(), roamingType) + provider!!.write(providerPath, byteOut.getInternalBuffer(), byteOut.size(), roamingType) } if (externalInfo == null) { diff --git a/platform/configuration-store-impl/src/XmlElementStorage.kt b/platform/configuration-store-impl/src/XmlElementStorage.kt index 1fd9fcf666cc..5b0ee7f5e55a 100644 --- a/platform/configuration-store-impl/src/XmlElementStorage.kt +++ b/platform/configuration-store-impl/src/XmlElementStorage.kt @@ -139,7 +139,7 @@ abstract class XmlElementStorage protected constructor(protected val fileSpec: S else { // we should use standard line-separator (\n) - stream provider can share file content on any OS val content = StorageUtil.writeToBytes(element, "\n") - provider.saveContent(storage.fileSpec, content.getInternalBuffer(), content.size(), storage.roamingType) + provider.write(storage.fileSpec, content.getInternalBuffer(), content.size(), storage.roamingType) } } else { diff --git a/platform/configuration-store-impl/testSrc/ApplicationStoreTest.kt b/platform/configuration-store-impl/testSrc/ApplicationStoreTest.kt index b2f391c9404a..a489077d5961 100644 --- a/platform/configuration-store-impl/testSrc/ApplicationStoreTest.kt +++ b/platform/configuration-store-impl/testSrc/ApplicationStoreTest.kt @@ -111,7 +111,7 @@ class ApplicationStoreTest { private class MyStreamProvider : StreamProvider { public val data: MutableMap> = THashMap() - override fun saveContent(fileSpec: String, content: ByteArray, size: Int, roamingType: RoamingType) { + override fun write(fileSpec: String, content: ByteArray, size: Int, roamingType: RoamingType) { getMap(roamingType).put(fileSpec, String(content, 0, size, CharsetToolkit.UTF8_CHARSET)) } diff --git a/platform/configuration-store-impl/testSrc/MockStreamProvider.kt b/platform/configuration-store-impl/testSrc/MockStreamProvider.kt index d383107dd0fc..cd9442a1c766 100644 --- a/platform/configuration-store-impl/testSrc/MockStreamProvider.kt +++ b/platform/configuration-store-impl/testSrc/MockStreamProvider.kt @@ -9,7 +9,7 @@ import java.io.FileInputStream import java.io.InputStream class MockStreamProvider(private val myBaseDir: File) : StreamProvider { - override fun saveContent(fileSpec: String, content: ByteArray, size: Int, roamingType: RoamingType) { + override fun write(fileSpec: String, content: ByteArray, size: Int, roamingType: RoamingType) { FileUtil.writeToFile(File(myBaseDir, fileSpec), content, 0, size) } diff --git a/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/StreamProvider.kt b/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/StreamProvider.kt index 6767af9599cb..d3c25919c3b4 100644 --- a/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/StreamProvider.kt +++ b/platform/platform-impl/src/com/intellij/openapi/components/impl/stores/StreamProvider.kt @@ -30,7 +30,7 @@ public interface StreamProvider { * @param content bytes of content, size of array is not actual size of data, you must use `size` * @param size actual size of data */ - public fun saveContent(fileSpec: String, content: ByteArray, size: Int, roamingType: RoamingType) + public fun write(fileSpec: String, content: ByteArray, size: Int, roamingType: RoamingType) public fun loadContent(fileSpec: String, roamingType: RoamingType): InputStream? diff --git a/plugins/settings-repository/src/IcsManager.kt b/plugins/settings-repository/src/IcsManager.kt index 27ff98ad2fb9..a7b504ccef36 100644 --- a/plugins/settings-repository/src/IcsManager.kt +++ b/plugins/settings-repository/src/IcsManager.kt @@ -211,7 +211,7 @@ class IcsManager(dir: File) { repositoryManager.processChildren(fullPath, filter, { name, input -> processor(name, input, false) }) } - override fun saveContent(fileSpec: String, content: ByteArray, size: Int, roamingType: RoamingType) { + override fun write(fileSpec: String, content: ByteArray, size: Int, roamingType: RoamingType) { if (syncManager.writeAndDeleteProhibited) { throw IllegalStateException("Save is prohibited now") } diff --git a/plugins/settings-repository/testSrc/GitTest.kt b/plugins/settings-repository/testSrc/GitTest.kt index b9f307f7bfd3..588fa1fd5d08 100644 --- a/plugins/settings-repository/testSrc/GitTest.kt +++ b/plugins/settings-repository/testSrc/GitTest.kt @@ -17,7 +17,6 @@ package org.jetbrains.settingsRepository.test import com.intellij.mock.MockVirtualFileSystem import com.intellij.openapi.components.RoamingType -import com.intellij.openapi.components.impl.stores.StreamProvider import com.intellij.openapi.util.io.FileUtil import com.intellij.openapi.vcs.merge.MergeSession import com.intellij.openapi.vfs.CharsetToolkit @@ -84,7 +83,7 @@ class GitTest : TestCase() { private fun addAndCommit(path: String): FileInfo { val data = FileUtil.loadFileBytes(File(testDataPath, PathUtilRt.getFileName(path))) - provider.save(path, data) + provider.write(path, data) repositoryManager.commit() return FileInfo(path, data) } @@ -92,7 +91,7 @@ class GitTest : TestCase() { Test fun add() { val data = FileUtil.loadFileBytes(File(testDataPath, "remote.xml")) val addedFile = "remote.xml" - provider.save(addedFile, data) + provider.write(addedFile, data) val diff = repository.computeIndexDiff() assertThat(diff.diff()).isTrue() @@ -109,8 +108,8 @@ class GitTest : TestCase() { val data2 = FileUtil.loadFileBytes(File(testDataPath, "local.xml")) val addedFile = "remote.xml" val addedFile2 = "local.xml" - provider.save(addedFile, data) - provider.save(addedFile2, data2) + provider.write(addedFile, data) + provider.write(addedFile2, data2) val diff = repository.computeIndexDiff() assertThat(diff.diff()).isTrue() @@ -127,7 +126,7 @@ class GitTest : TestCase() { fun delete(data: ByteArray, directory: Boolean) { val dir = "dir" val fullFileSpec = "$dir/$addedFile" - provider.save(fullFileSpec, data) + provider.write(fullFileSpec, data) provider.delete(if (directory) dir else fullFileSpec, RoamingType.PER_USER) val diff = repository.computeIndexDiff() @@ -272,7 +271,7 @@ class GitTest : TestCase() { createLocalRepository(null) val data = AM.MARKER_ACCEPT_MY - provider.save("remote.xml", data) + provider.write("remote.xml", data) sync(SyncType.MERGE) @@ -286,7 +285,7 @@ class GitTest : TestCase() { sync(SyncType.MERGE) val data = AM.MARKER_ACCEPT_THEIRS - provider.save("remote.xml", data) + provider.write("remote.xml", data) repositoryManager.commit() remoteRepository.deletePath("remote.xml") @@ -317,7 +316,7 @@ class GitTest : TestCase() { Test fun `commit if unmerged`() { createLocalRepository(null) - provider.saveContent("remote.xml", "") + provider.write("remote.xml", "") try { sync(SyncType.MERGE) @@ -379,7 +378,7 @@ class GitTest : TestCase() { val path = "local.xml" val data = FileUtil.loadFileBytes(File(testDataPath, PathUtilRt.getFileName(path))) - provider.save(path, data) + provider.write(path, data) sync(syncType) @@ -406,9 +405,4 @@ class GitTest : TestCase() { private fun sync(syncType: SyncType) { icsManager.sync(syncType, fixtureManager.projectFixture.getProject()) } -} - -fun StreamProvider.saveContent(fileSpec: String, content: String) { - val data = content.toByteArray() - saveContent(fileSpec, data, data.size(), RoamingType.PER_USER) } \ No newline at end of file diff --git a/plugins/settings-repository/testSrc/LoadTest.kt b/plugins/settings-repository/testSrc/LoadTest.kt index 67dedd53c9d7..5fc5fc29092a 100644 --- a/plugins/settings-repository/testSrc/LoadTest.kt +++ b/plugins/settings-repository/testSrc/LoadTest.kt @@ -37,7 +37,7 @@ class LoadTest : TestCase() { public Test fun `load scheme`() { val localScheme = TestScheme("local") val data = localScheme.serialize().toByteArray() - provider.save("$dirPath/local.xml", data) + provider.write("$dirPath/local.xml", data) val schemesManager = createSchemeManager(dirPath) schemesManager.loadSchemes() @@ -47,8 +47,8 @@ class LoadTest : TestCase() { public Test fun `load scheme with the same names`() { val localScheme = TestScheme("local") val data = localScheme.serialize().toByteArray() - provider.save("$dirPath/local.xml", data) - provider.save("$dirPath/local2.xml", data) + provider.write("$dirPath/local.xml", data) + provider.write("$dirPath/local2.xml", data) val schemesManager = createSchemeManager(dirPath) schemesManager.loadSchemes() @@ -58,7 +58,7 @@ class LoadTest : TestCase() { public Test fun `load scheme from repo and read-only repo`() { val localScheme = TestScheme("local") - provider.save("$dirPath/local.xml", localScheme.serialize().toByteArray()) + provider.write("$dirPath/local.xml", localScheme.serialize().toByteArray()) val remoteScheme = TestScheme("remote") val remoteRepository = tempDirManager.createRepository() @@ -79,7 +79,7 @@ class LoadTest : TestCase() { val schemeName = "Emacs" val localScheme = TestScheme(schemeName, "local") - provider.save("$dirPath/$schemeName.xml", localScheme.serialize().toByteArray()) + provider.write("$dirPath/$schemeName.xml", localScheme.serialize().toByteArray()) val remoteScheme = TestScheme(schemeName, "remote") val remoteRepository = tempDirManager.createRepository("remote") diff --git a/plugins/settings-repository/testSrc/TestCase.kt b/plugins/settings-repository/testSrc/TestCase.kt index 115ec54891b7..47ca047e0544 100644 --- a/plugins/settings-repository/testSrc/TestCase.kt +++ b/plugins/settings-repository/testSrc/TestCase.kt @@ -33,8 +33,13 @@ import kotlin.properties.Delegates val testDataPath: String = "${PlatformTestUtil.getCommunityPath()}/plugins/settings-repository/testData" -fun StreamProvider.save(path: String, data: ByteArray) { - saveContent(path, data, data.size(), RoamingType.PER_USER) +fun StreamProvider.write(path: String, data: ByteArray) { + write(path, data, data.size(), RoamingType.PER_USER) +} + +fun StreamProvider.write(fileSpec: String, content: String) { + val data = content.toByteArray() + write(fileSpec, data, data.size(), RoamingType.PER_USER) } fun Repository.add(data: ByteArray, path: String): Repository {