Introduce tooling model for annotation based projects
Introduce Gradle models for plugins 'kotlin-allopen', 'kotlin-noarg' and 'kotlin-sam-with-receiver'. Corresponding model builders are registered in each one of those plugin main classes.
This commit is contained in:
committed by
Sergey Igushkin
parent
5671dbb929
commit
5a423e8dcd
@@ -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'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
test.executable = "${JDK_18}/bin/java"
|
||||
+5
-1
@@ -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<Project> {
|
||||
class AllOpenGradleSubplugin @Inject internal constructor(private val registry: ToolingModelBuilderRegistry) : Plugin<Project> {
|
||||
companion object {
|
||||
fun isEnabled(project: Project) = project.plugins.findPlugin(AllOpenGradleSubplugin::class.java) != null
|
||||
|
||||
@@ -38,6 +41,7 @@ class AllOpenGradleSubplugin : Plugin<Project> {
|
||||
|
||||
override fun apply(project: Project) {
|
||||
project.extensions.create("allOpen", AllOpenExtension::class.java)
|
||||
registry.register(AllOpenModelBuilder())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+31
@@ -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
|
||||
}
|
||||
}
|
||||
+39
@@ -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<String>,
|
||||
private val myPresets: List<String>
|
||||
) : AllOpen, Serializable {
|
||||
|
||||
override fun getModelVersion(): Long {
|
||||
return serialVersionUID
|
||||
}
|
||||
|
||||
override fun getName(): String {
|
||||
return myName
|
||||
}
|
||||
|
||||
override fun getAnnotations(): List<String> {
|
||||
return myAnnotations
|
||||
}
|
||||
|
||||
override fun getPresets(): List<String> {
|
||||
return myPresets
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val serialVersionUID = 1L
|
||||
}
|
||||
}
|
||||
+20
@@ -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"))
|
||||
}
|
||||
}
|
||||
+19
@@ -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()
|
||||
}
|
||||
}
|
||||
@@ -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",
|
||||
|
||||
+34
@@ -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)
|
||||
}
|
||||
}
|
||||
+36
@@ -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)
|
||||
}
|
||||
}
|
||||
+34
@@ -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)
|
||||
}
|
||||
}
|
||||
+49
@@ -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<String> getAnnotations();
|
||||
|
||||
/**
|
||||
* Return the list of presets.
|
||||
*
|
||||
* @return the list of presets.
|
||||
*/
|
||||
@NotNull
|
||||
List<String> getPresets();
|
||||
}
|
||||
+57
@@ -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<String> getAnnotations();
|
||||
|
||||
/**
|
||||
* Return the list of presets.
|
||||
*
|
||||
* @return the list of presets.
|
||||
*/
|
||||
@NotNull
|
||||
List<String> getPresets();
|
||||
|
||||
/**
|
||||
* Return if should invoke initializers.
|
||||
* Only makes sense for type NO_ARG.
|
||||
*
|
||||
* @return if initializers should be invoked.
|
||||
*/
|
||||
boolean isInvokeInitializers();
|
||||
}
|
||||
+49
@@ -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<String> getAnnotations();
|
||||
|
||||
/**
|
||||
* Return the list of presets.
|
||||
*
|
||||
* @return the list of presets.
|
||||
*/
|
||||
@NotNull
|
||||
List<String> getPresets();
|
||||
}
|
||||
@@ -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'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
test.executable = "${JDK_18}/bin/java"
|
||||
+5
-1
@@ -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<Project> {
|
||||
class NoArgGradleSubplugin @Inject internal constructor(private val registry: ToolingModelBuilderRegistry) : Plugin<Project> {
|
||||
companion object {
|
||||
fun isEnabled(project: Project) = project.plugins.findPlugin(NoArgGradleSubplugin::class.java) != null
|
||||
|
||||
@@ -39,6 +42,7 @@ class NoArgGradleSubplugin : Plugin<Project> {
|
||||
|
||||
override fun apply(project: Project) {
|
||||
project.extensions.create("noArg", NoArgExtension::class.java)
|
||||
registry.register(NoArgModelBuilder())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+31
@@ -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
|
||||
}
|
||||
}
|
||||
+44
@@ -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<String>,
|
||||
private val myPresets: List<String>,
|
||||
private val myInvokeInitializers: Boolean
|
||||
) : NoArg, Serializable {
|
||||
|
||||
override fun getModelVersion(): Long {
|
||||
return serialVersionUID
|
||||
}
|
||||
|
||||
override fun getName(): String {
|
||||
return myName
|
||||
}
|
||||
|
||||
override fun getAnnotations(): List<String> {
|
||||
return myAnnotations
|
||||
}
|
||||
|
||||
override fun getPresets(): List<String> {
|
||||
return myPresets
|
||||
}
|
||||
|
||||
override fun isInvokeInitializers(): Boolean {
|
||||
return myInvokeInitializers
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val serialVersionUID = 1L
|
||||
}
|
||||
}
|
||||
+20
@@ -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"))
|
||||
}
|
||||
}
|
||||
+18
@@ -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()
|
||||
}
|
||||
}
|
||||
@@ -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"
|
||||
+5
-1
@@ -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<Project> {
|
||||
class SamWithReceiverGradleSubplugin @Inject internal constructor(private val registry: ToolingModelBuilderRegistry) : Plugin<Project> {
|
||||
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())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+31
@@ -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
|
||||
}
|
||||
}
|
||||
+39
@@ -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<String>,
|
||||
private val myPresets: List<String>
|
||||
) : SamWithReceiver, Serializable {
|
||||
|
||||
override fun getModelVersion(): Long {
|
||||
return serialVersionUID
|
||||
}
|
||||
|
||||
override fun getName(): String {
|
||||
return myName
|
||||
}
|
||||
|
||||
override fun getAnnotations(): List<String> {
|
||||
return myAnnotations
|
||||
}
|
||||
|
||||
override fun getPresets(): List<String> {
|
||||
return myPresets
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val serialVersionUID = 1L
|
||||
}
|
||||
}
|
||||
+20
@@ -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"))
|
||||
}
|
||||
}
|
||||
+18
@@ -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()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user