Skip to content

Commit

Permalink
RIDER-99856: Remove notifications when executing from Terminal (#204)
Browse files Browse the repository at this point in the history
  • Loading branch information
seclerp authored Nov 7, 2023
1 parent d60fd2a commit 0e2a3c1
Show file tree
Hide file tree
Showing 32 changed files with 260 additions and 233 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ import com.intellij.openapi.components.service
import com.intellij.openapi.project.Project
import com.jetbrains.rider.plugins.efcore.EfCoreUiBundle
import com.jetbrains.rider.plugins.efcore.cli.api.models.DotnetEfVersion
import com.jetbrains.rider.plugins.efcore.cli.execution.CommonOptions
import com.jetbrains.rider.plugins.efcore.cli.execution.DotnetCommand
import com.jetbrains.rider.plugins.efcore.cli.execution.EfCoreCommandBuilder
import com.jetbrains.rider.plugins.efcore.cli.execution.KnownEfCommands
import com.jetbrains.rider.plugins.efcore.cli.execution.*
import org.jetbrains.annotations.NonNls

@Service(Service.Level.PROJECT)
Expand All @@ -18,17 +15,27 @@ class DatabaseCommandFactory(private val intellijProject: Project) {
fun getInstance(project: Project) = project.service<DatabaseCommandFactory>()
}

fun update(efCoreVersion: DotnetEfVersion, options: CommonOptions, targetMigration: String, connectionString: String? = null): DotnetCommand =
EfCoreCommandBuilder(intellijProject, KnownEfCommands.Database.update, options, EfCoreUiBundle.message("update.database.presentable.name")).apply {
fun update(efCoreVersion: DotnetEfVersion, options: CommonOptions, targetMigration: String, connectionString: String? = null): CliCommand {
val presentation = CliCommandPresentationInfo(
EfCoreUiBundle.message("update.database.presentable.name"),
EfCoreUiBundle.message("database.has.been.updated"))

return EfCoreCommandBuilder(intellijProject, KnownEfCommands.Database.update, options, presentation).apply {
add(targetMigration)

if (efCoreVersion.major >= 5 && connectionString != null) {
addNamed("--connection", connectionString)
}
}.build()
}

fun drop(options: CommonOptions): DotnetCommand =
EfCoreCommandBuilder(intellijProject, KnownEfCommands.Database.drop, options, EfCoreUiBundle.message("drop.database.presentable.name")).apply {
fun drop(options: CommonOptions): CliCommand {
val presentation = CliCommandPresentationInfo(
EfCoreUiBundle.message("drop.database.presentable.name"),
EfCoreUiBundle.message("database.has.been.deleted"))

return EfCoreCommandBuilder(intellijProject, KnownEfCommands.Database.drop, options, presentation).apply {
add("--force")
}.build()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ import com.intellij.openapi.components.service
import com.intellij.openapi.project.Project
import com.jetbrains.rider.plugins.efcore.EfCoreUiBundle
import com.jetbrains.rider.plugins.efcore.cli.api.models.DotnetEfVersion
import com.jetbrains.rider.plugins.efcore.cli.execution.CommonOptions
import com.jetbrains.rider.plugins.efcore.cli.execution.DotnetCommand
import com.jetbrains.rider.plugins.efcore.cli.execution.EfCoreCommandBuilder
import com.jetbrains.rider.plugins.efcore.cli.execution.KnownEfCommands
import com.jetbrains.rider.plugins.efcore.cli.execution.*

@Service(Service.Level.PROJECT)
class DbContextCommandFactory(private val intellijProject: Project) {
Expand All @@ -19,8 +16,12 @@ class DbContextCommandFactory(private val intellijProject: Project) {
fun scaffold(efCoreVersion: DotnetEfVersion, options: CommonOptions, connection: String, provider: String,
outputFolder: String, useAttributes: Boolean, useDatabaseNames: Boolean, generateOnConfiguring: Boolean,
usePluralizer: Boolean, dbContextName: String, dbContextFolder: String, scaffoldAllTables: Boolean,
tablesList: List<String>, scaffoldAllSchemas: Boolean, schemasList: List<String>): DotnetCommand =
EfCoreCommandBuilder(intellijProject, KnownEfCommands.DbContext.scaffold, options, EfCoreUiBundle.message("scaffold.dbcontext.presentable.name")).apply {
tablesList: List<String>, scaffoldAllSchemas: Boolean, schemasList: List<String>): CliCommand {
val presentation = CliCommandPresentationInfo(
EfCoreUiBundle.message("scaffold.dbcontext.presentable.name"),
EfCoreUiBundle.message("dbcontext.has.been.scaffolded"))

return EfCoreCommandBuilder(intellijProject, KnownEfCommands.DbContext.scaffold, options, presentation).apply {
add(connection)
add(provider)

Expand Down Expand Up @@ -49,4 +50,5 @@ class DbContextCommandFactory(private val intellijProject: Project) {
addIf("--no-pluralize", !usePluralizer)
}
}.build()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import com.intellij.openapi.components.Service
import com.intellij.openapi.components.service
import com.intellij.openapi.project.Project
import com.jetbrains.rider.plugins.efcore.EfCoreUiBundle
import com.jetbrains.rider.plugins.efcore.cli.execution.DotnetCommand
import com.jetbrains.rider.plugins.efcore.cli.execution.CliCommand
import com.jetbrains.rider.plugins.efcore.cli.execution.CliCommandPresentationInfo
import com.jetbrains.rider.plugins.efcore.cli.execution.DotnetCommandBuilder

@Service(Service.Level.PROJECT)
Expand All @@ -13,11 +14,16 @@ class ManagementCommandFactory(private val intellijProject: Project) {
fun getInstance(project: Project) = project.service<ManagementCommandFactory>()
}

fun installEfCoreTools(): DotnetCommand =
DotnetCommandBuilder(EfCoreUiBundle.message("install.dotnet.tool.presentable.name"), intellijProject, "tool", "install").apply {
fun installEfCoreTools(): CliCommand {
val presentation = CliCommandPresentationInfo(
EfCoreUiBundle.message("install.dotnet.tool.presentable.name"),
EfCoreUiBundle.message("ef.core.global.tools.have.been.successfully.installed"))

return DotnetCommandBuilder(presentation, intellijProject, "tool", "install").apply {
add("--ignore-failed-sources")
addNamed("--add-source", "https://api.nuget.org/v3/index.json")
add("--global")
add("dotnet-ef")
}.build()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,35 @@ class MigrationsCommandFactory(private val intellijProject: Project) {
fun getInstance(project: Project) = project.service<MigrationsCommandFactory>()
}

fun add(options: CommonOptions, migrationName: String, outputDirectory: String? = null, namespace: String? = null): DotnetCommand =
EfCoreCommandBuilder(intellijProject, KnownEfCommands.Migrations.add, options, EfCoreUiBundle.message("add.migration.presentable.name")).apply {
fun add(options: CommonOptions, migrationName: String, outputDirectory: String? = null, namespace: String? = null): CliCommand {
val presentation = CliCommandPresentationInfo(
EfCoreUiBundle.message("add.migration.presentable.name"),
EfCoreUiBundle.message("new.migration.has.been.created"))

return EfCoreCommandBuilder(intellijProject, KnownEfCommands.Migrations.add, options, presentation).apply {
add(migrationName)
addNamedNullable("--output-dir", outputDirectory)
addNamedNullable("--namespace", namespace)
}.build()
}

fun removeLast(options: CommonOptions): CliCommand {
val presentation = CliCommandPresentationInfo(
EfCoreUiBundle.message("remove.last.migration.presentable.name"),
EfCoreUiBundle.message("last.migration.has.been.removed"))

fun removeLast(options: CommonOptions): DotnetCommand =
EfCoreCommandBuilder(intellijProject, KnownEfCommands.Migrations.remove, options, EfCoreUiBundle.message("remove.last.migration.presentable.name")).apply {
return EfCoreCommandBuilder(intellijProject, KnownEfCommands.Migrations.remove, options, presentation).apply {
add("--force")
}.build()
}

fun generateScript(efCoreVersion: DotnetEfVersion, options: CommonOptions, fromMigration: String, toMigration: String?,
outputFile: String, idempotent: Boolean, noTransactions: Boolean): DotnetCommand =
EfCoreCommandBuilder(intellijProject, KnownEfCommands.Migrations.script, options, EfCoreUiBundle.message("generate.sql.script.presentable.name")).apply {
outputFile: String, idempotent: Boolean, noTransactions: Boolean): CliCommand {
val presentation = CliCommandPresentationInfo(
EfCoreUiBundle.message("generate.sql.script.presentable.name"),
EfCoreUiBundle.message("script.has.been.generated"))

return EfCoreCommandBuilder(intellijProject, KnownEfCommands.Migrations.script, options, presentation).apply {
add(fromMigration)
addNullable(toMigration)
addNamed("--output", outputFile)
Expand All @@ -36,4 +50,5 @@ class MigrationsCommandFactory(private val intellijProject: Project) {
addIf("--no-transactions", noTransactions)
}
}.build()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,8 @@ data class DotnetEfVersion(val major: Int, val minor: Int, val patch: Int) {
return DotnetEfVersion(major.toInt(), minor.toInt(), patch.toInt())
}
}

override fun toString(): String {
return "$major.$minor.$patch"
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package com.jetbrains.rider.plugins.efcore.cli.execution

import com.intellij.execution.configurations.GeneralCommandLine
import com.intellij.openapi.util.NlsContexts

open class DotnetCommand(
open class CliCommand(
val dotnetPath: String,
val commandLine: GeneralCommandLine,
@NlsContexts.TabTitle
val presentableName: String
val presentationInfo: CliCommandPresentationInfo
)
Original file line number Diff line number Diff line change
@@ -1,9 +1,32 @@
package com.jetbrains.rider.plugins.efcore.cli.execution

import com.intellij.openapi.diagnostic.logger
import com.intellij.openapi.project.Project
import com.intellij.openapi.vfs.VirtualFileManager

abstract class CliCommandExecutor(
protected val intellijProject: Project
) {
abstract fun execute(command: DotnetCommand, resultProcessor: CliCommandResultProcessor? = null)
companion object {
val logger = logger<CliCommandExecutor>()
}

suspend fun execute(command: CliCommand): CliCommandResult? {
try {
return doExecute(command)
}
catch (t: Throwable) {
logger.error(t)
return null
}
finally {
refreshSolution()
}
}

protected abstract suspend fun doExecute(command: CliCommand): CliCommandResult?

private fun refreshSolution() {
VirtualFileManager.getInstance().refreshWithoutFileWatcher(true)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.jetbrains.rider.plugins.efcore.cli.execution

import com.intellij.openapi.util.NlsContexts

data class CliCommandPresentationInfo(
@NlsContexts.TabTitle
val name: String,
@NlsContexts.NotificationContent
val onSuccessNotification: String
)

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import java.io.File
import java.nio.charset.Charset

open class DotnetCommandBuilder(
private val presentableName: String,
private val presentation: CliCommandPresentationInfo,
private val intellijProject: Project,
vararg baseCommands: @NonNls String
) {
Expand Down Expand Up @@ -58,7 +58,7 @@ open class DotnetCommandBuilder(
generalCommandLine = generalCommandLine.withParameters(name, value)
}

open fun build() = DotnetCommand(generalCommandLine.exePath, generalCommandLine, presentableName)
open fun build() = CliCommand(generalCommandLine.exePath, generalCommandLine, presentation)

private fun getDotnetExePath() =
activeRuntime?.dotNetCliExePath
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ class EfCoreCommandBuilder(
intellijProject: Project,
baseCommand: String,
private val commonOptions: CommonOptions,
presentableName: String
presentation: CliCommandPresentationInfo
) : DotnetCommandBuilder(
presentableName,
presentation,
intellijProject,
KnownEfCommands.ef, baseCommand
) {
Expand All @@ -24,15 +24,15 @@ class EfCoreCommandBuilder(
addIf("--verbose", commonOptions.enableDiagnosticLogging)
}

override fun build(): DotnetCommand {
override fun build(): CliCommand {
val command = super.build()
var commandLine = command.commandLine
if (commonOptions.additionalArguments.isNotEmpty()) {
add("--")
commandLine = commandLine.withRawParameters(commonOptions.additionalArguments)
}

return DotnetCommand(command.dotnetPath, commandLine, command.presentableName)
return CliCommand(command.dotnetPath, commandLine, command.presentationInfo)
}

private fun makeRelativeProjectPath(projectDirectory: String): String {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ class EfCoreConsoleToolWindowProvider(intellijProject: Project) {
}
}

fun createTab(command: DotnetCommand, console: ConsoleView) {
fun createTab(command: CliCommand, console: ConsoleView) {
val contentManager = toolWindow.contentManager
val factory = contentManager.factory
val content = factory.createContent(console.component, command.presentableName, true)
val content = factory.createContent(console.component, command.presentationInfo.name, true)
contentManager.addContent(content)
toolWindow.activate {
contentManager.setSelectedContent(content)
Expand Down

This file was deleted.

Loading

0 comments on commit 0e2a3c1

Please sign in to comment.