diff --git a/libraries/tools/kotlin-allopen/build.gradle b/libraries/tools/kotlin-allopen/build.gradle index bc2b760f09b..f4d3614c409 100644 --- a/libraries/tools/kotlin-allopen/build.gradle +++ b/libraries/tools/kotlin-allopen/build.gradle @@ -10,12 +10,17 @@ repositories { dependencies { compile project(':kotlin-gradle-plugin-api') + compile project(':kotlin-gradle-plugin-model') compile project(':kotlin-stdlib') compileOnly project(path: ':kotlin-compiler-embeddable', configuration: 'runtimeJar') compileOnly project(':kotlin-allopen-compiler-plugin') compileOnly gradleApi() + + testCompile gradleApi() + testCompile "junit:junit:4.12" + testCompile "nl.jqno.equalsverifier:equalsverifier:2.1.5" } evaluationDependsOn(":kotlin-allopen-compiler-plugin") @@ -44,4 +49,6 @@ pluginBundle { description = displayName = 'Kotlin Spring compiler plugin' } } -} \ No newline at end of file +} + +test.executable = "${JDK_18}/bin/java" \ No newline at end of file diff --git a/libraries/tools/kotlin-allopen/src/main/kotlin/org/jetbrains/kotlin/allopen/gradle/AllOpenSubplugin.kt b/libraries/tools/kotlin-allopen/src/main/kotlin/org/jetbrains/kotlin/allopen/gradle/AllOpenSubplugin.kt index e31a6c38588..638c24014e9 100644 --- a/libraries/tools/kotlin-allopen/src/main/kotlin/org/jetbrains/kotlin/allopen/gradle/AllOpenSubplugin.kt +++ b/libraries/tools/kotlin-allopen/src/main/kotlin/org/jetbrains/kotlin/allopen/gradle/AllOpenSubplugin.kt @@ -22,12 +22,15 @@ import org.gradle.api.artifacts.ResolvedArtifact import org.gradle.api.internal.AbstractTask import org.gradle.api.tasks.SourceSet import org.gradle.api.tasks.compile.AbstractCompile +import org.gradle.tooling.provider.model.ToolingModelBuilderRegistry +import org.jetbrains.kotlin.allopen.gradle.model.builder.AllOpenModelBuilder import org.jetbrains.kotlin.gradle.plugin.JetBrainsSubpluginArtifact import org.jetbrains.kotlin.gradle.plugin.KotlinGradleSubplugin import org.jetbrains.kotlin.gradle.plugin.SubpluginArtifact import org.jetbrains.kotlin.gradle.plugin.SubpluginOption +import javax.inject.Inject -class AllOpenGradleSubplugin : Plugin { +class AllOpenGradleSubplugin @Inject internal constructor(private val registry: ToolingModelBuilderRegistry) : Plugin { companion object { fun isEnabled(project: Project) = project.plugins.findPlugin(AllOpenGradleSubplugin::class.java) != null @@ -38,6 +41,7 @@ class AllOpenGradleSubplugin : Plugin { override fun apply(project: Project) { project.extensions.create("allOpen", AllOpenExtension::class.java) + registry.register(AllOpenModelBuilder()) } } diff --git a/libraries/tools/kotlin-allopen/src/main/kotlin/org/jetbrains/kotlin/allopen/gradle/model/builder/AllOpenModelBuilder.kt b/libraries/tools/kotlin-allopen/src/main/kotlin/org/jetbrains/kotlin/allopen/gradle/model/builder/AllOpenModelBuilder.kt new file mode 100644 index 00000000000..af165898b6d --- /dev/null +++ b/libraries/tools/kotlin-allopen/src/main/kotlin/org/jetbrains/kotlin/allopen/gradle/model/builder/AllOpenModelBuilder.kt @@ -0,0 +1,31 @@ +/* + * Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.allopen.gradle.model.builder + +import org.gradle.api.Project +import org.gradle.tooling.provider.model.ToolingModelBuilder +import org.jetbrains.kotlin.allopen.gradle.AllOpenExtension +import org.jetbrains.kotlin.allopen.gradle.model.impl.AllOpenImpl +import org.jetbrains.kotlin.gradle.model.AllOpen + +/** + * [ToolingModelBuilder] for [AllOpen] models. + * This model builder is registered for Kotlin All Open sub-plugin. + */ +class AllOpenModelBuilder : ToolingModelBuilder { + + override fun canBuild(modelName: String): Boolean { + return modelName == AllOpen::class.java.name + } + + override fun buildAll(modelName: String, project: Project): Any? { + if (modelName == AllOpen::class.java.name) { + val extension = project.extensions.getByType(AllOpenExtension::class.java) + return AllOpenImpl(project.name, extension.myAnnotations, extension.myPresets) + } + return null + } +} \ No newline at end of file diff --git a/libraries/tools/kotlin-allopen/src/main/kotlin/org/jetbrains/kotlin/allopen/gradle/model/impl/AllOpenImpl.kt b/libraries/tools/kotlin-allopen/src/main/kotlin/org/jetbrains/kotlin/allopen/gradle/model/impl/AllOpenImpl.kt new file mode 100644 index 00000000000..86590a1d45f --- /dev/null +++ b/libraries/tools/kotlin-allopen/src/main/kotlin/org/jetbrains/kotlin/allopen/gradle/model/impl/AllOpenImpl.kt @@ -0,0 +1,39 @@ +/* + * Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.allopen.gradle.model.impl + +import org.jetbrains.kotlin.gradle.model.AllOpen +import java.io.Serializable + +/** + * Implementation of the [AllOpen] interface. + */ +data class AllOpenImpl( + private val myName: String, + private val myAnnotations: List, + private val myPresets: List +) : AllOpen, Serializable { + + override fun getModelVersion(): Long { + return serialVersionUID + } + + override fun getName(): String { + return myName + } + + override fun getAnnotations(): List { + return myAnnotations + } + + override fun getPresets(): List { + return myPresets + } + + companion object { + private const val serialVersionUID = 1L + } +} \ No newline at end of file diff --git a/libraries/tools/kotlin-allopen/src/test/kotlin/org/jetbrains/kotlin/allopen/gradle/model/builder/AllOpenModelBuilderTest.kt b/libraries/tools/kotlin-allopen/src/test/kotlin/org/jetbrains/kotlin/allopen/gradle/model/builder/AllOpenModelBuilderTest.kt new file mode 100644 index 00000000000..b1cbb03f49c --- /dev/null +++ b/libraries/tools/kotlin-allopen/src/test/kotlin/org/jetbrains/kotlin/allopen/gradle/model/builder/AllOpenModelBuilderTest.kt @@ -0,0 +1,20 @@ +/* + * Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.allopen.gradle.model.builder + +import org.jetbrains.kotlin.gradle.model.AllOpen +import org.junit.Assert.assertFalse +import org.junit.Assert.assertTrue +import org.junit.Test + +class AllOpenModelBuilderTest { + @Test + fun testCanBuild() { + val modelBuilder = AllOpenModelBuilder() + assertTrue(modelBuilder.canBuild(AllOpen::class.java.name)) + assertFalse(modelBuilder.canBuild("wrongModel")) + } +} \ No newline at end of file diff --git a/libraries/tools/kotlin-allopen/src/test/kotlin/org/jetbrains/kotlin/allopen/gradle/model/impl/AllOpenImplTest.kt b/libraries/tools/kotlin-allopen/src/test/kotlin/org/jetbrains/kotlin/allopen/gradle/model/impl/AllOpenImplTest.kt new file mode 100644 index 00000000000..b9b9570b84b --- /dev/null +++ b/libraries/tools/kotlin-allopen/src/test/kotlin/org/jetbrains/kotlin/allopen/gradle/model/impl/AllOpenImplTest.kt @@ -0,0 +1,19 @@ +/* + * Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.allopen.gradle.model.impl + + +import nl.jqno.equalsverifier.EqualsVerifier +import nl.jqno.equalsverifier.Warning +import org.junit.Test + +class AllOpenImplTest { + @Test + @Throws(Exception::class) + fun equals() { + EqualsVerifier.forClass(AllOpenImpl::class.java).suppress(Warning.NULL_FIELDS).verify() + } +} \ No newline at end of file diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/build.gradle b/libraries/tools/kotlin-gradle-plugin-integration-tests/build.gradle index 094dbd5763f..e0b74faa10e 100644 --- a/libraries/tools/kotlin-gradle-plugin-integration-tests/build.gradle +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/build.gradle @@ -17,6 +17,8 @@ dependencies { testCompile project(':kotlin-gradle-plugin').sourceSets.test.output testCompile project(':kotlin-gradle-subplugin-example') testCompile project(':kotlin-allopen') + testCompile project(':kotlin-noarg') + testCompile project(':kotlin-sam-with-receiver') testCompile project(':kotlin-test:kotlin-test-jvm') testCompile project(path: ':kotlin-compiler-embeddable', configuration: 'runtimeJar') @@ -43,6 +45,8 @@ dependencies { test.dependsOn(":kotlin-gradle-plugin:validateTaskProperties") test.dependsOn(":kotlin-allopen:install", + ":kotlin-noarg:install", + ":kotlin-sam-with-receiver:install", ":kotlin-android-extensions:install", ":kotlin-build-common:install", ":kotlin-compiler-embeddable:install", diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/model/AllOpenModelIT.kt b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/model/AllOpenModelIT.kt new file mode 100644 index 00000000000..88eef06827f --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/model/AllOpenModelIT.kt @@ -0,0 +1,34 @@ +/* + * Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.gradle.model + +import org.jetbrains.kotlin.gradle.BaseGradleIT +import org.junit.Test +import kotlin.test.assertEquals +import kotlin.test.assertNull +import kotlin.test.assertTrue + +class AllOpenModelIT : BaseGradleIT() { + + @Test + fun testAllOpenSimple() { + val project = Project("allOpenSimple") + val allOpenModel = project.getModels(AllOpen::class.java).getModel(":")!! + assertEquals(1L, allOpenModel.modelVersion) + assertEquals("allOpenSimple", allOpenModel.name) + assertEquals(1, allOpenModel.annotations.size) + assertTrue(allOpenModel.annotations.contains("lib.AllOpen")) + assertTrue(allOpenModel.presets.isEmpty()) + } + + @Test + fun testNonAllOpenProjects() { + val project = Project("kotlinProject") + val model = project.getModels(AllOpen::class.java).getModel(":") + + assertNull(model) + } +} \ No newline at end of file diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/model/NoArgModelIT.kt b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/model/NoArgModelIT.kt new file mode 100644 index 00000000000..94b47b6ab25 --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/model/NoArgModelIT.kt @@ -0,0 +1,36 @@ +/* + * Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.gradle.model + +import org.jetbrains.kotlin.gradle.BaseGradleIT +import org.junit.Test +import kotlin.test.assertEquals +import kotlin.test.assertFalse +import kotlin.test.assertNull +import kotlin.test.assertTrue + +class NoArgModelIT : BaseGradleIT() { + + @Test + fun testNoArgKt18668() { + val project = Project("noArgKt18668") + val noArgModel = project.getModels(NoArg::class.java).getModel(":")!! + assertEquals(1L, noArgModel.modelVersion) + assertEquals("noArgKt18668", noArgModel.name) + assertEquals(1, noArgModel.annotations.size) + assertTrue(noArgModel.annotations.contains("test.NoArg")) + assertTrue(noArgModel.presets.isEmpty()) + assertFalse(noArgModel.isInvokeInitializers) + } + + @Test + fun testNonNoArgProjects() { + val project = Project("kotlinProject") + val model = project.getModels(NoArg::class.java).getModel(":") + + assertNull(model) + } +} \ No newline at end of file diff --git a/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/model/SamWithReceiverModelIT.kt b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/model/SamWithReceiverModelIT.kt new file mode 100644 index 00000000000..b1c200cd35f --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin-integration-tests/src/test/kotlin/org/jetbrains/kotlin/gradle/model/SamWithReceiverModelIT.kt @@ -0,0 +1,34 @@ +/* + * Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.gradle.model + +import org.jetbrains.kotlin.gradle.BaseGradleIT +import org.junit.Test +import kotlin.test.assertEquals +import kotlin.test.assertNull +import kotlin.test.assertTrue + +class SamWithReceiverModelIT : BaseGradleIT() { + + @Test + fun testSamWithReceiverSimple() { + val project = Project("samWithReceiverSimple") + val samWithReceiverModel = project.getModels(SamWithReceiver::class.java).getModel(":")!! + assertEquals(1L, samWithReceiverModel.modelVersion) + assertEquals("samWithReceiverSimple", samWithReceiverModel.name) + assertEquals(1, samWithReceiverModel.annotations.size) + assertTrue(samWithReceiverModel.annotations.contains("lib.SamWithReceiver")) + assertTrue(samWithReceiverModel.presets.isEmpty()) + } + + @Test + fun testNonSamWithReceiverProjects() { + val project = Project("kotlinProject") + val model = project.getModels(SamWithReceiver::class.java).getModel(":") + + assertNull(model) + } +} \ No newline at end of file diff --git a/libraries/tools/kotlin-gradle-plugin-model/src/main/java/org/jetbrains/kotlin/gradle/model/AllOpen.java b/libraries/tools/kotlin-gradle-plugin-model/src/main/java/org/jetbrains/kotlin/gradle/model/AllOpen.java new file mode 100644 index 00000000000..94021e04d6c --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin-model/src/main/java/org/jetbrains/kotlin/gradle/model/AllOpen.java @@ -0,0 +1,49 @@ +/* + * Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.gradle.model; + +import org.jetbrains.annotations.NotNull; + +import java.util.List; + +/** + * Entry point for Kotlin All Open models. + * Represents the description of annotations interpreted by 'kotlin-allopen' plugin. + */ +public interface AllOpen { + + /** + * Return a number representing the version of this API. + * Always increasing if changed. + * + * @return the version of this model. + */ + long getModelVersion(); + + /** + * Returns the module (Gradle project) name. + * + * @return the module name. + */ + @NotNull + String getName(); + + /** + * Return the list of annotations. + * + * @return the list of annotations. + */ + @NotNull + List getAnnotations(); + + /** + * Return the list of presets. + * + * @return the list of presets. + */ + @NotNull + List getPresets(); +} diff --git a/libraries/tools/kotlin-gradle-plugin-model/src/main/java/org/jetbrains/kotlin/gradle/model/NoArg.java b/libraries/tools/kotlin-gradle-plugin-model/src/main/java/org/jetbrains/kotlin/gradle/model/NoArg.java new file mode 100644 index 00000000000..dd49d1d97b8 --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin-model/src/main/java/org/jetbrains/kotlin/gradle/model/NoArg.java @@ -0,0 +1,57 @@ +/* + * Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.gradle.model; + +import org.jetbrains.annotations.NotNull; + +import java.util.List; + +/** + * Entry point for Kotlin No Arg models. + * Represents the description of annotations interpreted by 'kotlin-noarg' plugin. + */ +public interface NoArg { + + /** + * Return a number representing the version of this API. + * Always increasing if changed. + * + * @return the version of this model. + */ + long getModelVersion(); + + /** + * Returns the module (Gradle project) name. + * + * @return the module name. + */ + @NotNull + String getName(); + + /** + * Return the list of annotations. + * + * @return the list of annotations. + */ + @NotNull + List getAnnotations(); + + /** + * Return the list of presets. + * + * @return the list of presets. + */ + @NotNull + List getPresets(); + + /** + * Return if should invoke initializers. + * Only makes sense for type NO_ARG. + * + * @return if initializers should be invoked. + */ + boolean isInvokeInitializers(); +} diff --git a/libraries/tools/kotlin-gradle-plugin-model/src/main/java/org/jetbrains/kotlin/gradle/model/SamWithReceiver.java b/libraries/tools/kotlin-gradle-plugin-model/src/main/java/org/jetbrains/kotlin/gradle/model/SamWithReceiver.java new file mode 100644 index 00000000000..03799106aa7 --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin-model/src/main/java/org/jetbrains/kotlin/gradle/model/SamWithReceiver.java @@ -0,0 +1,49 @@ +/* + * Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.gradle.model; + +import org.jetbrains.annotations.NotNull; + +import java.util.List; + +/** + * Entry point for Kotlin Sam With Receiver models. + * Represents the description of annotations interpreted by 'kotlin-sam-with-receiver' plugin. + */ +public interface SamWithReceiver { + + /** + * Return a number representing the version of this API. + * Always increasing if changed. + * + * @return the version of this model. + */ + long getModelVersion(); + + /** + * Returns the module (Gradle project) name. + * + * @return the module name. + */ + @NotNull + String getName(); + + /** + * Return the list of annotations. + * + * @return the list of annotations. + */ + @NotNull + List getAnnotations(); + + /** + * Return the list of presets. + * + * @return the list of presets. + */ + @NotNull + List getPresets(); +} diff --git a/libraries/tools/kotlin-noarg/build.gradle b/libraries/tools/kotlin-noarg/build.gradle index 8cc6ccf1ac0..ae0039393cc 100644 --- a/libraries/tools/kotlin-noarg/build.gradle +++ b/libraries/tools/kotlin-noarg/build.gradle @@ -16,12 +16,17 @@ repositories { dependencies { compile project(':kotlin-gradle-plugin-api') + compile project(':kotlin-gradle-plugin-model') compile project(':kotlin-stdlib') compileOnly project(':compiler') compileOnly project(':kotlin-noarg-compiler-plugin') compileOnly gradleApi() + + testCompile gradleApi() + testCompile "junit:junit:4.12" + testCompile "nl.jqno.equalsverifier:equalsverifier:2.1.5" } evaluationDependsOn(":kotlin-noarg-compiler-plugin") @@ -50,4 +55,6 @@ pluginBundle { description = displayName = 'Kotlin JPA compiler plugin' } } -} \ No newline at end of file +} + +test.executable = "${JDK_18}/bin/java" \ No newline at end of file diff --git a/libraries/tools/kotlin-noarg/src/main/kotlin/org/jetbrains/kotlin/noarg/gradle/NoArgSubplugin.kt b/libraries/tools/kotlin-noarg/src/main/kotlin/org/jetbrains/kotlin/noarg/gradle/NoArgSubplugin.kt index 0edffc60b9b..e7c5b1ba567 100644 --- a/libraries/tools/kotlin-noarg/src/main/kotlin/org/jetbrains/kotlin/noarg/gradle/NoArgSubplugin.kt +++ b/libraries/tools/kotlin-noarg/src/main/kotlin/org/jetbrains/kotlin/noarg/gradle/NoArgSubplugin.kt @@ -23,12 +23,15 @@ import org.gradle.api.artifacts.ResolvedArtifact import org.gradle.api.internal.ConventionTask import org.gradle.api.tasks.SourceSet import org.gradle.api.tasks.compile.AbstractCompile +import org.gradle.tooling.provider.model.ToolingModelBuilderRegistry import org.jetbrains.kotlin.gradle.plugin.JetBrainsSubpluginArtifact import org.jetbrains.kotlin.gradle.plugin.KotlinGradleSubplugin import org.jetbrains.kotlin.gradle.plugin.SubpluginArtifact import org.jetbrains.kotlin.gradle.plugin.SubpluginOption +import org.jetbrains.kotlin.noarg.gradle.model.builder.NoArgModelBuilder +import javax.inject.Inject -class NoArgGradleSubplugin : Plugin { +class NoArgGradleSubplugin @Inject internal constructor(private val registry: ToolingModelBuilderRegistry) : Plugin { companion object { fun isEnabled(project: Project) = project.plugins.findPlugin(NoArgGradleSubplugin::class.java) != null @@ -39,6 +42,7 @@ class NoArgGradleSubplugin : Plugin { override fun apply(project: Project) { project.extensions.create("noArg", NoArgExtension::class.java) + registry.register(NoArgModelBuilder()) } } diff --git a/libraries/tools/kotlin-noarg/src/main/kotlin/org/jetbrains/kotlin/noarg/gradle/model/builder/NoArgModelBuilder.kt b/libraries/tools/kotlin-noarg/src/main/kotlin/org/jetbrains/kotlin/noarg/gradle/model/builder/NoArgModelBuilder.kt new file mode 100644 index 00000000000..e55d7695420 --- /dev/null +++ b/libraries/tools/kotlin-noarg/src/main/kotlin/org/jetbrains/kotlin/noarg/gradle/model/builder/NoArgModelBuilder.kt @@ -0,0 +1,31 @@ +/* + * Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.noarg.gradle.model.builder + +import org.gradle.api.Project +import org.gradle.tooling.provider.model.ToolingModelBuilder +import org.jetbrains.kotlin.gradle.model.NoArg +import org.jetbrains.kotlin.noarg.gradle.NoArgExtension +import org.jetbrains.kotlin.noarg.gradle.model.impl.NoArgImpl + +/** + * [ToolingModelBuilder] for [NoArg] models. + * This model builder is registered for Kotlin No Arg sub-plugin. + */ +class NoArgModelBuilder : ToolingModelBuilder { + + override fun canBuild(modelName: String): Boolean { + return modelName == NoArg::class.java.name + } + + override fun buildAll(modelName: String, project: Project): Any? { + if (modelName == NoArg::class.java.name) { + val extension = project.extensions.getByType(NoArgExtension::class.java) + return NoArgImpl(project.name, extension.myAnnotations, extension.myPresets, extension.invokeInitializers) + } + return null + } +} \ No newline at end of file diff --git a/libraries/tools/kotlin-noarg/src/main/kotlin/org/jetbrains/kotlin/noarg/gradle/model/impl/NoArgImpl.kt b/libraries/tools/kotlin-noarg/src/main/kotlin/org/jetbrains/kotlin/noarg/gradle/model/impl/NoArgImpl.kt new file mode 100644 index 00000000000..22d02d46aef --- /dev/null +++ b/libraries/tools/kotlin-noarg/src/main/kotlin/org/jetbrains/kotlin/noarg/gradle/model/impl/NoArgImpl.kt @@ -0,0 +1,44 @@ +/* + * Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.noarg.gradle.model.impl + +import org.jetbrains.kotlin.gradle.model.NoArg +import java.io.Serializable + +/** + * Implementation of the [NoArg] interface. + */ +data class NoArgImpl( + private val myName: String, + private val myAnnotations: List, + private val myPresets: List, + private val myInvokeInitializers: Boolean +) : NoArg, Serializable { + + override fun getModelVersion(): Long { + return serialVersionUID + } + + override fun getName(): String { + return myName + } + + override fun getAnnotations(): List { + return myAnnotations + } + + override fun getPresets(): List { + return myPresets + } + + override fun isInvokeInitializers(): Boolean { + return myInvokeInitializers + } + + companion object { + private const val serialVersionUID = 1L + } +} \ No newline at end of file diff --git a/libraries/tools/kotlin-noarg/src/test/kotlin/org/jetbrains/kotlin/noarg/gradle/model/builder/NoArgModelBuilderTest.kt b/libraries/tools/kotlin-noarg/src/test/kotlin/org/jetbrains/kotlin/noarg/gradle/model/builder/NoArgModelBuilderTest.kt new file mode 100644 index 00000000000..35c22cf011d --- /dev/null +++ b/libraries/tools/kotlin-noarg/src/test/kotlin/org/jetbrains/kotlin/noarg/gradle/model/builder/NoArgModelBuilderTest.kt @@ -0,0 +1,20 @@ +/* + * Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.noarg.gradle.model.builder + +import org.jetbrains.kotlin.gradle.model.NoArg +import org.junit.Assert.assertFalse +import org.junit.Assert.assertTrue +import org.junit.Test + +class NoArgModelBuilderTest { + @Test + fun testCanBuild() { + val modelBuilder = NoArgModelBuilder() + assertTrue(modelBuilder.canBuild(NoArg::class.java.name)) + assertFalse(modelBuilder.canBuild("wrongModel")) + } +} \ No newline at end of file diff --git a/libraries/tools/kotlin-noarg/src/test/kotlin/org/jetbrains/kotlin/noarg/gradle/model/impl/NoArgImplTest.kt b/libraries/tools/kotlin-noarg/src/test/kotlin/org/jetbrains/kotlin/noarg/gradle/model/impl/NoArgImplTest.kt new file mode 100644 index 00000000000..3b1b3665aae --- /dev/null +++ b/libraries/tools/kotlin-noarg/src/test/kotlin/org/jetbrains/kotlin/noarg/gradle/model/impl/NoArgImplTest.kt @@ -0,0 +1,18 @@ +/* + * Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.noarg.gradle.model.impl + +import nl.jqno.equalsverifier.EqualsVerifier +import nl.jqno.equalsverifier.Warning +import org.junit.Test + +class NoArgImplTest { + @Test + @Throws(Exception::class) + fun equals() { + EqualsVerifier.forClass(NoArgImpl::class.java).suppress(Warning.NULL_FIELDS).verify() + } +} \ No newline at end of file diff --git a/libraries/tools/kotlin-sam-with-receiver/build.gradle b/libraries/tools/kotlin-sam-with-receiver/build.gradle index 154e0d9800e..3e1ffa61f76 100644 --- a/libraries/tools/kotlin-sam-with-receiver/build.gradle +++ b/libraries/tools/kotlin-sam-with-receiver/build.gradle @@ -16,12 +16,17 @@ repositories { dependencies { compile project(':kotlin-gradle-plugin-api') + compile project(':kotlin-gradle-plugin-model') compile project(':kotlin-stdlib') compileOnly project(':compiler') compileOnly project(':kotlin-sam-with-receiver-compiler-plugin') compileOnly gradleApi() + + testCompile gradleApi() + testCompile "junit:junit:4.12" + testCompile "nl.jqno.equalsverifier:equalsverifier:2.1.5" } evaluationDependsOn(":kotlin-sam-with-receiver-compiler-plugin") @@ -38,3 +43,5 @@ artifacts { archives sourcesJar archives javadocJar } + +test.executable = "${JDK_18}/bin/java" \ No newline at end of file diff --git a/libraries/tools/kotlin-sam-with-receiver/src/main/kotlin/org/jetbrains/kotlin/noarg/gradle/SamWithReceiverSubplugin.kt b/libraries/tools/kotlin-sam-with-receiver/src/main/kotlin/org/jetbrains/kotlin/noarg/gradle/SamWithReceiverSubplugin.kt index 9e1b35bd083..8b5550aaf8f 100644 --- a/libraries/tools/kotlin-sam-with-receiver/src/main/kotlin/org/jetbrains/kotlin/noarg/gradle/SamWithReceiverSubplugin.kt +++ b/libraries/tools/kotlin-sam-with-receiver/src/main/kotlin/org/jetbrains/kotlin/noarg/gradle/SamWithReceiverSubplugin.kt @@ -23,18 +23,22 @@ import org.gradle.api.artifacts.ResolvedArtifact import org.gradle.api.internal.ConventionTask import org.gradle.api.tasks.SourceSet import org.gradle.api.tasks.compile.AbstractCompile +import org.gradle.tooling.provider.model.ToolingModelBuilderRegistry import org.jetbrains.kotlin.gradle.plugin.JetBrainsSubpluginArtifact import org.jetbrains.kotlin.gradle.plugin.KotlinGradleSubplugin import org.jetbrains.kotlin.gradle.plugin.SubpluginArtifact import org.jetbrains.kotlin.gradle.plugin.SubpluginOption +import org.jetbrains.kotlin.noarg.gradle.model.builder.SamWithReceiverModelBuilder +import javax.inject.Inject -class SamWithReceiverGradleSubplugin : Plugin { +class SamWithReceiverGradleSubplugin @Inject internal constructor(private val registry: ToolingModelBuilderRegistry) : Plugin { companion object { fun isEnabled(project: Project) = project.plugins.findPlugin(SamWithReceiverGradleSubplugin::class.java) != null } override fun apply(project: Project) { project.extensions.create("samWithReceiver", SamWithReceiverExtension::class.java) + registry.register(SamWithReceiverModelBuilder()) } } diff --git a/libraries/tools/kotlin-sam-with-receiver/src/main/kotlin/org/jetbrains/kotlin/noarg/gradle/model/builder/SamWithReceiverModelBuilder.kt b/libraries/tools/kotlin-sam-with-receiver/src/main/kotlin/org/jetbrains/kotlin/noarg/gradle/model/builder/SamWithReceiverModelBuilder.kt new file mode 100644 index 00000000000..2b802ca39f2 --- /dev/null +++ b/libraries/tools/kotlin-sam-with-receiver/src/main/kotlin/org/jetbrains/kotlin/noarg/gradle/model/builder/SamWithReceiverModelBuilder.kt @@ -0,0 +1,31 @@ +/* + * Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.noarg.gradle.model.builder + +import org.gradle.api.Project +import org.gradle.tooling.provider.model.ToolingModelBuilder +import org.jetbrains.kotlin.gradle.model.SamWithReceiver +import org.jetbrains.kotlin.noarg.gradle.model.impl.SamWithReceiverImpl +import org.jetbrains.kotlin.samWithReceiver.gradle.SamWithReceiverExtension + +/** + * [ToolingModelBuilder] for [SamWithReceiver] models. + * This model builder is registered for Kotlin Sam With Receiver sub-plugin. + */ +class SamWithReceiverModelBuilder : ToolingModelBuilder { + + override fun canBuild(modelName: String): Boolean { + return modelName == SamWithReceiver::class.java.name + } + + override fun buildAll(modelName: String, project: Project): Any? { + if (modelName == SamWithReceiver::class.java.name) { + val extension = project.extensions.getByType(SamWithReceiverExtension::class.java) + return SamWithReceiverImpl(project.name, extension.myAnnotations, extension.myPresets) + } + return null + } +} \ No newline at end of file diff --git a/libraries/tools/kotlin-sam-with-receiver/src/main/kotlin/org/jetbrains/kotlin/noarg/gradle/model/impl/SamWithReceiverImpl.kt b/libraries/tools/kotlin-sam-with-receiver/src/main/kotlin/org/jetbrains/kotlin/noarg/gradle/model/impl/SamWithReceiverImpl.kt new file mode 100644 index 00000000000..3f3ef50a3e4 --- /dev/null +++ b/libraries/tools/kotlin-sam-with-receiver/src/main/kotlin/org/jetbrains/kotlin/noarg/gradle/model/impl/SamWithReceiverImpl.kt @@ -0,0 +1,39 @@ +/* + * Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.noarg.gradle.model.impl + +import org.jetbrains.kotlin.gradle.model.SamWithReceiver +import java.io.Serializable + +/** + * Implementation of the [SamWithReceiver] interface. + */ +data class SamWithReceiverImpl( + private val myName: String, + private val myAnnotations: List, + private val myPresets: List +) : SamWithReceiver, Serializable { + + override fun getModelVersion(): Long { + return serialVersionUID + } + + override fun getName(): String { + return myName + } + + override fun getAnnotations(): List { + return myAnnotations + } + + override fun getPresets(): List { + return myPresets + } + + companion object { + private const val serialVersionUID = 1L + } +} \ No newline at end of file diff --git a/libraries/tools/kotlin-sam-with-receiver/src/test/kotlin/org/jetbrains/kotlin/noarg/gradle/model/builder/SamWithReceiverModelBuilderTest.kt b/libraries/tools/kotlin-sam-with-receiver/src/test/kotlin/org/jetbrains/kotlin/noarg/gradle/model/builder/SamWithReceiverModelBuilderTest.kt new file mode 100644 index 00000000000..13586c0a104 --- /dev/null +++ b/libraries/tools/kotlin-sam-with-receiver/src/test/kotlin/org/jetbrains/kotlin/noarg/gradle/model/builder/SamWithReceiverModelBuilderTest.kt @@ -0,0 +1,20 @@ +/* + * Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.noarg.gradle.model.builder + +import org.jetbrains.kotlin.gradle.model.SamWithReceiver +import org.junit.Assert.assertFalse +import org.junit.Assert.assertTrue +import org.junit.Test + +class SamWithReceiverModelBuilderTest { + @Test + fun testCanBuild() { + val modelBuilder = SamWithReceiverModelBuilder() + assertTrue(modelBuilder.canBuild(SamWithReceiver::class.java.name)) + assertFalse(modelBuilder.canBuild("wrongModel")) + } +} \ No newline at end of file diff --git a/libraries/tools/kotlin-sam-with-receiver/src/test/kotlin/org/jetbrains/kotlin/noarg/gradle/model/impl/SamWithReceiverImplTest.kt b/libraries/tools/kotlin-sam-with-receiver/src/test/kotlin/org/jetbrains/kotlin/noarg/gradle/model/impl/SamWithReceiverImplTest.kt new file mode 100644 index 00000000000..0a4f0cc355c --- /dev/null +++ b/libraries/tools/kotlin-sam-with-receiver/src/test/kotlin/org/jetbrains/kotlin/noarg/gradle/model/impl/SamWithReceiverImplTest.kt @@ -0,0 +1,18 @@ +/* + * Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.noarg.gradle.model.impl + +import nl.jqno.equalsverifier.EqualsVerifier +import nl.jqno.equalsverifier.Warning +import org.junit.Test + +class SamWithReceiverImplTest { + @Test + @Throws(Exception::class) + fun equals() { + EqualsVerifier.forClass(SamWithReceiverImpl::class.java).suppress(Warning.NULL_FIELDS).verify() + } +} \ No newline at end of file