From 3828c26fa95091f46bb0591f1c0621f51a483710 Mon Sep 17 00:00:00 2001 From: Sergey Igushkin Date: Fri, 13 Jul 2018 01:36:04 +0300 Subject: [PATCH] Introduce new API These interfaces are needed for both new MPP design and getting rid of the Java plugin source sets in favor of Kotlin source sets --- .../gradle/plugin/HasKotlinDependencies.kt | 28 +++++++++ .../kotlin/gradle/plugin/KotlinCompilation.kt | 57 +++++++++++++++++++ .../gradle/plugin/KotlinPlatformType.kt | 25 ++++++++ .../kotlin/gradle/plugin/KotlinTarget.kt | 33 +++++++++++ .../gradle/plugin/KotlinTargetPreset.kt | 12 ++++ .../gradle/plugin/source/KotlinSourceSet.kt | 26 +++++++++ .../kotlin/gradle/plugin/KotlinSourceSet.kt | 26 --------- 7 files changed, 181 insertions(+), 26 deletions(-) create mode 100644 libraries/tools/kotlin-gradle-plugin-api/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/HasKotlinDependencies.kt create mode 100644 libraries/tools/kotlin-gradle-plugin-api/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/KotlinCompilation.kt create mode 100644 libraries/tools/kotlin-gradle-plugin-api/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/KotlinPlatformType.kt create mode 100644 libraries/tools/kotlin-gradle-plugin-api/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/KotlinTarget.kt create mode 100644 libraries/tools/kotlin-gradle-plugin-api/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/KotlinTargetPreset.kt create mode 100644 libraries/tools/kotlin-gradle-plugin-api/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/source/KotlinSourceSet.kt delete mode 100644 libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/KotlinSourceSet.kt diff --git a/libraries/tools/kotlin-gradle-plugin-api/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/HasKotlinDependencies.kt b/libraries/tools/kotlin-gradle-plugin-api/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/HasKotlinDependencies.kt new file mode 100644 index 00000000000..1a98edd8fe4 --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin-api/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/HasKotlinDependencies.kt @@ -0,0 +1,28 @@ +/* + * 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.plugin + +import groovy.lang.Closure + +interface KotlinDependencyHandler { + fun api(dependencyNotation: Any) + fun implementation(dependencyNotation: Any) + fun compileOnly(dependencyNotation: Any) + fun runtimeOnly(dependencyNotation: Any) +} + +interface HasKotlinDependencies { + fun dependencies(configure: KotlinDependencyHandler.() -> Unit) + fun dependencies(configureClosure: Closure) + + val apiConfigurationName: String + val implementationConfigurationName: String + val compileOnlyConfigurationName: String + val runtimeOnlyConfigurationName: String + + val relatedConfigurationNames: List + get() = listOf(apiConfigurationName, implementationConfigurationName, compileOnlyConfigurationName, runtimeOnlyConfigurationName) +} diff --git a/libraries/tools/kotlin-gradle-plugin-api/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/KotlinCompilation.kt b/libraries/tools/kotlin-gradle-plugin-api/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/KotlinCompilation.kt new file mode 100644 index 00000000000..0c96f6fcbd5 --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin-api/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/KotlinCompilation.kt @@ -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.plugin + +import org.gradle.api.Named +import org.gradle.api.attributes.HasAttributes +import org.gradle.api.file.FileCollection +import org.gradle.api.tasks.SourceSetOutput +import org.jetbrains.kotlin.gradle.plugin.source.KotlinSourceSet + +interface KotlinCompilation: Named, HasAttributes, HasKotlinDependencies { + val target: KotlinTarget + + val compilationName: String + + val kotlinSourceSets: Set + + val compileDependencyConfigurationName: String + + var compileDependencyFiles: FileCollection + + val output: SourceSetOutput + + val platformType get() = target.platformType + + val compileKotlinTaskName: String + + val compileAllTaskName: String + + companion object { + const val MAIN_COMPILATION_NAME = "main" + const val TEST_COMPILATION_NAME = "test" + } + + fun source(sourceSet: KotlinSourceSet) + + override fun getName(): String = compilationName + + override val relatedConfigurationNames: List + get() = super.relatedConfigurationNames + compileDependencyConfigurationName +} + +interface KotlinCompilationToRunnableFiles : KotlinCompilation { + val runtimeDependencyConfigurationName: String + + var runtimeDependencyFiles: FileCollection + + override val relatedConfigurationNames: List + get() = super.relatedConfigurationNames + runtimeDependencyConfigurationName +} + +interface KotlinCompilationWithResources : KotlinCompilation { + val processResourcesTaskName: String +} \ No newline at end of file diff --git a/libraries/tools/kotlin-gradle-plugin-api/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/KotlinPlatformType.kt b/libraries/tools/kotlin-gradle-plugin-api/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/KotlinPlatformType.kt new file mode 100644 index 00000000000..8656d436bf6 --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin-api/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/KotlinPlatformType.kt @@ -0,0 +1,25 @@ +/* + * 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.plugin + +import org.gradle.api.Named +import org.gradle.api.attributes.Attribute +import java.io.Serializable + +enum class KotlinPlatformType: Named, Serializable { + common, jvm, js, + native; // TODO: split native into separate entries here or transform the enum to interface and implement entries in K/N + + override fun toString(): String = name + override fun getName(): String = name + + companion object { + val attribute = Attribute.of( + "org.jetbrains.kotlin.platform.type", + KotlinPlatformType::class.java + ) + } +} \ No newline at end of file diff --git a/libraries/tools/kotlin-gradle-plugin-api/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/KotlinTarget.kt b/libraries/tools/kotlin-gradle-plugin-api/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/KotlinTarget.kt new file mode 100644 index 00000000000..6ca5e36f7ab --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin-api/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/KotlinTarget.kt @@ -0,0 +1,33 @@ +/* + * 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.plugin + +import org.gradle.api.Named +import org.gradle.api.NamedDomainObjectContainer +import org.gradle.api.Project +import org.gradle.api.attributes.HasAttributes +import org.gradle.api.internal.component.UsageContext + +interface KotlinTarget: Named, HasAttributes { + val targetName: String + val disambiguationClassifier: String? get() = targetName + + val platformType: KotlinPlatformType + + val compilations: NamedDomainObjectContainer + + val project: Project + + val artifactsTaskName: String + + val defaultConfigurationName: String + val apiElementsConfigurationName: String + val runtimeElementsConfigurationName: String + + fun createUsageContexts(): Set + + override fun getName(): String = targetName +} \ No newline at end of file diff --git a/libraries/tools/kotlin-gradle-plugin-api/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/KotlinTargetPreset.kt b/libraries/tools/kotlin-gradle-plugin-api/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/KotlinTargetPreset.kt new file mode 100644 index 00000000000..590e835556a --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin-api/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/KotlinTargetPreset.kt @@ -0,0 +1,12 @@ +/* + * 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.plugin + +import org.gradle.api.Named + +interface KotlinTargetPreset : Named { + fun createTarget(name: String): T +} \ No newline at end of file diff --git a/libraries/tools/kotlin-gradle-plugin-api/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/source/KotlinSourceSet.kt b/libraries/tools/kotlin-gradle-plugin-api/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/source/KotlinSourceSet.kt new file mode 100644 index 00000000000..4c9701c260e --- /dev/null +++ b/libraries/tools/kotlin-gradle-plugin-api/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/source/KotlinSourceSet.kt @@ -0,0 +1,26 @@ +/* + * 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.plugin.source + +import groovy.lang.Closure +import org.gradle.api.Named +import org.gradle.api.file.SourceDirectorySet +import org.jetbrains.kotlin.gradle.plugin.HasKotlinDependencies + +interface KotlinSourceSet : Named, HasKotlinDependencies { + val kotlin: SourceDirectorySet + + fun kotlin(configureClosure: Closure): SourceDirectorySet + + companion object { + const val COMMON_MAIN_SOURCE_SET_NAME = "commonMain" + const val COMMON_TEST_SOURCE_SET_NAME = "commonTest" + } +} + +interface KotlinSourceSetWithResources : KotlinSourceSet { + val resources: SourceDirectorySet +} \ No newline at end of file diff --git a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/KotlinSourceSet.kt b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/KotlinSourceSet.kt deleted file mode 100644 index f78cbeb3f95..00000000000 --- a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/KotlinSourceSet.kt +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright 2010-2016 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.jetbrains.kotlin.gradle.plugin - -import groovy.lang.Closure -import org.gradle.api.file.SourceDirectorySet - -interface KotlinSourceSet { - val kotlin: SourceDirectorySet - - fun kotlin(configureClosure: Closure?): KotlinSourceSet -} \ No newline at end of file