mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-15 02:59:33 +07:00
CharsetToolkit not required for aalto xml
GitOrigin-RevId: e0165ef48d77a60df50e9093311d8b3319ad26cc
This commit is contained in:
committed by
intellij-monorepo-bot
parent
14aefd3cf6
commit
7b11bf5bfd
@@ -11,7 +11,6 @@ import com.intellij.openapi.options.NonLazySchemeProcessor
|
||||
import com.intellij.openapi.options.Scheme
|
||||
import com.intellij.openapi.project.ProjectBundle
|
||||
import com.intellij.openapi.util.JDOMUtil
|
||||
import com.intellij.openapi.vfs.CharsetToolkit
|
||||
import com.intellij.openapi.vfs.VfsUtil
|
||||
import com.intellij.openapi.vfs.VirtualFile
|
||||
import com.intellij.util.containers.ContainerUtil
|
||||
@@ -28,10 +27,10 @@ import java.util.concurrent.atomic.AtomicBoolean
|
||||
import javax.xml.stream.XMLStreamConstants
|
||||
import javax.xml.stream.XMLStreamReader
|
||||
|
||||
internal class SchemeLoader<T: Scheme, MUTABLE_SCHEME : T>(private val schemeManager: SchemeManagerImpl<T, MUTABLE_SCHEME>,
|
||||
private val oldSchemes: List<T>,
|
||||
private val preScheduledFilesToDelete: MutableSet<String>,
|
||||
private val isDuringLoad: Boolean) {
|
||||
internal class SchemeLoader<T : Scheme, MUTABLE_SCHEME : T>(private val schemeManager: SchemeManagerImpl<T, MUTABLE_SCHEME>,
|
||||
private val oldSchemes: List<T>,
|
||||
private val preScheduledFilesToDelete: MutableSet<String>,
|
||||
private val isDuringLoad: Boolean) {
|
||||
private val filesToDelete: MutableSet<String> = HashSet()
|
||||
|
||||
private val schemes: MutableList<T> = oldSchemes.toMutableList()
|
||||
@@ -58,7 +57,7 @@ internal class SchemeLoader<T: Scheme, MUTABLE_SCHEME : T>(private val schemeMan
|
||||
*/
|
||||
fun apply(): List<T> {
|
||||
LOG.assertTrue(isApplied.compareAndSet(false, true))
|
||||
if (filesToDelete.isNotEmpty() || preScheduledFilesToDelete.isNotEmpty()) {
|
||||
if (!filesToDelete.isEmpty() || !preScheduledFilesToDelete.isEmpty()) {
|
||||
LOG.debug {
|
||||
"Schedule to delete: ${filesToDelete.joinToString()} (and preScheduledFilesToDelete: ${preScheduledFilesToDelete.joinToString()})"
|
||||
}
|
||||
@@ -66,6 +65,10 @@ internal class SchemeLoader<T: Scheme, MUTABLE_SCHEME : T>(private val schemeMan
|
||||
schemeManager.filesToDelete.addAll(preScheduledFilesToDelete)
|
||||
}
|
||||
|
||||
if (newSchemesOffset == schemes.size) {
|
||||
return emptyList()
|
||||
}
|
||||
|
||||
val result = schemes.subList(newSchemesOffset, schemes.size)
|
||||
schemeManager.schemeListManager.replaceSchemeList(oldList = oldSchemes, newList = schemes, newSchemeToInfo = schemeToInfo)
|
||||
if (!isDuringLoad) {
|
||||
@@ -161,7 +164,7 @@ internal class SchemeLoader<T: Scheme, MUTABLE_SCHEME : T>(private val schemeMan
|
||||
|
||||
var scheme: MUTABLE_SCHEME? = null
|
||||
if (processor is LazySchemeProcessor) {
|
||||
val bytes = preloadedBytes ?: input!!.readBytes()
|
||||
val bytes = preloadedBytes ?: input!!.readAllBytes()
|
||||
lazyPreloadScheme(bytes, schemeManager.isOldSchemeNaming) { name, parser ->
|
||||
val attributeProvider: (String) -> String? = {
|
||||
if (parser.eventType == XMLStreamConstants.START_ELEMENT) {
|
||||
@@ -178,20 +181,24 @@ internal class SchemeLoader<T: Scheme, MUTABLE_SCHEME : T>(private val schemeMan
|
||||
return null
|
||||
}
|
||||
|
||||
val externalInfo = createInfo(schemeKey, null)
|
||||
scheme = processor.createScheme(SchemeDataHolderImpl(processor, bytes, externalInfo), schemeKey, attributeProvider)
|
||||
val externalInfo = createInfo(schemeName = schemeKey, element = null)
|
||||
scheme = processor.createScheme(
|
||||
dataHolder = SchemeDataHolderImpl(processor = processor, bytes = bytes, externalInfo = externalInfo),
|
||||
name = schemeKey,
|
||||
attributeProvider = attributeProvider,
|
||||
)
|
||||
schemeToInfo.put(scheme!!, externalInfo)
|
||||
retainProbablyScheduledForDeleteFile(fileName)
|
||||
}
|
||||
}
|
||||
else {
|
||||
val element = when (preloadedBytes) {
|
||||
null -> JDOMUtil.load(input)
|
||||
else -> JDOMUtil.load(CharsetToolkit.inputStreamSkippingBOM(preloadedBytes.inputStream()))
|
||||
}
|
||||
val element = if (preloadedBytes == null) JDOMUtil.load(input) else JDOMUtil.load(preloadedBytes)
|
||||
scheme = (processor as NonLazySchemeProcessor).readScheme(element, isDuringLoad) ?: return null
|
||||
val schemeKey = processor.getSchemeKey(scheme!!)
|
||||
if (!checkExisting(schemeKey, fileName, fileNameWithoutExtension, extension)) {
|
||||
if (!checkExisting(schemeKey = schemeKey,
|
||||
fileName = fileName,
|
||||
fileNameWithoutExtension = fileNameWithoutExtension,
|
||||
extension = extension)) {
|
||||
return null
|
||||
}
|
||||
|
||||
@@ -221,7 +228,9 @@ internal class SchemeLoader<T: Scheme, MUTABLE_SCHEME : T>(private val schemeMan
|
||||
}
|
||||
}
|
||||
|
||||
internal inline fun lazyPreloadScheme(bytes: ByteArray, isOldSchemeNaming: Boolean, consumer: (name: String?, parser: XMLStreamReader) -> Unit) {
|
||||
internal inline fun lazyPreloadScheme(bytes: ByteArray,
|
||||
isOldSchemeNaming: Boolean,
|
||||
consumer: (name: String?, parser: XMLStreamReader) -> Unit) {
|
||||
val reader = createXmlStreamReader(bytes)
|
||||
consumer(preload(isOldSchemeNaming, reader), reader)
|
||||
}
|
||||
@@ -304,6 +313,6 @@ internal fun createDir(ioDir: Path, requestor: StorageManagerFileWriteRequestor)
|
||||
ioDir.createDirectories()
|
||||
val parentFile = ioDir.parent
|
||||
val parentVirtualFile = (if (parentFile == null) null else VfsUtil.createDirectoryIfMissing(parentFile.systemIndependentPath))
|
||||
?: throw IOException(ProjectBundle.message("project.configuration.save.file.not.found", parentFile))
|
||||
?: throw IOException(ProjectBundle.message("project.configuration.save.file.not.found", parentFile))
|
||||
return parentVirtualFile.getOrCreateChild(ioDir.fileName.toString(), requestor)
|
||||
}
|
||||
@@ -22,5 +22,5 @@ internal inline fun <T> catchAndLog(file: () -> String, runnable: () -> T): T? {
|
||||
}
|
||||
|
||||
internal fun nameIsMissed(bytes: ByteArray): RuntimeException {
|
||||
return RuntimeException("Name is missed:\n${bytes.toString(Charsets.UTF_8)}")
|
||||
return RuntimeException("Name is missed:\n${bytes.decodeToString()}")
|
||||
}
|
||||
@@ -18,7 +18,7 @@ import com.intellij.testFramework.*
|
||||
import com.intellij.testFramework.rules.InMemoryFsRule
|
||||
import com.intellij.util.PathUtil
|
||||
import com.intellij.util.io.*
|
||||
import com.intellij.util.toBufferExposingByteArray
|
||||
import com.intellij.util.toByteArray
|
||||
import com.intellij.util.xmlb.annotations.Tag
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
import org.assertj.core.api.Assertions.assertThatThrownBy
|
||||
@@ -143,7 +143,7 @@ internal class SchemeManagerTest {
|
||||
}
|
||||
|
||||
fun TestScheme.save(file: Path) {
|
||||
file.write(serialize(this)!!.toBufferExposingByteArray().toByteArray())
|
||||
file.write(serialize(this)!!.toByteArray())
|
||||
}
|
||||
|
||||
@Test fun `different extensions - old, new`() {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.configurationStore
|
||||
|
||||
import com.intellij.openapi.components.RoamingType
|
||||
@@ -46,7 +46,10 @@ interface StreamProvider {
|
||||
/**
|
||||
* `true` if provider is fully responsible and local sources must be not used.
|
||||
*/
|
||||
fun processChildren(path: String, roamingType: RoamingType, filter: (name: String) -> Boolean, processor: (name: String, input: InputStream, readOnly: Boolean) -> Boolean): Boolean
|
||||
fun processChildren(path: String,
|
||||
roamingType: RoamingType,
|
||||
filter: (name: String) -> Boolean,
|
||||
processor: (name: String, input: InputStream, readOnly: Boolean) -> Boolean): Boolean
|
||||
|
||||
/**
|
||||
* Delete file or directory
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
@file:Suppress("ReplacePutWithAssignment", "ReplaceGetOrSet")
|
||||
|
||||
package com.intellij.configurationStore
|
||||
@@ -9,14 +9,15 @@ import com.intellij.openapi.util.SimpleModificationTracker
|
||||
import com.intellij.openapi.util.io.FileUtil
|
||||
import com.intellij.util.PathUtilRt
|
||||
import com.intellij.util.text.UniqueNameGenerator
|
||||
import com.intellij.util.toBufferExposingByteArray
|
||||
import com.intellij.util.toByteArray
|
||||
import org.jdom.Element
|
||||
import java.io.InputStream
|
||||
import java.util.concurrent.locks.ReentrantReadWriteLock
|
||||
import kotlin.concurrent.read
|
||||
import kotlin.concurrent.write
|
||||
|
||||
class SchemeManagerIprProvider(private val subStateTagName: String, private val comparator: Comparator<String>? = null) : StreamProvider, SimpleModificationTracker() {
|
||||
class SchemeManagerIprProvider(private val subStateTagName: String,
|
||||
private val comparator: Comparator<String>? = null) : StreamProvider, SimpleModificationTracker() {
|
||||
private val lock = ReentrantReadWriteLock()
|
||||
private var nameToData = LinkedHashMap<String, ByteArray>()
|
||||
|
||||
@@ -90,7 +91,7 @@ class SchemeManagerIprProvider(private val subStateTagName: String, private val
|
||||
continue
|
||||
}
|
||||
|
||||
nameToData.put(nameGenerator.generateUniqueName("${FileUtil.sanitizeFileName(name, false)}.xml"), child.toBufferExposingByteArray().toByteArray())
|
||||
nameToData.put(nameGenerator.generateUniqueName("${FileUtil.sanitizeFileName(name, false)}.xml"), child.toByteArray())
|
||||
}
|
||||
|
||||
lock.write {
|
||||
@@ -115,7 +116,7 @@ class SchemeManagerIprProvider(private val subStateTagName: String, private val
|
||||
names.sortWith(comparator)
|
||||
}
|
||||
for (name in names) {
|
||||
nameToData.get(name)?.let { state.addContent(JDOMUtil.load(it.inputStream())) }
|
||||
nameToData.get(name)?.let { state.addContent(JDOMUtil.load(it)) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ import com.intellij.openapi.extensions.PluginId
|
||||
import com.intellij.settingsSync.SettingsSnapshot.MetaInfo
|
||||
import com.intellij.settingsSync.plugins.SettingsSyncPluginsState
|
||||
import com.intellij.settingsSync.plugins.SettingsSyncPluginsState.PluginData
|
||||
import com.intellij.util.toBufferExposingByteArray
|
||||
import com.intellij.util.toByteArray
|
||||
import com.intellij.util.xmlb.Constants
|
||||
import org.jdom.Element
|
||||
import org.jetbrains.annotations.ApiStatus
|
||||
@@ -68,7 +68,7 @@ internal fun PersistentStateComponent<*>.serialize(): ByteArray {
|
||||
|
||||
val appElement = Element("application")
|
||||
appElement.addContent(compElement)
|
||||
return appElement.toBufferExposingByteArray().toByteArray()
|
||||
return appElement.toByteArray()
|
||||
}
|
||||
|
||||
internal fun settingsSnapshot(metaInfo: MetaInfo = MetaInfo(Instant.now(), getLocalApplicationInfo()),
|
||||
|
||||
Reference in New Issue
Block a user