Skip to content

Commit

Permalink
Merge pull request #147 from kolmar/runMigrations_haltOnDependencyError
Browse files Browse the repository at this point in the history
runMigrations: add haltOnDependencyError flag
  • Loading branch information
HeikoBecker authored Oct 10, 2023
2 parents 56feaf7 + a8ea389 commit d67a4c3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,9 @@ Parameters:
* `mpsLocation` - location where to place the MPS files.
* `mpsVersion` - if you use a [custom distribution](#custom-mps-distribution) of MPS.
* `projectLocation` - location of the project that should be migrated.
* `force` - ignores the marker files for projects which allow pending migrations, migrate them anyway (supported in 2021.3.0 and higher)
* `force` - ignores the marker files for projects which allow pending migrations, migrate them anyway. Supported in 2021.3.0 and higher.
* `haltOnPrecheckFailure` - controls whether migration is aborted if pre-checks fail (except the check for migrated dependecies) Default: `true`. Supported in 2021.1 and higher.
* `haltOnDependencyError` - controls whether migration is aborted when non-migrated dependencies are discovered. Default: `true`. Supported in 2021.3.4 and 2023.2 and higher.
* `maxHeap` (since 1.15) - maximum heap size setting for the JVM that executes the migrations. The value is a string
understood by the JVM command line argument `-Xmx` e.g. `3G` or `512M`.

Expand Down
20 changes: 15 additions & 5 deletions src/main/kotlin/de/itemis/mps/gradle/runmigrations/Plugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,27 @@ import javax.inject.Inject

open class MigrationExecutorPluginExtensions @Inject constructor(of: ObjectFactory) : BasePluginExtensions(of) {
/**
* (Since MPS 2021.1) Whether to halt if a pre-check has failed. Note that the check for migrated dependencies
* cannot be skipped.
* (Since MPS 2021.1) Whether to halt if a pre-check has failed. Note that to ignore the check for migrated
* dependencies the [haltOnDependencyError] option must be set to `false` as well.
*/
var haltOnPrecheckFailure: Boolean? = null

/**
* (Since MPS 2021.3) Whether to force a migration even if the project directory contains `.allow-pending-migrations` file.
* (Since MPS 2021.3.4) Whether to halt when a non-migrated dependency is discovered.
*/
var haltOnDependencyError: Boolean? = null

/**
* (Since MPS 2021.3) Whether to force a migration even if the project directory contains `.allow-pending-migrations` file.
*/
var force: Boolean? = null
}

@Suppress("unused")
open class RunMigrationsMpsProjectPlugin : Plugin<Project> {
companion object {
val MIN_VERSION_FOR_HALT_ON_PRECHECK_FAILURE = SemVer(2021, 1)
val MIN_VERSION_FOR_HALT_ON_DEPENDENCY_ERROR = SemVer(2021, 3, 4)
val MIN_VERSION_FOR_FORCE = SemVer(2021, 3)
}

Expand All @@ -57,6 +62,10 @@ open class RunMigrationsMpsProjectPlugin : Plugin<Project> {
throw GradleException("The 'do not halt on pre-check failure' option is only supported for MPS version $MIN_VERSION_FOR_HALT_ON_PRECHECK_FAILURE and higher.")
}

if (extension.haltOnDependencyError != null && parsedMPSVersion < MIN_VERSION_FOR_HALT_ON_DEPENDENCY_ERROR) {
throw GradleException("The 'do not halt on dependency error' option is only supported for MPS version $MIN_VERSION_FOR_HALT_ON_DEPENDENCY_ERROR and higher.")
}

val resolveMps: Task = if (extension.mpsConfig != null) {
tasks.create("resolveMpsForMigrations", Copy::class.java) {
from({ extension.mpsConfig!!.resolve().map(::zipTree) })
Expand Down Expand Up @@ -84,8 +93,9 @@ open class RunMigrationsMpsProjectPlugin : Plugin<Project> {
add("project" to projectLocation)
add("mpsHome" to mpsLocation)

if (extension.force != null) add("force" to extension.force!!)
if (extension.haltOnPrecheckFailure != null) add("haltOnPrecheckFailure" to extension.haltOnPrecheckFailure!!)
extension.force?.let { add("force" to it) }
extension.haltOnPrecheckFailure?.let { add("haltOnPrecheckFailure" to it) }
extension.haltOnDependencyError?.let { add("haltOnDependencyError" to it) }

toTypedArray()
}
Expand Down

0 comments on commit d67a4c3

Please sign in to comment.