Skip to content

Commit

Permalink
Merge branch 'feature/IJMP-1819' into 'release/v2.1.0'
Browse files Browse the repository at this point in the history
IJMP-1819: add check for folder sync

See merge request ijmp/for-mainframe!609
  • Loading branch information
Dzianis Lisiankou committed Oct 31, 2024
2 parents e695d47 + 236ab50 commit fbf4240
Show file tree
Hide file tree
Showing 7 changed files with 264 additions and 159 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ package eu.ibagroup.formainframe.explorer.actions
import com.intellij.openapi.actionSystem.ActionUpdateThread
import com.intellij.openapi.actionSystem.AnAction
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.progress.runBackgroundableTask
import com.intellij.openapi.progress.runModalTask
import com.intellij.openapi.project.Project
import com.intellij.openapi.vfs.VirtualFile
import eu.ibagroup.formainframe.analytics.AnalyticsService
Expand Down Expand Up @@ -64,7 +64,7 @@ class RenameAction : AnAction() {
newName: String,
node: ExplorerTreeNode<*, *>
) {
runBackgroundableTask(
runModalTask(
title = "Renaming $type ${file.name} to $newName",
project = project,
cancellable = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,9 @@ class ExplorerPasteProvider : PasteProvider {
excludedOperations.forEach { operation ->
copyPasteSupport.removeFromBuffer { nodeData -> nodeData.file == operation.source }
}

val filesToMoveTotal = filteredOperations.size
if (filesToMoveTotal == 0) return

runMoveOrCopyTask(
titlePrefix,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package eu.ibagroup.formainframe.explorer.ui

import com.intellij.ide.projectView.PresentationData
import com.intellij.ide.util.treeView.AbstractTreeNode
import com.intellij.openapi.progress.runBackgroundableTask
import com.intellij.openapi.project.Project
import com.intellij.openapi.vfs.VirtualFile
import com.intellij.ui.SimpleTextAttributes
Expand Down Expand Up @@ -139,10 +138,11 @@ abstract class FileFetchNode<Connection : ConnectionConfigBase, Value : Any, R :
} else {
if (possibleToFetch) {
possibleToFetch = false
runBackgroundableTask(
runBackgroundableSyncTask(
title = makeFetchTaskTitle(q),
project = project,
cancellable = true
cancellable = true,
virtualFile = virtualFile
) {
var isMembersFetchOnInvalidDS = false
// This functionality is going to skip the fetch of dataset members
Expand Down
27 changes: 27 additions & 0 deletions src/main/kotlin/eu/ibagroup/formainframe/utils/openapiUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import com.intellij.openapi.fileEditor.FileEditorManager
import com.intellij.openapi.progress.ProgressIndicator
import com.intellij.openapi.progress.ProgressManager
import com.intellij.openapi.progress.Task
import com.intellij.openapi.progress.runBackgroundableTask
import com.intellij.openapi.project.Project
import com.intellij.openapi.project.ProjectManager
import com.intellij.openapi.vfs.VirtualFile
Expand All @@ -34,6 +35,7 @@ import eu.ibagroup.formainframe.dataops.attributes.FileAttributes
import eu.ibagroup.formainframe.dataops.attributes.RemoteDatasetAttributes
import eu.ibagroup.formainframe.dataops.attributes.RemoteMemberAttributes
import eu.ibagroup.formainframe.dataops.attributes.RemoteUssAttributes
import eu.ibagroup.formainframe.dataops.content.service.SyncProcessService
import org.jetbrains.annotations.Nls
import org.jetbrains.concurrency.AsyncPromise
import org.jetbrains.concurrency.Promise
Expand Down Expand Up @@ -176,6 +178,31 @@ inline fun <reified T> runTask(
})
}

/**
* Run the specified task in the background with sync tracking
* @param title the title of the task to be shown in the progress
* @param project the optional project value to make the specific project handling
* @param cancellable the value to specify if the task is cancellable
* @param virtualFile the virtual file for sync tracking
* @param task the task to execute
*/
inline fun runBackgroundableSyncTask(
title: String,
project: Project? = null,
cancellable: Boolean = true,
virtualFile: VirtualFile? = null,
crossinline task: (indicator: ProgressIndicator) -> Unit
) {
runBackgroundableTask(title, project, cancellable) { indicator ->
virtualFile?.let { SyncProcessService.getService().startFileSync(it, indicator) }
runCatching {
task(indicator)
}.also {
virtualFile?.let { SyncProcessService.getService().stopFileSync(it) }
}
}
}

fun runInEdtAndWait(runnable: () -> Unit) {
ApplicationManager.getApplication().invokeAndWait(runnable)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package eu.ibagroup.formainframe.explorer.ui
import com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode
import com.intellij.openapi.actionSystem.CommonDataKeys
import com.intellij.openapi.actionSystem.DataContext
import com.intellij.openapi.components.service
import com.intellij.openapi.progress.ProgressIndicator
import com.intellij.openapi.project.Project
import com.intellij.openapi.ui.Messages
Expand Down Expand Up @@ -1799,7 +1798,7 @@ class ExplorerPasteProviderTestSpec : WithApplicationShouldSpec({
}

should("filter operations with files that are currently being synchronized") {
var filesToMoveTotal = 1
isPastePerformed = false

every { mockedDataContext.getData(IS_DRAG_AND_DROP_KEY) } returns null
every { mockedDataContext.getData(CommonDataKeys.PROJECT) } returns mockedProject
Expand All @@ -1821,7 +1820,7 @@ class ExplorerPasteProviderTestSpec : WithApplicationShouldSpec({
any<Project>()
)
} answers {
filesToMoveTotal = secondArg<Int>()
isPastePerformed = true
this
}

Expand All @@ -1830,7 +1829,7 @@ class ExplorerPasteProviderTestSpec : WithApplicationShouldSpec({
clearMocks(mockedExplorerPasteProvider)

assertSoftly {
filesToMoveTotal shouldBe 0
isPastePerformed shouldBe false
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* Copyright (c) 2024 IBA Group.
*
* This program and the accompanying materials are made available under the terms of the
* Eclipse Public License v2.0 which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-v20.html
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* IBA Group
* Zowe Community
*/

package eu.ibagroup.formainframe.utils

import com.intellij.openapi.progress.ProgressIndicator
import com.intellij.openapi.vfs.VirtualFile
import eu.ibagroup.formainframe.dataops.content.service.SyncProcessService
import eu.ibagroup.formainframe.testutils.WithApplicationShouldSpec
import eu.ibagroup.formainframe.testutils.testServiceImpl.TestSyncProcessServiceImpl
import io.kotest.assertions.assertSoftly
import io.kotest.matchers.shouldBe
import io.mockk.mockk

class OpenapiUtilsTestSpec : WithApplicationShouldSpec({

context("runBackgroundableSyncTask") {

var isStartFileSyncPerformed = false
var isStopFileSyncPerformed = false

beforeEach {
isStartFileSyncPerformed = false
isStopFileSyncPerformed = false

val syncProcessService = SyncProcessService.getService() as TestSyncProcessServiceImpl
syncProcessService.testInstance = object : TestSyncProcessServiceImpl() {
override fun startFileSync(file: VirtualFile, progressIndicator: ProgressIndicator) {
isStartFileSyncPerformed = true
}

override fun stopFileSync(file: VirtualFile) {
isStopFileSyncPerformed = true
}
}
}

should("run backgroundable sync task when virtual file is null") {
runBackgroundableSyncTask(
"Title",
null,
true,
null,
) { }

assertSoftly {
isStartFileSyncPerformed shouldBe false
isStopFileSyncPerformed shouldBe false
}
}
should("run backgroundable sync task when virtual file is not null") {
runBackgroundableSyncTask(
"Title",
null,
true,
mockk(),
) { }

assertSoftly {
isStartFileSyncPerformed shouldBe true
isStopFileSyncPerformed shouldBe true
}
}

}
})
Loading

0 comments on commit fbf4240

Please sign in to comment.