Disallow unsafe reads of KPM PluginData from Compile Task
This commit is contained in:
+6
@@ -10,6 +10,12 @@ import kotlin.test.assertTrue
|
|||||||
|
|
||||||
class KpmCompilerPluginIT : BaseGradleIT() {
|
class KpmCompilerPluginIT : BaseGradleIT() {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gradle implementation of KPM uses features of 6.4+ version
|
||||||
|
*/
|
||||||
|
override val defaultGradleVersion: GradleVersionRequired
|
||||||
|
get() = GradleVersionRequired.AtLeast("6.4")
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testTransientPluginOptions() {
|
fun testTransientPluginOptions() {
|
||||||
val project = transformProjectWithPluginsDsl("kpmTransientPluginOptions")
|
val project = transformProjectWithPluginsDsl("kpmTransientPluginOptions")
|
||||||
|
|||||||
+20
@@ -118,6 +118,26 @@ class KpmCompilerPluginTest {
|
|||||||
assertEquals(1, pluginDataObtainCount)
|
assertEquals(1, pluginDataObtainCount)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `it should not be possible to read plugin data during configuration phase`() {
|
||||||
|
val project = buildProjectWithKPM {
|
||||||
|
plugins.apply(TestPluginWithListeners::class.java)
|
||||||
|
|
||||||
|
projectModel {
|
||||||
|
main {
|
||||||
|
jvm
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Getting task shouldn't fail due to laziness
|
||||||
|
val task = tasks.getByName("compileKotlinJvm") as AbstractKotlinCompile<*>
|
||||||
|
// But trying to get pluginData during "configuration" should fail
|
||||||
|
assertFailsWith<IllegalStateException> { task.kotlinPluginData!!.get() }
|
||||||
|
}
|
||||||
|
|
||||||
|
project.evaluate()
|
||||||
|
}
|
||||||
|
|
||||||
private fun Project.pluginDataOfTask(taskName: String) = this
|
private fun Project.pluginDataOfTask(taskName: String) = this
|
||||||
.tasks
|
.tasks
|
||||||
.getByName(taskName)
|
.getByName(taskName)
|
||||||
|
|||||||
+1
-1
@@ -42,7 +42,7 @@ private fun Project.compilerPluginDataProvider(
|
|||||||
val builder = CompilerPluginOptionsBuilder(project, configurationName)
|
val builder = CompilerPluginOptionsBuilder(project, configurationName)
|
||||||
builder += pluginDataList()
|
builder += pluginDataList()
|
||||||
builder.build()
|
builder.build()
|
||||||
}.apply { finalizeValueOnRead() }
|
}.apply { disallowUnsafeRead() }
|
||||||
}
|
}
|
||||||
|
|
||||||
internal class CompilerPluginOptionsBuilder(
|
internal class CompilerPluginOptionsBuilder(
|
||||||
|
|||||||
Reference in New Issue
Block a user