From ed225b9644b1f1dc124fdb43d2e778ecaa82de64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergej=20Ko=C5=A1=C4=8Dejev?= Date: Fri, 27 Oct 2023 16:23:50 +0200 Subject: [PATCH] 1.19.3: fix explicitly specified javaExec in checkmodels and generate --- CHANGELOG.md | 7 ++ build.gradle.kts | 2 +- .../de/itemis/mps/gradle/generate/Plugin.kt | 7 +- .../de/itemis/mps/gradle/modelcheck/Plugin.kt | 6 +- .../itemis/mps/gradle/GenerateModelsTest.kt | 44 ++++++++ .../mps/gradle/ModelCheckWithPluginTest.kt | 102 +++++++++++------- 6 files changed, 122 insertions(+), 46 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d889dd9f..5f795563 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,13 @@ 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.19.3 + +### Fixed + +- Support for explicitly setting `javaExec` property of `generate` and `checkmodels` (the Java executable to use) was + broken in 1.19.1 and 1.19.2 and should now be fixed. + ## 1.19.2 ### Fixed diff --git a/build.gradle.kts b/build.gradle.kts index fa7c1374..b1973aac 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.19.2" +val baseVersion = "1.19.3" group = "de.itemis.mps" diff --git a/src/main/kotlin/de/itemis/mps/gradle/generate/Plugin.kt b/src/main/kotlin/de/itemis/mps/gradle/generate/Plugin.kt index 60ea60d8..cd4a6182 100644 --- a/src/main/kotlin/de/itemis/mps/gradle/generate/Plugin.kt +++ b/src/main/kotlin/de/itemis/mps/gradle/generate/Plugin.kt @@ -83,10 +83,13 @@ open class GenerateMpsProjectPlugin : Plugin { } }) - if (extension.javaExec != null) + if (extension.javaExec != null) { + javaLauncher.set(null) executable(extension.javaExec!!) - else + } else { validateDefaultJvm() + } + group = "build" description = "Generates models in the project" classpath(fileTree(File(mpsLocation, "/lib")).include("**/*.jar")) diff --git a/src/main/kotlin/de/itemis/mps/gradle/modelcheck/Plugin.kt b/src/main/kotlin/de/itemis/mps/gradle/modelcheck/Plugin.kt index 544f59b9..4e108a88 100644 --- a/src/main/kotlin/de/itemis/mps/gradle/modelcheck/Plugin.kt +++ b/src/main/kotlin/de/itemis/mps/gradle/modelcheck/Plugin.kt @@ -84,10 +84,12 @@ open class ModelcheckMpsProjectPlugin : Plugin { args }) - if (extension.javaExec != null) + if (extension.javaExec != null) { + javaLauncher.set(null) executable(extension.javaExec!!) - else + } else { validateDefaultJvm() + } group = "test" description = "Check models in the project" diff --git a/src/test/kotlin/test/de/itemis/mps/gradle/GenerateModelsTest.kt b/src/test/kotlin/test/de/itemis/mps/gradle/GenerateModelsTest.kt index 3a0897a1..62439b2d 100644 --- a/src/test/kotlin/test/de/itemis/mps/gradle/GenerateModelsTest.kt +++ b/src/test/kotlin/test/de/itemis/mps/gradle/GenerateModelsTest.kt @@ -301,4 +301,48 @@ class GenerateModelsTest { .buildAndFail() MatcherAssert.assertThat(result.output, CoreMatchers.containsString(ErrorMessages.MUST_SET_CONFIG_OR_VERSION)) } + + @Test + fun `explicit javaExec`() { + buildFile.writeText( + """ + import de.itemis.mps.gradle.downloadJBR.DownloadJbrForPlatform + + plugins { + id("generate-models") + id("download-jbr") + } + + downloadJbr { + jbrVersion = "11_0_10-b1341.41" + } + + generate { + projectLocation = projectDir + mpsLocation = file("build/mps") + mpsVersion = "2020.3.3" + javaExec = (tasks.getByName("downloadJbr") as DownloadJbrForPlatform).javaExecutable + } + + tasks.register("verify") { + doLast { + val generateLauncherPresent = (tasks.getByName("generate") as JavaExec).javaLauncher.isPresent + println("generate.javaLauncher.isPresent: " + generateLauncherPresent) + } + } + """.trimIndent() + ) + + val result = GradleRunner.create() + .withProjectDir(testProjectDir.root) + .withArguments("verify") + .withPluginClasspath() + .build() + + Assert.assertEquals(TaskOutcome.SUCCESS, result.task(":verify")?.outcome) + + // When javaExec is explicitly set, the launcher should be absent + Assert.assertTrue("generate.javaLauncher should not be present", + result.output.contains("generate.javaLauncher.isPresent: false")) + } } \ No newline at end of file diff --git a/src/test/kotlin/test/de/itemis/mps/gradle/ModelCheckWithPluginTest.kt b/src/test/kotlin/test/de/itemis/mps/gradle/ModelCheckWithPluginTest.kt index 0394c699..194ceef9 100644 --- a/src/test/kotlin/test/de/itemis/mps/gradle/ModelCheckWithPluginTest.kt +++ b/src/test/kotlin/test/de/itemis/mps/gradle/ModelCheckWithPluginTest.kt @@ -1,6 +1,10 @@ package test.de.itemis.mps.gradle import de.itemis.mps.gradle.ErrorMessages +import de.itemis.mps.gradle.downloadJBR.DownloadJbrConfiguration +import de.itemis.mps.gradle.modelcheck.ModelCheckPluginExtensions +import org.gradle.kotlin.dsl.configure +import org.gradle.testfixtures.ProjectBuilder import org.gradle.testkit.runner.GradleRunner import org.gradle.testkit.runner.TaskOutcome import org.hamcrest.CoreMatchers @@ -31,6 +35,10 @@ class ModelCheckWithPluginTest { private fun extractProject(name: String) = extractTestProject(name, mpsTestPrjLocation) + private fun settingsBoilerplate() = """ + rootProject.name = "hello-world" + """.trimIndent() + private fun buildScriptBoilerplate(mpsVersion: String) = """ plugins { id("modelcheck") @@ -49,14 +57,10 @@ class ModelCheckWithPluginTest { """.trimIndent() + "\n" @Test - fun `check model works with latest MPS`() { + fun `check model works with MPS 2020_3_3`() { extractProject("test-project") - settingsFile.writeText( - """ - rootProject.name = "hello-world" - """.trimIndent() - ) + settingsFile.writeText(settingsBoilerplate()) buildFile.writeText( buildScriptBoilerplate("2020.3.3") + """ @@ -77,15 +81,55 @@ class ModelCheckWithPluginTest { Assert.assertTrue(junitFile.exists()) } + @Test + fun `explicit javaExec`() { + buildFile.writeText( + """ + import de.itemis.mps.gradle.downloadJBR.DownloadJbrForPlatform + + plugins { + id("modelcheck") + id("download-jbr") + } + + downloadJbr { + jbrVersion = "11_0_10-b1341.41" + } + + modelcheck { + projectLocation = projectDir + mpsLocation = file("build/mps") + mpsVersion = "2020.3.3" + javaExec = (tasks.getByName("downloadJbr") as DownloadJbrForPlatform).javaExecutable + } + + tasks.register("verify") { + doLast { + val checkmodelsLauncherPresent = (tasks.getByName("checkmodels") as JavaExec).javaLauncher.isPresent + println("checkmodels.javaLauncher.isPresent: " + checkmodelsLauncherPresent) + } + } + """.trimIndent() + ) + + val result = GradleRunner.create() + .withProjectDir(testProjectDir.root) + .withArguments("verify") + .withPluginClasspath() + .build() + + Assert.assertEquals(TaskOutcome.SUCCESS, result.task(":verify")?.outcome) + + // When javaExec is explicitly set, the launcher should be absent + Assert.assertTrue("checkmodels.javaLauncher should not be present", + result.output.contains("checkmodels.javaLauncher.isPresent: false")) + } + @Test fun `check model fails if errors are found`() { extractProject("test-project-with-errors") - settingsFile.writeText( - """ - rootProject.name = "hello-world" - """.trimIndent() - ) + settingsFile.writeText(settingsBoilerplate()) buildFile.writeText( buildScriptBoilerplate("2021.1.4") + @@ -111,11 +155,7 @@ class ModelCheckWithPluginTest { fun `check model works with latest MPS and excluded models`() { extractProject("test-project-with-errors") - settingsFile.writeText( - """ - rootProject.name = "hello-world" - """.trimIndent() - ) + settingsFile.writeText(settingsBoilerplate()) buildFile.writeText( buildScriptBoilerplate("2021.1.4") + @@ -142,11 +182,7 @@ class ModelCheckWithPluginTest { fun `check model fails with unsupported MPS`() { extractProject("test-project") - settingsFile.writeText( - """ - rootProject.name = "hello-world" - """.trimIndent() - ) + settingsFile.writeText(settingsBoilerplate()) buildFile.writeText( buildScriptBoilerplate("2019.3.7") + @@ -172,11 +208,7 @@ class ModelCheckWithPluginTest { fun `check model works with set MPS version and path`() { extractProject("test-project") - settingsFile.writeText( - """ - rootProject.name = "hello-world" - """.trimIndent() - ) + settingsFile.writeText(settingsBoilerplate()) buildFile.writeText( buildScriptBoilerplate("2020.3.3") + @@ -201,11 +233,7 @@ class ModelCheckWithPluginTest { fun `check model fails with set MPS invalid version and path`() { extractProject("test-project") - settingsFile.writeText( - """ - rootProject.name = "hello-world" - """.trimIndent() - ) + settingsFile.writeText(settingsBoilerplate()) buildFile.writeText( buildScriptBoilerplate("2020.3.3") + @@ -230,11 +258,7 @@ class ModelCheckWithPluginTest { fun `check model fails with only MPS version set`() { extractProject("test-project") - settingsFile.writeText( - """ - rootProject.name = "hello-world" - """.trimIndent() - ) + settingsFile.writeText(settingsBoilerplate()) buildFile.writeText( buildScriptBoilerplate("2020.3.3") + @@ -257,11 +281,7 @@ class ModelCheckWithPluginTest { } @Test fun `check model fails with only MPS path set`() { - settingsFile.writeText( - """ - rootProject.name = "hello-world" - """.trimIndent() - ) + settingsFile.writeText(settingsBoilerplate()) buildFile.writeText( buildScriptBoilerplate("2020.3.3") +