From f28e9fc21ed3472d0f4b1538719fc0fe732decb1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergej=20Ko=C5=A1=C4=8Dejev?= Date: Sun, 4 Feb 2024 20:54:39 +0100 Subject: [PATCH] 1.23.0: Add MpsMigrate task --- CHANGELOG.md | 6 + README.md | 35 +++ api/mps-gradle-plugin.api | 18 ++ build.gradle.kts | 2 +- .../de/itemis/mps/gradle/tasks/Libraries.kt | 36 +++ .../de/itemis/mps/gradle/tasks/MpsMigrate.kt | 222 ++++++++++++++++++ .../de/itemis/mps/gradle/RunMigrationsTest.kt | 38 +++ 7 files changed, 356 insertions(+), 1 deletion(-) create mode 100644 src/main/kotlin/de/itemis/mps/gradle/tasks/Libraries.kt create mode 100644 src/main/kotlin/de/itemis/mps/gradle/tasks/MpsMigrate.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index 10c2e7e5..369919f2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## 1.23.0 + +### Added + +- `MpsMigrate` task for migrating a project (or projects), similar to the `runMigrations` extension. + ## 1.22.2 ### Fixed diff --git a/README.md b/README.md index 88b09cad..648a20ab 100644 --- a/README.md +++ b/README.md @@ -546,6 +546,41 @@ Parameters: Compatibility note: `MpsGenerate` task currently extends `JavaExec` but this may change in the future. Do not rely on this. +## `MpsMigrate` Task Type + +Migrates the specified projects. + +### Usage + +```groovy +import de.itemis.mps.gradle.tasks.MpsMigrate + +plugins { + // Required in order to use the task + id("de.itemis.mps.gradle.common") +} + +tasks.register('migrate', MpsMigrate) { + mpsHome = mpsHomeDir + + // MpsMigrate task can migrate multiple projects at once + projectDirectories.from(projectDir) + + ... +} +``` + +Parameters: + +* `mpsHome` - the home directory of the MPS distribution (or RCP) to use for testing. +* `mpsVersion` - the MPS version, such as "2021.3". Autodetected by reading `$mpsHome/build.properties` by default. +* `haltOnPrecheckFailure` - fail if the migration pre-check (e.g. broken references) fails. +* `haltOnDependencyError` - fail if non-migrated dependencies are found. +* `projectDirectories` - project directories to migrate. +* `folderMacros` - path variables/macros that are necessary to open the project. Path macros are not considered part of + Gradle build cache key. +* `pluginRoots` - directories that will be searched (recursively) for additional plugins to load. + ## Run migrations Run all pending migrations in the project. diff --git a/api/mps-gradle-plugin.api b/api/mps-gradle-plugin.api index 7a201482..31e0320a 100644 --- a/api/mps-gradle-plugin.api +++ b/api/mps-gradle-plugin.api @@ -359,3 +359,21 @@ public abstract class de/itemis/mps/gradle/tasks/MpsGenerate : org/gradle/api/ta public final fun getVarMacros ()Lorg/gradle/api/provider/MapProperty; } +public abstract class de/itemis/mps/gradle/tasks/MpsMigrate : org/gradle/api/DefaultTask { + public fun (Lorg/gradle/api/model/ObjectFactory;Lorg/gradle/api/provider/ProviderFactory;)V + public final fun execute ()V + protected final fun getAllProjectFiles ()Lorg/gradle/api/provider/Provider; + public final fun getAntJvmArgs ()Lorg/gradle/api/provider/ListProperty; + public final fun getFolderMacros ()Lorg/gradle/api/provider/MapProperty; + public final fun getHaltOnDependencyError ()Lorg/gradle/api/provider/Property; + public final fun getHaltOnPrecheckFailure ()Lorg/gradle/api/provider/Property; + public final fun getJavaExecutable ()Lorg/gradle/api/file/RegularFileProperty; + public final fun getJavaLauncher ()Lorg/gradle/api/provider/Property; + public final fun getJvmArgs ()Lorg/gradle/api/provider/ListProperty; + public final fun getMaxHeapSize ()Lorg/gradle/api/provider/Property; + public final fun getMpsHome ()Lorg/gradle/api/file/DirectoryProperty; + public final fun getMpsVersion ()Lorg/gradle/api/provider/Property; + public final fun getPluginRoots ()Lorg/gradle/api/file/ConfigurableFileCollection; + public final fun getProjectDirectories ()Lorg/gradle/api/file/ConfigurableFileCollection; +} + diff --git a/build.gradle.kts b/build.gradle.kts index 3e0af992..d96c84fc 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -24,7 +24,7 @@ plugins { id("org.jetbrains.kotlinx.binary-compatibility-validator") version "0.13.2" } -val baseVersion = "1.22.2" +val baseVersion = "1.23.0" group = "de.itemis.mps" diff --git a/src/main/kotlin/de/itemis/mps/gradle/tasks/Libraries.kt b/src/main/kotlin/de/itemis/mps/gradle/tasks/Libraries.kt new file mode 100644 index 00000000..ab96d00d --- /dev/null +++ b/src/main/kotlin/de/itemis/mps/gradle/tasks/Libraries.kt @@ -0,0 +1,36 @@ +package de.itemis.mps.gradle.tasks + +import org.gradle.api.file.Directory +import java.io.File +import java.io.FileNotFoundException + +internal fun readLibraries(projectDir: File, getMacroPath: (String) -> Directory?) = try { + projectDir.resolve(".mps/libraries.xml").useLines { lines -> + lines + .map { pathRegex.find(it) } + .filterNotNull() + .map { it.groups[1]!!.value } + .map { substituteMacros(it, projectDir, getMacroPath) } + .toList() + } +} catch (e : FileNotFoundException) { + listOf() +} + +private val pathRegex = """