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
This commit is contained in:
Sergey Igushkin
2018-07-13 01:36:04 +03:00
parent a1c10956cb
commit 3828c26fa9
7 changed files with 181 additions and 26 deletions
@@ -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<Any?>)
val apiConfigurationName: String
val implementationConfigurationName: String
val compileOnlyConfigurationName: String
val runtimeOnlyConfigurationName: String
val relatedConfigurationNames: List<String>
get() = listOf(apiConfigurationName, implementationConfigurationName, compileOnlyConfigurationName, runtimeOnlyConfigurationName)
}
@@ -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<KotlinSourceSet>
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<String>
get() = super.relatedConfigurationNames + compileDependencyConfigurationName
}
interface KotlinCompilationToRunnableFiles : KotlinCompilation {
val runtimeDependencyConfigurationName: String
var runtimeDependencyFiles: FileCollection
override val relatedConfigurationNames: List<String>
get() = super.relatedConfigurationNames + runtimeDependencyConfigurationName
}
interface KotlinCompilationWithResources : KotlinCompilation {
val processResourcesTaskName: String
}
@@ -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
)
}
}
@@ -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<out KotlinCompilation>
val project: Project
val artifactsTaskName: String
val defaultConfigurationName: String
val apiElementsConfigurationName: String
val runtimeElementsConfigurationName: String
fun createUsageContexts(): Set<UsageContext>
override fun getName(): String = targetName
}
@@ -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<T: KotlinTarget> : Named {
fun createTarget(name: String): T
}
@@ -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<Any?>): 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
}
@@ -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<Any?>?): KotlinSourceSet
}