2N67RQZCVGL6GYJJLM2US4YVCEIUK25AHCLD66C7HR4PPTNUOCWAC
ISO7J5ZH5UB7NFZKTKKJQHQHCP4DWQ3F7SM2NDMVYJAGGIKDLX4QC
ZCRW57C5MSBXYGUMGQTZNHGHO4HGHFBICW53X5I2IMGP3H2CKWRQC
MTPTFTHGAOKQGRUDXC55AM6XJHZZZ5EF6FPVXKFVCUYVXJNEANYQC
GGYFPXND4VBCROZZXTKAP7Y4JOP2OOYQAFVLMUE7SLFM225EUSIAC
B43WNBLFFR2UQIH3C6KIZAQTAEQOQM3J3IYLGQMVGJHYOME73OKQC
FNNW5IEAXQ43WKB6QSQB7DFLG3Y3T5FYPXIUX7KQ2URR2GU3QLTAC
6CR2EFUN7JXFHCBTNX3WWOOP4WFOCFO6KSPEBN6V6J5HFZO2LHNQC
FRFFQV7VNYKGCA7ZAOSRPC2HHYTAIZ6AGGR7A5QEV6QPAQGFDYGAC
Q7FXTHVUPVAFMNY277C3NFJO3VXLZU5G6C6UYSD5QPURHSG3A7OQC
Q35OTML226J2HZLHOCPV5OY6ZUM2XU4RZBE5E3GDWVHVFASHFEJAC
expert.mode.notification.failure=Failed to record changes with exit code <bold>{0}</bold> and message: <tt>{1}</tt>.
expert.mode.notification.failure=Failed to record changes with exit code <bold>{0}</bold> and message: <tt>{1}</tt>.
cache.invalidate.text=Invalidating caches...
cache.invalidate.current.text=Invalidating <em>{0}</em>...
cache.invalidate.finish.text=Invalidated caches
install.pijul.title=Install pijul
install.pijul.title2=Install Pijul
install.pijul.text=Cannot find pijul binaries.\n\
Do you want to install pijul using rust cargo?
install.editor.server.title=Install editor-server
install.editor.server.title2=Install Editor Server
install.editor.server.text=Cannot find editor-server binaries.\n\
Dracon depends on editor-server for interfacing with Pijul.\n\
Do you want to install editor-server using rust cargo?
install.cargo.title=Install Rustup and Cargo
install.cargo.text=In order to install <tt>{0}</tt> you need to have cargo installed.\n\
However we cannot find cargo installed in this machine.\n\
Do you want to install rustup with cargo?\n\
If you agree, we will download rustup and launch the installer, you take from there.
install.pijul.warning.text=You won't be able to use Dracon plugin since some dependencies could not be installed.
install.cargo.running.text=Running cargo install...
constructor(root: Path,
filePath: FilePath,
revision: PijulRevisionNumber,
project: Project): this(root, Paths.get(filePath.path), revision, project)
override fun getContent(): String {
return loadStateInRevision(this.revision.hash, this.project, root, this.filePath)
}
constructor(
root: Path,
filePath: FilePath,
revision: PijulRevisionNumber,
project: Project
) : this(root, Paths.get(filePath.path), revision, project)
private val content = this.project.service<FileRevisionCache>().loadAsync(this)
override fun getContent(): String = String(this.content.get(), Charsets.UTF_8)
fun loadAsync(rev: PijulContentRevision): CompletableFuture<ByteArray> {
val root = project.service<PijulVcsContext>().root
val fileRev = FileRevisionRef(rev.filePath.toAbsolutePath().toString(), rev.revision.hash)
return this.cache.queryOrLoadAsync(fileRev) {
loadStateInRevision(
rev.revision.hash,
this.project,
root,
rev.filePath
).toByteArray(Charsets.UTF_8)
}
}
fun invalidate() {
this.cache.invalidate()
}
package com.github.jonathanxd.dracon.activity
import com.github.jonathanxd.dracon.i18n.BUNDLE
import com.github.jonathanxd.dracon.i18n.DraconBundle
import com.github.jonathanxd.dracon.pijul.NonZeroExitStatusCode
import com.github.jonathanxd.dracon.pijul.Pijul
import com.github.jonathanxd.dracon.pijul.pijul
import com.github.jonathanxd.dracon.util.escapeXml
import com.github.jonathanxd.dracon.util.findBinary
import com.github.jonathanxd.dracon.util.findBinaryOrNull
import com.github.jonathanxd.dracon.util.wrapInHml
import com.github.jonathanxd.dracon.vcs.DraconVcsUtil
import com.github.jonathanxd.dracon.vcs.NotificationIds
import com.intellij.execution.configurations.GeneralCommandLine
import com.intellij.execution.util.ExecUtil
import com.intellij.openapi.progress.ProgressIndicator
import com.intellij.openapi.progress.Task
import com.intellij.openapi.project.Project
import com.intellij.openapi.startup.StartupActivity
import com.intellij.openapi.ui.Messages
import com.intellij.openapi.util.SystemInfo
import com.intellij.openapi.vcs.VcsNotifier
import com.intellij.util.download.DownloadableFileService
import com.intellij.util.download.FileDownloader
import com.intellij.util.io.IdeUtilIoBundle
import com.intellij.vcsUtil.VcsUtil
import org.jetbrains.annotations.PropertyKey
import java.nio.file.Paths
import java.util.concurrent.CompletableFuture
class PijulPostStartupActivity : StartupActivity {
override fun runActivity(project: Project) {
val path = project.basePath?.let { Paths.get(it) } ?: return
if (Pijul.isUnderPijul(path)) {
val hasPijul = findBinaryOrNull("pijul") != null
val hasEditorServer = findBinaryOrNull("editor-server") != null
if (!hasPijul) {
val hasCargo = findBinaryOrNull("cargo") != null
if (!hasCargo) {
this.askForCargoInstallation(project, "pijul").handle { t, u ->
if (t != null && checkForCargo(project)) {
cargoInstallPijul(project)
}
if (u != null) {
warnDraconWillNotWork(project)
u.printStackTrace()
}
}
} else {
cargoInstallPijul(project)
}
}
if (!hasEditorServer) {
val hasCargo = findBinaryOrNull("cargo") != null
if (!hasCargo) {
this.askForCargoInstallation(project, "editor-server").handle { t, u ->
if (t != null && checkForCargo(project)) {
cargoInstallEditor(project)
}
if (u != null) {
warnDraconWillNotWork(project)
u.printStackTrace()
}
}
} else {
cargoInstallEditor(project)
}
}
}
}
fun cargoInstallPijul(project: Project) {
val dialog = Messages.showYesNoDialog(
project,
DraconBundle.message("install.pijul.text").wrapInHml(),
DraconBundle.message("install.pijul.title2"),
Messages.getWarningIcon()
)
if (dialog == Messages.YES) {
object : Task.Backgroundable(project, DraconBundle.message("install.pijul.title")) {
override fun run(indicator: ProgressIndicator) {
indicator.isIndeterminate = true
indicator.text = DraconBundle.message("install.pijul.title")
indicator.text2 = DraconBundle.message("install.cargo.running.text")
execInTerminal("install.pijul.title", "cargo install pijul --version '~1.0.0-alpha'")
}
}.queue()
} else {
warnDraconWillNotWork(project)
}
}
fun cargoInstallEditor(project: Project) {
val dialog = Messages.showYesNoDialog(
project,
DraconBundle.message("install.editor.server.text").wrapInHml(),
DraconBundle.message("install.editor.server.title2"),
Messages.getWarningIcon()
)
if (dialog == Messages.YES) {
object : Task.Backgroundable(project, DraconBundle.message("install.editor.server.title")) {
override fun run(indicator: ProgressIndicator) {
indicator.isIndeterminate = true
indicator.text = DraconBundle.message("install.editor.server.title")
indicator.text2 = DraconBundle.message("install.cargo.running.text")
execInTerminal("install.editor.server.title", "cargo install editor-server")
}
}.queue()
} else {
warnDraconWillNotWork(project)
}
}
fun checkForCargo(project: Project): Boolean {
if (findBinaryOrNull("cargo") == null) {
warnDraconWillNotWork(project)
return false
}
return true
}
fun warnDraconWillNotWork(project: Project) {
Messages.showWarningDialog(
project,
DraconBundle.message("install.pijul.warning.text").wrapInHml(),
DraconBundle.message("install.pijul.title")
)
}
fun askForCargoInstallation(project: Project, sub: String): CompletableFuture<Unit> {
val dialog = Messages.showYesNoDialog(
project,
DraconBundle.message("install.cargo.text", sub.escapeXml()).wrapInHml(),
DraconBundle.message("install.cargo.title"),
Messages.getWarningIcon()
)
if (dialog == Messages.YES) {
val download = if (SystemInfo.isWindows) {
DownloadableFileService.getInstance().createDownloader(listOf(
DownloadableFileService.getInstance()
.createFileDescription(
"https://win.rustup.rs/x86_64",
"rustup-init.exe"
)
), "Rustup")
} else {
DownloadableFileService.getInstance().createDownloader(listOf(
DownloadableFileService.getInstance()
.createFileDescription(
"https://sh.rustup.rs",
"rustup-init.sh"
)
), "Rustup")
}
return download.downloadWithBackgroundProgress(null, project)
.handle { t, u ->
if (t != null && t.isNotEmpty()) {
val file = Paths.get(VcsUtil.getFilePath(t.single().first).path).toAbsolutePath()
if (SystemInfo.isWindows) {
this.execInTerminal("install.cargo.title", file.toString())
} else {
this.execInTerminal("install.cargo.title", "sh $file")
}
}
u?.printStackTrace()
}
} else {
return CompletableFuture.failedFuture(IllegalStateException("User not accepted cargo installation."))
}
}
fun execInTerminal(
@PropertyKey(resourceBundle = BUNDLE) name: String,
command: String
) {
ExecUtil.execAndGetOutput(GeneralCommandLine(ExecUtil.getTerminalCommand(DraconBundle.message(name), command)))
}
}
/**
* Dracon - An IntelliJ-Pijul integration.
* Copyright 2021 JonathanxD <jhrldev@gmail.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package com.github.jonathanxd.dracon.actions
import com.github.jonathanxd.dracon.cache.FileRevisionCache
import com.github.jonathanxd.dracon.cache.FileStatusCache
import com.github.jonathanxd.dracon.cache.PijulLogEntryCache
import com.github.jonathanxd.dracon.cache.PijulLogEntryChangeCache
import com.github.jonathanxd.dracon.i18n.DraconBundle
import com.github.jonathanxd.dracon.pijul.NonZeroExitStatusCode
import com.github.jonathanxd.dracon.pijul.Pijul
import com.github.jonathanxd.dracon.pijul.pijul
import com.github.jonathanxd.dracon.util.wrapInHml
import com.github.jonathanxd.dracon.vcs.DraconVcsUtil
import com.github.jonathanxd.dracon.vcs.NotificationIds
import com.github.jonathanxd.dracon.vfs.DraconVfsUtil
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.actionSystem.CommonDataKeys
import com.intellij.openapi.components.service
import com.intellij.openapi.fileChooser.FileChooser
import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory
import com.intellij.openapi.progress.ProgressIndicator
import com.intellij.openapi.progress.Task
import com.intellij.openapi.project.DumbAwareAction
import com.intellij.openapi.project.ProjectManager
import com.intellij.openapi.ui.Messages
import com.intellij.openapi.vcs.ProjectLevelVcsManager
import com.intellij.openapi.vcs.VcsNotifier
import com.intellij.openapi.vcs.changes.VcsDirtyScopeManager
import com.intellij.vcsUtil.VcsUtil
class PijulInvalidateCaches: DumbAwareAction() {
override fun actionPerformed(e: AnActionEvent) {
val project = e.getData(CommonDataKeys.PROJECT) ?: ProjectManager.getInstance().defaultProject
object : Task.Backgroundable(project, DraconBundle.Dracon.refreshing) {
override fun run(indicator: ProgressIndicator) {
indicator.isIndeterminate = false
indicator.text = DraconBundle.message("cache.invalidate.text")
indicator.fraction = 0.0
val fileRevisionCache = project.service<FileRevisionCache>()
indicator.text2 = DraconBundle.message("cache.invalidate.current.text", "file revision cache")
fileRevisionCache.invalidate()
indicator.fraction = 0.25
val fileStatusCache = project.service<FileStatusCache>()
indicator.text2 = DraconBundle.message("cache.invalidate.current.text", "file status cache")
fileStatusCache.invalidate()
indicator.fraction = 0.50
val logEntryCache = project.service<PijulLogEntryCache>()
indicator.text2 = DraconBundle.message("cache.invalidate.current.text", "pijul log entry cache")
logEntryCache.invalidate()
indicator.fraction = 0.75
val logEntryChangeCache = project.service<PijulLogEntryChangeCache>()
indicator.text2 = DraconBundle.message("cache.invalidate.current.text", "pijul log entry changes cache")
logEntryChangeCache.invalidate()
indicator.fraction = 1.0
indicator.text2 = DraconBundle.message("cache.invalidate.finish.text")
}
}.queue()
}
}