mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-05 01:50:56 +07:00
drop settingsSync.fileSystem from repo
Signed-off-by: Sergey Pak <sergey.pak@jetbrains.com> (cherry picked from commit 34d13d568936ae84a24490655116302344b48ba0) GitOrigin-RevId: 4334dcdf29b15eacc087d2333a67297eb6b2218e
This commit is contained in:
committed by
intellij-monorepo-bot
parent
c1d089565c
commit
f8175a2887
@@ -1,20 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/resources" type="java-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/testResources" type="java-test-resource" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" name="kotlin-stdlib" level="project" />
|
||||
<orderEntry type="module" module-name="intellij.settingsSync.core" />
|
||||
<orderEntry type="module" module-name="intellij.platform.core.ui" />
|
||||
<orderEntry type="module" module-name="intellij.platform.ide.core" />
|
||||
<orderEntry type="module" module-name="intellij.platform.ide.impl" />
|
||||
<orderEntry type="module" module-name="intellij.platform.lang.impl" />
|
||||
</component>
|
||||
</module>
|
||||
@@ -1,10 +0,0 @@
|
||||
<!-- Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. -->
|
||||
<idea-plugin package="intellij.settingsSync.fileSystem">
|
||||
<extensions defaultExtensionNs="com.intellij">
|
||||
<settingsSync.communicatorProvider implementation="intellij.settingsSync.fileSystem.FSCommunicatorProvider"/>
|
||||
</extensions>
|
||||
<actions resource-bundle="messages.BackupNSyncFSBundle">
|
||||
<action class="intellij.settingsSync.fileSystem.EnableBackupNSyncRemotely" id="settingsSync.enableRemotely"
|
||||
icon="AllIcons.General.Settings"/>
|
||||
</actions>
|
||||
</idea-plugin>
|
||||
@@ -1 +0,0 @@
|
||||
action.settingsSync.enableRemotely.text = Enable Backup Sync (from FS)
|
||||
@@ -1,52 +0,0 @@
|
||||
package intellij.settingsSync.fileSystem
|
||||
|
||||
import com.intellij.ide.util.PropertiesComponent
|
||||
import com.intellij.openapi.actionSystem.ActionUpdateThread
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent
|
||||
import com.intellij.openapi.application.ApplicationManager
|
||||
import com.intellij.openapi.diagnostic.logger
|
||||
import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory
|
||||
import com.intellij.openapi.fileChooser.FileChooserFactory
|
||||
import com.intellij.openapi.project.DumbAwareAction
|
||||
import com.intellij.settingsSync.SettingsSyncLocalSettings
|
||||
import com.intellij.settingsSync.SettingsSyncSettings
|
||||
import com.intellij.settingsSync.UpdateResult.*
|
||||
import com.intellij.settingsSync.config.SettingsSyncEnabler
|
||||
import com.intellij.util.containers.toMutableSmartList
|
||||
|
||||
class EnableBackupNSyncRemotely : DumbAwareAction() {
|
||||
override fun getActionUpdateThread() = ActionUpdateThread.BGT
|
||||
|
||||
override fun actionPerformed(e: AnActionEvent) {
|
||||
ApplicationManager.getApplication().invokeLater {
|
||||
val folderDescriptor = FileChooserDescriptorFactory.createSingleFolderDescriptor()
|
||||
.withTitle("Select root folder")
|
||||
val chooser = FileChooserFactory.getInstance().createPathChooser(folderDescriptor, null, null)
|
||||
chooser.choose(null) {
|
||||
val path = it.single().path
|
||||
val availableAccounts = (PropertiesComponent.getInstance().getList("FSAuthServiceAccounts") ?: emptyList()).toMutableSmartList()
|
||||
availableAccounts.add(path)
|
||||
SettingsSyncLocalSettings.getInstance().userId = path
|
||||
SettingsSyncLocalSettings.getInstance().providerCode = "fs"
|
||||
PropertiesComponent.getInstance().setList("FSAuthServiceAccounts", availableAccounts)
|
||||
}
|
||||
SettingsSyncSettings.getInstance().syncEnabled = true
|
||||
val enabler = SettingsSyncEnabler()
|
||||
val serverState = enabler.getServerState()
|
||||
when (serverState) {
|
||||
is NoFileOnServer, FileDeletedFromServer -> {
|
||||
enabler.pushSettingsToServer()
|
||||
}
|
||||
is Success -> {
|
||||
enabler.getSettingsFromServer(null)
|
||||
}
|
||||
is Error -> {
|
||||
logger<EnableBackupNSyncRemotely>().error(serverState.message)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -1,80 +0,0 @@
|
||||
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package intellij.settingsSync.fileSystem
|
||||
|
||||
import com.intellij.ide.util.PropertiesComponent
|
||||
import com.intellij.openapi.application.EDT
|
||||
import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory
|
||||
import com.intellij.openapi.fileChooser.FileChooserFactory
|
||||
import com.intellij.platform.ide.progress.ModalTaskOwner
|
||||
import com.intellij.platform.ide.progress.TaskCancellation
|
||||
import com.intellij.platform.ide.progress.withModalProgress
|
||||
import com.intellij.settingsSync.auth.SettingsSyncAuthService
|
||||
import com.intellij.settingsSync.communicator.SettingsSyncUserData
|
||||
import com.intellij.util.containers.mapSmart
|
||||
import com.intellij.util.containers.toMutableSmartList
|
||||
import kotlinx.coroutines.*
|
||||
import java.awt.Component
|
||||
import java.nio.file.Path
|
||||
import javax.swing.Icon
|
||||
import kotlin.io.path.absolutePathString
|
||||
import kotlin.io.path.name
|
||||
import kotlin.coroutines.resume
|
||||
|
||||
|
||||
internal class FSAuthService : SettingsSyncAuthService {
|
||||
override val providerCode: String
|
||||
get() = "fs"
|
||||
override val providerName: String
|
||||
get() = "File System"
|
||||
|
||||
override val icon: Icon?
|
||||
get() = com.intellij.icons.AllIcons.Actions.ModuleDirectory
|
||||
|
||||
override suspend fun login(parentComponent: Component?): SettingsSyncUserData? {
|
||||
val modalTaskOwner = if (parentComponent != null)
|
||||
ModalTaskOwner.component(parentComponent)
|
||||
else
|
||||
ModalTaskOwner.guess()
|
||||
return withModalProgress(modalTaskOwner, "Getting data", TaskCancellation.cancellable(), ) {
|
||||
val folderDescriptor = FileChooserDescriptorFactory.createSingleFolderDescriptor()
|
||||
.withTitle("Select root folder")
|
||||
withContext(Dispatchers.EDT) {
|
||||
val chooser = FileChooserFactory.getInstance().createPathChooser(folderDescriptor, null, null)
|
||||
suspendCancellableCoroutine<SettingsSyncUserData?> { cont ->
|
||||
cont.invokeOnCancellation {
|
||||
cont.resume(null)
|
||||
}
|
||||
chooser.choose(null) {
|
||||
val path = it.single().path
|
||||
val userData = userDataFromPath(path)
|
||||
val availableAccounts = (PropertiesComponent.getInstance().getList("FSAuthServiceAccounts") ?: emptyList()).toMutableSmartList()
|
||||
if (!availableAccounts.contains(path)) {
|
||||
availableAccounts.add(path)
|
||||
PropertiesComponent.getInstance().setList("FSAuthServiceAccounts", availableAccounts)
|
||||
}
|
||||
cont.resume(userData)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun getUserData(userId: String): SettingsSyncUserData? {
|
||||
return getAvailableUserAccounts().find { it.id == userId }
|
||||
}
|
||||
|
||||
override fun getAvailableUserAccounts(): List<SettingsSyncUserData> {
|
||||
return PropertiesComponent.getInstance().getList("FSAuthServiceAccounts")?.mapSmart { userDataFromPath(it) } ?: emptyList()
|
||||
}
|
||||
|
||||
private fun userDataFromPath(pathStr: String) : SettingsSyncUserData {
|
||||
val path = Path.of(pathStr)
|
||||
return SettingsSyncUserData(
|
||||
path.absolutePathString(),
|
||||
providerCode,
|
||||
path.name,
|
||||
"noname@email.com"
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,59 +0,0 @@
|
||||
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package intellij.settingsSync.fileSystem
|
||||
|
||||
import com.intellij.openapi.diagnostic.logger
|
||||
import com.intellij.settingsSync.*
|
||||
import java.io.InputStream
|
||||
import java.nio.file.Path
|
||||
import kotlin.io.path.getLastModifiedTime
|
||||
|
||||
internal class FSCommunicator(override val userId: String) : AbstractServerCommunicator() {
|
||||
|
||||
private val basePath: Path = Path.of(userId)
|
||||
|
||||
companion object {
|
||||
private val LOG = logger<FSCommunicator>()
|
||||
}
|
||||
|
||||
override fun requestSuccessful() {
|
||||
LOG.info("requestSuccessful")
|
||||
}
|
||||
|
||||
override fun handleRemoteError(e: Throwable): String {
|
||||
LOG.warn("remote error occurred", e)
|
||||
return e.message ?: "Remote error occurred: ${e.javaClass.name}"
|
||||
}
|
||||
|
||||
override fun readFileInternal(filePath: String): Pair<InputStream?, String?> {
|
||||
val path = basePath.resolve(filePath)
|
||||
val file = path.toFile()
|
||||
if (file.exists()) {
|
||||
return Pair(file.inputStream(), path.getLastModifiedTime().toString())
|
||||
}
|
||||
return Pair(null, null)
|
||||
}
|
||||
|
||||
override fun writeFileInternal(filePath: String, versionId: String?, content: InputStream): String? {
|
||||
val path = basePath.resolve(filePath)
|
||||
if (path.toFile().exists() && path.getLastModifiedTime().toString() != versionId) {
|
||||
throw InvalidVersionIdException("Expected versionId is $versionId, but actual is ${path.getLastModifiedTime()}")
|
||||
}
|
||||
if (!path.parent.toFile().exists()) {
|
||||
path.parent.toFile().mkdirs()
|
||||
}
|
||||
path.toFile().outputStream().use { content.copyTo(it) }
|
||||
return path.getLastModifiedTime().toString()
|
||||
}
|
||||
|
||||
override fun getLatestVersion(filePath: String): String? {
|
||||
val path = basePath.resolve(filePath)
|
||||
if (!path.toFile().exists())
|
||||
return null
|
||||
return path.getLastModifiedTime().toString()
|
||||
}
|
||||
|
||||
override fun deleteFileInternal(filePath: String) {
|
||||
val path = basePath.resolve(filePath)
|
||||
path.toFile().delete()
|
||||
}
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package intellij.settingsSync.fileSystem
|
||||
|
||||
import com.intellij.settingsSync.SettingsSyncRemoteCommunicator
|
||||
import com.intellij.settingsSync.auth.SettingsSyncAuthService
|
||||
import com.intellij.settingsSync.communicator.SettingsSyncCommunicatorProvider
|
||||
|
||||
class FSCommunicatorProvider : SettingsSyncCommunicatorProvider {
|
||||
private val authServiceLazy = lazy<FSAuthService> { FSAuthService() }
|
||||
|
||||
override val providerCode: String
|
||||
get() = "fs"
|
||||
|
||||
override val authService: SettingsSyncAuthService
|
||||
get() = authServiceLazy.value
|
||||
|
||||
override fun createCommunicator(userId: String): SettingsSyncRemoteCommunicator? {
|
||||
return FSCommunicator(userId)
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user