Build: introduce javaPluginConvention extension on project

`ExtensionAware.the<T>()` introduced in gradle 4.7 made existing calls `the<JavaPluginConvention>()` invalid (on wrong receiver)
This commit is contained in:
Vyacheslav Gerasimov
2018-06-09 20:43:16 +03:00
parent 94c636adc3
commit 992a31af88
34 changed files with 52 additions and 50 deletions
+1 -1
View File
@@ -347,7 +347,7 @@ allprojects {
fun FileCollection.printClassPath(role: String) =
println("${project.path} $role classpath:\n ${joinToString("\n ") { it.toProjectRootRelativePathOrSelf() } }")
try { the<JavaPluginConvention>() } catch (_: UnknownDomainObjectException) { null }?.let { javaConvention ->
try { javaPluginConvention() } catch (_: UnknownDomainObjectException) { null }?.let { javaConvention ->
task("printCompileClasspath") { doFirst { javaConvention.sourceSets["main"].compileClasspath.printClassPath("compile") } }
task("printRuntimeClasspath") { doFirst { javaConvention.sourceSets["main"].runtimeClasspath.printClassPath("runtime") } }
task("printTestCompileClasspath") { doFirst { javaConvention.sourceSets["test"].compileClasspath.printClassPath("test compile") } }
+1 -1
View File
@@ -346,7 +346,7 @@ allprojects {
fun FileCollection.printClassPath(role: String) =
println("${project.path} $role classpath:\n ${joinToString("\n ") { it.toProjectRootRelativePathOrSelf() } }")
try { the<JavaPluginConvention>() } catch (_: UnknownDomainObjectException) { null }?.let { javaConvention ->
try { javaPluginConvention() } catch (_: UnknownDomainObjectException) { null }?.let { javaConvention ->
task("printCompileClasspath") { doFirst { javaConvention.sourceSets["main"].compileClasspath.printClassPath("compile") } }
task("printRuntimeClasspath") { doFirst { javaConvention.sourceSets["main"].runtimeClasspath.printClassPath("runtime") } }
task("printTestCompileClasspath") { doFirst { javaConvention.sourceSets["test"].compileClasspath.printClassPath("test compile") } }
+6 -4
View File
@@ -31,15 +31,15 @@ inline fun<T: Any> Project.withJavaPlugin(crossinline body: () -> T?): T? {
}
fun Project.getCompiledClasses(): SourceSetOutput? = withJavaPlugin {
the<JavaPluginConvention>().sourceSets.getByName("main").output
javaPluginConvention().sourceSets.getByName("main").output
}
fun Project.getSources(): SourceDirectorySet? = withJavaPlugin {
the<JavaPluginConvention>().sourceSets.getByName("main").allSource
javaPluginConvention().sourceSets.getByName("main").allSource
}
fun Project.getResourceFiles(): SourceDirectorySet? = withJavaPlugin {
the<JavaPluginConvention>().sourceSets.getByName("main").resources
javaPluginConvention().sourceSets.getByName("main").resources
}
fun File(root: File, vararg children: String): File = children.fold(root, { f, c -> File(f, c) })
@@ -54,7 +54,7 @@ var Project.javaHome: String?
set(v) { extra["javaHome"] = v }
fun Project.generator(fqName: String, sourceSet: SourceSet? = null) = smartJavaExec {
classpath = (sourceSet ?: the<JavaPluginConvention>().sourceSets["test"]).runtimeClasspath
classpath = (sourceSet ?: javaPluginConvention().sourceSets["test"]).runtimeClasspath
main = fqName
workingDir = rootDir
}
@@ -66,3 +66,5 @@ fun Project.getBooleanProperty(name: String): Boolean? = this.findProperty(name)
}
inline fun CopySourceSpec.from(crossinline filesProvider: () -> Any?): CopySourceSpec = from(Callable { filesProvider() })
fun Project.javaPluginConvention(): JavaPluginConvention = the()
+3 -3
View File
@@ -23,7 +23,7 @@ fun Project.classesDirsArtifact(): FileCollection {
val classesDirsCfg = configurations.getOrCreate("classes-dirs")
val classesDirs = the<JavaPluginConvention>().sourceSets["main"].output.classesDirs
val classesDirs = javaPluginConvention().sourceSets["main"].output.classesDirs
val classesTask = tasks["classes"]
@@ -44,7 +44,7 @@ fun Project.testsJar(body: Jar.() -> Unit = {}): Jar {
return task<Jar>(MAGIC_DO_NOT_CHANGE_TEST_JAR_TASK_NAME) {
dependsOn("testClasses")
pluginManager.withPlugin("java") {
from(project.the<JavaPluginConvention>().sourceSets.getByName("test").output)
from(project.javaPluginConvention().sourceSets.getByName("test").output)
}
classifier = "tests"
body()
@@ -88,7 +88,7 @@ fun Project.sourcesJar(sourceSet: String? = "main", body: Jar.() -> Unit = {}):
try {
if (sourceSet != null) {
project.pluginManager.withPlugin("java-base") {
from(project.the<JavaPluginConvention>().sourceSets[sourceSet].allSource)
from(project.javaPluginConvention().sourceSets[sourceSet].allSource)
}
}
} catch (e: UnknownDomainObjectException) {
+3 -3
View File
@@ -45,7 +45,7 @@ fun Project.configureInstrumentation() {
// classes from the "friendly directory" to the compile classpath.
val testCompile = tasks.findByName("compileTestKotlin") as AbstractCompile?
testCompile?.doFirst {
val mainSourceSet = the<JavaPluginConvention>().sourceSets.getByName("main")
val mainSourceSet = javaPluginConvention().sourceSets.getByName("main")
testCompile.classpath = (testCompile.classpath
- mainSourceSet.output.classesDirs
+ files((mainSourceSet as ExtensionAware).extra.get("classesDirsCopy")))
@@ -59,7 +59,7 @@ fun Project.configureInstrumentation() {
}
afterEvaluate {
the<JavaPluginConvention>().sourceSets.all { sourceSetParam ->
javaPluginConvention().sourceSets.all { sourceSetParam ->
// This copy will ignore filters, but they are unlikely to be used.
val classesDirs = (sourceSetParam.output.classesDirs as ConfigurableFileCollection).from as Collection<Any>
@@ -150,7 +150,7 @@ open class IntelliJInstrumentCodeTask : ConventionTask() {
// Instrumentation needs to have access to sources of forms for inclusion
val depSourceDirectorySets = project.configurations["compile"].dependencies.withType(ProjectDependency::class.java)
.map { p -> p.dependencyProject.the<JavaPluginConvention>().sourceSets.getByName("main").allSource.sourceDirectories }
.map { p -> p.dependencyProject.javaPluginConvention().sourceSets.getByName("main").allSource.sourceDirectories }
val instrumentationClasspath =
depSourceDirectorySets.fold(sourceSet!!.compileClasspath) { acc, v -> acc + v }.asPath.also {
logger.info("Using following dependency source dirs: $it")
+3 -3
View File
@@ -45,7 +45,7 @@ fun Project.configureInstrumentation() {
// classes from the "friendly directory" to the compile classpath.
val testCompile = tasks.findByName("compileTestKotlin") as AbstractCompile?
testCompile?.doFirst {
val mainSourceSet = the<JavaPluginConvention>().sourceSets.getByName("main")
val mainSourceSet = javaPluginConvention().sourceSets.getByName("main")
testCompile.classpath = (testCompile.classpath
- mainSourceSet.output.classesDirs
+ files((mainSourceSet as ExtensionAware).extra.get("classesDirsCopy")))
@@ -59,7 +59,7 @@ fun Project.configureInstrumentation() {
}
afterEvaluate {
the<JavaPluginConvention>().sourceSets.all { sourceSetParam ->
javaPluginConvention().sourceSets.all { sourceSetParam ->
// This copy will ignore filters, but they are unlikely to be used.
val classesDirs = (sourceSetParam.output.classesDirs as ConfigurableFileCollection).from as Collection<Any>
@@ -150,7 +150,7 @@ open class IntelliJInstrumentCodeTask : ConventionTask() {
// Instrumentation needs to have access to sources of forms for inclusion
val depSourceDirectorySets = project.configurations["compile"].dependencies.withType(ProjectDependency::class.java)
.map { p -> p.dependencyProject.the<JavaPluginConvention>().sourceSets.getByName("main").allSource.sourceDirectories }
.map { p -> p.dependencyProject.javaPluginConvention().sourceSets.getByName("main").allSource.sourceDirectories }
val instrumentationClasspath =
depSourceDirectorySets.fold(sourceSet!!.compileClasspath) { acc, v -> acc + v }.asPath.also {
logger.info("Using following dependency source dirs: $it")
@@ -118,7 +118,7 @@ fun Project.runIdeTask(name: String, ideaPluginDir: File, ideaSandboxDir: File,
return task<JavaExec>(name) {
val ideaSandboxConfigDir = File(ideaSandboxDir, "config")
classpath = the<JavaPluginConvention>().sourceSets["main"].runtimeClasspath
classpath = javaPluginConvention().sourceSets["main"].runtimeClasspath
main = "com.intellij.idea.Main"
+2 -2
View File
@@ -13,7 +13,7 @@ class SourceSetsBuilder(val project: Project) {
inline operator fun String.invoke(crossinline body: SourceSet.() -> Unit): SourceSet {
val sourceSetName = this
return project.the<JavaPluginConvention>().sourceSets.maybeCreate(sourceSetName).apply {
return project.javaPluginConvention().sourceSets.maybeCreate(sourceSetName).apply {
none()
body()
}
@@ -52,7 +52,7 @@ fun SourceSet.projectDefault() {
fun Project.getSourceSetsFrom(projectPath: String): SourceSetContainer {
evaluationDependsOn(projectPath)
return project(projectPath).the<JavaPluginConvention>().sourceSets
return project(projectPath).javaPluginConvention().sourceSets
}
+1 -1
View File
@@ -72,7 +72,7 @@ fun Project.projectTest(taskName: String = "test", body: Test.() -> Unit = {}):
systemProperty("idea.is.unit.test", "true")
systemProperty("idea.home.path", intellijRootDir().canonicalPath)
environment("NO_FS_ROOTS_ACCESS_CHECK", "true")
environment("PROJECT_CLASSES_DIRS", the<JavaPluginConvention>().sourceSets.getByName("test").output.classesDirs.asPath)
environment("PROJECT_CLASSES_DIRS", javaPluginConvention().sourceSets.getByName("test").output.classesDirs.asPath)
environment("PROJECT_BUILD_DIR", buildDir)
systemProperty("jps.kotlin.home", rootProject.extra["distKotlinHomeDir"])
systemProperty("kotlin.ni", if (rootProject.hasProperty("newInferenceTests")) "true" else "false")
+1 -1
View File
@@ -113,7 +113,7 @@ jar.from("../idea/src") {
projectTest {
dependsOn(*testDistProjects.map { "$it:dist" }.toTypedArray())
workingDir = rootDir
systemProperty("kotlin.test.script.classpath", the<JavaPluginConvention>().sourceSets.getByName("test").output.classesDirs.joinToString(File.pathSeparator))
systemProperty("kotlin.test.script.classpath", javaPluginConvention().sourceSets.getByName("test").output.classesDirs.joinToString(File.pathSeparator))
doFirst {
systemProperty("kotlin.ant.classpath", antLauncherJar.asPath)
systemProperty("kotlin.ant.launcher.class", "org.apache.tools.ant.Main")
@@ -35,7 +35,7 @@ sourceSets {
noDefaultJar()
runtimeJar(task<ShadowJar>("shadowJar")) {
from(the<JavaPluginConvention>().sourceSets.getByName("main").output)
from(javaPluginConvention().sourceSets.getByName("main").output)
fromEmbeddedComponents()
}
@@ -34,7 +34,7 @@ sourceSets {
noDefaultJar()
runtimeJar(task<ShadowJar>("shadowJar")) {
from(the<JavaPluginConvention>().sourceSets.getByName("main").output)
from(javaPluginConvention().sourceSets.getByName("main").output)
fromEmbeddedComponents()
}
+1 -1
View File
@@ -27,7 +27,7 @@ projectTest {
executable = "${rootProject.extra["JDK_18"]!!}/bin/java"
dependsOn(":dist")
workingDir = rootDir
systemProperty("kotlin.test.script.classpath", the<JavaPluginConvention>().sourceSets.getByName("test").output.classesDirs.joinToString(File.pathSeparator))
systemProperty("kotlin.test.script.classpath", javaPluginConvention().sourceSets.getByName("test").output.classesDirs.joinToString(File.pathSeparator))
systemProperty("idea.home.path", intellijRootDir().canonicalPath)
}
+1 -1
View File
@@ -9,7 +9,7 @@ sourceSets {
"test" { projectDefault() }
}
val builtinsSourceSet = the<JavaPluginConvention>().sourceSets.create("builtins") {
val builtinsSourceSet = javaPluginConvention().sourceSets.create("builtins") {
java.srcDir("builtins")
}
val builtinsCompile by configurations
+1 -1
View File
@@ -9,7 +9,7 @@ sourceSets {
"test" { projectDefault() }
}
val builtinsSourceSet = the<JavaPluginConvention>().sourceSets.create("builtins") {
val builtinsSourceSet = javaPluginConvention().sourceSets.create("builtins") {
java.srcDir("builtins")
}
val builtinsCompile by configurations
+1 -1
View File
@@ -9,7 +9,7 @@ sourceSets {
"test" { projectDefault() }
}
val builtinsSourceSet = the<JavaPluginConvention>().sourceSets.create("builtins") {
val builtinsSourceSet = javaPluginConvention().sourceSets.create("builtins") {
java.srcDir("builtins")
}
val builtinsCompile by configurations
+1 -1
View File
@@ -128,7 +128,7 @@ val performanceTestRuntime by configurations.creating {
}
val performanceTest by run {
val sourceSets = the<JavaPluginConvention>().sourceSets
val sourceSets = javaPluginConvention().sourceSets
sourceSets.creating {
compileClasspath += sourceSets["test"].output
compileClasspath += sourceSets["main"].output
+1 -1
View File
@@ -60,7 +60,7 @@ testsJar()
val testForWebDemo by task<Test> {
include("**/*JavaToKotlinConverterForWebDemoTestGenerated*")
classpath = the<JavaPluginConvention>().sourceSets["test"].runtimeClasspath
classpath = javaPluginConvention().sourceSets["test"].runtimeClasspath
workingDir = rootDir
}
val cleanTestForWebDemo by tasks
+1 -1
View File
@@ -58,7 +58,7 @@ testsJar()
val testForWebDemo by task<Test> {
include("**/*JavaToKotlinConverterForWebDemoTestGenerated*")
classpath = the<JavaPluginConvention>().sourceSets["test"].runtimeClasspath
classpath = javaPluginConvention().sourceSets["test"].runtimeClasspath
workingDir = rootDir
}
val cleanTestForWebDemo by tasks
+1 -1
View File
@@ -59,7 +59,7 @@ testsJar()
val testForWebDemo by task<Test> {
include("**/*JavaToKotlinConverterForWebDemoTestGenerated*")
classpath = the<JavaPluginConvention>().sourceSets["test"].runtimeClasspath
classpath = javaPluginConvention().sourceSets["test"].runtimeClasspath
workingDir = rootDir
}
val cleanTestForWebDemo by tasks
+1 -1
View File
@@ -60,7 +60,7 @@ testsJar()
val testForWebDemo by task<Test> {
include("**/*JavaToKotlinConverterForWebDemoTestGenerated*")
classpath = the<JavaPluginConvention>().sourceSets["test"].runtimeClasspath
classpath = javaPluginConvention().sourceSets["test"].runtimeClasspath
workingDir = rootDir
}
val cleanTestForWebDemo by tasks
@@ -49,7 +49,7 @@ val shadowJar = task<ShadowJar>("shadowJar") {
callGroovy("manifestAttributes", manifest, project)
manifest.attributes["Implementation-Version"] = version
from(the<JavaPluginConvention>().sourceSets["main"].output)
from(javaPluginConvention().sourceSets["main"].output)
exclude("**/*.proto")
configurations = listOf(shadows)
+3 -3
View File
@@ -131,11 +131,11 @@ val reflectShadowJar by task<ShadowJar> {
version = null
callGroovy("manifestAttributes", manifest, project, "Main", true)
from(the<JavaPluginConvention>().sourceSets.getByName("main").output)
from(project(":core:descriptors.jvm").the<JavaPluginConvention>().sourceSets.getByName("main").resources) {
from(javaPluginConvention().sourceSets.getByName("main").output)
from(project(":core:descriptors.jvm").javaPluginConvention().sourceSets.getByName("main").resources) {
include("META-INF/services/**")
}
from(project(":core:deserialization").the<JavaPluginConvention>().sourceSets.getByName("main").resources) {
from(project(":core:deserialization").javaPluginConvention().sourceSets.getByName("main").resources) {
include("META-INF/services/**")
}
+1 -1
View File
@@ -32,7 +32,7 @@ val shadowJar by task<ShadowJar> {
classifier = "shadow"
version = null
configurations = listOf(shadows)
from(the<JavaPluginConvention>().sourceSets.getByName("main").output)
from(javaPluginConvention().sourceSets.getByName("main").output)
manifest {
attributes["Main-Class"] = "org.jetbrains.kotlin.kotlinp.Main"
}
@@ -42,7 +42,7 @@ projectTest {
":kotlin-script-runtime:dist")
workingDir = File(rootDir, "libraries/tools/kotlin-compiler-client-embeddable-test/src")
doFirst {
systemProperty("kotlin.test.script.classpath", the<JavaPluginConvention>().sourceSets.getByName("test").output.classesDirs.joinToString(File.pathSeparator))
systemProperty("kotlin.test.script.classpath", javaPluginConvention().sourceSets.getByName("test").output.classesDirs.joinToString(File.pathSeparator))
systemProperty("compilerJar", testRuntimeCompilerJar.singleFile.canonicalPath)
systemProperty("stdlibJar", testStdlibJar.singleFile.canonicalPath)
systemProperty("scriptRuntimeJar", testScriptRuntimeJar.singleFile.canonicalPath)
+1 -1
View File
@@ -37,7 +37,7 @@ val compilerModules: Array<String> by rootProject.extra
compilerModules.forEach { evaluationDependsOn(it) }
val compiledModulesSources = compilerModules.map {
project(it).the<JavaPluginConvention>().sourceSets.getByName("main").allSource
project(it).javaPluginConvention().sourceSets.getByName("main").allSource
}
dependencies {
+1 -1
View File
@@ -37,7 +37,7 @@ val compilerModules: Array<String> by rootProject.extra
compilerModules.forEach { evaluationDependsOn(it) }
val compiledModulesSources = compilerModules.map {
project(it).the<JavaPluginConvention>().sourceSets.getByName("main").allSource
project(it).javaPluginConvention().sourceSets.getByName("main").allSource
}
dependencies {
+1 -1
View File
@@ -37,7 +37,7 @@ val compilerModules: Array<String> by rootProject.extra
compilerModules.forEach { evaluationDependsOn(it) }
val compiledModulesSources = compilerModules.map {
project(it).the<JavaPluginConvention>().sourceSets.getByName("main").allSource
project(it).javaPluginConvention().sourceSets.getByName("main").allSource
}
dependencies {
+1 -1
View File
@@ -10,7 +10,7 @@ runtimeJar {
dependsOn(":idea:formatter:classes")
project(":idea:formatter").let { p ->
p.pluginManager.withPlugin("java") {
from(p.the<JavaPluginConvention>().sourceSets.getByName("main").output)
from(p.javaPluginConvention().sourceSets.getByName("main").output)
}
}
from(fileTree("$rootDir/idea/formatter")) { include("src/**") } // Eclipse formatter sources navigation depends on this
+1 -1
View File
@@ -32,7 +32,7 @@ runtimeJar {
dependsOn(":idea:ide-common:classes")
project(":idea:ide-common").let { p ->
p.pluginManager.withPlugin("java") {
from(p.the<JavaPluginConvention>().sourceSets.getByName("main").output)
from(p.javaPluginConvention().sourceSets.getByName("main").output)
}
}
from(fileTree("$rootDir/idea/ide-common")) { include("src/**") } // Eclipse formatter sources navigation depends on this
+2 -2
View File
@@ -8,7 +8,7 @@ plugins {
kotlin("jvm")
}
val ideaProjectResources = project(":idea").the<JavaPluginConvention>().sourceSets["main"].output.resourcesDir
val ideaProjectResources = project(":idea").javaPluginConvention().sourceSets["main"].output.resourcesDir
evaluationDependsOn(":prepare:idea-plugin")
@@ -169,7 +169,7 @@ val jar = runtimeJar(task<ShadowJar>("shadowJar")) {
val communityPluginJar = project(communityPluginProject).configurations["runtimeJar"].artifacts.files.singleFile
from(zipTree(communityPluginJar), { exclude("META-INF/plugin.xml") })
from(preparedResources, { include("META-INF/plugin.xml") })
from(the<JavaPluginConvention>().sourceSets.getByName("main").output)
from(javaPluginConvention().sourceSets.getByName("main").output)
archiveName = "kotlin-plugin.jar"
}
+2 -2
View File
@@ -8,7 +8,7 @@ plugins {
kotlin("jvm")
}
val ideaProjectResources = project(":idea").the<JavaPluginConvention>().sourceSets["main"].output.resourcesDir
val ideaProjectResources = project(":idea").javaPluginConvention().sourceSets["main"].output.resourcesDir
evaluationDependsOn(":prepare:idea-plugin")
@@ -168,7 +168,7 @@ val jar = runtimeJar(task<ShadowJar>("shadowJar")) {
val communityPluginJar = project(communityPluginProject).configurations["runtimeJar"].artifacts.files.singleFile
from(zipTree(communityPluginJar), { exclude("META-INF/plugin.xml") })
from(preparedResources, { include("META-INF/plugin.xml") })
from(the<JavaPluginConvention>().sourceSets.getByName("main").output)
from(javaPluginConvention().sourceSets.getByName("main").output)
archiveName = "kotlin-plugin.jar"
}
+2 -2
View File
@@ -10,7 +10,7 @@ plugins {
kotlin("jvm")
}
val ideaProjectResources = project(":idea").the<JavaPluginConvention>().sourceSets["main"].output.resourcesDir
val ideaProjectResources = project(":idea").javaPluginConvention().sourceSets["main"].output.resourcesDir
evaluationDependsOn(":prepare:idea-plugin")
@@ -170,7 +170,7 @@ val jar = runtimeJar(task<ShadowJar>("shadowJar")) {
val communityPluginJar = project(communityPluginProject).configurations["runtimeJar"].artifacts.files.singleFile
from(zipTree(communityPluginJar), { exclude("META-INF/plugin.xml") })
from(preparedResources, { include("META-INF/plugin.xml") })
from(the<JavaPluginConvention>().sourceSets.getByName("main").output)
from(javaPluginConvention().sourceSets.getByName("main").output)
archiveName = "kotlin-plugin.jar"
}
+2 -2
View File
@@ -10,7 +10,7 @@ plugins {
kotlin("jvm")
}
val ideaProjectResources = project(":idea").the<JavaPluginConvention>().sourceSets["main"].output.resourcesDir
val ideaProjectResources = project(":idea").javaPluginConvention().sourceSets["main"].output.resourcesDir
evaluationDependsOn(":prepare:idea-plugin")
@@ -171,7 +171,7 @@ val jar = runtimeJar(task<ShadowJar>("shadowJar")) {
val communityPluginJar = project(communityPluginProject).configurations["runtimeJar"].artifacts.files.singleFile
from(zipTree(communityPluginJar), { exclude("META-INF/plugin.xml") })
from(preparedResources, { include("META-INF/plugin.xml") })
from(the<JavaPluginConvention>().sourceSets.getByName("main").output)
from(javaPluginConvention().sourceSets.getByName("main").output)
archiveName = "kotlin-plugin.jar"
}