KotlinScriptPluginFactory.kt

Clone Tools
  • last updated a few seconds ago
Constraints
Constraints: committers
 
Constraints: files
Constraints: dates
Convert to multi-project build in preparation to adding new modules

See #304

  1. … 263 more files in changeset.
@Inject KotlinScriptPluginFactory

Tighten exported API

This commit adds `internal` or `private` to internal members

The only exported API that includes Gradle internals is now in .provider

See #209

  1. … 23 more files in changeset.
Dedupe script classpath computation

  1. … 4 more files in changeset.
Polish

- Normalise placement of `private`, `protected`, `internal` and

`inline` modifiers

  1. … 42 more files in changeset.
Favor `<expr>.run { ... }` over `with (<expr>) { ... }`

  1. … 4 more files in changeset.
Polish top-level definitions, parameter lists and exceptions

* Separate top-level definitions by two lines

* Segregate visibility modifier of top-level definition to

its own line

* Prefer starting long parameter lists at the next line (more

sustainable in face of method renames)

* Remove unnecessary `Exception` suffix from class names

* Remove unnecessary prefixes from field names

* Use better name for exception variables

  1. … 38 more files in changeset.
Support the `plugins` block :tada:

We use a new type - `KotlinPluginDependenciesHandler` - as the target

for the top-level plugins block instead of the core type

`PluginDependenciesSpec` so we can annotate it with a `@DslMarker`

annotation - `@BuildScriptBlockMarker` - in the hopes that once IntelliJ

starts recognising it, the code completion experience will be better.

Better documentation comments and validation will come in subsequent

commits.

See #186

  1. … 10 more files in changeset.
Cache compiled scripts

- Introduce CachingKotlinCompiler

- Add compilation ClassPath (as ClassLoader) to cache key

- Add version number to script cache

- Honor `--recompile-scripts`

- Report compilation progress

Resolves #31

  1. … 5 more files in changeset.
Generate Action<T> extensions at runtime

This ensures the generated extensions match the Gradle API being used by

the build script.

See: #117

  1. … 10 more files in changeset.
Compile scripts against generated Kotlin API jar

We would like Kotlin build scripts to behave as if all the `Action<T>`

parameters in the Gradle API had been declared as `T.() -> Unit` to

avoid the need for explicitly qualifying the single argument to the

given lambda expressions with `it`.

In other words, we would like users to be writing code like:

copySpec {

from("src")

into("out")

}

Instead of:

copySpec {

it.from("src")

it.into("out")

}

Where `copySpec` is declared in the Gradle Java API as:

CopySpec copySpec(Action<? super CopySpec> configuration)

So far we have been able to avoid the qualifying `it` in some situations

via mindful use of inheritance and Kotlin extensions but a comprehensive

solution was still lacking. The underlying issue is that while Kotlin

does provide a type extension mechanism, type members still take

precedence over extensions and currently there's no mechanism to

instruct Kotlin otherwise.

In the future we might be able to implement a different solution to this

particular issue via a new Kotlin language feature still in discussion:

- https://youtrack.jetbrains.com/issue/KT-12848

In the meantime, by giving the Kotlin compiler a carefully crafted API

jar with all members that could potentially conflict with our provided

extensions removed we can work around the fact that interface members

take precedence over extension members and expose all the extensions we

want.

And that is the solution implemented in this commit:

- Remove all API methods that take a last `Action<T>` parameter

- Generate shim extensions that take a last `T.() -> Unit`

Proper treatment for generic types will be implemented in a future

commit.

Resolves: #52

See also: #54, #117

  1. … 27 more files in changeset.
Polish `KotlinScriptPluginFactory`

Extract explaining methods

Compile against generated Gradle API jar

  1. … 2 more files in changeset.
Only apply `classpath` mode to top level scripts

Otherwise Groovy scripts that rely on the execution of Kotlin scripts

will be broken (such as our own build).

See #97

  1. … 1 more file in changeset.
Ignore compilation errors when serving classpath

Resolves #97

  1. … 3 more files in changeset.
Upgrade to Kotlin 1.1-M01 :tada:

Resolves #98

Resolves #93

Resolves #92

  1. … 8 more files in changeset.
Use isolated ClassLoader for Kotlin jars

Due to the lack of isolation between gradle-script-kotlin and the

compiled buildscript(s), referenced Kotlin types could leak into

different ClassLoader scopes causing all sorts of loader constraint

violations. That lack of isolation also meant that only the specific

version of Kotlin shipped with gsk could ever be used.

This commit mitigates these limitations by subverting the ClassLoader

delegation model when Kotlin jars are detected in the buildscript

classpath. In that case, all jars in the script classpath together with

the Kotlin jars are segregated into a ClassLoader that will first try to

load classes locally before delegating to its parent from the

ClassLoader scope hierarchy.

This solution is only a stepping stone and comes with its own set of

limitations, buildscript block and script body cannot exchange Kotlin

library values for one. A better solution will demand more isolation

between gradle-script-kotlin and core.

Resolves #84

Resolves #86

Resolves #25

    • -135
    • +10
    ./KotlinScriptPluginFactory.kt
  1. … 12 more files in changeset.
Include buildSrc outputs in script model classpath

See #92

  1. … 3 more files in changeset.
Polish `KotlinScriptPluginFactory`

Add `buildSrc` output to the compilation classpath

See #38

  1. … 1 more file in changeset.
Add implicit imports to `buildscript` blocks

By reusing `GradleKotlinScriptDependenciesResolver` for `buildscript`

block compilation.

Resolves #90

  1. … 2 more files in changeset.
Polish Kotlin sources

- Add Apache license header where missing

- Replace wildcard imports with individual imports

- Organize import statements

- Wrap code at 120 chars

- Wrap KDoc at 90 chars

- Eliminate newlines between KDoc tags

  1. … 20 more files in changeset.
Merge branch 'master' into refactor-buildscript-handling

# Conflicts:

# src/main/kotlin/org/gradle/script/lang/kotlin/KotlinBuildScript.kt

# src/main/kotlin/org/gradle/script/lang/kotlin/provider/KotlinScriptPluginFactory.kt

  1. … 4 more files in changeset.
Support plugin application

- export script classpath directly to target ClassLoaderScope

- set context ClassLoader around script execution to mimic Groovy behaviour

- support configuring buildscript repositories

  1. … 2 more files in changeset.
Fix buildscript classpath computation after Kotlin update

  1. … 2 more files in changeset.
Merge branch 'master' into refactor-buildscript-handling

  1. … 1 more file in changeset.
Load script class in a child ClassLoader of the buildscript ClassLoader

See #63

  1. … 1 more file in changeset.
Support for `buildscript` section (wip)

  1. … 10 more files in changeset.
Implement prototype of script def based on annotated base class

  1. … 5 more files in changeset.
Attempt to reproduce 'loader constraint violation'

This is a work in progress attempt at reproducing the 'loader constraint

violation' observed when defining the following task:

task<Zip>("repackageKotlinCompilerEmbeddable") {

baseName = "kotlin-compiler-embeddable"

version = "${kotlinVersion}a"

extension = "jar"

entryCompression = ZipEntryCompression.STORED

from(Callable {

val files = configurations.getByName("compile").files

zipTree(files.single { it.name.startsWith(baseName) })

})

exclude("META-INF/services/java.nio.charset.spi.CharsetProvider")

destinationDir = buildDir

description = "Repackages '$baseName:$version' to remove broken META-INF/services files"

}

Which caused the following error:

loader constraint violation: when resolving method

"org.gradle.script.lang.kotlin.ProjectExtensionsKt.task(

Lorg/gradle/api/Project;Ljava/lang/String;Lkotlin/reflect/KClass;

Lkotlin/jvm/functions/Function1;)Lorg/gradle/api/Task;"

the class loader (instance of

org/jetbrains/kotlin/codegen/GeneratedClassLoader) of the current

class, Build_gradle, and the class loader (instance of

org/gradle/internal/classloader/MutableURLClassLoader) for the method's

defining class, org/gradle/script/lang/kotlin/ProjectExtensionsKt, have

different Class objects for the type kotlin/reflect/KClass used in the

signature

See #25

  1. … 3 more files in changeset.