diff --git a/CHANGELOG.md b/CHANGELOG.md index a7b1f04..28d6372 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## 1.2 -- Record and Delete snapshots for a test class or package from the Project View under the More Run/Debug menu +- Record and Delete snapshots for a test class, package or module from the Project View under the More Run/Debug menu ## 1.1 diff --git a/README.md b/README.md index dee79cd..fb7a6a5 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ Features - View previously-recorded golden snapshots for the currently opened test class - View golden snapshots of the current focussed test method - View failure diffs for the current test class or method -- Record, Verify and Delete snapshots for individual tests or for entire test class +- Record, Verify and Delete snapshots for individual tests or for entire test class, package or module - Zoom options for Actual Size and Fit to Window - Fully supported for test files written in Java or Kotlin diff --git a/src/main/kotlin/com/getyourguide/paparazzi/Utils.kt b/src/main/kotlin/com/getyourguide/paparazzi/Utils.kt index d2329b7..b94aefd 100644 --- a/src/main/kotlin/com/getyourguide/paparazzi/Utils.kt +++ b/src/main/kotlin/com/getyourguide/paparazzi/Utils.kt @@ -1,14 +1,9 @@ package com.getyourguide.paparazzi import com.getyourguide.paparazzi.service.Snapshot -import com.intellij.execution.executors.DefaultRunExecutor import com.intellij.openapi.application.ModalityState import com.intellij.openapi.application.ReadAction import com.intellij.openapi.editor.CaretModel -import com.intellij.openapi.externalSystem.model.execution.ExternalSystemTaskExecutionSettings -import com.intellij.openapi.externalSystem.service.execution.ProgressExecutionMode -import com.intellij.openapi.externalSystem.task.TaskCallback -import com.intellij.openapi.externalSystem.util.ExternalSystemUtil import com.intellij.openapi.fileEditor.FileEditor import com.intellij.openapi.fileEditor.TextEditor import com.intellij.openapi.project.Project @@ -25,7 +20,6 @@ import com.intellij.util.concurrency.AppExecutorUtil import org.jetbrains.kotlin.idea.util.projectStructure.getModule import org.jetbrains.kotlin.idea.util.projectStructure.getModuleDir import org.jetbrains.kotlin.psi.psiUtil.parents -import org.jetbrains.plugins.gradle.util.GradleConstants import org.jetbrains.uast.UClass import org.jetbrains.uast.UMethod import org.jetbrains.uast.getContainingUFile @@ -67,17 +61,12 @@ internal fun VirtualFile.methods(project: Project): List { } internal fun Project.modulePath(file: VirtualFile): String? { - basePath?.let { projectPath -> - val relativePath = FileUtil.getRelativePath(projectPath, file.path, File.separatorChar) - val moduleName = relativePath?.split(File.separator)?.firstOrNull() - if (moduleName != null) { - return projectPath + File.separator + moduleName + return modules.asSequence().map { it.getModuleDir() }.firstOrNull { file.path.startsWith(it) } + ?: basePath?.let { projectPath -> + val relativePath = FileUtil.getRelativePath(projectPath, file.path, File.separatorChar) + val moduleName = relativePath?.split(File.separator)?.firstOrNull() + if (moduleName != null) projectPath + File.separator + moduleName else null } - } - return modules - .asSequence() - .map { it.getModuleDir() } - .firstOrNull { file.path.startsWith(it) } } internal inline fun nonBlocking(crossinline asyncAction: () -> T, crossinline uiThreadAction: (T) -> Unit) { diff --git a/src/main/kotlin/com/getyourguide/paparazzi/actions/group/GroupAction.kt b/src/main/kotlin/com/getyourguide/paparazzi/actions/group/GroupAction.kt index 1e48552..f061006 100644 --- a/src/main/kotlin/com/getyourguide/paparazzi/actions/group/GroupAction.kt +++ b/src/main/kotlin/com/getyourguide/paparazzi/actions/group/GroupAction.kt @@ -5,6 +5,7 @@ import com.intellij.openapi.actionSystem.ActionUpdateThread import com.intellij.openapi.actionSystem.AnAction import com.intellij.openapi.actionSystem.AnActionEvent import com.intellij.openapi.actionSystem.LangDataKeys +import com.intellij.openapi.module.ModuleUtilCore import com.intellij.psi.PsiDirectory import com.intellij.psi.PsiFile import com.intellij.psi.PsiRecursiveElementVisitor @@ -18,7 +19,8 @@ abstract class GroupAction(name: String, icon: Icon) : AnAction(name, null, icon override fun update(e: AnActionEvent) { super.update(e) - e.presentation.isVisible = getPaparazziClass(e) != null || getPaparazziDirectory(e) != null + e.presentation.isVisible = + getPaparazziClass(e) != null || getPaparazziDirectory(e) != null || getPaparazziModule(e) != null } override fun getActionUpdateThread() = ActionUpdateThread.BGT @@ -42,6 +44,12 @@ abstract class GroupAction(name: String, icon: Icon) : AnAction(name, null, icon return if (found) psiDirectory else null } + protected fun getPaparazziModule(e: AnActionEvent): PsiDirectory? { + val psiDirectory = LangDataKeys.IDE_VIEW.getData(e.dataContext)?.directories?.firstOrNull() ?: return null + ModuleUtilCore.findModuleForPsiElement(psiDirectory) ?: return null + return psiDirectory + } + private fun PsiDirectory.isPackage(): Boolean { return getPackage()?.qualifiedName?.isNotEmpty() == true } diff --git a/src/main/kotlin/com/getyourguide/paparazzi/actions/group/GroupDeleteAction.kt b/src/main/kotlin/com/getyourguide/paparazzi/actions/group/GroupDeleteAction.kt index 6f413ba..ffe161a 100644 --- a/src/main/kotlin/com/getyourguide/paparazzi/actions/group/GroupDeleteAction.kt +++ b/src/main/kotlin/com/getyourguide/paparazzi/actions/group/GroupDeleteAction.kt @@ -26,14 +26,23 @@ class GroupDeleteAction : GroupAction(ACTION_NAME, AllIcons.Actions.GC) { val snapshots = fileInfo.allSnapshots() val files = snapshots.map { it.file } deleteSnapshots(project, files) - } else { - val psiDirectory = getPaparazziDirectory(e) - if (psiDirectory != null) { - val fileInfoList = getPaparazziFileInfo(psiDirectory, project) - val snapshots = fileInfoList.flatMap { it.allSnapshots() }.map { it.file } - deleteSnapshots(project, snapshots) - } + return + } + val psiDirectory = getPaparazziDirectory(e) + if (psiDirectory != null) { + val fileInfoList = getPaparazziFileInfo(psiDirectory, project) + val snapshots = fileInfoList.flatMap { it.allSnapshots() }.map { it.file } + deleteSnapshots(project, snapshots) + return } + val module = getPaparazziModule(e) + if (module != null) { + val fileInfoList = getPaparazziFileInfo(module, project) + val snapshots = fileInfoList.flatMap { it.allSnapshots() }.map { it.file } + deleteSnapshots(project, snapshots) + return + } + } private fun getPaparazziFileInfo(psiDirectory: PsiDirectory, project: Project): List { diff --git a/src/main/kotlin/com/getyourguide/paparazzi/actions/group/GroupRecordAction.kt b/src/main/kotlin/com/getyourguide/paparazzi/actions/group/GroupRecordAction.kt index 266dc9a..24c83fb 100644 --- a/src/main/kotlin/com/getyourguide/paparazzi/actions/group/GroupRecordAction.kt +++ b/src/main/kotlin/com/getyourguide/paparazzi/actions/group/GroupRecordAction.kt @@ -24,14 +24,21 @@ class GroupRecordAction : GroupAction(ACTION_NAME, AllIcons.Debugger.Db_set_brea val psiClass = uClass.javaPsi val testName = getQualifiedTestName(psiClass, null) runRecordTask(project, testName, modulePath, RecordTaskCallback(project, psiClass, null)) - } else { - val psiDirectory = getPaparazziDirectory(e) - if (psiDirectory != null) { - val modulePath = project.modulePath(psiDirectory.virtualFile) ?: return - val psiPackage = psiDirectory.getPackage() ?: return - val testName = psiPackage.qualifiedName + ".*" - runRecordTask(project, testName, modulePath) - } + return + } + val psiDirectory = getPaparazziDirectory(e) + if (psiDirectory != null) { + val modulePath = project.modulePath(psiDirectory.virtualFile) ?: return + val psiPackage = psiDirectory.getPackage() ?: return + val testName = psiPackage.qualifiedName + ".*" + runRecordTask(project, testName, modulePath) + return + } + val module = getPaparazziModule(e) + if (module != null) { + val modulePath = project.modulePath(module.virtualFile) ?: return + runRecordTask(project, null, modulePath) + return } } diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index e114e7b..e96638d 100644 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -12,7 +12,7 @@
  • View previously-recorded golden snapshots for the current test file opened in the editor
  • View golden snapshots of the current focussed test method
  • View failure diffs for the current test class or method
  • -
  • Record, Verify and Delete snapshots for individual tests or for entire test class
  • +
  • Record, Verify and Delete snapshots for individual tests or for entire test class, package or module
  • Zoom options for Actual Size and Fit to Window
  • Fully supported for test files written in Java or Kotlin
  • @@ -20,7 +20,7 @@ 1.2
      -
    • Record and Delete snapshots for a test class or package from the Project View under the More Run/Debug menu
    • +
    • Record and Delete snapshots for a test class, package or module from the Project View under the More Run/Debug menu

    1.1