[Git][java-team/gradle-kotlin-dsl][upstream] 2 commits: New upstream version 0.14.0
Emmanuel Bourg (@ebourg)
gitlab at salsa.debian.org
Wed Sep 23 12:01:23 BST 2026
Emmanuel Bourg pushed to branch upstream at Debian Java Maintainers / gradle-kotlin-dsl
Commits:
ff2707aa by Emmanuel Bourg at 2023-10-04T18:50:59+02:00
New upstream version 0.14.0
- - - - -
5da31524 by Emmanuel Bourg at 2026-09-21T13:45:40+02:00
New upstream version 0.14.2
- - - - -
26 changed files:
- README.md
- build.gradle.kts
- + doc/release-notes/0.13.1.md
- − doc/release-notes/0.13.2.md
- + doc/release-notes/0.14.0.md
- kotlin-version.txt
- plugins/src/test/kotlin/org/gradle/kotlin/dsl/plugins/embedded/EmbeddedKotlinPluginTest.kt
- provider/src/main/kotlin/org/gradle/kotlin/dsl/GroovyInteroperability.kt
- provider/src/main/kotlin/org/gradle/kotlin/dsl/KotlinSettingsScript.kt
- provider/src/main/kotlin/org/gradle/kotlin/dsl/accessors/ProjectSchema.kt
- provider/src/main/kotlin/org/gradle/kotlin/dsl/codegen/PluginIdExtensions.kt
- + provider/src/main/kotlin/org/gradle/kotlin/dsl/resolver/ExtractGradleSourcesTransform.kt
- provider/src/main/kotlin/org/gradle/kotlin/dsl/resolver/KotlinBuildScriptDependenciesResolver.kt
- provider/src/main/kotlin/org/gradle/kotlin/dsl/resolver/ResolverEvent.kt
- + provider/src/main/kotlin/org/gradle/kotlin/dsl/resolver/SourceDistributionProvider.kt
- provider/src/main/kotlin/org/gradle/kotlin/dsl/resolver/SourcePathProvider.kt
- provider/src/main/kotlin/org/gradle/kotlin/dsl/support/KotlinCompiler.kt
- provider/src/main/kotlin/org/gradle/kotlin/dsl/support/zipTo.kt → provider/src/main/kotlin/org/gradle/kotlin/dsl/support/zip.kt
- provider/src/test/kotlin/org/gradle/kotlin/dsl/GroovyInteroperabilityTest.kt
- provider/src/test/kotlin/org/gradle/kotlin/dsl/accessors/ProjectSchemaAccessorsIntegrationTest.kt
- provider/src/test/kotlin/org/gradle/kotlin/dsl/codegen/UserGuideLinkTest.kt
- + provider/src/test/kotlin/org/gradle/kotlin/dsl/resolver/SourceDistributionResolverIntegrationTest.kt
- provider/src/test/kotlin/org/gradle/kotlin/dsl/resolver/SourcePathProviderTest.kt
- test-fixtures/src/main/kotlin/org/gradle/kotlin/dsl/fixtures/AbstractIntegrationTest.kt
- tooling-builders/src/main/kotlin/org/gradle/kotlin/dsl/tooling/builders/KotlinBuildScriptModelBuilder.kt
- tooling-builders/src/main/kotlin/org/gradle/kotlin/dsl/tooling/builders/KotlinLibSources.kt
Changes:
=====================================
README.md
=====================================
@@ -30,11 +30,7 @@ Staying in Touch
Come chat with us in the #gradle channel of the public [Kotlin Slack](http://slack.kotlinlang.org/) instance.
-Limitations
------------
- * `settings.gradle` cannot yet be written Kotlin, continue to use Groovy there for now.
-
License
-------
Like the rest of Gradle, the _Gradle Kotlin DSL_ is released under version 2.0 of the [Apache License](LICENSE.md).
=====================================
build.gradle.kts
=====================================
@@ -26,11 +26,11 @@ plugins {
allprojects {
group = "org.gradle"
- version = "0.13.2"
+ version = "0.14.2"
}
-val publishedPluginsVersion by extra { "0.13.1" }
-val futurePluginsVersion = "0.13.2"
+val publishedPluginsVersion by extra { "0.14.0" }
+val futurePluginsVersion = "0.14.1"
project(":plugins") {
group = "org.gradle.kotlin"
version = futurePluginsVersion
=====================================
doc/release-notes/0.13.1.md
=====================================
@@ -0,0 +1,40 @@
+Gradle Kotlin DSL 0.13.1 Release Notes
+============================
+
+Gradle Kotlin DSL v0.13.1 brings support for `settings.gradle.kts` files, Kotlin standard library extensions to the Java 7 and Java 8 APIs for use in build scripts, improvements to the `plugins {}` DSL, and more!
+
+v0.13.1 is included in Gradle 4.4 RC1.
+
+The features in this release are also available for immediate use within the latest Gradle Kotlin DSL distribution snapshot. To use it, upgrade your Gradle wrapper in the following fashion:
+
+ $ cd $YOUR_PROJECT_ROOT
+ $ gradle wrapper --gradle-distribution-url
+ https://repo.gradle.org/gradle/dist-snapshots/gradle-kotlin-dsl-4.4-20171117171149+0000-all.zip
+
+Once Gradle 4.4 RC1 is out, we encourage all users to upgrade in the following fashion:
+
+ $ cd $YOUR_PROJECT_ROOT
+ $ gradle wrapper --gradle-version 4.4-rc-1 --distribution-type all
+
+
+Updates since v0.12.3
+----------------------
+
+ * **Support settings file written in Kotlin** (#56). Gradle will now look for a file named `settings.gradle.kts` whenever `settings.gradle` cannot be found during the [initialization phase](https://docs.gradle.org/current/userguide/build_lifecycle.html#sec:build_phases). `settings.gradle.kts` is evaluated against the [Gradle Settings object](https://docs.gradle.org/current/dsl/org.gradle.api.initialization.Settings.html) so all of its members can be referenced without qualification. In addition, all members of the [ScriptApi interface](https://github.com/gradle/kotlin-dsl/blob/37c28af671d0498c72c9e72d24227cddc7d3932e/provider/src/main/kotlin/org/gradle/kotlin/dsl/provider/ScriptApi.kt#L50) are supported and can also be referenced without qualification. Support for authoring `settings.gradle.kts` landed on IntelliJ IDEA starting with version `1.1.60-eap-43` of the Kotlin plugin (#531):
+
+ 
+
+ All [samples](https://github.com/gradle/kotlin-dsl/tree/95d1fcb02655f5abb1e47fa23f5c76b948dc4dba/samples) have been updated to take advantage of `settings.gradle.kts` support (#550) and new samples have been added demonstrating how to use `settings.gradle.kts` to configure:
+ * the [build cache](https://guides.gradle.org/using-build-cache/) (#570, [sample](https://github.com/gradle/kotlin-dsl/tree/95d1fcb02655f5abb1e47fa23f5c76b948dc4dba/samples/build-cache))
+ * dependency substitutions in [composite builds](https://docs.gradle.org/current/userguide/composite_builds.html) (#571, [sample](https://github.com/gradle/kotlin-dsl/tree/95d1fcb02655f5abb1e47fa23f5c76b948dc4dba/samples/composite-builds))
+ * [source dependencies](https://github.com/gradle/gradle-native/issues/42) (#572, [sample](https://github.com/gradle/kotlin-dsl/tree/95d1fcb02655f5abb1e47fa23f5c76b948dc4dba/samples/source-control))
+
+ * **Default `build-scan` plugin version is the same as the one applied by Gradle when the `--scan` option is specified** (#490). Prior to this release, the default version of the `build-scan` plugin was hard-coded in the `kotlin-dsl` distribution. That information is now managed by Gradle Core.
+
+ * **Expose Kotlin standard library extensions for Java 7 and Java 8 to build scripts** (#558). The build script classpath now includes `kotlin-stdlib-jre8` and `kotlin-stdlib-jre7` enabling the use of features such as [named regex groups](https://github.com/gradle/gradle/issues/3194), [kotlin.streams](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.streams/index.html) among other things.
+
+ * **Android sample update** (#586). Now on Android Gradle Plugin 3.0.0 thanks to @liutikas. Thank you, @liutikas!
+
+ * **kotlin2js plugin sample updated to leverage the `plugins` block** (#539).
+
+ * **Account for `PropertyState` deprecation in favor of `Property`** (#540). [`org.gradle.api.provider.PropertyState`](https://docs.gradle.org/current/javadoc/index.html?org/gradle/api/provider/PropertyState.html) has been deprecated in favour of [`org.gradle.api.provider.Property`](https://docs.gradle.org/current/javadoc/index.html?org/gradle/api/provider/PropertyState.html). Samples and API extensions have been updated to take the change into account.
=====================================
doc/release-notes/0.13.2.md deleted
=====================================
@@ -1,29 +0,0 @@
-Gradle Kotlin DSL 0.13.2 Release Notes
-=============================
-
-Gradle Kotlin DSL v0.13.2 fixes a regression in [v0.13.1][v0.13.1] that prevented the use of nested Kotlin build scripts together with the `--scan` command line option.
-
-v0.13.2 will be included in the upcoming Gradle 4.4.1.
-
-The features in this release are also available for immediate use within the latest Gradle Kotlin DSL distribution snapshot. To use it, upgrade your Gradle wrapper in the following fashion:
-
- $ cd $YOUR_PROJECT_ROOT
- $ gradle wrapper --gradle-distribution-url https://repo.gradle.org/gradle/dist-snapshots/gradle-kotlin-dsl-4.4-20171208150335+0000-all.zip
-
-Once Gradle 4.4.1 is out, we encourage all users to upgrade in the following fashion:
-
-To use it, upgrade your Gradle wrapper in the following fashion:
-
- $ cd $YOUR_PROJECT_ROOT
- $ gradle wrapper --gradle-version 4.4.1 --distribution-type all
-
-## Breaking changes
-
-_There are no breaking changes upgrading from 0.13.1 to 0.13.2._
-
-Fixes since v0.13.1
--------------------
-
- * **Plugin with id 'com.gradle.build-scan' not found** (gradle/gradle#3759).
-
-[v0.13.1]: https://github.com/gradle/kotlin-dsl/releases/tag/v0.13.1
=====================================
doc/release-notes/0.14.0.md
=====================================
@@ -0,0 +1,32 @@
+Gradle Kotlin DSL 0.14.0 Release Notes
+============================
+
+Gradle Kotlin DSL v0.14.0 brings the latest and greatest Kotlin 1.2, improved interoperability with Groovy plugins and more.
+
+v0.14.0 will be included in Gradle 4.5.
+
+The features in this release are also available for immediate use within the latest Gradle Kotlin DSL distribution snapshot. To use it, upgrade your Gradle wrapper in the following fashion:
+
+ $ cd $YOUR_PROJECT_ROOT
+ $ gradle wrapper --gradle-distribution-url https://repo.gradle.org/gradle/dist-snapshots/gradle-kotlin-dsl-4.5-20171202002741+0000-all.zip
+
+Once Gradle 4.5 RC1 is out, we encourage all users to upgrade in the following fashion:
+
+ $ cd $YOUR_PROJECT_ROOT
+ $ gradle wrapper --gradle-version 4.5-rc-1 --distribution-type all
+
+Breaking changes
+----------------
+
+There are no breaking changes upgrading from 0.13.1 to 0.14.0.
+
+Updates since v0.13.1
+----------------------
+
+ * **Kotlin 1.2** (#617, #526). The embedded Kotlin version was upgraded from Kotlin 1.1.51 to the latest [Kotlin 1.2 release](https://blog.jetbrains.com/kotlin/2017/11/kotlin-1-2-released/).
+
+ * **Improved Groovy interop with null receiving closures** (#594). Thanks to @JLLeitschuh it's now much easier to interact with plugins that expect Groovy closures that either accept or return `null`.
+
+ * **Navigation to Gradle sources in IDEA with a `-bin` distribution** (#604). Previously, the Kotlin DSL runtime expected an `-all` Gradle distribution to be used in order to enable navigation to the Gradle sources. When this distribution wasn't used (typically with the wrapper) navigating to Gradle sources wasn't possible. Starting with this release, whenever the Gradle sources are not available locally, the Kotlin DSL runtime will do its best to download a compatible source distribution and make it available to the IDE for navigation.
+
+ * **Android sample update** (#586). Now on Android Gradle Plugin 3.0.1.
=====================================
kotlin-version.txt
=====================================
@@ -1 +1 @@
-1.1.51
+1.2.0
=====================================
plugins/src/test/kotlin/org/gradle/kotlin/dsl/plugins/embedded/EmbeddedKotlinPluginTest.kt
=====================================
@@ -102,8 +102,6 @@ class EmbeddedKotlinPluginTest : AbstractPluginTest() {
withBuildScript("""
- import org.gradle.plugins.ide.internal.IdeDependenciesExtractor
-
plugins {
`embedded-kotlin`
}
@@ -116,20 +114,38 @@ class EmbeddedKotlinPluginTest : AbstractPluginTest() {
${dependencyDeclarationsFor("compile", listOf("stdlib", "reflect"))}
}
- configurations["compileClasspath"].files.map { println(it) }
-
- tasks {
- "downloadAuxiliaries" {
- val depsExtractor = IdeDependenciesExtractor()
- val deps = depsExtractor.extractRepoFileDependencies(dependencies,
- listOf(configurations["compileClasspath"]),
- emptyList(),
- true, true)
- deps.forEach { it.sourceFiles.forEach { println(it.name) } }
- deps.forEach { it.javadocFiles.forEach { println(it.name) } }
- }
- }
-
+ configurations["compileClasspath"].files.forEach {
+ println(it)
+ }
+
+ val components =
+ configurations
+ .compile
+ .incoming
+ .artifactView { lenient(true) }
+ .artifacts
+ .map { it.id.componentIdentifier }
+
+ val resolvedComponents =
+ dependencies
+ .createArtifactResolutionQuery()
+ .forComponents(*components.toTypedArray())
+ .withArtifacts(
+ JvmLibrary::class.java,
+ SourcesArtifact::class.java,
+ JavadocArtifact::class.java)
+ .execute()
+ .resolvedComponents
+
+ inline
+ fun <reified T : Artifact> printFileNamesOf() =
+ resolvedComponents
+ .flatMap { it.getArtifacts(T::class.java) }
+ .filterIsInstance<ResolvedArtifactResult>()
+ .forEach { println(it.file.name) }
+
+ printFileNamesOf<SourcesArtifact>()
+ printFileNamesOf<JavadocArtifact>()
""")
val result = buildWithPlugin("help")
=====================================
provider/src/main/kotlin/org/gradle/kotlin/dsl/GroovyInteroperability.kt
=====================================
@@ -33,7 +33,7 @@ import org.codehaus.groovy.runtime.InvokerHelper.getMetaClass
*
* @see [KotlinClosure1]
*/
-fun <T : Any> Any.closureOf(action: T.() -> Unit): Closure<Any?> =
+fun <T> Any.closureOf(action: T.() -> Unit): Closure<Any?> =
KotlinClosure1(action, this, this)
@@ -84,7 +84,7 @@ open class KotlinClosure0<V : Any>(
*
* @see [Closure]
*/
-class KotlinClosure1<in T : Any, V : Any>(
+class KotlinClosure1<in T : Any?, V : Any>(
val function: T.() -> V?,
owner: Any? = null,
thisObject: Any? = null) : Closure<V?>(owner, thisObject) {
@@ -106,7 +106,7 @@ class KotlinClosure1<in T : Any, V : Any>(
*
* @see [Closure]
*/
-class KotlinClosure2<in T : Any, in U : Any, V : Any>(
+class KotlinClosure2<in T : Any?, in U : Any?, V : Any>(
val function: (T, U) -> V?,
owner: Any? = null,
thisObject: Any? = null) : Closure<V?>(owner, thisObject) {
=====================================
provider/src/main/kotlin/org/gradle/kotlin/dsl/KotlinSettingsScript.kt
=====================================
@@ -46,6 +46,7 @@ import org.gradle.api.internal.file.collections.DirectoryFileTreeFactory
import org.gradle.internal.hash.FileHasher
import org.gradle.internal.hash.StreamHasher
import org.gradle.internal.reflect.Instantiator
+import org.gradle.process.internal.ExecFactory
import java.io.File
import java.net.URI
@@ -394,5 +395,6 @@ fun fileOperationsFor(settings: Settings): DefaultFileOperations {
fileLookup,
settings.serviceOf<DirectoryFileTreeFactory>(),
settings.serviceOf<StreamHasher>(),
- settings.serviceOf<FileHasher>())
+ settings.serviceOf<FileHasher>(),
+ settings.serviceOf<ExecFactory>())
}
=====================================
provider/src/main/kotlin/org/gradle/kotlin/dsl/accessors/ProjectSchema.kt
=====================================
@@ -19,6 +19,7 @@ package org.gradle.kotlin.dsl.accessors
import groovy.json.JsonOutput.toJson
import org.gradle.api.Project
+import org.gradle.api.plugins.ExtensionsSchema
import org.gradle.api.reflect.TypeOf
import org.gradle.api.reflect.TypeOf.typeOf
@@ -54,20 +55,22 @@ fun multiProjectSchemaFor(root: Project): Map<String, ProjectSchema<TypeOf<*>>>
internal
fun schemaFor(project: Project): ProjectSchema<TypeOf<*>> =
accessibleProjectSchemaFrom(
- project.extensions.schema,
+ project.extensions.extensionsSchema,
project.convention.plugins,
project.configurations.names.toList())
internal
fun accessibleProjectSchemaFrom(
- extensionSchema: Map<String, TypeOf<*>>,
+ extensionSchema: ExtensionsSchema,
conventionPlugins: Map<String, Any>,
configurationNames: List<String>): ProjectSchema<TypeOf<*>> =
ProjectSchema(
extensions = extensionSchema
- .filterKeys(::isPublic),
+ .filter { isPublic(it.name) }
+ .associateBy { it.name }
+ .mapValues { it.value.publicType },
conventions = conventionPlugins
.filterKeys(::isPublic)
.mapValues { typeOf(it.value::class.java) },
=====================================
provider/src/main/kotlin/org/gradle/kotlin/dsl/codegen/PluginIdExtensions.kt
=====================================
@@ -236,9 +236,7 @@ object UserGuideLink {
"war" to "war_plugin.html",
"windows-resource-script" to "native_software.html#native_binaries:windows-resources",
- "windows-resources" to "native_software.html#native_binaries:windows-resources",
-
- "wrapper" to "wrapper_plugin.html")
+ "windows-resources" to "native_software.html#native_binaries:windows-resources")
}
=====================================
provider/src/main/kotlin/org/gradle/kotlin/dsl/resolver/ExtractGradleSourcesTransform.kt
=====================================
@@ -0,0 +1,54 @@
+/*
+ * Copyright 2017 the original author or authors.
+ *
+ * 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.gradle.kotlin.dsl.resolver
+
+import org.gradle.api.artifacts.transform.ArtifactTransform
+
+import org.gradle.kotlin.dsl.support.unzipTo
+
+import java.io.File
+
+/**
+ * This dependency transform is responsible for extracting the sources from
+ * a downloaded ZIP of the Gradle sources, and will return the list of main sources
+ * subdirectories for all subprojects.
+ */
+class ExtractGradleSourcesTransform : ArtifactTransform() {
+
+ override fun transform(input: File): List<File> {
+ unzipTo(outputDirectory, input)
+ return sourceDirectories()
+ }
+
+ private
+ fun sourceDirectories() =
+ unzippedSubProjectsDir()?.let {
+ subDirsOf(it).flatMap { subProject ->
+ subDirsOf(File(subProject, "src/main"))
+ }
+ } ?: emptyList()
+
+ private
+ fun unzippedSubProjectsDir(): File? =
+ unzippedDistroDir()?.let {
+ File(it, "subprojects")
+ }
+
+ private
+ fun unzippedDistroDir(): File? =
+ outputDirectory.listFiles().singleOrNull()
+}
=====================================
provider/src/main/kotlin/org/gradle/kotlin/dsl/resolver/KotlinBuildScriptDependenciesResolver.kt
=====================================
@@ -59,7 +59,7 @@ class KotlinBuildScriptDependenciesResolver : ScriptDependenciesResolver {
}
}
} catch (e: Exception) {
- log(ResolutionFailure(script.file, e))
+ log(ResolutionFailure(script.file, environment, e))
previousDependencies
}
}
=====================================
provider/src/main/kotlin/org/gradle/kotlin/dsl/resolver/ResolverEvent.kt
=====================================
@@ -30,6 +30,7 @@ sealed class ResolverEvent
internal
data class ResolutionFailure(
val scriptFile: File?,
+ val environment: Map<String, Any?>?,
val failure: Exception) : ResolverEvent()
=====================================
provider/src/main/kotlin/org/gradle/kotlin/dsl/resolver/SourceDistributionProvider.kt
=====================================
@@ -0,0 +1,162 @@
+/*
+ * Copyright 2017 the original author or authors.
+ *
+ * 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.gradle.kotlin.dsl.resolver
+
+import org.gradle.api.Project
+import org.gradle.api.artifacts.Dependency
+import org.gradle.api.artifacts.repositories.ArtifactRepository
+import org.gradle.api.artifacts.repositories.IvyArtifactRepository
+import org.gradle.api.artifacts.repositories.IvyPatternRepositoryLayout
+import org.gradle.api.artifacts.transform.VariantTransform
+import org.gradle.api.attributes.Attribute
+
+import org.gradle.kotlin.dsl.create
+
+import java.io.File
+
+import java.lang.Integer.max
+
+
+interface SourceDistributionProvider {
+ fun sourceDirs(): Collection<File>
+}
+
+
+class SourceDistributionResolver(val project: Project) : SourceDistributionProvider {
+
+ companion object {
+ val artifactType = Attribute.of("artifactType", String::class.java)
+ val zipType = "zip"
+ val sourceDirectory = "src-directory"
+ }
+
+ override fun sourceDirs(): Collection<File> =
+ withSourceRepository {
+ registerTransforms()
+ transientConfigurationForSourcesDownload().files
+ }
+
+ private
+ fun <T> withSourceRepository(produce: () -> T): T =
+ createSourceRepository().let {
+ try {
+ produce()
+ } finally {
+ repositories.remove(it)
+ }
+ }
+
+ private
+ fun registerTransforms() =
+ registerTransform {
+ from.attribute(artifactType, zipType)
+ to.attribute(artifactType, sourceDirectory)
+ artifactTransform(ExtractGradleSourcesTransform::class.java)
+ }
+
+ private
+ fun transientConfigurationForSourcesDownload() =
+ detachedConfigurationFor(gradleSourceDependency()).apply {
+ attributes.attribute(artifactType, sourceDirectory)
+ }
+
+ private
+ fun detachedConfigurationFor(dependency: Dependency) =
+ configurations.detachedConfiguration(dependency)
+
+ private
+ fun gradleSourceDependency() = dependencies.create(
+ group = "gradle",
+ name = "gradle",
+ version = dependencyVersion(gradleVersion),
+ configuration = null,
+ classifier = "src",
+ ext = "zip")
+
+ private
+ fun createSourceRepository() = ivy {
+ val repoName = repositoryNameFor(gradleVersion)
+ name = "Gradle $repoName"
+ setUrl("https://services.gradle.org/$repoName")
+ layout("pattern") {
+ val layout = it as IvyPatternRepositoryLayout
+ if (isSnapshot(gradleVersion)) {
+ layout.ivy("/dummy") // avoids a lookup that interferes with version listing
+ }
+ layout.artifact("[module]-[revision](-[classifier])(.[ext])")
+ }
+ }.also {
+ // push the repository first in the list, for performance
+ makeItFirstInTheList(it)
+ }
+
+ private
+ fun repositoryNameFor(gradleVersion: String) =
+ if (isSnapshot(gradleVersion)) "distributions-snapshots" else "distributions"
+
+ private
+ fun dependencyVersion(gradleVersion: String) =
+ if (isSnapshot(gradleVersion)) toVersionRange(gradleVersion) else gradleVersion
+
+ private
+ fun isSnapshot(gradleVersion: String) = gradleVersion.contains('+')
+
+ private
+ fun toVersionRange(gradleVersion: String) =
+ "(${previousMinor(gradleVersion)}, $gradleVersion]"
+
+ private
+ fun previousMinor(gradleVersion: String): String =
+ gradleVersion
+ .split('.')
+ .take(2)
+ .map { it.takeWhile { it != '-' }.toInt() }
+ .mapIndexed { i, v -> if (i == 0) v else max(v - 1, 0) }
+ .joinToString(".") { it.toString() }
+
+ private
+ fun makeItFirstInTheList(repository: ArtifactRepository) {
+ repositories.apply {
+ remove(repository)
+ addFirst(repository)
+ }
+ }
+
+ private
+ fun registerTransform(configure: VariantTransform.() -> Unit) =
+ dependencies.registerTransform { configure(it) }
+
+ private
+ fun ivy(configure: IvyArtifactRepository.() -> Unit) =
+ repositories.ivy { configure(it) }
+
+ private
+ val repositories
+ get() = project.repositories
+
+ private
+ val configurations
+ get() = project.configurations
+
+ private
+ val dependencies
+ get() = project.dependencies
+
+ private
+ val gradleVersion
+ get() = project.gradle.gradleVersion
+}
=====================================
provider/src/main/kotlin/org/gradle/kotlin/dsl/resolver/SourcePathProvider.kt
=====================================
@@ -28,11 +28,12 @@ object SourcePathProvider {
fun sourcePathFor(
classPath: ClassPath,
projectDir: File,
- gradleHomeDir: File?): ClassPath {
+ gradleHomeDir: File?,
+ sourceDistributionResolver: SourceDistributionProvider): ClassPath {
val gradleKotlinDslJar = classPath.filter { it.name.startsWith("gradle-kotlin-dsl-") }
val projectBuildSrcRoots = buildSrcRootsOf(projectDir)
- val gradleSourceRoots = gradleHomeDir?.let { sourceRootsOf(it) } ?: emptyList()
+ val gradleSourceRoots = gradleHomeDir?.let { sourceRootsOf(it, sourceDistributionResolver) } ?: emptyList()
return gradleKotlinDslJar + projectBuildSrcRoots + gradleSourceRoots
}
@@ -48,13 +49,22 @@ object SourcePathProvider {
subDirsOf(File(projectRoot, "buildSrc/src/main"))
private
- fun sourceRootsOf(gradleInstallation: File): Collection<File> =
- subDirsOf(File(gradleInstallation, "src"))
+ fun sourceRootsOf(gradleInstallation: File, sourceDistributionResolver: SourceDistributionProvider): Collection<File> =
+ gradleInstallationSources(gradleInstallation) ?: downloadedSources(sourceDistributionResolver)
private
- fun subDirsOf(dir: File): Collection<File> =
- if (dir.isDirectory)
- dir.listFiles().filter { it.isDirectory }
- else
- emptyList()
+ fun gradleInstallationSources(gradleInstallation: File) =
+ File(gradleInstallation, "src").takeIf { it.exists() }?.let { subDirsOf(it) }
+
+ private
+ fun downloadedSources(sourceDistributionResolver: SourceDistributionProvider) =
+ sourceDistributionResolver.sourceDirs()
}
+
+
+internal
+fun subDirsOf(dir: File): Collection<File> =
+ if (dir.isDirectory)
+ dir.listFiles().filter { it.isDirectory }
+ else
+ emptyList()
=====================================
provider/src/main/kotlin/org/gradle/kotlin/dsl/support/KotlinCompiler.kt
=====================================
@@ -27,7 +27,6 @@ import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.compileBunchOfSources
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.compileScript
import org.jetbrains.kotlin.cli.jvm.config.addJvmClasspathRoot
-import org.jetbrains.kotlin.cli.jvm.config.addJvmClasspathRoots
import org.jetbrains.kotlin.codegen.CompilationException
@@ -187,13 +186,6 @@ private
fun compilerConfigurationFor(messageCollector: MessageCollector, sourceFiles: Iterable<File>): CompilerConfiguration =
CompilerConfiguration().apply {
addKotlinSourceRoots(sourceFiles.map { it.canonicalPath })
- addJvmClasspathRoots(PathUtil.getJdkClassesRootsFromCurrentJre())
- /*
- * Without this the compiler won't work with JDK 9.
- * See the discussion here:
- * https://youtrack.jetbrains.com/issue/KT-20167
- */
- put(JVMConfigurationKeys.JDK_HOME, File(System.getProperty("java.home")))
put<MessageCollector>(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY, messageCollector)
}
@@ -242,7 +234,7 @@ fun messageCollectorFor(log: Logger, pathTranslation: (String) -> String = { it
"${severity.presentableName[0]}: ${msg()}"
when (severity) {
- in CompilerMessageSeverity.ERRORS -> {
+ CompilerMessageSeverity.ERROR, CompilerMessageSeverity.EXCEPTION -> {
errors++
log.error { taggedMsg() }
}
=====================================
provider/src/main/kotlin/org/gradle/kotlin/dsl/support/zipTo.kt → provider/src/main/kotlin/org/gradle/kotlin/dsl/support/zip.kt
=====================================
@@ -19,9 +19,11 @@ package org.gradle.kotlin.dsl.support
import org.gradle.util.TextUtil.normaliseFileSeparators
import java.io.File
+import java.io.InputStream
import java.io.OutputStream
import java.util.zip.ZipEntry
+import java.util.zip.ZipFile
import java.util.zip.ZipOutputStream
@@ -57,3 +59,28 @@ fun zipTo(outputStream: OutputStream, entries: Sequence<Pair<String, ByteArray>>
}
}
+
+internal
+fun unzipTo(outputDirectory: File, zipFile: File) {
+ ZipFile(zipFile).use { zip ->
+ for (entry in zip.entries()) {
+ unzipEntryTo(outputDirectory, zip, entry)
+ }
+ }
+}
+
+
+private
+fun unzipEntryTo(outputDirectory: File, zip: ZipFile, entry: ZipEntry) {
+ val output = File(outputDirectory, entry.name)
+ if (entry.isDirectory) {
+ output.mkdirs()
+ } else {
+ zip.getInputStream(entry).use { it.copyTo(output) }
+ }
+}
+
+
+private
+fun InputStream.copyTo(file: File): Long =
+ file.outputStream().use { copyTo(it) }
=====================================
provider/src/test/kotlin/org/gradle/kotlin/dsl/GroovyInteroperabilityTest.kt
=====================================
@@ -17,6 +17,7 @@ import org.hamcrest.CoreMatchers.sameInstance
import org.hamcrest.MatcherAssert.assertThat
import org.junit.Assert.assertEquals
+import org.junit.Assert.assertNull
import org.junit.Test
class GroovyInteroperabilityTest {
@@ -28,6 +29,13 @@ class GroovyInteroperabilityTest {
assertEquals(42, list.first())
}
+ @Test
+ fun `can use closure with single nullable argument call`() {
+ var passedIntoClosure : Any? = "Something non null"
+ closureOf<Any?> { passedIntoClosure = this }.call(null)
+ assertNull(passedIntoClosure)
+ }
+
@Test
fun `can use closure with delegate call`() {
val list = arrayListOf<Int>()
@@ -37,6 +45,15 @@ class GroovyInteroperabilityTest {
}
assertEquals(42, list.first())
}
+ @Test
+ fun `can use closure with a null delegate call`() {
+ var passedIntoClosure : Any? = "Something non null"
+ delegateClosureOf<Any?> { passedIntoClosure = this }.apply {
+ delegate = null
+ call()
+ }
+ assertNull(passedIntoClosure)
+ }
@Test
fun `can adapt parameterless function using KotlinClosure0`() {
@@ -48,6 +65,15 @@ class GroovyInteroperabilityTest {
closure { "GROOVY" }.call())
}
+ @Test
+ fun `can adapt parameterless null returning function using KotlinClosure0`() {
+ fun closure(function: () -> String?) = KotlinClosure0(function)
+
+ assertEquals(
+ null,
+ closure { null }.call())
+ }
+
@Test
fun `can adapt unary function using KotlinClosure1`() {
@@ -58,6 +84,15 @@ class GroovyInteroperabilityTest {
closure { toUpperCase() }.call("groovy"))
}
+ @Test
+ fun `can adapt unary null receiving function using KotlinClosure1`() {
+ fun closure(function: String?.() -> String?) = KotlinClosure1(function)
+
+ assertEquals(
+ null,
+ closure { null }.call(null))
+ }
+
@Test
fun `can adapt binary function using KotlinClosure2`() {
@@ -68,6 +103,16 @@ class GroovyInteroperabilityTest {
closure { x, y -> x + y }.call("foo", "bar"))
}
+ @Test
+ fun `can adapt binary null receiving function using KotlinClosure2`() {
+
+ fun closure(function: (String?, String?) -> String?) = KotlinClosure2(function)
+
+ assertEquals(
+ null,
+ closure { _, _ -> null }.call(null, null))
+ }
+
@Test
fun `can invoke Closure`() {
=====================================
provider/src/test/kotlin/org/gradle/kotlin/dsl/accessors/ProjectSchemaAccessorsIntegrationTest.kt
=====================================
@@ -283,7 +283,7 @@ class ProjectSchemaAccessorsIntegrationTest : AbstractIntegrationTest() {
private
fun setOfAutomaticAccessorsFor(plugins: Set<String>): File {
val script = "plugins {\n${plugins.joinToString(separator = "\n")}\n}"
- val buildFile = withBuildScript(script, produceFile = this::newOrExisting)
+ val buildFile = withBuildScript(script, produceFile = ::newOrExisting)
return accessorsJarFor(buildFile)!!.relativeTo(buildFile.parentFile)
}
=====================================
provider/src/test/kotlin/org/gradle/kotlin/dsl/codegen/UserGuideLinkTest.kt
=====================================
@@ -39,7 +39,7 @@ class UserGuideLinkTest {
"scala", "scala-base", "signing", "standard-tool-chains",
"visual-studio",
"war",
- "windows-resource-script", "windows-resources", "wrapper")
+ "windows-resource-script", "windows-resources")
linkedPlugins.forEach {
assertThat(
"$it is linked",
@@ -56,7 +56,8 @@ class UserGuideLinkTest {
"language-base", "lifecycle-base",
"publishing",
"rhino",
- "scala-lang")
+ "scala-lang",
+ "wrapper")
unlinkedPlugins.forEach {
assertThat(
"$it is not linked",
=====================================
provider/src/test/kotlin/org/gradle/kotlin/dsl/resolver/SourceDistributionResolverIntegrationTest.kt
=====================================
@@ -0,0 +1,92 @@
+package org.gradle.kotlin.dsl.resolver
+
+import org.gradle.kotlin.dsl.fixtures.AbstractIntegrationTest
+
+import org.gradle.util.TextUtil.normaliseFileSeparators
+
+import org.hamcrest.CoreMatchers.equalTo
+import org.hamcrest.MatcherAssert.assertThat
+
+import org.junit.Test
+
+
+class SourceDistributionResolverIntegrationTest : AbstractIntegrationTest() {
+
+ @Test
+ fun `can download source distribution`() {
+
+ withBuildScript("""
+
+ val resolver = ${SourceDistributionResolver::class.qualifiedName}(project)
+ for (sourceDir in resolver.sourceDirs()) {
+ val path = sourceDir.toPath()
+ val relativePath = path.parent.parent.parent.parent.relativize(path)
+ println("*" + relativePath)
+ }
+
+ """)
+
+ assertThat(
+ build().output.linesPrefixedBy("*").map(::normaliseFileSeparators).toSet(),
+ equalTo(expectedSourceDirs))
+ }
+
+ private
+ fun String.linesPrefixedBy(prefix: String) =
+ lineSequence().filter { it.startsWith(prefix) }.map { it.removePrefix(prefix) }
+
+ private
+ val expectedSourceDirs = setOf(
+ "announce/src/main/java", "announce/src/main/resources",
+ "antlr/src/main/java", "antlr/src/main/resources",
+ "base-services/src/main/java", "base-services-groovy/src/main/java",
+ "build-cache/src/main/java", "build-cache-http/src/main/java",
+ "build-cache-http/src/main/resources", "build-comparison/src/main/groovy",
+ "build-comparison/src/main/java", "build-comparison/src/main/resources",
+ "build-init/src/main/groovy", "build-init/src/main/java",
+ "build-init/src/main/resources", "build-option/src/main/java",
+ "cli/src/main/java", "code-quality/src/main/groovy", "code-quality/src/main/resources",
+ "composite-builds/src/main/java", "composite-builds/src/main/resources",
+ "core/src/main/java", "core/src/main/resources", "core-api/src/main/java",
+ "dependency-management/src/main/java", "dependency-management/src/main/resources",
+ "diagnostics/src/main/java", "diagnostics/src/main/resources",
+ "ear/src/main/java", "ear/src/main/resources",
+ "ide/src/main/java", "ide/src/main/resources",
+ "ide-native/src/main/groovy", "ide-native/src/main/java", "ide-native/src/main/resources",
+ "ide-play/src/main/java", "ide-play/src/main/resources", "installation-beacon/src/main/java",
+ "internal-android-performance-testing/src/main/java",
+ "internal-integ-testing/src/main/groovy", "internal-integ-testing/src/main/resources",
+ "internal-performance-testing/src/main/groovy", "internal-performance-testing/src/main/resources",
+ "internal-testing/src/main/groovy", "ivy/src/main/java", "ivy/src/main/resources",
+ "jacoco/src/main/java", "jacoco/src/main/resources",
+ "javascript/src/main/java", "javascript/src/main/resources",
+ "jvm-services/src/main/java", "language-groovy/src/main/java",
+ "language-java/src/main/java", "language-java/src/main/resources",
+ "language-jvm/src/main/java", "language-jvm/src/main/resources",
+ "language-native/src/main/java", "language-native/src/main/resources",
+ "language-scala/src/main/java", "language-scala/src/main/resources",
+ "launcher/src/main/java", "launcher/src/main/resources",
+ "logging/src/main/java", "maven/src/main/java", "maven/src/main/resources",
+ "messaging/src/main/java", "model-core/src/main/java", "model-groovy/src/main/java",
+ "native/src/main/java", "osgi/src/main/java", "osgi/src/main/resources",
+ "persistent-cache/src/main/java", "platform-base/src/main/java", "platform-base/src/main/resources",
+ "platform-jvm/src/main/java", "platform-jvm/src/main/resources",
+ "platform-native/src/main/java", "platform-native/src/main/resources",
+ "platform-play/src/main/java", "platform-play/src/main/resources",
+ "plugin-development/src/main/java", "plugin-development/src/main/resources",
+ "plugin-use/src/main/java", "plugin-use/src/main/resources",
+ "plugins/src/main/java", "plugins/src/main/resources",
+ "process-services/src/main/java", "publish/src/main/java",
+ "publish/src/main/resources", "reporting/src/main/java", "reporting/src/main/resources",
+ "resources/src/main/java", "resources-gcs/src/main/java",
+ "resources-gcs/src/main/resources", "resources-http/src/main/java", "resources-http/src/main/resources",
+ "resources-s3/src/main/java", "resources-s3/src/main/resources",
+ "resources-sftp/src/main/java", "resources-sftp/src/main/resources",
+ "scala/src/main/java", "scala/src/main/resources", "signing/src/main/java", "signing/src/main/resources",
+ "test-kit/src/main/java", "testing-base/src/main/java", "testing-base/src/main/resources",
+ "testing-jvm/src/main/java", "testing-jvm/src/main/resources",
+ "testing-native/src/main/java", "testing-native/src/main/resources",
+ "tooling-api/src/main/java", "tooling-api-builders/src/main/java", "tooling-api-builders/src/main/resources",
+ "version-control/src/main/java", "version-control/src/main/resources",
+ "workers/src/main/java", "workers/src/main/resources", "wrapper/src/main/java")
+}
=====================================
provider/src/test/kotlin/org/gradle/kotlin/dsl/resolver/SourcePathProviderTest.kt
=====================================
@@ -1,16 +1,19 @@
package org.gradle.kotlin.dsl.resolver
-import org.gradle.internal.classpath.ClassPath
+import com.nhaarman.mockito_kotlin.doReturn
+import com.nhaarman.mockito_kotlin.mock
-import org.gradle.kotlin.dsl.resolver.SourcePathProvider.sourcePathFor
+import org.gradle.internal.classpath.ClassPath
import org.gradle.kotlin.dsl.fixtures.FolderBasedTest
+import org.gradle.kotlin.dsl.resolver.SourcePathProvider.sourcePathFor
import org.hamcrest.CoreMatchers.hasItems
import org.hamcrest.MatcherAssert.assertThat
import org.junit.Test
+
class SourcePathProviderTest : FolderBasedTest() {
@Test
@@ -34,11 +37,46 @@ class SourcePathProviderTest : FolderBasedTest() {
sourcePathFor(
classPath = ClassPath.EMPTY,
projectDir = folder("project"),
- gradleHomeDir = folder("gradle")).asFiles,
+ gradleHomeDir = folder("gradle"),
+ sourceDistributionResolver = mock()).asFiles,
hasItems(
folder("project/buildSrc/src/main/foo"),
folder("project/buildSrc/src/main/bar"),
folder("gradle/src/gradle-foo"),
folder("gradle/src/gradle-bar")))
}
+
+ @Test
+ fun `when src dir is missing from Gradle distribution, it will try to download it`() {
+ withFolders {
+ "project" {
+ "buildSrc/src/main" {
+ +"foo"
+ +"bar"
+ }
+ }
+ "gradle" {
+ }
+ "sourceDistribution" {
+ "src-foo" {}
+ "src-bar" {}
+ }
+ }
+
+ val resolver = mock<SourceDistributionProvider> {
+ on { sourceDirs() } doReturn subDirsOf(folder("sourceDistribution"))
+ }
+
+ assertThat(
+ sourcePathFor(
+ classPath = ClassPath.EMPTY,
+ projectDir = folder("project"),
+ gradleHomeDir = folder("gradle"),
+ sourceDistributionResolver = resolver).asFiles,
+ hasItems(
+ folder("project/buildSrc/src/main/foo"),
+ folder("project/buildSrc/src/main/bar"),
+ folder("sourceDistribution/src-foo"),
+ folder("sourceDistribution/src-bar")))
+ }
}
=====================================
test-fixtures/src/main/kotlin/org/gradle/kotlin/dsl/fixtures/AbstractIntegrationTest.kt
=====================================
@@ -37,23 +37,23 @@ open class AbstractIntegrationTest {
get() = File(temporaryFolder.root, toSafeFileName(testName.methodName)).apply { mkdirs() }
protected
- fun withSettings(script: String, produceFile: (String) -> File = this::newFile): File =
+ fun withSettings(script: String, produceFile: (String) -> File = ::newFile): File =
withSettingsIn(".", script, produceFile)
protected
- fun withSettingsIn(baseDir: String, script: String, produceFile: (String) -> File = this::newFile): File =
+ fun withSettingsIn(baseDir: String, script: String, produceFile: (String) -> File = ::newFile): File =
withFile("$baseDir/settings.gradle.kts", script, produceFile)
protected
- fun withBuildScript(script: String, produceFile: (String) -> File = this::newFile): File =
+ fun withBuildScript(script: String, produceFile: (String) -> File = ::newFile): File =
withBuildScriptIn(".", script, produceFile)
protected
- fun withBuildScriptIn(baseDir: String, script: String, produceFile: (String) -> File = this::newFile): File =
+ fun withBuildScriptIn(baseDir: String, script: String, produceFile: (String) -> File = ::newFile): File =
withFile("$baseDir/build.gradle.kts", script, produceFile)
protected
- fun withFile(fileName: String, text: String = "", produceFile: (String) -> File = this::newFile) =
+ fun withFile(fileName: String, text: String = "", produceFile: (String) -> File = ::newFile) =
writeFile(produceFile(fileName), text)
protected
=====================================
tooling-builders/src/main/kotlin/org/gradle/kotlin/dsl/tooling/builders/KotlinBuildScriptModelBuilder.kt
=====================================
@@ -16,33 +16,36 @@
package org.gradle.kotlin.dsl.tooling.builders
+
import org.gradle.api.Project
import org.gradle.api.initialization.Settings
import org.gradle.api.initialization.dsl.ScriptHandler
import org.gradle.api.internal.GradleInternal
import org.gradle.api.internal.SettingsInternal
import org.gradle.api.internal.project.ProjectInternal
+
import org.gradle.internal.classloader.ClasspathUtil
import org.gradle.internal.classpath.ClassPath
import org.gradle.internal.classpath.DefaultClassPath
-import org.gradle.tooling.provider.model.ToolingModelBuilder
import org.gradle.kotlin.dsl.accessors.AccessorsClassPath
import org.gradle.kotlin.dsl.accessors.accessorsClassPathFor
import org.gradle.kotlin.dsl.provider.KotlinScriptClassPathProvider
import org.gradle.kotlin.dsl.provider.gradleKotlinDslOf
import org.gradle.kotlin.dsl.resolver.SourcePathProvider
+import org.gradle.kotlin.dsl.resolver.SourceDistributionResolver
import org.gradle.kotlin.dsl.resolver.kotlinBuildScriptModelTarget
import org.gradle.kotlin.dsl.support.ImplicitImports
import org.gradle.kotlin.dsl.support.serviceOf
-
import org.gradle.kotlin.dsl.tooling.models.KotlinBuildScriptModel
+import org.gradle.tooling.provider.model.ToolingModelBuilder
import java.io.File
import java.io.Serializable
import kotlin.coroutines.experimental.buildSequence
+
import kotlin.reflect.KClass
@@ -69,13 +72,14 @@ object KotlinBuildScriptModelBuilder : ToolingModelBuilder {
private
fun requestParameterOf(modelRequestProject: Project) =
- KotlinBuildScriptModelParameter(modelRequestProject.findProperty(kotlinBuildScriptModelTarget) as String?)
+ KotlinBuildScriptModelParameter(
+ modelRequestProject.findProperty(kotlinBuildScriptModelTarget) as? String)
private
fun scriptModelBuilderFor(modelRequestProject: Project, parameter: KotlinBuildScriptModelParameter) =
when {
parameter.noScript -> projectScriptModelBuilder(modelRequestProject)
- parameter.settingsScript -> settingsScriptModelBuilder(modelRequestProject.settings)
+ parameter.settingsScript -> settingsScriptModelBuilder(modelRequestProject)
else -> resolveScriptModelBuilderFor(parameter.scriptFile!!, modelRequestProject)
}
@@ -92,52 +96,41 @@ object KotlinBuildScriptModelBuilder : ToolingModelBuilder {
private
-fun settingsScriptModelBuilder(settings: Settings) =
+fun settingsScriptModelBuilder(project: Project) = project.run {
KotlinScriptTargetModelBuilder(
- settings,
type = Settings::class,
- rootDir = settings.rootDir,
- gradleHomeDir = settings.gradle.gradleHomeDir,
+ project = project,
scriptClassPath = settings.scriptCompilationClassPath,
- sourceLookupScriptHandlers = listOf(settings.buildscript),
- implicitImports = settings.scriptImplicitImports)
+ sourceLookupScriptHandlers = listOf(settings.buildscript))
+}
private
fun projectScriptModelBuilder(project: Project) =
KotlinScriptTargetModelBuilder(
- project,
type = Project::class,
- rootDir = project.rootProject.rootDir,
- gradleHomeDir = project.gradle.gradleHomeDir,
+ project = project,
scriptClassPath = project.scriptCompilationClassPath,
- accessorsClassPath = { classPath: ClassPath -> accessorsClassPathFor(project, classPath) },
- sourceLookupScriptHandlers = project.hierarchy.map { it.buildscript }.toList(),
- implicitImports = project.scriptImplicitImports)
+ accessorsClassPath = { classPath -> accessorsClassPathFor(project, classPath) },
+ sourceLookupScriptHandlers = project.hierarchy.map { it.buildscript }.toList())
private
fun defaultScriptModelBuilder(project: Project) =
KotlinScriptTargetModelBuilder(
- project,
type = Project::class,
- rootDir = project.rootDir,
- gradleHomeDir = project.gradle.gradleHomeDir,
+ project = project,
scriptClassPath = project.defaultScriptCompilationClassPath,
- sourceLookupScriptHandlers = listOf(project.buildscript),
- implicitImports = project.scriptImplicitImports)
+ sourceLookupScriptHandlers = listOf(project.buildscript))
private
-data class KotlinScriptTargetModelBuilder<out T : Any>(
- val `object`: T,
- private val type: KClass<T>,
- val rootDir: File,
- val gradleHomeDir: File?,
+data class KotlinScriptTargetModelBuilder<T : Any>(
+ val type: KClass<T>,
+ val project: Project,
val scriptClassPath: ClassPath,
val accessorsClassPath: (ClassPath) -> AccessorsClassPath = { AccessorsClassPath.empty },
- val sourceLookupScriptHandlers: List<ScriptHandler>,
- val implicitImports: List<String>) {
+ val sourceLookupScriptHandlers: List<ScriptHandler>) {
fun buildModel(): KotlinBuildScriptModel {
val accessorsClassPath = accessorsClassPath(scriptClassPath)
@@ -150,7 +143,17 @@ data class KotlinScriptTargetModelBuilder<out T : Any>(
private
fun gradleSource() =
- SourcePathProvider.sourcePathFor(scriptClassPath, rootDir, gradleHomeDir)
+ SourcePathProvider.sourcePathFor(
+ scriptClassPath, rootDir, gradleHomeDir, SourceDistributionResolver(project))
+
+ val gradleHomeDir
+ get() = project.gradle.gradleHomeDir
+
+ val rootDir
+ get() = project.rootDir
+
+ val implicitImports
+ get() = project.scriptImplicitImports
}
@@ -158,10 +161,12 @@ private
val KotlinBuildScriptModelParameter.noScript
get() = scriptPath == null
+
private
val KotlinBuildScriptModelParameter.settingsScript
get() = scriptFile?.name == "settings.gradle.kts"
+
private
val KotlinBuildScriptModelParameter.scriptFile
get() = scriptPath?.let { canonicalFile(it) }
@@ -171,27 +176,27 @@ private
val Settings.scriptCompilationClassPath
get() = serviceOf<KotlinScriptClassPathProvider>().compilationClassPathOf(classLoaderScope)
+
private
val Settings.classLoaderScope
get() = (this as SettingsInternal).classLoaderScope
-private
-val Settings.scriptImplicitImports
- get() = serviceOf<ImplicitImports>().list
-
private
val Project.settings
get() = (gradle as GradleInternal).settings
+
private
val Project.scriptCompilationClassPath
get() = serviceOf<KotlinScriptClassPathProvider>().compilationClassPathOf((this as ProjectInternal).classLoaderScope)
+
private
val Project.defaultScriptCompilationClassPath
get() = DefaultClassPath.of(project.buildSrcClassPath + gradleKotlinDslOf(rootProject))
+
private
val Project.buildSrcClassPath
get() = ClasspathUtil
@@ -199,10 +204,12 @@ val Project.buildSrcClassPath
.asFiles
.filter { it.name == "buildSrc.jar" }
+
private
val Project.scriptImplicitImports
get() = serviceOf<ImplicitImports>().list
+
private
val Project.hierarchy: Sequence<Project>
get() = buildSequence {
=====================================
tooling-builders/src/main/kotlin/org/gradle/kotlin/dsl/tooling/builders/KotlinLibSources.kt
=====================================
@@ -16,14 +16,14 @@
package org.gradle.kotlin.dsl.tooling.builders
-import org.gradle.api.artifacts.ModuleVersionIdentifier
import org.gradle.api.artifacts.component.ComponentIdentifier
import org.gradle.api.artifacts.component.ModuleComponentIdentifier
import org.gradle.api.artifacts.dsl.DependencyHandler
+import org.gradle.api.artifacts.query.ArtifactResolutionQuery
import org.gradle.api.artifacts.result.ResolvedArtifactResult
+
import org.gradle.api.initialization.dsl.ScriptHandler
import org.gradle.api.initialization.dsl.ScriptHandler.CLASSPATH_CONFIGURATION
-import org.gradle.api.internal.artifacts.DefaultModuleVersionIdentifier
import org.gradle.internal.classpath.ClassPath
import org.gradle.internal.classpath.DefaultClassPath
@@ -35,17 +35,19 @@ import org.gradle.kotlin.dsl.get
import org.gradle.language.base.artifact.SourcesArtifact
-import org.gradle.plugins.ide.internal.resolver.DefaultIdeDependencyResolver
-
internal
fun sourcePathFor(scriptHandlers: List<ScriptHandler>): ClassPath {
var sourcePath = ClassPath.EMPTY
- val resolvedDependencies = hashSetOf<ModuleVersionIdentifier>()
+
+ val resolvedDependencies = hashSetOf<ComponentIdentifier>()
for (buildscript in scriptHandlers.asReversed()) {
- val classpathDependencies = classpathDependenciesOf(buildscript).filter { it !in resolvedDependencies }
- if (resolvedDependencies.addAll(classpathDependencies)) {
- sourcePath += resolveSourcesUsing(buildscript.dependencies, classpathDependencies.map { it.toModuleId() })
+ val unresolvedDependencies = classpathDependenciesOf(buildscript).filter { it !in resolvedDependencies }
+ if (unresolvedDependencies.isNotEmpty()) {
+ sourcePath += resolveSourcesUsing(buildscript.dependencies) {
+ forComponents(unresolvedDependencies)
+ }
+ resolvedDependencies += unresolvedDependencies
}
}
@@ -58,39 +60,50 @@ fun sourcePathFor(scriptHandlers: List<ScriptHandler>): ClassPath {
private
-fun containsBuiltinKotlinModules(resolvedDependencies: HashSet<ModuleVersionIdentifier>) =
- resolvedDependencies.containsAll(
- builtinKotlinModules.map(::kotlinModuleVersionIdentifier))
-
-
-private
-fun classpathDependenciesOf(buildscript: ScriptHandler): List<ModuleVersionIdentifier> =
- DefaultIdeDependencyResolver()
- .getIdeRepoFileDependencies(buildscript.configurations[CLASSPATH_CONFIGURATION])
- .map { it.id }
+fun containsBuiltinKotlinModules(resolvedDependencies: Collection<ComponentIdentifier>): Boolean {
+ val resolvedModules = resolvedDependencies.filterIsInstance<ModuleComponentIdentifier>()
+ return builtinKotlinModules.all { kotlinModule ->
+ resolvedModules.any { resolved ->
+ resolved.module == kotlinModule && resolved.version == embeddedKotlinVersion
+ }
+ }
+}
private
-fun ModuleVersionIdentifier.toModuleId() = moduleId(group, name, version)
+fun classpathDependenciesOf(buildscript: ScriptHandler): List<ComponentIdentifier> =
+ buildscript
+ .configurations[CLASSPATH_CONFIGURATION]
+ .incoming
+ .artifactView { it.lenient(true) }
+ .artifacts
+ .map { it.id.componentIdentifier }
internal
fun kotlinLibSourcesFor(scriptHandlers: List<ScriptHandler>): ClassPath =
scriptHandlers
+ .asSequence()
.filter { it.repositories.isNotEmpty() }
.map { resolveKotlinLibSourcesUsing(it.dependencies) }
.find { !it.isEmpty } ?: ClassPath.EMPTY
+
private
fun resolveKotlinLibSourcesUsing(dependencyHandler: DependencyHandler): ClassPath =
- resolveSourcesUsing(dependencyHandler, kotlinComponentIdentifiers)
+ resolveSourcesUsing(dependencyHandler) {
+ builtinKotlinModules.forEach { kotlinModule ->
+ forModule("org.jetbrains.kotlin", kotlinModule, embeddedKotlinVersion)
+ }
+ }
+
private
-fun resolveSourcesUsing(dependencyHandler: DependencyHandler, components: List<ComponentIdentifier>): ClassPath =
+fun resolveSourcesUsing(dependencyHandler: DependencyHandler, query: ArtifactResolutionQuery.() -> Unit): ClassPath =
DefaultClassPath.of(
dependencyHandler
.createArtifactResolutionQuery()
- .forComponents(components)
+ .apply(query)
.withArtifacts(JvmLibrary::class.java, SourcesArtifact::class.java)
.execute()
.resolvedComponents
@@ -101,29 +114,3 @@ fun resolveSourcesUsing(dependencyHandler: DependencyHandler, components: List<C
private
val builtinKotlinModules = listOf("kotlin-stdlib-jre8", "kotlin-reflect")
-
-
-private
-val kotlinComponentIdentifiers by lazy {
- builtinKotlinModules.map(::kotlinComponent)
-}
-
-
-private
-fun kotlinComponent(module: String): ComponentIdentifier =
- moduleId("org.jetbrains.kotlin", module, embeddedKotlinVersion)
-
-
-private
-fun kotlinModuleVersionIdentifier(module: String): ModuleVersionIdentifier =
- DefaultModuleVersionIdentifier("org.jetbrains.kotlin", module, embeddedKotlinVersion)
-
-
-private
-fun moduleId(group: String, module: String, version: String) =
- object : ModuleComponentIdentifier {
- override fun getGroup() = group
- override fun getModule() = module
- override fun getVersion() = version
- override fun getDisplayName() = "$group:$module:$version"
- }
View it on GitLab: https://salsa.debian.org/java-team/gradle-kotlin-dsl/-/compare/379f364bbc2c0e819339ddec0ea5b3e67bc64b51...5da315246dda2b80ae85e4c3c3de187d6d00eb10
--
View it on GitLab: https://salsa.debian.org/java-team/gradle-kotlin-dsl/-/compare/379f364bbc2c0e819339ddec0ea5b3e67bc64b51...5da315246dda2b80ae85e4c3c3de187d6d00eb10
You're receiving this email because of your account on salsa.debian.org. Manage all notifications: https://salsa.debian.org/-/profile/notifications | Help: https://salsa.debian.org/help
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/pkg-java-commits/attachments/20260923/575ce283/attachment.htm>
More information about the pkg-java-commits
mailing list