-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add the possibility to omit explicitly specifying a version in annota…
…tionProcessorPaths Resolve the version of the annotation processor path (specified in annotationProcessorPaths) in kapt plugin if it is already specified in dependencies of this module or parent module. Plugin management is also supported. #KT-59521 In Fixed Merge-request: KT-MR-10761 Merged-by: Aleksei Cherepanov <aleksei.cherepanov@jetbrains.com>
- Loading branch information
1 parent
e4d1e62
commit a3583ea
Showing
7 changed files
with
223 additions
and
1 deletion.
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
...kapt-annotationProcessorPaths-without-version/annotation-processor-second-version/pom.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>org.jetbrains.kotlin.testkapt</groupId> | ||
<artifactId>annotation-processor-second-version</artifactId> | ||
<version>2.0-SNAPSHOT</version> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.jetbrains.kotlin</groupId> | ||
<artifactId>kotlin-stdlib</artifactId> | ||
<version>${kotlin.version}</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<pluginManagement> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>2.3.2</version> | ||
<configuration> | ||
<source>1.6</source> | ||
<target>1.6</target> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-source-plugin</artifactId> | ||
<version>2.1.2</version> | ||
</plugin> | ||
</plugins> | ||
</pluginManagement> | ||
|
||
<sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory> | ||
<plugins> | ||
<plugin> | ||
<artifactId>kotlin-maven-plugin</artifactId> | ||
<groupId>org.jetbrains.kotlin</groupId> | ||
<version>${kotlin.version}</version> | ||
<executions> | ||
<execution> | ||
<id>compile</id> | ||
<phase>process-sources</phase> | ||
<goals> | ||
<goal>compile</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
46 changes: 46 additions & 0 deletions
46
...version/annotation-processor-second-version/src/main/kotlin/ExampleAnnotationProcessor.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors. | ||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. | ||
*/ | ||
|
||
package example | ||
|
||
import java.io.File | ||
import javax.annotation.processing.AbstractProcessor | ||
import javax.annotation.processing.RoundEnvironment | ||
import javax.lang.model.SourceVersion | ||
import javax.lang.model.element.ElementKind | ||
import javax.lang.model.element.TypeElement | ||
import javax.tools.Diagnostic | ||
import kotlin.reflect.KClass | ||
|
||
annotation class Anno | ||
|
||
class ExampleAnnotationProcessor : AbstractProcessor() { | ||
private companion object { | ||
val KAPT_KOTLIN_GENERATED_OPTION = "kapt.kotlin.generated" | ||
} | ||
|
||
override fun process(annotations: MutableSet<out TypeElement>?, roundEnv: RoundEnvironment): Boolean { | ||
val elements = roundEnv.getElementsAnnotatedWith(Anno::class.java) | ||
val kotlinGenerated = processingEnv.options[KAPT_KOTLIN_GENERATED_OPTION] | ||
|
||
for (element in elements) { | ||
val packageName = processingEnv.elementUtils.getPackageOf(element).qualifiedName.toString() | ||
val simpleName = element.simpleName.toString() | ||
|
||
if (kotlinGenerated != null && element.kind == ElementKind.CLASS) { | ||
File(kotlinGenerated, "$simpleName.kt").writer().buffered().use { | ||
it.appendLine("package $packageName") | ||
it.appendLine("fun $simpleName.customToString() = \"$simpleName: \" + toString()") | ||
} | ||
} | ||
} | ||
|
||
return true | ||
} | ||
|
||
override fun getSupportedSourceVersion() = SourceVersion.RELEASE_6 | ||
override fun getSupportedAnnotationTypes() = setOf(Anno::class.java.name) | ||
override fun getSupportedOptions() = emptySet<String>() | ||
} |
72 changes: 72 additions & 0 deletions
72
...ugin-test/src/it/test-kapt-annotationProcessorPaths-without-version/app-with-kapt/pom.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" | ||
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> | ||
|
||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>org.jetbrains.kotlin.testkapt</groupId> | ||
<artifactId>app-with-kapt</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
|
||
<properties> | ||
<junit.version>4.13.1</junit.version> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.jetbrains.kotlin.testkapt</groupId> | ||
<artifactId>annotation-processor-second-version</artifactId> | ||
<version>2.0-SNAPSHOT</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.jetbrains.kotlin</groupId> | ||
<artifactId>kotlin-stdlib</artifactId> | ||
<version>${kotlin.version}</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<artifactId>kotlin-maven-plugin</artifactId> | ||
<groupId>org.jetbrains.kotlin</groupId> | ||
<version>${kotlin.version}</version> | ||
<executions> | ||
<execution> | ||
<id>kapt</id> | ||
<goals> | ||
<goal>kapt</goal> | ||
</goals> | ||
<configuration> | ||
<sourceDirs> | ||
<sourceDir>src/main/kotlin</sourceDir> | ||
</sourceDirs> | ||
<annotationProcessors> | ||
<annotationProcessor>example.ExampleAnnotationProcessor</annotationProcessor> | ||
</annotationProcessors> | ||
<annotationProcessorPaths> | ||
<annotationProcessorPath> | ||
<groupId>org.jetbrains.kotlin.testkapt</groupId> | ||
<artifactId>annotation-processor-second-version</artifactId> | ||
</annotationProcessorPath> | ||
</annotationProcessorPaths> | ||
</configuration> | ||
</execution> | ||
<execution> | ||
<id>compile</id> | ||
<goals> | ||
<goal>compile</goal> | ||
</goals> | ||
<configuration> | ||
<sourceDirs> | ||
<sourceDir>src/main/kotlin</sourceDir> | ||
</sourceDirs> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
8 changes: 8 additions & 0 deletions
8
.../test-kapt-annotationProcessorPaths-without-version/app-with-kapt/src/main/kotlin/test.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package test | ||
|
||
@example.Anno | ||
class MyClass { | ||
fun test() { | ||
println(this.customToString()) | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
...otlin-maven-plugin-test/src/it/test-kapt-annotationProcessorPaths-without-version/pom.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>org.jetbrains.kotlin.testkapt</groupId> | ||
<artifactId>test-kapt-annotationProcessorPaths-without-version</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
<modules> | ||
<module>annotation-processor-second-version</module> | ||
<module>app-with-kapt</module> | ||
</modules> | ||
<packaging>pom</packaging> | ||
|
||
</project> |
6 changes: 6 additions & 0 deletions
6
...in-maven-plugin-test/src/it/test-kapt-annotationProcessorPaths-without-version/verify.bsh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import java.io.*; | ||
|
||
File file = new File(basedir, "app-with-kapt/target/app-with-kapt-1.0-SNAPSHOT.jar"); | ||
if (!file.exists() || !file.isFile()) { | ||
throw new FileNotFoundException("Could not find generated JAR: " + file); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters