-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use
BeforeRunTaskProvider
for Tomcat (#300)
* wip * Moved logic to a callback run in a before run task * Changelog * Doc extended * Extra doc
- Loading branch information
Showing
4 changed files
with
121 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Tomcat executions are now stopped when mirrord setup fails. |
47 changes: 47 additions & 0 deletions
47
...mcat/src/main/kotlin/com/metalbear/mirrord/products/tomcat/TomcatBeforeRunTaskProvider.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package com.metalbear.mirrord.products.tomcat | ||
|
||
import com.intellij.execution.BeforeRunTask | ||
import com.intellij.execution.BeforeRunTaskProvider | ||
import com.intellij.execution.configurations.RunConfiguration | ||
import com.intellij.execution.runners.ExecutionEnvironment | ||
import com.intellij.openapi.actionSystem.DataContext | ||
import com.intellij.openapi.util.Key | ||
|
||
val KEY: Key<TomcatBeforeRunTaskProvider.TomcatBeforeRunTask> = Key("MirrordTomcatBeforeRunTask") | ||
|
||
class TomcatBeforeRunTaskProvider : BeforeRunTaskProvider<TomcatBeforeRunTaskProvider.TomcatBeforeRunTask>() { | ||
/** | ||
* Simple task that only executes the given callback. | ||
* Must throw an [Exception] in case execution should be stopped. | ||
*/ | ||
class TomcatBeforeRunTask(val callback: () -> Unit) : BeforeRunTask<TomcatBeforeRunTask>(KEY) | ||
|
||
override fun getId(): Key<TomcatBeforeRunTask> = KEY | ||
|
||
override fun getName(): String = "TomcatBeforeRunTask" | ||
|
||
/** | ||
* Always returns null. Otherwise, the task would be visible to the users in the run configuration dialog when they add their own before launch tasks. | ||
*/ | ||
override fun createTask(runConfiguration: RunConfiguration): TomcatBeforeRunTask? { | ||
return null | ||
} | ||
|
||
/** | ||
* Returning `false` here prevents the execution. | ||
*/ | ||
override fun executeTask( | ||
context: DataContext, | ||
configuration: RunConfiguration, | ||
environment: ExecutionEnvironment, | ||
task: TomcatBeforeRunTask | ||
): Boolean { | ||
return try { | ||
task.callback.invoke() | ||
true | ||
} catch (_: Exception) { | ||
// Exceptions already handled in `MirrordExecManager` | ||
false | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters