Skip to content

Commit

Permalink
1.19.3: fix explicitly specified javaExec in checkmodels and generate
Browse files Browse the repository at this point in the history
  • Loading branch information
sergej-koscejev committed Oct 27, 2023
1 parent 72424d4 commit ed225b9
Show file tree
Hide file tree
Showing 6 changed files with 122 additions and 46 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
7 changes: 5 additions & 2 deletions src/main/kotlin/de/itemis/mps/gradle/generate/Plugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,13 @@ open class GenerateMpsProjectPlugin : Plugin<Project> {
}
})

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"))
Expand Down
6 changes: 4 additions & 2 deletions src/main/kotlin/de/itemis/mps/gradle/modelcheck/Plugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,12 @@ open class ModelcheckMpsProjectPlugin : Plugin<Project> {
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"
Expand Down
44 changes: 44 additions & 0 deletions src/test/kotlin/test/de/itemis/mps/gradle/GenerateModelsTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
}
}
102 changes: 61 additions & 41 deletions src/test/kotlin/test/de/itemis/mps/gradle/ModelCheckWithPluginTest.kt
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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")
Expand All @@ -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") + """
Expand All @@ -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") +
Expand All @@ -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") +
Expand All @@ -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") +
Expand All @@ -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") +
Expand All @@ -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") +
Expand All @@ -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") +
Expand All @@ -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") +
Expand Down

0 comments on commit ed225b9

Please sign in to comment.